From e619d753f82e3432c47e39409cd2a930d597db38 Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Fri, 22 May 2026 10:37:07 +0500 Subject: [PATCH 1/2] Resolve conflicts in src/backend/executor/execMain.c 1) Commit 1375422 in src/backend/executor/execMain.c removed the conditional initialization of ResultRelInfo in the InitPlan function, while the earlier commit 6b0e52b had already added a comment before this same location. 2) Commit 1375422 in src/backend/executor/execMain.c separated part of the ExecEndPlan function into a new function, ExecCloseResultRelations, while the earlier commit 6b0e52b had already reversed the loop for calling ExecCloseIndices in this same location. --- src/backend/executor/execMain.c | 97 --------------------------------- 1 file changed, 97 deletions(-) diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c index 284db49baf08..a59046a5d398 100644 --- a/src/backend/executor/execMain.c +++ b/src/backend/executor/execMain.c @@ -1710,94 +1710,6 @@ InitPlan(QueryDesc *queryDesc, int eflags) estate->es_plannedstmt = plannedstmt; /* -<<<<<<< HEAD - * Initialize ResultRelInfo data structures, and open the result rels. - * - * CDB: Note that we need this info even if we aren't the slice that will be doing - * the actual updating, since it's where we learn things, such as if the row needs to - * contain OIDs or not. - */ - if (plannedstmt->resultRelations) - { - List *resultRelations = plannedstmt->resultRelations; - int numResultRelations = list_length(resultRelations); - ResultRelInfo *resultRelInfos; - ResultRelInfo *resultRelInfo; - - resultRelInfos = (ResultRelInfo *) - palloc(numResultRelations * sizeof(ResultRelInfo)); - resultRelInfo = resultRelInfos; - foreach(l, plannedstmt->resultRelations) - { - Index resultRelationIndex = lfirst_int(l); - Relation resultRelation; - - resultRelation = ExecGetRangeTableRelation(estate, - resultRelationIndex); - InitResultRelInfo(resultRelInfo, - resultRelation, - resultRelationIndex, - NULL, - estate->es_instrument); - resultRelInfo++; - } - estate->es_result_relations = resultRelInfos; - estate->es_num_result_relations = numResultRelations; - - /* es_result_relation_info is NULL except when within ModifyTable */ - estate->es_result_relation_info = NULL; - - /* - * In the partitioned result relation case, also build ResultRelInfos - * for all the partitioned table roots, because we will need them to - * fire statement-level triggers, if any. - */ - if (plannedstmt->rootResultRelations) - { - int num_roots = list_length(plannedstmt->rootResultRelations); - - resultRelInfos = (ResultRelInfo *) - palloc(num_roots * sizeof(ResultRelInfo)); - resultRelInfo = resultRelInfos; - foreach(l, plannedstmt->rootResultRelations) - { - Index resultRelIndex = lfirst_int(l); - Relation resultRelDesc; - - resultRelDesc = ExecGetRangeTableRelation(estate, - resultRelIndex); - InitResultRelInfo(resultRelInfo, - resultRelDesc, - resultRelIndex, - NULL, - estate->es_instrument); - resultRelInfo++; - } - - estate->es_root_result_relations = resultRelInfos; - estate->es_num_root_result_relations = num_roots; - } - else - { - estate->es_root_result_relations = NULL; - estate->es_num_root_result_relations = 0; - } - } - else - { - /* - * if no result relation, then set state appropriately - */ - estate->es_result_relations = NULL; - estate->es_num_result_relations = 0; - estate->es_result_relation_info = NULL; - estate->es_root_result_relations = NULL; - estate->es_num_root_result_relations = 0; - } - - /* -======= ->>>>>>> f81e97d0475cd4bc597adc23b665bd84fbf79a0d * Next, build the ExecRowMark array from the PlanRowMark(s), if any. */ if (plannedstmt->rowMarks) @@ -2543,14 +2455,6 @@ ExecEndPlan(PlanState *planstate, EState *estate) * Close any Relations that have been opened for range table entries or * result relations. */ -<<<<<<< HEAD - resultRelInfo = estate->es_result_relations; - for (i = 0; i < estate->es_num_result_relations; i++) - { - ExecCloseIndices(resultRelInfo); - resultRelInfo++; - } -======= ExecCloseResultRelations(estate); ExecCloseRangeTableRelations(estate); } @@ -2562,7 +2466,6 @@ void ExecCloseResultRelations(EState *estate) { ListCell *l; ->>>>>>> f81e97d0475cd4bc597adc23b665bd84fbf79a0d /* * close indexes of result relation(s) if any. (Rels themselves are From 01712cdc3a9e13d1736829fa1dac2df0d7069eff Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Thu, 28 May 2026 10:20:15 +0500 Subject: [PATCH 2/2] fix 3) Commit a04daa9 removed the es_result_relation_info field from the EState structure in src/include/nodes/execnodes.h. Remove it in GPDB-specific locations. 4) Commit 1375422 removed the es_num_result_relations field from the EState structure in src/include/nodes/execnodes.h, replacing it with the new es_opened_result_relations field. Replace it in GPDB-specific locations. --- src/backend/access/aocs/aocs_compaction.c | 2 -- src/backend/access/appendonly/appendonly_compaction.c | 2 -- src/backend/commands/copy.c | 6 ------ src/backend/executor/execMain.c | 5 +++-- 4 files changed, 3 insertions(+), 12 deletions(-) diff --git a/src/backend/access/aocs/aocs_compaction.c b/src/backend/access/aocs/aocs_compaction.c index 2cb52b79eb4d..af5231107ae8 100644 --- a/src/backend/access/aocs/aocs_compaction.c +++ b/src/backend/access/aocs/aocs_compaction.c @@ -264,8 +264,6 @@ AOCSSegmentFileFullCompaction(Relation aorel, resultRelInfo->ri_TrigDesc = NULL; /* we don't fire triggers */ ExecOpenIndices(resultRelInfo, false); estate->es_result_relations = resultRelInfo; - estate->es_num_result_relations = 1; - estate->es_result_relation_info = resultRelInfo; /* * We don't want uniqueness checks to be performed while "insert"ing tuples diff --git a/src/backend/access/appendonly/appendonly_compaction.c b/src/backend/access/appendonly/appendonly_compaction.c index a9ca318d06d1..189bc126269c 100644 --- a/src/backend/access/appendonly/appendonly_compaction.c +++ b/src/backend/access/appendonly/appendonly_compaction.c @@ -445,8 +445,6 @@ AppendOnlySegmentFileFullCompaction(Relation aorel, resultRelInfo->ri_TrigDesc = NULL; /* we don't fire triggers */ ExecOpenIndices(resultRelInfo, false); estate->es_result_relations = resultRelInfo; - estate->es_num_result_relations = 1; - estate->es_result_relation_info = resultRelInfo; /* * We don't want uniqueness checks to be performed while "insert"ing tuples diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index 5f671b9115bf..f556b77ca8a0 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -4232,12 +4232,6 @@ CopyFrom(CopyState cstate) { if (!NextCopyFromExecute(cstate, econtext, myslot->tts_values, myslot->tts_isnull)) break; - - /* - * NextCopyFromExecute set up estate->es_result_relation_info, - * and stored the tuple in the correct slot. - */ - resultRelInfo = estate->es_result_relation_info; } else { diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c index a59046a5d398..e91a1410ee5d 100644 --- a/src/backend/executor/execMain.c +++ b/src/backend/executor/execMain.c @@ -4019,14 +4019,15 @@ AdjustReplicatedTableCounts(EState *estate) ResultRelInfo *resultRelInfo; bool containReplicatedTable = false; int numsegments = 1; + ListCell *l; if (Gp_role != GP_ROLE_DISPATCH) return; /* check if result_relations contain replicated table*/ - for (i = 0; i < estate->es_num_result_relations; i++) + foreach(l, estate->es_opened_result_relations) { - resultRelInfo = estate->es_result_relations + i; + resultRelInfo = lfirst(l); if (!resultRelInfo->ri_RelationDesc->rd_cdbpolicy) continue;