Skip to content

Cherry-pick AOCS related work that changes catalog version #1008

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/backend/access/aocs/aocs_compaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ AOCSSegmentFileFullCompaction(Relation aorel,

AppendOnlyVisimap_Init(&visiMap,
insertDesc->visimaprelid,
insertDesc->visimapidxid,
ShareLock,
snapshot);

Expand Down
22 changes: 8 additions & 14 deletions src/backend/access/aocs/aocsam.c
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,6 @@ aocs_beginscan_internal(Relation relation,
AOCSScanDesc scan;
AttrNumber natts;
Oid visimaprelid;
Oid visimapidxid;

scan = (AOCSScanDesc) palloc0(sizeof(AOCSScanDescData));
scan->rs_base.rs_rd = relation;
Expand Down Expand Up @@ -599,13 +598,12 @@ aocs_beginscan_internal(Relation relation,
NULL);

GetAppendOnlyEntryAuxOids(relation,
NULL, NULL, NULL,
&visimaprelid, &visimapidxid);
NULL, NULL,
&visimaprelid);

if (scan->total_seg != 0)
AppendOnlyVisimap_Init(&scan->visibilityMap,
visimaprelid,
visimapidxid,
AccessShareLock,
appendOnlyMetaDataSnapshot);

Expand Down Expand Up @@ -1083,8 +1081,8 @@ aocs_insert_init(Relation rel, int segno)
desc->compType = NameStr(nd);

GetAppendOnlyEntryAuxOids(rel,
&desc->segrelid, &desc->blkdirrelid, NULL,
&desc->visimaprelid, &desc->visimapidxid);
&desc->segrelid, &desc->blkdirrelid,
&desc->visimaprelid);

OpenAOCSDatumStreams(desc);

Expand Down Expand Up @@ -1545,10 +1543,9 @@ aocs_fetch_init(Relation relation,

bool checksum;
Oid visimaprelid;
Oid visimapidxid;
GetAppendOnlyEntryAuxOids(relation,
&aocsFetchDesc->segrelid, NULL, NULL,
&visimaprelid, &visimapidxid);
&aocsFetchDesc->segrelid, NULL,
&visimaprelid);

GetAppendOnlyEntryAttributes(relation->rd_id,
NULL,
Expand Down Expand Up @@ -1641,7 +1638,6 @@ aocs_fetch_init(Relation relation,
pfree(opts);
AppendOnlyVisimap_Init(&aocsFetchDesc->visibilityMap,
visimaprelid,
visimapidxid,
AccessShareLock,
appendOnlyMetaDataSnapshot);

Expand Down Expand Up @@ -1912,20 +1908,18 @@ aocs_delete_init(Relation rel)
* Get the pg_appendonly information
*/
Oid visimaprelid;
Oid visimapidxid;
AOCSDeleteDesc aoDeleteDesc = palloc0(sizeof(AOCSDeleteDescData));

aoDeleteDesc->aod_rel = rel;

Snapshot snapshot = GetCatalogSnapshot(InvalidOid);

GetAppendOnlyEntryAuxOids(rel,
NULL, NULL, NULL,
&visimaprelid, &visimapidxid);
NULL, NULL,
&visimaprelid);

AppendOnlyVisimap_Init(&aoDeleteDesc->visibilityMap,
visimaprelid,
visimapidxid,
RowExclusiveLock,
snapshot);

Expand Down
103 changes: 77 additions & 26 deletions src/backend/access/aocs/aocsam_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -607,15 +607,13 @@ extractcolumns_from_node(Node *expr, bool *cols, AttrNumber natts)
return ecCtx.found;
}

static TableScanDesc
aoco_beginscan_extractcolumns(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key,
ParallelTableScanDesc parallel_scan,
PlanState *ps, uint32 flags)
AOCSScanDesc
aoco_beginscan_extractcolumns_quals(Relation rel, Snapshot snapshot,
List *targetlist, List *qual,
ParallelTableScanDesc parallel_scan, uint32 flags)
{
AOCSScanDesc aoscan;
AttrNumber natts = RelationGetNumberOfAttributes(rel);
List *targetlist = ps->plan->targetlist;
List *qual = ps->plan->qual;
bool *cols;
bool found = false;

Expand All @@ -639,6 +637,19 @@ aoco_beginscan_extractcolumns(Relation rel, Snapshot snapshot, int nkeys, struct
flags);

pfree(cols);
return aoscan;
}

static TableScanDesc
aoco_beginscan_extractcolumns(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key,
ParallelTableScanDesc parallel_scan,
PlanState *ps, uint32 flags)
{
AOCSScanDesc aoscan;
List *targetlist = ps->plan->targetlist;
List *qual = ps->plan->qual;

aoscan = aoco_beginscan_extractcolumns_quals(rel, snapshot, targetlist, qual, parallel_scan, flags);

if (gp_enable_predicate_pushdown)
ps->qual = aocs_predicate_pushdown_prepare(aoscan, qual, ps->qual, ps->ps_ExprContext, ps);
Expand Down Expand Up @@ -1378,8 +1389,8 @@ aoco_relation_nontransactional_truncate(Relation rel)
/* Also truncate the aux tables */
GetAppendOnlyEntryAuxOids(rel,
&aoseg_relid,
&aoblkdir_relid, NULL,
&aovisimap_relid, NULL);
&aoblkdir_relid,
&aovisimap_relid);

heap_truncate_one_relid(aoseg_relid);
heap_truncate_one_relid(aoblkdir_relid);
Expand Down Expand Up @@ -1687,14 +1698,12 @@ aoco_index_build_range_scan(Relation heapRelation,
int64 total_blockcount = 0;
BlockNumber lastBlock = start_blockno;
int64 blockcounts = 0;
#if 0
bool need_create_blk_directory = false;
List *tlist = NIL;
List *qual = indexInfo->ii_Predicate;
#endif
Oid blkdirrelid;
Oid blkidxrelid;
int64 previous_blkno = -1;
Relation blkdir;

/*
* sanity checks
Expand Down Expand Up @@ -1734,6 +1743,17 @@ aoco_index_build_range_scan(Relation heapRelation,
/* Set up execution state for predicate, if any. */
predicate = ExecPrepareQual(indexInfo->ii_Predicate, estate);

/*
* If block directory is empty, it must also be built along with the index.
*/
GetAppendOnlyEntryAuxOids(heapRelation, NULL,
&blkdirrelid, NULL);

blkdir = relation_open(blkdirrelid, AccessShareLock);

need_create_blk_directory = RelationGetNumberOfBlocks(blkdir) == 0;
relation_close(blkdir, NoLock);

if (!scan)
{
/*
Expand All @@ -1744,12 +1764,50 @@ aoco_index_build_range_scan(Relation heapRelation,
*/
snapshot = SnapshotAny;

scan = table_beginscan_strat(heapRelation, /* relation */
snapshot, /* snapshot */
0, /* number of keys */
NULL, /* scan key */
true, /* buffer access strategy OK */
allow_sync); /* syncscan OK? */
/*
* Scan all columns if we need to create block directory.
*/
if (need_create_blk_directory)
{
scan = table_beginscan_strat(heapRelation, /* relation */
snapshot, /* snapshot */
0, /* number of keys */
NULL, /* scan key */
true, /* buffer access strategy OK */
allow_sync); /* syncscan OK? */
}
else
{
uint32 flags = SO_TYPE_SEQSCAN |
SO_ALLOW_STRAT | SO_ALLOW_SYNC | SO_ALLOW_PAGEMODE;
/*
* if block directory has created, we can only scan needed column.
*/
for (int i = 0; i < indexInfo->ii_NumIndexAttrs; i++)
{
AttrNumber attrnum = indexInfo->ii_IndexAttrNumbers[i];
Form_pg_attribute attr = TupleDescAttr(RelationGetDescr(heapRelation), attrnum - 1);
Var *var = makeVar(i,
attrnum,
attr->atttypid,
attr->atttypmod,
attr->attcollation,
0);

/* Build a target list from index info */
tlist = lappend(tlist,
makeTargetEntry((Expr *) var,
list_length(tlist) + 1,
NULL,
false));
}

/* Push down target list and qual to scan */
scan = (TableScanDesc)aoco_beginscan_extractcolumns_quals(heapRelation, /* relation */
snapshot, /* snapshot */
tlist, /* targetlist */
qual, NULL, flags); /* qual */
}
}
else
{
Expand All @@ -1767,11 +1825,6 @@ aoco_index_build_range_scan(Relation heapRelation,

aocoscan = (AOCSScanDesc) scan;

/*
* If block directory is empty, it must also be built along with the index.
*/
GetAppendOnlyEntryAuxOids(heapRelation, NULL,
&blkdirrelid, &blkidxrelid, NULL, NULL);
/*
* Note that block directory is created during creation of the first
* index. If it is found empty, it means the block directory was created
Expand All @@ -1781,8 +1834,7 @@ aoco_index_build_range_scan(Relation heapRelation,
* blocked. We can rest assured of exclusive access to the block
* directory relation.
*/
Relation blkdir = relation_open(blkdirrelid, AccessShareLock);
if (RelationGetNumberOfBlocks(blkdir) == 0)
if (need_create_blk_directory)
{
/*
* Allocate blockDirectory in scan descriptor to let the access method
Expand All @@ -1792,7 +1844,6 @@ aoco_index_build_range_scan(Relation heapRelation,
Assert(aocoscan->blockDirectory == NULL);
aocoscan->blockDirectory = palloc0(sizeof(AppendOnlyBlockDirectory));
}
relation_close(blkdir, NoLock);


/* Publish number of blocks to scan */
Expand Down Expand Up @@ -2086,7 +2137,7 @@ aoco_relation_get_block_sequence(Relation rel,
{
Oid segrelid;

GetAppendOnlyEntryAuxOids(rel, &segrelid, NULL, NULL, NULL, NULL);
GetAppendOnlyEntryAuxOids(rel, &segrelid, NULL, NULL);
AOSegment_PopulateBlockSequence(sequence, segrelid, AOSegmentGet_segno(blkNum));
}

Expand Down
35 changes: 17 additions & 18 deletions src/backend/access/aocs/aocssegfiles.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,10 @@ GetAOCSFileSegInfo(Relation prel,
Datum *d;
bool *null;
bool isNull;
Oid segrelid;

Oid segrelid;
GetAppendOnlyEntryAuxOids(prel,
&segrelid, NULL, NULL,
NULL, NULL);
GetAppendOnlyEntryAuxOids(prel,
&segrelid, NULL, NULL);

segrel = heap_open(segrelid, AccessShareLock);
tupdesc = RelationGetDescr(segrel);
Expand Down Expand Up @@ -329,7 +328,7 @@ GetAllAOCSFileSegInfo(Relation prel,
Assert(RelationStorageIsAoCols(prel));

GetAppendOnlyEntryAuxOids(prel,
&segrelid, NULL, NULL,
&segrelid,
NULL, NULL);

if (segrelid == InvalidOid)
Expand Down Expand Up @@ -587,7 +586,7 @@ MarkAOCSFileSegInfoAwaitingDrop(Relation prel, int segno)

appendOnlyMetaDataSnapshot = RegisterSnapshot(GetCatalogSnapshot(InvalidOid));
GetAppendOnlyEntryAuxOids(prel,
&segrelid, NULL, NULL,
&segrelid,
NULL, NULL);
UnregisterSnapshot(appendOnlyMetaDataSnapshot);

Expand Down Expand Up @@ -675,7 +674,7 @@ ClearAOCSFileSegInfo(Relation prel, int segno)

appendOnlyMetaDataSnapshot = RegisterSnapshot(GetCatalogSnapshot(InvalidOid));
GetAppendOnlyEntryAuxOids(prel,
&segrelid, NULL, NULL,
&segrelid,
NULL, NULL);
UnregisterSnapshot(appendOnlyMetaDataSnapshot);

Expand Down Expand Up @@ -957,7 +956,7 @@ AOCSFileSegInfoAddVpe(Relation prel, int32 segno,

Oid segrelid;
GetAppendOnlyEntryAuxOids(prel,
&segrelid, NULL, NULL,
&segrelid,
NULL, NULL);
segrel = heap_open(segrelid, RowExclusiveLock);
tupdesc = RelationGetDescr(segrel);
Expand Down Expand Up @@ -1071,7 +1070,7 @@ AOCSFileSegInfoAddCount(Relation prel, int32 segno,

Oid segrelid;
GetAppendOnlyEntryAuxOids(prel,
&segrelid, NULL, NULL,
&segrelid,
NULL, NULL);

segrel = heap_open(segrelid, RowExclusiveLock);
Expand Down Expand Up @@ -1201,6 +1200,7 @@ gp_aocsseg_internal(PG_FUNCTION_ARGS, Oid aocsRelOid)
Relation aocsRel;
Relation pg_aocsseg_rel;
Snapshot appendOnlyMetaDataSnapshot = RegisterSnapshot(GetLatestSnapshot());
Oid segrelid;

/* create a function context for cross-call persistence */
funcctx = SRF_FIRSTCALL_INIT();
Expand Down Expand Up @@ -1254,10 +1254,9 @@ gp_aocsseg_internal(PG_FUNCTION_ARGS, Oid aocsRelOid)
/* Remember the number of columns. */
context->relnatts = aocsRel->rd_rel->relnatts;

Oid segrelid;
GetAppendOnlyEntryAuxOids(aocsRel,
&segrelid, NULL, NULL,
NULL, NULL);
GetAppendOnlyEntryAuxOids(aocsRel,
&segrelid,
NULL, NULL);
pg_aocsseg_rel = heap_open(segrelid, AccessShareLock);

context->aocsSegfileArray = GetAllAOCSFileSegInfo_pg_aocsseg_rel(
Expand Down Expand Up @@ -1419,6 +1418,7 @@ gp_aocsseg_history(PG_FUNCTION_ARGS)
MemoryContext oldcontext;
Relation aocsRel;
Relation pg_aocsseg_rel;
Oid segrelid;

/* create a function context for cross-call persistence */
funcctx = SRF_FIRSTCALL_INIT();
Expand Down Expand Up @@ -1474,10 +1474,9 @@ gp_aocsseg_history(PG_FUNCTION_ARGS)
/* Remember the number of columns. */
context->relnatts = aocsRel->rd_rel->relnatts;

Oid segrelid;
GetAppendOnlyEntryAuxOids(aocsRel,
&segrelid, NULL, NULL,
NULL, NULL);
GetAppendOnlyEntryAuxOids(aocsRel,
&segrelid,
NULL, NULL);

pg_aocsseg_rel = heap_open(segrelid, AccessShareLock);

Expand Down Expand Up @@ -1609,7 +1608,7 @@ aocol_compression_ratio_internal(Relation parentrel)
Assert(Gp_role == GP_ROLE_DISPATCH || Gp_role == GP_ROLE_UTILITY);

GetAppendOnlyEntryAuxOids(parentrel,
&segrelid, NULL, NULL, NULL, NULL);
&segrelid, NULL, NULL);
Assert(OidIsValid(segrelid));

/*
Expand Down
2 changes: 1 addition & 1 deletion src/backend/access/appendonly/aomd.c
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ ao_rel_get_physical_size(Relation aorel)
Assert(RelationStorageIsAO(aorel));

GetAppendOnlyEntryAuxOids(aorel,
&segrelid, NULL, NULL, NULL, NULL);
&segrelid, NULL, NULL);

pg_aoseg_rel = heap_open(segrelid, AccessShareLock);
pg_aoseg_dsc = RelationGetDescr(pg_aoseg_rel);
Expand Down
Loading
Loading