From b86ac4f2a356d8d51331f1b1afef5b3ca82f4cdd Mon Sep 17 00:00:00 2001 From: Halil Ozan Akgul Date: Wed, 18 Aug 2021 15:51:22 +0300 Subject: [PATCH] Introduces ExecSimpleRelationInsert_compat and modifyStateResultRelInfo macros es_result_relation_info is removed from Estate. In this commit we make some changes to handle that. resultRelationInfo filed is added to ModifyState to support the removed field. Relevant PG commits: 1375422c7826a2bf387be29895e961614f69de4b a04daa97a4339c38e304cd6164d37da540d665a8 --- src/backend/columnar/columnar_metadata.c | 33 ++++++++++++------- .../columnar/columnar_version_compat.h | 6 ++++ 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/backend/columnar/columnar_metadata.c b/src/backend/columnar/columnar_metadata.c index 1150dc1ac..2dce3b8d2 100644 --- a/src/backend/columnar/columnar_metadata.c +++ b/src/backend/columnar/columnar_metadata.c @@ -64,6 +64,9 @@ typedef struct { Relation rel; EState *estate; +#if PG_VERSION_NUM >= PG_VERSION_14 + ResultRelInfo *resultRelInfo; +#endif } ModifyState; /* RowNumberLookupMode to be used in StripeMetadataLookupRowNumber */ @@ -1144,12 +1147,22 @@ 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; +#if PG_VERSION_NUM >= PG_VERSION_14 + modifyState->resultRelInfo = resultRelInfo; +#endif return modifyState; } @@ -1171,7 +1184,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); } @@ -1183,7 +1196,7 @@ static void DeleteTupleAndEnforceConstraints(ModifyState *state, HeapTuple heapTuple) { EState *estate = state->estate; - ResultRelInfo *resultRelInfo = estate->es_result_relation_info; + ResultRelInfo *resultRelInfo = modifyStateResultRelInfo(state); ItemPointer tid = &(heapTuple->t_self); simple_heap_delete(state->rel, tid); @@ -1199,10 +1212,15 @@ DeleteTupleAndEnforceConstraints(ModifyState *state, HeapTuple heapTuple) static void FinishModifyRelation(ModifyState *state) { - ExecCloseIndices(state->estate->es_result_relation_info); + ExecCloseIndices(modifyStateResultRelInfo(state)); 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); } @@ -1229,13 +1247,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..eb343e035 100644 --- a/src/include/columnar/columnar_version_compat.h +++ b/src/include/columnar/columnar_version_compat.h @@ -19,12 +19,18 @@ 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) +#define modifyStateResultRelInfo(a) ((a)->resultRelInfo) #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) +#define modifyStateResultRelInfo(a) ((a)->estate->es_result_relation_info) #endif #define ACLCHECK_OBJECT_TABLE OBJECT_TABLE