diff --git a/src/backend/columnar/columnar_metadata.c b/src/backend/columnar/columnar_metadata.c index 936fe39a5..3f622a44d 100644 --- a/src/backend/columnar/columnar_metadata.c +++ b/src/backend/columnar/columnar_metadata.c @@ -64,6 +64,7 @@ typedef struct { Relation rel; EState *estate; + ResultRelInfo *resultRelInfo; } ModifyState; /* RowNumberLookupMode to be used in StripeMetadataLookupRowNumber */ @@ -1314,12 +1315,20 @@ StartModifyRelation(Relation rel) { EState *estate = create_estate_for_relation(rel); +#if PG_VERSION_NUM >= PG_VERSION_14 + ResultRelInfo *resultRelInfo = makeNode(ResultRelInfo); + InitResultRelInfo(resultRelInfo, rel, 1, NULL, 0); +#else + ResultRelInfo *resultRelInfo = estate->es_result_relation_info; +#endif + /* ExecSimpleRelationInsert, ... require caller to open indexes */ - ExecOpenIndices(estate->es_result_relation_info, false); + ExecOpenIndices(resultRelInfo, false); ModifyState *modifyState = palloc(sizeof(ModifyState)); modifyState->rel = rel; modifyState->estate = estate; + modifyState->resultRelInfo = resultRelInfo; return modifyState; } @@ -1341,7 +1350,7 @@ InsertTupleAndEnforceConstraints(ModifyState *state, Datum *values, bool *nulls) ExecStoreHeapTuple(tuple, slot, false); /* use ExecSimpleRelationInsert to enforce constraints */ - ExecSimpleRelationInsert(state->estate, slot); + ExecSimpleRelationInsert_compat(state->resultRelInfo, state->estate, slot); } @@ -1353,7 +1362,7 @@ static void DeleteTupleAndEnforceConstraints(ModifyState *state, HeapTuple heapTuple) { EState *estate = state->estate; - ResultRelInfo *resultRelInfo = estate->es_result_relation_info; + ResultRelInfo *resultRelInfo = state->resultRelInfo; ItemPointer tid = &(heapTuple->t_self); simple_heap_delete(state->rel, tid); @@ -1369,10 +1378,15 @@ DeleteTupleAndEnforceConstraints(ModifyState *state, HeapTuple heapTuple) static void FinishModifyRelation(ModifyState *state) { - ExecCloseIndices(state->estate->es_result_relation_info); + ExecCloseIndices(state->resultRelInfo); AfterTriggerEndQuery(state->estate); +#if PG_VERSION_NUM >= PG_VERSION_14 + ExecCloseResultRelations(state->estate); + ExecCloseRangeTableRelations(state->estate); +#else ExecCleanUpTriggerState(state->estate); +#endif ExecResetTupleTable(state->estate->es_tupleTable, false); FreeExecutorState(state->estate); @@ -1401,13 +1415,6 @@ create_estate_for_relation(Relation rel) rte->rellockmode = AccessShareLock; ExecInitRangeTable(estate, list_make1(rte)); - ResultRelInfo *resultRelInfo = makeNode(ResultRelInfo); - InitResultRelInfo(resultRelInfo, rel, 1, NULL, 0); - - estate->es_result_relations = resultRelInfo; - estate->es_num_result_relations = 1; - estate->es_result_relation_info = resultRelInfo; - estate->es_output_cid = GetCurrentCommandId(true); /* Prepare to catch AFTER triggers. */ diff --git a/src/include/columnar/columnar_version_compat.h b/src/include/columnar/columnar_version_compat.h index 8e301f3ac..e418561d0 100644 --- a/src/include/columnar/columnar_version_compat.h +++ b/src/include/columnar/columnar_version_compat.h @@ -19,12 +19,16 @@ PrevProcessUtilityHook(a, b, c, d, e, f, g, h) #define GetOldestNonRemovableTransactionId_compat(a, b) \ GetOldestNonRemovableTransactionId(a) +#define ExecSimpleRelationInsert_compat(a, b, c) \ + ExecSimpleRelationInsert(a, b, c) #else #define ColumnarProcessUtility_compat(a, b, c, d, e, f, g, h) \ ColumnarProcessUtility(a, b, d, e, f, g, h) #define PrevProcessUtilityHook_compat(a, b, c, d, e, f, g, h) \ PrevProcessUtilityHook(a, b, d, e, f, g, h) #define GetOldestNonRemovableTransactionId_compat(a, b) GetOldestXmin(a, b) +#define ExecSimpleRelationInsert_compat(a, b, c) \ + ExecSimpleRelationInsert(b, c) #endif #define ACLCHECK_OBJECT_TABLE OBJECT_TABLE