Skip to content

Commit 1e13f60

Browse files
committed
Move the global ext_dml_init_hook/ext_dml_fini_hook to AM scoped
The hooks ext_dml_init_hook and ext_dml_fini_hook are used to initialize and cleanup resources for table DML operation. It's table AM specific. The current behavior uses global function pointers. The side effect is that the hooks must check whether the relation is expected and call the hook chain for other table AM implementations. This commit moves the hooks to the table AM structure, so the above assumption could be discarded.
1 parent e7e07c2 commit 1e13f60

File tree

14 files changed

+44
-105
lines changed

14 files changed

+44
-105
lines changed

contrib/pax_storage/src/cpp/access/pax_access_handle.cc

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,6 @@ void CCPaxAccessMethod::FinishBulkInsert(Relation relation, int options) {
412412
}
413413

414414
void CCPaxAccessMethod::ExtDmlInit(Relation rel, CmdType operation) {
415-
if (!RELATION_IS_PAX(rel)) return;
416-
417415
CBDB_TRY();
418416
{ pax::CPaxDmlStateLocal::Instance()->InitDmlState(rel, operation); }
419417
CBDB_CATCH_DEFAULT();
@@ -422,8 +420,6 @@ void CCPaxAccessMethod::ExtDmlInit(Relation rel, CmdType operation) {
422420
}
423421

424422
void CCPaxAccessMethod::ExtDmlFini(Relation rel, CmdType operation) {
425-
if (!RELATION_IS_PAX(rel)) return;
426-
427423
CBDB_TRY();
428424
{ pax::CPaxDmlStateLocal::Instance()->FinishDmlState(rel, operation); }
429425
CBDB_CATCH_DEFAULT();
@@ -791,6 +787,8 @@ static const TableAmRoutine kPaxColumnMethods = {
791787
.scan_sample_next_block = pax::CCPaxAccessMethod::ScanSampleNextBlock,
792788
.scan_sample_next_tuple = pax::CCPaxAccessMethod::ScanSampleNextTuple,
793789

790+
.dml_init = pax::CCPaxAccessMethod::ExtDmlInit,
791+
.dml_fini = pax::CCPaxAccessMethod::ExtDmlFini,
794792
.amoptions = paxc::PaxAccessMethod::AmOptions,
795793
.swap_relation_files = paxc::PaxAccessMethod::SwapRelationFiles,
796794
.validate_column_encoding_clauses =
@@ -1191,9 +1189,6 @@ void _PG_init(void) { // NOLINT
11911189
prev_object_access_hook = object_access_hook;
11921190
object_access_hook = PaxObjectAccessHook;
11931191

1194-
ext_dml_init_hook = pax::CCPaxAccessMethod::ExtDmlInit;
1195-
ext_dml_finish_hook = pax::CCPaxAccessMethod::ExtDmlFini;
1196-
11971192
prev_ProcessUtilit_hook = ProcessUtility_hook;
11981193
ProcessUtility_hook = paxProcessUtility;
11991194

contrib/pax_storage/src/cpp/access/pax_access_handle.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,3 @@ class CCPaxAccessMethod final {
197197
};
198198

199199
} // namespace pax
200-
201-
extern ext_dml_func_hook_type ext_dml_init_hook;
202-
extern ext_dml_func_hook_type ext_dml_finish_hook;

src/backend/access/aocs/aocsam_handler.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ remove_dml_state(const Oid relationOid)
270270
*
271271
* This function should be called exactly once per relation.
272272
*/
273-
void
273+
static void
274274
aoco_dml_init(Relation relation, CmdType operation)
275275
{
276276
init_aoco_dml_states();
@@ -280,7 +280,7 @@ aoco_dml_init(Relation relation, CmdType operation)
280280
/*
281281
* This function should be called exactly once per relation.
282282
*/
283-
void
283+
static void
284284
aoco_dml_finish(Relation relation, CmdType operation)
285285
{
286286
AOCODMLState *state;
@@ -2658,6 +2658,8 @@ static TableAmRoutine ao_column_methods = {
26582658
.scan_sample_next_block = aoco_scan_sample_next_block,
26592659
.scan_sample_next_tuple = aoco_scan_sample_next_tuple,
26602660

2661+
.dml_init = aoco_dml_init,
2662+
.dml_fini = aoco_dml_finish,
26612663
.amoptions = ao_amoptions,
26622664
.swap_relation_files = aoco_swap_relation_files,
26632665
.validate_column_encoding_clauses = aoco_validate_column_encoding_clauses,

src/backend/access/appendonly/appendonlyam_handler.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ remove_dml_state(const Oid relationOid)
228228
*
229229
* This function should be called exactly once per relation.
230230
*/
231-
void
231+
static void
232232
appendonly_dml_init(Relation relation, CmdType operation)
233233
{
234234
init_appendonly_dml_states();
@@ -238,7 +238,7 @@ appendonly_dml_init(Relation relation, CmdType operation)
238238
/*
239239
* This function should be called exactly once per relation.
240240
*/
241-
void
241+
static void
242242
appendonly_dml_finish(Relation relation, CmdType operation)
243243
{
244244
AppendOnlyDMLState *state;
@@ -2360,6 +2360,8 @@ static const TableAmRoutine ao_row_methods = {
23602360
.scan_sample_next_block = appendonly_scan_sample_next_block,
23612361
.scan_sample_next_tuple = appendonly_scan_sample_next_tuple,
23622362

2363+
.dml_init = appendonly_dml_init,
2364+
.dml_fini = appendonly_dml_finish,
23632365
.amoptions = ao_amoptions,
23642366
.swap_relation_files = appendonly_swap_relation_files,
23652367
};

src/backend/access/table/tableamapi.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ GetTableAmRoutine(Oid amhandler)
104104
(routine->scan_bitmap_next_tuple == NULL));
105105
Assert(routine->scan_sample_next_block != NULL);
106106
Assert(routine->scan_sample_next_tuple != NULL);
107+
/* dml_init and dml_fini should both set or ignored */
108+
Assert((routine->dml_init != NULL) == (routine->dml_fini != NULL));
107109

108110
return routine;
109111
}

src/backend/commands/copyfrom.c

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2007,18 +2007,7 @@ CopyFrom(CopyFromState cstate)
20072007

20082008
CopyInitDataParser(cstate);
20092009

2010-
/*
2011-
* GPDB_12_MERGE_FIXME: We still have to perform the initialization
2012-
* here for AO relations. It is preferreable by all means to perform the
2013-
* initialization via the table AP API, however it simply does not
2014-
* provide a good enough interface for this yet.
2015-
*/
2016-
if (RelationIsAoRows(resultRelInfo->ri_RelationDesc))
2017-
appendonly_dml_init(resultRelInfo->ri_RelationDesc, CMD_INSERT);
2018-
else if (RelationIsAoCols(resultRelInfo->ri_RelationDesc))
2019-
aoco_dml_init(resultRelInfo->ri_RelationDesc, CMD_INSERT);
2020-
else if (ext_dml_init_hook)
2021-
ext_dml_init_hook(resultRelInfo->ri_RelationDesc, CMD_INSERT);
2010+
table_dml_init(resultRelInfo->ri_RelationDesc, CMD_INSERT);
20222011

20232012
for (;;)
20242013
{
@@ -2451,18 +2440,7 @@ CopyFrom(CopyFromState cstate)
24512440
if (bistate != NULL)
24522441
FreeBulkInsertState(bistate);
24532442

2454-
/*
2455-
* GPDB_12_MERGE_FIXME: We still have to perform the finishment
2456-
* here for AO relations. It is preferreable by all means to perform the
2457-
* finishment via the table AP API, however it simply does not
2458-
* provide a good enough interface for this yet.
2459-
*/
2460-
if (RelationIsAoRows(resultRelInfo->ri_RelationDesc))
2461-
appendonly_dml_finish(resultRelInfo->ri_RelationDesc, CMD_INSERT);
2462-
else if (RelationIsAoCols(resultRelInfo->ri_RelationDesc))
2463-
aoco_dml_finish(resultRelInfo->ri_RelationDesc, CMD_INSERT);
2464-
else if (ext_dml_finish_hook)
2465-
ext_dml_finish_hook(resultRelInfo->ri_RelationDesc, CMD_INSERT);
2443+
table_dml_fini(resultRelInfo->ri_RelationDesc, CMD_INSERT);
24662444

24672445
MemoryContextSwitchTo(oldcontext);
24682446

src/backend/commands/createas.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -838,21 +838,8 @@ CreateIntoRelDestReceiver(IntoClause *intoClause)
838838
static void
839839
intorel_startup_dummy(DestReceiver *self, int operation, TupleDesc typeinfo)
840840
{
841-
/*
842-
* In PostgreSQL, this is a no-op, but in GPDB, AO relations do need some
843-
* initialization of state, because the tableam API does not provide a
844-
* good enough interface for handling with this later, we need to
845-
* specifically all the init at start up.
846-
*/
847-
848841
/* See intorel_initplan() for explanation */
849-
850-
if (RelationIsAoRows(((DR_intorel *)self)->rel))
851-
appendonly_dml_init(((DR_intorel *)self)->rel, CMD_INSERT);
852-
else if (RelationIsAoCols(((DR_intorel *)self)->rel))
853-
aoco_dml_init(((DR_intorel *)self)->rel, CMD_INSERT);
854-
else if (ext_dml_init_hook)
855-
ext_dml_init_hook(((DR_intorel *)self)->rel, CMD_INSERT);
842+
table_dml_init(((DR_intorel *)self)->rel, CMD_INSERT);
856843
}
857844

858845
/*

src/backend/commands/matview.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -966,12 +966,7 @@ transientrel_startup(DestReceiver *self, int operation, TupleDesc typeinfo)
966966
myState->bistate = GetBulkInsertState();
967967
myState->processed = 0;
968968

969-
if (RelationIsAoRows(myState->transientrel))
970-
appendonly_dml_init(myState->transientrel, CMD_INSERT);
971-
else if (RelationIsAoCols(myState->transientrel))
972-
aoco_dml_init(myState->transientrel, CMD_INSERT);
973-
else if (ext_dml_init_hook)
974-
ext_dml_init_hook(myState->transientrel, CMD_INSERT);
969+
table_dml_init(myState->transientrel, CMD_INSERT);
975970

976971
/*
977972
* Valid smgr_targblock implies something already wrote to the relation.

src/backend/commands/tablecmds.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7560,12 +7560,8 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
75607560
snapshot = RegisterSnapshot(GetLatestSnapshot());
75617561
scan = table_beginscan(oldrel, snapshot, 0, NULL);
75627562

7563-
if (newrel && RelationIsAoRows(newrel))
7564-
appendonly_dml_init(newrel, CMD_INSERT);
7565-
else if (newrel && RelationIsAoCols(newrel))
7566-
aoco_dml_init(newrel, CMD_INSERT);
7567-
else if (newrel && ext_dml_init_hook)
7568-
ext_dml_init_hook(newrel, CMD_INSERT);
7563+
if (newrel)
7564+
table_dml_init(newrel, CMD_INSERT);
75697565

75707566
/*
75717567
* Switch to per-tuple memory context and reset it for each tuple

src/backend/executor/execPartition.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -916,12 +916,7 @@ ExecInitPartitionInfo(ModifyTableState *mtstate, EState *estate,
916916
lappend(estate->es_tuple_routing_result_relations,
917917
leaf_part_rri);
918918

919-
if (RelationIsAoRows(leaf_part_rri->ri_RelationDesc))
920-
appendonly_dml_init(leaf_part_rri->ri_RelationDesc, mtstate->operation);
921-
else if (RelationIsAoCols(leaf_part_rri->ri_RelationDesc))
922-
aoco_dml_init(leaf_part_rri->ri_RelationDesc, mtstate->operation);
923-
else if (ext_dml_init_hook)
924-
ext_dml_init_hook(leaf_part_rri->ri_RelationDesc, mtstate->operation);
919+
table_dml_init(leaf_part_rri->ri_RelationDesc, mtstate->operation);
925920

926921
MemoryContextSwitchTo(oldcxt);
927922

@@ -1234,12 +1229,7 @@ ExecCleanupTupleRouting(ModifyTableState *mtstate,
12341229
* Only leaf node can have a valid access method. If we find an
12351230
* appendoptimized table, ensure the DML operation is finished.
12361231
*/
1237-
if (RelationIsAoRows(resultRelInfo->ri_RelationDesc))
1238-
appendonly_dml_finish(resultRelInfo->ri_RelationDesc, mtstate->operation);
1239-
else if (RelationIsAoCols(resultRelInfo->ri_RelationDesc))
1240-
aoco_dml_finish(resultRelInfo->ri_RelationDesc, mtstate->operation);
1241-
else if (ext_dml_finish_hook)
1242-
ext_dml_finish_hook(resultRelInfo->ri_RelationDesc, mtstate->operation);
1232+
table_dml_fini(resultRelInfo->ri_RelationDesc, mtstate->operation);
12431233

12441234
ExecCloseIndices(resultRelInfo);
12451235
table_close(resultRelInfo->ri_RelationDesc, NoLock);

0 commit comments

Comments
 (0)