From 12eece5fd54c2aa3dbdefb6de7f18566f5c00357 Mon Sep 17 00:00:00 2001 From: Amit Kapila Date: Tue, 8 Apr 2025 15:35:42 +0530 Subject: Fix uninitialized index information access during apply. The issue happens when building conflict information during apply of INSERT or UPDATE operations that violate unique constraints on leaf partitions. The problem was introduced in commit 9ff68679b5, which removed the redundant calls to ExecOpenIndices/ExecCloseIndices. The previous code was relying on the redundant ExecOpenIndices call in apply_handle_tuple_routing() to build the index information required for unique key conflict detection. The fix is to delay building the index information until a conflict is detected instead of relying on ExecOpenIndices to do the same. The additional benefit of this approach is that it avoids building index information when there is no conflict. Author: Hou Zhijie Reviewed-by:Reviewed-by: Amit Kapila Discussion: https://postgr.es/m/TYAPR01MB57244ADA33DDA57119B9D26494A62@TYAPR01MB5724.jpnprd01.prod.outlook.com --- src/backend/executor/execIndexing.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/backend/executor/execIndexing.c') diff --git a/src/backend/executor/execIndexing.c b/src/backend/executor/execIndexing.c index e3fe9b78bb5..bdf862b2406 100644 --- a/src/backend/executor/execIndexing.c +++ b/src/backend/executor/execIndexing.c @@ -214,9 +214,8 @@ ExecOpenIndices(ResultRelInfo *resultRelInfo, bool speculative) ii = BuildIndexInfo(indexDesc); /* - * If the indexes are to be used for speculative insertion or conflict - * detection in logical replication, add extra information required by - * unique index entries. + * If the indexes are to be used for speculative insertion, add extra + * information required by unique index entries. */ if (speculative && ii->ii_Unique && !indexDesc->rd_index->indisexclusion) BuildSpeculativeIndexInfo(indexDesc, ii); -- cgit v1.2.3