Skip to content

Commit b413e0b

Browse files
gfphoenix78wuhao
andauthored
Add macro RelationIsNonblockRelation to expand code path like AO/CO (#347)
The builtin types of tables, in kernel, are standard heap table and AO/CO. The custom table AM will fall one of the two code paths. RelationIsAppendOptimized will only choose the builtin AO/CO relations. Some custom table AM, like PAX, will run the same code path as AO/CO. RelationIsNonblockRelation looks replacable by `!RelationIsHeap`, but they have different meanings. RelationIsNonblockRelation expand the relation type to run the code path like AO/CO. `!RelationIsHeap` emphasizes NOT heap relation. To work with this change, we preserve and oid for pax, to prevent oid clash in the future. Co-authored-by: wuhao <wuhao@hashdata.cn> Reviewed-by: Zhang Mingli <avamingli@gmail.com>
1 parent 04f496c commit b413e0b

8 files changed

Lines changed: 47 additions & 16 deletions

File tree

src/backend/commands/analyze.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,8 +1621,9 @@ acquire_sample_rows(Relation onerel, int elevel,
16211621
* GPDB_12_MERGE_FIXME: BlockNumber is uint32 and Number of tuples is uint64.
16221622
* That means that after row number UINT_MAX we will never analyze the table.
16231623
*/
1624-
if (RelationIsAppendOptimized(onerel))
1624+
if (RelationIsNonblockRelation(onerel))
16251625
{
1626+
/* AO/CO/PAX use non-fixed block layout */
16261627
BlockNumber pages;
16271628
double tuples;
16281629
double allvisfrac;
@@ -1653,7 +1654,7 @@ acquire_sample_rows(Relation onerel, int elevel,
16531654
* because Blocks is not same as Heap tables.
16541655
* Set prefetch_maximum to zero seems the easiest way to bypass.
16551656
*/
1656-
if (RelationIsAppendOptimized(onerel))
1657+
if (RelationIsNonblockRelation(onerel))
16571658
{
16581659
prefetch_maximum = 0;
16591660
}

src/backend/commands/trigger.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ CreateTriggerFiringOn(CreateTrigStmt *stmt, const char *queryString,
715715
}
716716

717717
/* Check GPDB limitations */
718-
if (RelationIsAppendOptimized(rel) &&
718+
if (RelationIsNonblockRelation(rel) &&
719719
TRIGGER_FOR_ROW(tgtype) &&
720720
!stmt->isconstraint)
721721
{
@@ -3105,7 +3105,7 @@ GetTupleForTrigger(EState *estate,
31053105
Relation relation = relinfo->ri_RelationDesc;
31063106

31073107
/* these should be rejected when you try to create such triggers, but let's check */
3108-
if (RelationIsAppendOptimized(relation))
3108+
if (RelationIsNonblockRelation(relation))
31093109
elog(ERROR, "UPDATE and DELETE triggers are not supported on append-only tables");
31103110

31113111
Assert(RelationIsHeap(relation));

src/backend/executor/nodeModifyTable.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,7 +1463,7 @@ ldelete:;
14631463
* triggers on an UPDATE that moves tuples from one partition to another.
14641464
* Should we follow that example with cross-segment UPDATEs too?
14651465
*/
1466-
if (!RelationIsAppendOptimized(resultRelationDesc) && !splitUpdate)
1466+
if (!RelationIsNonblockRelation(resultRelationDesc) && !splitUpdate)
14671467
{
14681468
ExecARDeleteTriggers(estate, resultRelInfo, tupleid, oldtuple,
14691469
ar_delete_trig_tcs);
@@ -1949,7 +1949,7 @@ lreplace:;
19491949
* AO case, as visimap update within same command happens at end
19501950
* of command.
19511951
*/
1952-
if (!RelationIsAppendOptimized(resultRelationDesc) &&
1952+
if (!RelationIsNonblockRelation(resultRelationDesc) &&
19531953
tmfd.cmax != estate->es_output_cid)
19541954
ereport(ERROR,
19551955
(errcode(ERRCODE_TRIGGERED_DATA_CHANGE_VIOLATION),
@@ -2075,7 +2075,7 @@ lreplace:;
20752075

20762076
/* AFTER ROW UPDATE Triggers */
20772077
/* GPDB: AO and AOCO tables don't support triggers */
2078-
if (!RelationIsAppendOptimized(resultRelationDesc))
2078+
if (!RelationIsNonblockRelation(resultRelationDesc))
20792079
ExecARUpdateTriggers(estate, resultRelInfo, tupleid, oldtuple, slot,
20802080
recheckIndexes,
20812081
mtstate->operation == CMD_INSERT ?
@@ -2664,8 +2664,11 @@ ExecModifyTable(PlanState *pstate)
26642664
* We need to fix this problem by redesigning AO/AOCS storage format or
26652665
* making the update plan is consistent whether it generated by pg optimizer
26662666
* or ORCA optimizer in the future.
2667+
*
2668+
* PAX_STORAGE_FIXME(gongxun):we reuse the logic of the AO table to implement ExecUpdate,
2669+
* If there is a better implementation, we need to revert it
26672670
*/
2668-
if (operation == CMD_UPDATE && !RelationIsHeap(resultRelInfo->ri_RelationDesc) &&
2671+
if (operation == CMD_UPDATE && RelationIsNonblockRelation(resultRelInfo->ri_RelationDesc) &&
26692672
AttributeNumberIsValid(resultRelInfo->ri_WholeRowNo))
26702673
{
26712674
/* ri_WholeRowNo refers to a wholerow attribute */
@@ -3137,7 +3140,7 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
31373140
elog(ERROR, "could not find junk ctid column");
31383141

31393142
/* extra GPDB junk columns for update AO table */
3140-
if (operation == CMD_UPDATE && !RelationIsHeap(resultRelInfo->ri_RelationDesc))
3143+
if (operation == CMD_UPDATE && RelationIsNonblockRelation(resultRelInfo->ri_RelationDesc))
31413144
{
31423145
resultRelInfo->ri_WholeRowNo =
31433146
ExecFindJunkAttributeInTlist(subplan->targetlist, "wholerow");

src/backend/gpopt/translate/CTranslatorRelcacheToDXL.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2435,17 +2435,17 @@ CTranslatorRelcacheToDXL::RetrieveRelStorageType(Relation rel)
24352435
break;
24362436
// FIXME: need to add support for custom table am!!!
24372437
//
2438-
// Why 7014 here?
2438+
// Why 7047 here?
24392439
// Because we defined a custom table am using columnar storage,
24402440
// the orca optimizer does not support am other than HEAP/AO/AOCS. At present,
24412441
// there is no way to extend orca to support custom table am. So here we use
2442-
// the am_id(7014) we assigned to the custom table am, and let the orca optimizer
2442+
// the am_id(7047) we assigned to the custom table am, and let the orca optimizer
24432443
// treat this columnar storage format as AOCS to generate an execution plan
24442444
//
2445-
// Why use the magic number 7014 instead of the macro definition?
2445+
// Why use the magic number 7047 instead of the macro definition?
24462446
// Just to make it look like it doesn't make sense,
24472447
// so others will notice that the logic needs to be refactored
2448-
case 7014:
2448+
case PAX_AM_OID:
24492449
case AO_COLUMN_TABLE_AM_OID:
24502450
rel_storage_type = IMDRelation::ErelstorageAppendOnlyCols;
24512451
break;

src/backend/optimizer/util/appendinfo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ add_row_identity_columns(PlannerInfo *root, Index rtindex,
953953
* redesigning AO/AOCS storage format or making the update plan is
954954
* consistent whether it generated by pg optimizer or ORCA optimizer.
955955
*/
956-
if (commandType == CMD_UPDATE && !RelationIsHeap(target_relation))
956+
if (commandType == CMD_UPDATE && RelationIsNonblockRelation(target_relation))
957957
{
958958
var = makeVar(rtindex,
959959
InvalidAttrNumber,

src/backend/utils/adt/dbsize.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,8 @@ calculate_relation_size(Relation rel, ForkNumber forknum)
463463
if (relation_size_hook)
464464
return (*relation_size_hook) (rel, forknum);
465465

466-
/* Call into the tableam api for AO/AOCO relations */
467-
if (RelationIsAppendOptimized(rel))
466+
/* Call into the tableam api if the table is not heap, i.e. AO/CO/PAX relations. */
467+
if (RelationIsNonblockRelation(rel))
468468
return table_relation_size(rel, forknum);
469469

470470
relationpath = relpathbackend(rel->rd_node, rel->rd_backend, forknum);

src/include/catalog/duplicate_oids

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ my $oids = Catalog::FindAllOidsFromHeaders(@input_files);
3232

3333
my %oidcounts;
3434

35+
# preserved oid for PAX table AM
36+
$oidcounts{7047}++;
37+
3538
foreach my $oid (@{$oids})
3639
{
3740
$oidcounts{$oid}++;

src/include/utils/rel.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "fmgr.h"
2121
#include "access/tupdesc.h"
2222
#include "access/xlog.h"
23+
#include "catalog/pg_am.h"
2324
#include "catalog/pg_appendonly.h"
2425
#include "catalog/pg_class.h"
2526
#include "catalog/pg_index.h"
@@ -516,6 +517,29 @@ typedef struct ViewOptions
516517
#define RelationIsAppendOptimized(relation) \
517518
AMHandlerIsAO((relation)->rd_amhandler)
518519

520+
/*
521+
* FIXME: CBDB should not know the am oid of PAX. We put here because the kernel
522+
* can't distinguish the PAX and renamed heap(heap_psql) in test `psql`.
523+
*/
524+
#define PAX_AM_OID 7047
525+
/*
526+
* CAUTION: this macro is a violation of the absraction that table AM and
527+
* index AM interfaces provide. Use of this macro is discouraged. If
528+
* table/index AM API falls short for your use case, consider enhancing the
529+
* interface.
530+
*
531+
* RelationIsNonblockRelation looks replacable by `!RelationIsHeap`, but
532+
* they have different meanings. RelationIsNonblockRelation expand the
533+
* relation type to run the code path like AO/CO. `!RelationIsHeap`
534+
* emphasizes NOT heap relation.
535+
*
536+
* RelationIsNonblockRelation
537+
* True iff relation(table) should run the code path as AO/CO
538+
*/
539+
#define RelationIsNonblockRelation(relation) \
540+
(RelationIsAppendOptimized(relation) || \
541+
(relation)->rd_rel->relam == PAX_AM_OID)
542+
519543
/*
520544
* RelationIsBitmapIndex
521545
* True iff relation is a bitmap index

0 commit comments

Comments
 (0)