From 6cd81fb3d2b7f2304c250142588b5ab8be8fd523 Mon Sep 17 00:00:00 2001 From: Richy Wang Date: Tue, 29 Mar 2022 15:25:08 +0800 Subject: [PATCH 1/3] Speed up AOCS index build by only scan needed columns. (#13012) On first index creation (block directory is created) and only that time all columns are scanned. Later any index creation just scans needed columns. cherry-picked. Note influence of https://github.com/greenplum-db/gpdb-archive/commit/8c92aa028f5396c1d720b320dd55c9a295b7fb05 --- src/backend/access/aocs/aocsam_handler.c | 96 ++++++++++++++++++------ src/include/cdb/cdbaocsam.h | 4 + src/test/regress/input/aocs.source | 30 +++++++- src/test/regress/output/aocs.source | 46 +++++++++++- 4 files changed, 152 insertions(+), 24 deletions(-) diff --git a/src/backend/access/aocs/aocsam_handler.c b/src/backend/access/aocs/aocsam_handler.c index 504e9c0fb7a..16c820a636f 100644 --- a/src/backend/access/aocs/aocsam_handler.c +++ b/src/backend/access/aocs/aocsam_handler.c @@ -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; @@ -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); @@ -1687,14 +1698,13 @@ 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 @@ -1734,6 +1744,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, &blkidxrelid, NULL, NULL); + + blkdir = relation_open(blkdirrelid, AccessShareLock); + + need_create_blk_directory = RelationGetNumberOfBlocks(blkdir) == 0; + relation_close(blkdir, NoLock); + if (!scan) { /* @@ -1744,12 +1765,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 { @@ -1767,11 +1826,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 @@ -1781,8 +1835,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 @@ -1792,7 +1845,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 */ diff --git a/src/include/cdb/cdbaocsam.h b/src/include/cdb/cdbaocsam.h index b4a4653bfd0..333f40fc639 100644 --- a/src/include/cdb/cdbaocsam.h +++ b/src/include/cdb/cdbaocsam.h @@ -401,6 +401,10 @@ extern void aoco_dml_init(Relation relation, CmdType operation); extern void aoco_dml_finish(Relation relation, CmdType operation); extern bool extractcolumns_from_node(Node *expr, bool *cols, AttrNumber natts); +extern AOCSScanDesc aoco_beginscan_extractcolumns_quals(Relation rel, Snapshot snapshot, + List *targetlist, List *qual, + ParallelTableScanDesc parallel_scan, uint32 flags); + extern ExprState * aocs_predicate_pushdown_prepare(AOCSScanDesc scan, List *qual, ExprState *state, diff --git a/src/test/regress/input/aocs.source b/src/test/regress/input/aocs.source index 74f040665fc..38650e4f061 100644 --- a/src/test/regress/input/aocs.source +++ b/src/test/regress/input/aocs.source @@ -623,7 +623,7 @@ insert into aocs_index_cols values (1, 'foo', 'bar'); -- Create an index on the table. This is the first index on the table, so it -- creates the ao block directory, and scans all columns. -create index on aocs_index_cols (id); +create index aocs_index_cols_id_idx on aocs_index_cols (id); -- Create a partial index. This index needs to scan two columns; one is used -- as the index column, and the other in the WHERE clause. @@ -639,6 +639,34 @@ select * from aocs_index_cols where a like 'f%'; select * from aocs_index_cols where length(b) = 3; reset enable_seqscan; +-- Recreate aocs_index_cols_id_idx. This index needs to scan only one columns. +drop index aocs_index_cols_id_idx; +create index aocs_index_cols_id_idx on aocs_index_cols (id); +-- Check that the row is found using the new index. +set enable_seqscan=off; +select * from aocs_index_cols where id = 1; + +-- Test for corner cases +drop table aocs_index_cols; +create table aocs_index_cols (id int4, a text, b text) with (appendonly=true, orientation=column); +insert into aocs_index_cols values (1, 'foo', 'bar'); +-- Create index in a txn first, then rollback, then create index again. +-- No blockdir will be created when rollback. +begin; +create index aocs_index_cols_id_idx on aocs_index_cols (id); +abort; +select blkdirrelid=0 as blk_dir_not_exist from pg_appendonly where relid = 'aocs_index_cols'::regclass; + +-- Create the first index and then drop it, blockdir existed. +create index aocs_index_cols_id_idx on aocs_index_cols (id); +drop index aocs_index_cols_id_idx; +select blkdirrelid=0 as blk_dir_not_exist from pg_appendonly where relid = 'aocs_index_cols'::regclass; + +-- Create again. This index needs to scan only one columns. +create index aocs_index_cols_id_idx on aocs_index_cols (id); +select * from aocs_index_cols where id = 1; + +reset enable_seqscan; -- Small content as well as bulk dense content headers need to be used -- appropriately if compression is found to be not useful. This test diff --git a/src/test/regress/output/aocs.source b/src/test/regress/output/aocs.source index df82c244344..81420586044 100644 --- a/src/test/regress/output/aocs.source +++ b/src/test/regress/output/aocs.source @@ -1250,7 +1250,7 @@ create table aocs_index_cols (id int4, a text, b text) with (appendonly=true, or insert into aocs_index_cols values (1, 'foo', 'bar'); -- Create an index on the table. This is the first index on the table, so it -- creates the ao block directory, and scans all columns. -create index on aocs_index_cols (id); +create index aocs_index_cols_id_idx on aocs_index_cols (id); -- Create a partial index. This index needs to scan two columns; one is used -- as the index column, and the other in the WHERE clause. create index on aocs_index_cols (id) WHERE a like 'f%'; @@ -1276,6 +1276,50 @@ select * from aocs_index_cols where length(b) = 3; 1 | foo | bar (1 row) +reset enable_seqscan; +-- Recreate aocs_index_cols_id_idx. This index needs to scan only one columns. +drop index aocs_index_cols_id_idx; +create index aocs_index_cols_id_idx on aocs_index_cols (id); +-- Check that the row is found using the new index. +set enable_seqscan=off; +select * from aocs_index_cols where id = 1; + id | a | b +----+-----+----- + 1 | foo | bar +(1 row) + +-- Test for corner cases +drop table aocs_index_cols; +create table aocs_index_cols (id int4, a text, b text) with (appendonly=true, orientation=column); +insert into aocs_index_cols values (1, 'foo', 'bar'); +-- Create index in a txn first, then rollback, then create index again. +-- No blockdir will be created when rollback. +begin; +create index aocs_index_cols_id_idx on aocs_index_cols (id); +abort; +select blkdirrelid=0 as blk_dir_not_exist from pg_appendonly where relid = 'aocs_index_cols'::regclass; + blk_dir_not_exist +------------------- + t +(1 row) + +-- Create the first index and then drop it, blockdir existed. +create index aocs_index_cols_id_idx on aocs_index_cols (id); +drop index aocs_index_cols_id_idx; +select blkdirrelid=0 as blk_dir_not_exist from pg_appendonly where relid = 'aocs_index_cols'::regclass; + blk_dir_not_exist +------------------- + f +(1 row) + +-- Create again. This index needs to scan only one columns. +create index aocs_index_cols_id_idx on aocs_index_cols (id); +select * from aocs_index_cols where id = 1; + id | a | b +----+-----+----- + 1 | foo | bar +(1 row) + reset enable_seqscan; -- Small content as well as bulk dense content headers need to be used -- appropriately if compression is found to be not useful. This test From 4f7dbfc82b8f8cbcfc9e56e1f80c856a18d44189 Mon Sep 17 00:00:00 2001 From: Huansong Fu Date: Wed, 15 Feb 2023 20:33:51 -0800 Subject: [PATCH 2/3] Remove visimapidxid and blkdiridxid fields from pg_appendonly We can get indexes for blkdir and visimap from pg_index via `RelationGetIndexList`. Removing these 2 fields will reduce catalog size. Basically, we now deal with these two properties in a more similar way as the indexes of toast tables, where we always open the toast table first and then get its index via `RelationGetIndexList`. In fact, in majority of the places currently we already have those two aux tables opened. The only place we didn't is in ATExecSetTableSpace(), but it shouldn't slow down that function too much anyway. The other notable thing is that we need to modify how we get these indexes in pg_dump - we now have to check the pg_index. --- src/backend/access/aocs/aocs_compaction.c | 1 - src/backend/access/aocs/aocsam.c | 22 ++++------- src/backend/access/aocs/aocsam_handler.c | 9 ++--- src/backend/access/aocs/aocssegfiles.c | 35 +++++++++-------- src/backend/access/appendonly/aomd.c | 2 +- src/backend/access/appendonly/aosegfiles.c | 20 +++++----- .../access/appendonly/appendonly_blkdir_udf.c | 4 +- .../access/appendonly/appendonly_compaction.c | 18 ++++----- .../access/appendonly/appendonly_visimap.c | 17 +++------ .../appendonly/appendonly_visimap_store.c | 8 +++- .../appendonly/appendonly_visimap_udf.c | 28 ++++++-------- src/backend/access/appendonly/appendonlyam.c | 11 ++---- .../access/appendonly/appendonlyam_handler.c | 13 +++---- .../appendonly/appendonlyblockdirectory.c | 38 +++++++++++-------- .../access/appendonly/appendonlywriter.c | 6 +-- src/backend/catalog/aocatalog.c | 26 +++++++------ src/backend/catalog/heap.c | 2 - src/backend/catalog/index.c | 4 +- src/backend/catalog/pg_appendonly.c | 33 ++-------------- src/backend/commands/indexcmds.c | 2 +- src/backend/commands/tablecmds.c | 31 +++++++++++---- src/backend/commands/vacuum.c | 8 ++-- src/backend/commands/vacuum_ao.c | 6 +-- src/backend/utils/adt/dbsize.c | 4 +- src/include/access/appendonly_visimap.h | 2 - src/include/access/appendonly_visimap_store.h | 1 - src/include/catalog/aocatalog.h | 17 +++++++++ src/include/catalog/catversion.h | 2 +- src/include/catalog/pg_appendonly.h | 14 ++----- src/include/cdb/cdbaocsam.h | 1 - .../regress/expected/uao_catalog_tables.out | 8 ++-- .../regress/expected/uaocs_catalog_tables.out | 8 ++-- src/test/regress/input/gp_tablespace.source | 4 +- .../input/uao_ddl/alter_ao_part_exch.source | 4 +- .../input/uao_ddl/alter_ao_part_tables.source | 10 +++-- ...alter_ao_part_tables_splitpartition.source | 12 +++--- .../uao_ddl/alter_ao_table_col_ddl.source | 12 +++--- .../uao_ddl/alter_ao_table_constraint.source | 4 +- .../uao_ddl/alter_ao_table_setdefault.source | 8 ++-- .../uao_ddl/alter_ao_table_setstorage.source | 12 +++--- .../uao_ddl/alter_ao_table_statistics.source | 4 +- .../uao_ddl/analyze_ao_table_every_dml.source | 4 +- .../regress/input/uao_ddl/blocksize.source | 9 ++--- .../regress/input/uao_ddl/compresstype.source | 12 +++--- .../uao_ddl/create_ao_table_500cols.source | 4 +- .../input/uao_ddl/create_ao_tables.source | 8 ++-- src/test/regress/output/gp_tablespace.source | 4 +- .../output/uao_ddl/alter_ao_part_exch.source | 4 +- .../uao_ddl/alter_ao_part_tables.source | 10 +++-- ...alter_ao_part_tables_splitpartition.source | 22 +++++------ .../uao_ddl/alter_ao_table_col_ddl.source | 18 ++++----- .../alter_ao_table_col_ddl_optimizer.source | 18 ++++----- .../uao_ddl/alter_ao_table_constraint.source | 6 +-- .../uao_ddl/alter_ao_table_setdefault.source | 12 +++--- .../uao_ddl/alter_ao_table_setstorage.source | 18 ++++----- .../uao_ddl/alter_ao_table_statistics.source | 6 +-- .../uao_ddl/analyze_ao_table_every_dml.source | 8 ++-- .../regress/output/uao_ddl/blocksize.source | 13 +++---- .../output/uao_ddl/compresstype.source | 18 ++++----- .../uao_ddl/create_ao_table_500cols.source | 8 ++-- .../output/uao_ddl/create_ao_tables.source | 12 +++--- src/test/regress/sql/uao_catalog_tables.sql | 2 +- src/test/regress/sql/uaocs_catalog_tables.sql | 2 +- 63 files changed, 331 insertions(+), 358 deletions(-) diff --git a/src/backend/access/aocs/aocs_compaction.c b/src/backend/access/aocs/aocs_compaction.c index e6ecea73de1..f89762547d2 100644 --- a/src/backend/access/aocs/aocs_compaction.c +++ b/src/backend/access/aocs/aocs_compaction.c @@ -259,7 +259,6 @@ AOCSSegmentFileFullCompaction(Relation aorel, AppendOnlyVisimap_Init(&visiMap, insertDesc->visimaprelid, - insertDesc->visimapidxid, ShareLock, snapshot); diff --git a/src/backend/access/aocs/aocsam.c b/src/backend/access/aocs/aocsam.c index a3f2b597977..599b63a9e1a 100644 --- a/src/backend/access/aocs/aocsam.c +++ b/src/backend/access/aocs/aocsam.c @@ -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; @@ -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); @@ -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); @@ -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, @@ -1641,7 +1638,6 @@ aocs_fetch_init(Relation relation, pfree(opts); AppendOnlyVisimap_Init(&aocsFetchDesc->visibilityMap, visimaprelid, - visimapidxid, AccessShareLock, appendOnlyMetaDataSnapshot); @@ -1912,7 +1908,6 @@ aocs_delete_init(Relation rel) * Get the pg_appendonly information */ Oid visimaprelid; - Oid visimapidxid; AOCSDeleteDesc aoDeleteDesc = palloc0(sizeof(AOCSDeleteDescData)); aoDeleteDesc->aod_rel = rel; @@ -1920,12 +1915,11 @@ aocs_delete_init(Relation rel) Snapshot snapshot = GetCatalogSnapshot(InvalidOid); GetAppendOnlyEntryAuxOids(rel, - NULL, NULL, NULL, - &visimaprelid, &visimapidxid); + NULL, NULL, + &visimaprelid); AppendOnlyVisimap_Init(&aoDeleteDesc->visibilityMap, visimaprelid, - visimapidxid, RowExclusiveLock, snapshot); diff --git a/src/backend/access/aocs/aocsam_handler.c b/src/backend/access/aocs/aocsam_handler.c index 16c820a636f..9ebf0e328de 100644 --- a/src/backend/access/aocs/aocsam_handler.c +++ b/src/backend/access/aocs/aocsam_handler.c @@ -1389,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); @@ -1702,7 +1702,6 @@ aoco_index_build_range_scan(Relation heapRelation, List *tlist = NIL; List *qual = indexInfo->ii_Predicate; Oid blkdirrelid; - Oid blkidxrelid; int64 previous_blkno = -1; Relation blkdir; @@ -1748,7 +1747,7 @@ aoco_index_build_range_scan(Relation heapRelation, * If block directory is empty, it must also be built along with the index. */ GetAppendOnlyEntryAuxOids(heapRelation, NULL, - &blkdirrelid, &blkidxrelid, NULL, NULL); + &blkdirrelid, NULL); blkdir = relation_open(blkdirrelid, AccessShareLock); @@ -2138,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)); } diff --git a/src/backend/access/aocs/aocssegfiles.c b/src/backend/access/aocs/aocssegfiles.c index aa06320ca41..9bf11055e9e 100644 --- a/src/backend/access/aocs/aocssegfiles.c +++ b/src/backend/access/aocs/aocssegfiles.c @@ -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); @@ -329,7 +328,7 @@ GetAllAOCSFileSegInfo(Relation prel, Assert(RelationStorageIsAoCols(prel)); GetAppendOnlyEntryAuxOids(prel, - &segrelid, NULL, NULL, + &segrelid, NULL, NULL); if (segrelid == InvalidOid) @@ -587,7 +586,7 @@ MarkAOCSFileSegInfoAwaitingDrop(Relation prel, int segno) appendOnlyMetaDataSnapshot = RegisterSnapshot(GetCatalogSnapshot(InvalidOid)); GetAppendOnlyEntryAuxOids(prel, - &segrelid, NULL, NULL, + &segrelid, NULL, NULL); UnregisterSnapshot(appendOnlyMetaDataSnapshot); @@ -675,7 +674,7 @@ ClearAOCSFileSegInfo(Relation prel, int segno) appendOnlyMetaDataSnapshot = RegisterSnapshot(GetCatalogSnapshot(InvalidOid)); GetAppendOnlyEntryAuxOids(prel, - &segrelid, NULL, NULL, + &segrelid, NULL, NULL); UnregisterSnapshot(appendOnlyMetaDataSnapshot); @@ -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); @@ -1071,7 +1070,7 @@ AOCSFileSegInfoAddCount(Relation prel, int32 segno, Oid segrelid; GetAppendOnlyEntryAuxOids(prel, - &segrelid, NULL, NULL, + &segrelid, NULL, NULL); segrel = heap_open(segrelid, RowExclusiveLock); @@ -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(); @@ -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( @@ -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(); @@ -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); @@ -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)); /* diff --git a/src/backend/access/appendonly/aomd.c b/src/backend/access/appendonly/aomd.c index 342e7771b7b..8fe9dd1a698 100644 --- a/src/backend/access/appendonly/aomd.c +++ b/src/backend/access/appendonly/aomd.c @@ -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); diff --git a/src/backend/access/appendonly/aosegfiles.c b/src/backend/access/appendonly/aosegfiles.c index f2997eb2044..56ee5ca4f22 100644 --- a/src/backend/access/appendonly/aosegfiles.c +++ b/src/backend/access/appendonly/aosegfiles.c @@ -109,7 +109,7 @@ InsertInitialSegnoEntry(Relation parentrel, int segno) /* New segments are always created in the latest format */ formatVersion = AOSegfileFormatVersion_GetLatest(); - GetAppendOnlyEntryAuxOids(parentrel, &segrelid, NULL, NULL, NULL, NULL); + GetAppendOnlyEntryAuxOids(parentrel, &segrelid, NULL, NULL); pg_aoseg_rel = heap_open(segrelid, RowExclusiveLock); @@ -194,7 +194,7 @@ GetFileSegInfo(Relation parentrel, Snapshot appendOnlyMetaDataSnapshot, int segn FileSegInfo *fsinfo; Oid segrelid; - GetAppendOnlyEntryAuxOids(parentrel, &segrelid, NULL, NULL, NULL, NULL); + GetAppendOnlyEntryAuxOids(parentrel, &segrelid, NULL, NULL); /* * Check the pg_aoseg relation to be certain the ao table segment file is @@ -360,7 +360,7 @@ GetAllFileSegInfo(Relation parentrel, FileSegInfo **result; Oid segrelid; - GetAppendOnlyEntryAuxOids(parentrel, &segrelid, NULL, NULL, NULL, NULL); + GetAppendOnlyEntryAuxOids(parentrel, &segrelid, NULL, NULL); if (segrelid == InvalidOid) elog(ERROR, "could not find pg_aoseg aux table for AO table \"%s\"", @@ -622,7 +622,7 @@ ClearFileSegInfo(Relation parentrel, int segno) bool isNull; Oid segrelid; - GetAppendOnlyEntryAuxOids(parentrel, &segrelid, NULL, NULL, NULL, NULL); + GetAppendOnlyEntryAuxOids(parentrel, &segrelid, NULL, NULL); elogif(Debug_appendonly_print_compaction, LOG, "Clear seg file info: segno %d table '%s'", @@ -759,7 +759,7 @@ UpdateFileSegInfo_internal(Relation parentrel, Oid segrelid; Assert(RelationStorageIsAoRows(parentrel)); - GetAppendOnlyEntryAuxOids(parentrel, &segrelid, NULL, NULL, NULL, NULL); + GetAppendOnlyEntryAuxOids(parentrel, &segrelid, NULL, NULL); Assert(newState >= AOSEG_STATE_USECURRENT && newState <= AOSEG_STATE_AWAITING_DROP); @@ -963,7 +963,7 @@ GetSegFilesTotals(Relation parentrel, Snapshot appendOnlyMetaDataSnapshot) result = (FileSegTotals *) palloc0(sizeof(FileSegTotals)); - GetAppendOnlyEntryAuxOids(parentrel, &segrelid, NULL, NULL, NULL, NULL); + GetAppendOnlyEntryAuxOids(parentrel, &segrelid, NULL, NULL); if (segrelid == InvalidOid) elog(ERROR, "could not find pg_aoseg aux table for AO table \"%s\"", @@ -1082,7 +1082,7 @@ gp_aoseg_history(PG_FUNCTION_ARGS) errmsg("Relation '%s' does not have appendoptimized row-oriented storage", RelationGetRelationName(aocsRel)))); - GetAppendOnlyEntryAuxOids(aocsRel, &segrelid, NULL, NULL, NULL, NULL); + GetAppendOnlyEntryAuxOids(aocsRel, &segrelid, NULL, NULL); pg_aoseg_rel = table_open(segrelid, AccessShareLock); @@ -1234,7 +1234,7 @@ gp_aoseg(PG_FUNCTION_ARGS) errmsg("Relation '%s' does not have appendoptimized row-oriented storage", RelationGetRelationName(aocsRel)))); - GetAppendOnlyEntryAuxOids(aocsRel, &segrelid, NULL, NULL, NULL, NULL); + GetAppendOnlyEntryAuxOids(aocsRel, &segrelid, NULL, NULL); pg_aoseg_rel = table_open(segrelid, AccessShareLock); @@ -1391,7 +1391,7 @@ get_ao_distribution(PG_FUNCTION_ARGS) RelationGetRelationName(parentrel)))); GetAppendOnlyEntryAuxOids(parentrel, - &segrelid, NULL, NULL, NULL, NULL); + &segrelid, NULL, NULL); Assert(OidIsValid(segrelid)); /* @@ -1575,7 +1575,7 @@ aorow_compression_ratio_internal(Relation parentrel) GetAppendOnlyEntryAuxOids(parentrel, &segrelid, - NULL, NULL, NULL, NULL); + NULL, NULL); Assert(OidIsValid(segrelid)); /* diff --git a/src/backend/access/appendonly/appendonly_blkdir_udf.c b/src/backend/access/appendonly/appendonly_blkdir_udf.c index 9e2b6e99ff3..ccf838f8a03 100644 --- a/src/backend/access/appendonly/appendonly_blkdir_udf.c +++ b/src/backend/access/appendonly/appendonly_blkdir_udf.c @@ -98,8 +98,8 @@ gp_aoblkdir(PG_FUNCTION_ARGS) errmsg("function not supported on non append-optimized relation"))); sst = GetLatestSnapshot(); GetAppendOnlyEntryAuxOids(context->aorel, - NULL, &blkdirrelid, NULL, - NULL, NULL); + NULL, &blkdirrelid, + NULL); sst = gp_select_invisible ? SnapshotAny : GetLatestSnapshot(); if (blkdirrelid == InvalidOid) ereport(ERROR, diff --git a/src/backend/access/appendonly/appendonly_compaction.c b/src/backend/access/appendonly/appendonly_compaction.c index 05b2143b246..409ff61b94a 100644 --- a/src/backend/access/appendonly/appendonly_compaction.c +++ b/src/backend/access/appendonly/appendonly_compaction.c @@ -140,13 +140,12 @@ AppendOnlyCompaction_ShouldCompact(Relation aoRelation, AppendOnlyVisimap visiMap; int64 hiddenTupcount; double hideRatio; - Oid visimaprelid; - Oid visimapidxid; + Oid visimaprelid; Assert(RelationStorageIsAO(aoRelation)); GetAppendOnlyEntryAuxOids(aoRelation, - NULL, NULL, NULL, - &visimaprelid, &visimapidxid); + NULL, NULL, + &visimaprelid); if (!gp_appendonly_compaction) { @@ -161,7 +160,6 @@ AppendOnlyCompaction_ShouldCompact(Relation aoRelation, AppendOnlyVisimap_Init(&visiMap, visimaprelid, - visimapidxid, ShareLock, appendOnlyMetaDataSnapshot); hiddenTupcount = AppendOnlyVisimap_GetSegmentFileHiddenTupleCount( @@ -403,7 +401,6 @@ AppendOnlySegmentFileFullCompaction(Relation aorel, int64 tupleCount = 0; int64 tuplePerPage = INT_MAX; Oid visimaprelid; - Oid visimapidxid; Oid blkdirrelid; int64 heap_blks_scanned = 0; @@ -419,12 +416,11 @@ AppendOnlySegmentFileFullCompaction(Relation aorel, relname = RelationGetRelationName(aorel); GetAppendOnlyEntryAuxOids(aorel, - NULL, &blkdirrelid, NULL, - &visimaprelid, &visimapidxid); + NULL, &blkdirrelid, + &visimaprelid); AppendOnlyVisimap_Init(&visiMap, visimaprelid, - visimapidxid, ShareUpdateExclusiveLock, appendOnlyMetaDataSnapshot); @@ -564,7 +560,7 @@ AppendOptimizedCollectDeadSegments(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); @@ -730,7 +726,7 @@ AppendOptimizedTruncateToEOF(Relation aorel, AOVacuumRelStats *vacrelstats) LockDatabaseObject(aorel->rd_node.dbNode, (Oid)aorel->rd_node.relNode, 0, ExclusiveLock); GetAppendOnlyEntryAuxOids(aorel, - &segrelid, NULL, NULL, NULL, NULL); + &segrelid, NULL, NULL); pg_aoseg_rel = heap_open(segrelid, AccessShareLock); pg_aoseg_dsc = RelationGetDescr(pg_aoseg_rel); diff --git a/src/backend/access/appendonly/appendonly_visimap.c b/src/backend/access/appendonly/appendonly_visimap.c index a4599e88f31..8b2ae4c2a79 100644 --- a/src/backend/access/appendonly/appendonly_visimap.c +++ b/src/backend/access/appendonly/appendonly_visimap.c @@ -118,7 +118,6 @@ void AppendOnlyVisimap_Init( AppendOnlyVisimap *visiMap, Oid visimapRelid, - Oid visimapIdxid, LOCKMODE lockmode, Snapshot appendOnlyMetaDataSnapshot) { @@ -126,7 +125,6 @@ AppendOnlyVisimap_Init( Assert(visiMap); Assert(OidIsValid(visimapRelid)); - Assert(OidIsValid(visimapIdxid)); visiMap->memoryContext = AllocSetContextCreate( CurrentMemoryContext, @@ -143,7 +141,6 @@ AppendOnlyVisimap_Init( AppendOnlyVisimapStore_Init(&visiMap->visimapStore, visimapRelid, - visimapIdxid, lockmode, appendOnlyMetaDataSnapshot, visiMap->memoryContext); @@ -318,15 +315,13 @@ void AppendOnlyVisimapScan_Init( AppendOnlyVisimapScan *visiMapScan, Oid visimapRelid, - Oid visimapIdxid, LOCKMODE lockmode, Snapshot appendonlyMetadataSnapshot) { Assert(visiMapScan); Assert(OidIsValid(visimapRelid)); - Assert(OidIsValid(visimapIdxid)); - AppendOnlyVisimap_Init(&visiMapScan->visimap, visimapRelid, visimapIdxid, + AppendOnlyVisimap_Init(&visiMapScan->visimap, visimapRelid, lockmode, appendonlyMetadataSnapshot); visiMapScan->indexScan = AppendOnlyVisimapStore_BeginScan( @@ -929,24 +924,22 @@ void AppendOnlyVisimap_Init_forUniqueCheck( Snapshot snapshot) { Oid visimaprelid; - Oid visimapidxid; Assert(snapshot->snapshot_type == SNAPSHOT_DIRTY || snapshot->snapshot_type == SNAPSHOT_SELF); GetAppendOnlyEntryAuxOids(aoRel, - NULL, NULL, NULL, &visimaprelid, &visimapidxid); - if (!OidIsValid(visimaprelid) || !OidIsValid(visimapidxid)) + NULL, NULL, &visimaprelid); + if (!OidIsValid(visimaprelid)) elog(ERROR, "Could not find block directory for relation: %u", aoRel->rd_id); ereportif(Debug_appendonly_print_visimap, LOG, (errmsg("Append-only visimap init for unique checks"), - errdetail("(aoRel = %u, visimaprel = %u, visimapidxrel = %u)", - aoRel->rd_id, visimaprelid, visimapidxid))); + errdetail("(aoRel = %u, visimaprel = %u)", + aoRel->rd_id, visimaprelid))); AppendOnlyVisimap_Init(visiMap, visimaprelid, - visimapidxid, AccessShareLock, InvalidSnapshot /* appendOnlyMetaDataSnapshot */); } diff --git a/src/backend/access/appendonly/appendonly_visimap_store.c b/src/backend/access/appendonly/appendonly_visimap_store.c index c0c1917a213..ef51e5d1728 100644 --- a/src/backend/access/appendonly/appendonly_visimap_store.c +++ b/src/backend/access/appendonly/appendonly_visimap_store.c @@ -16,6 +16,7 @@ #include "access/genam.h" #include "access/table.h" +#include "catalog/aocatalog.h" #include "catalog/aovisimap.h" #include "catalog/indexing.h" #include "access/appendonly_visimap_store.h" @@ -57,23 +58,26 @@ AppendOnlyVisimapStore_Finish(AppendOnlyVisimapStore *visiMapStore, void AppendOnlyVisimapStore_Init(AppendOnlyVisimapStore *visiMapStore, Oid visimapRelid, - Oid visimapIdxid, LOCKMODE lockmode, Snapshot snapshot, MemoryContext memoryContext) { TupleDesc heapTupleDesc; ScanKey scanKey; + Oid visimapIdxid; Assert(visiMapStore); Assert(CurrentMemoryContext == memoryContext); Assert(OidIsValid(visimapRelid)); - Assert(OidIsValid(visimapIdxid)); visiMapStore->snapshot = snapshot; visiMapStore->memoryContext = memoryContext; visiMapStore->visimapRelation = table_open(visimapRelid, lockmode); + + visimapIdxid = AppendonlyGetAuxIndex(visiMapStore->visimapRelation); + Assert(OidIsValid(visimapIdxid)); + visiMapStore->visimapIndex = index_open(visimapIdxid, lockmode); heapTupleDesc = diff --git a/src/backend/access/appendonly/appendonly_visimap_udf.c b/src/backend/access/appendonly/appendonly_visimap_udf.c index 7d405ec8592..445bfadee31 100644 --- a/src/backend/access/appendonly/appendonly_visimap_udf.c +++ b/src/backend/access/appendonly/appendonly_visimap_udf.c @@ -39,7 +39,6 @@ gp_aovisimap(PG_FUNCTION_ARGS) Datum result; Oid visimaprelid; - Oid visimapidxid; typedef struct Context { Relation aorel; @@ -89,13 +88,12 @@ gp_aovisimap(PG_FUNCTION_ARGS) Snapshot sst = GetLatestSnapshot(); - GetAppendOnlyEntryAuxOids(context->aorel, - NULL, NULL, NULL, - &visimaprelid, &visimapidxid); + GetAppendOnlyEntryAuxOids(context->aorel, + NULL, NULL, + &visimaprelid); AppendOnlyVisimapScan_Init(&context->visiMapScan, visimaprelid, - visimapidxid, AccessShareLock, sst); @@ -147,7 +145,6 @@ gp_aovisimap_hidden_info(PG_FUNCTION_ARGS) HeapTuple tuple; Datum result; Oid visimaprelid; - Oid visimapidxid; typedef struct Context { @@ -170,6 +167,7 @@ gp_aovisimap_hidden_info(PG_FUNCTION_ARGS) TupleDesc tupdesc; MemoryContext oldcontext; Snapshot snapshot; + Oid segrelid; /* create a function context for cross-call persistence */ funcctx = SRF_FIRSTCALL_INIT(); @@ -202,15 +200,13 @@ gp_aovisimap_hidden_info(PG_FUNCTION_ARGS) (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("function not supported on relation"))); - Oid segrelid; snapshot = GetLatestSnapshot(); - GetAppendOnlyEntryAuxOids(context->parentRelation, - &segrelid, NULL, NULL, - &visimaprelid, &visimapidxid); + GetAppendOnlyEntryAuxOids(context->parentRelation, + &segrelid, NULL, + &visimaprelid); AppendOnlyVisimap_Init(&context->visiMap, visimaprelid, - visimapidxid, AccessShareLock, snapshot); @@ -328,7 +324,6 @@ gp_aovisimap_entry(PG_FUNCTION_ARGS) HeapTuple tuple; Datum result; Oid visimaprelid; - Oid visimapidxid; typedef struct Context { @@ -382,15 +377,14 @@ gp_aovisimap_entry(PG_FUNCTION_ARGS) (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("function not supported on relation"))); - Snapshot sst = GetLatestSnapshot(); + Snapshot sst = GetLatestSnapshot(); - GetAppendOnlyEntryAuxOids(context->parentRelation, - NULL, NULL, NULL, - &visimaprelid, &visimapidxid); + GetAppendOnlyEntryAuxOids(context->parentRelation, + NULL, NULL, + &visimaprelid); AppendOnlyVisimap_Init(&context->visiMap, visimaprelid, - visimapidxid, AccessShareLock, sst); diff --git a/src/backend/access/appendonly/appendonlyam.c b/src/backend/access/appendonly/appendonlyam.c index 2f590a8678e..b40cbb76e8b 100755 --- a/src/backend/access/appendonly/appendonlyam.c +++ b/src/backend/access/appendonly/appendonlyam.c @@ -1434,14 +1434,12 @@ appendonly_beginrangescan_internal(Relation relation, if (segfile_count > 0) { Oid visimaprelid; - Oid visimapidxid; GetAppendOnlyEntryAuxOids(relation, - NULL, NULL, NULL, &visimaprelid, &visimapidxid); + NULL, NULL, &visimaprelid); AppendOnlyVisimap_Init(&scan->visibilityMap, visimaprelid, - visimapidxid, AccessShareLock, appendOnlyMetaDataSnapshot); } @@ -2158,7 +2156,6 @@ appendonly_fetch_init(Relation relation, AppendOnlyVisimap_Init(&aoFetchDesc->visibilityMap, aoFormData.visimaprelid, - aoFormData.visimapidxid, AccessShareLock, appendOnlyMetaDataSnapshot); @@ -2419,9 +2416,8 @@ appendonly_delete_init(Relation rel) Assert(!IsolationUsesXactSnapshot()); Oid visimaprelid; - Oid visimapidxid; - GetAppendOnlyEntryAuxOids(rel, NULL, NULL, NULL, &visimaprelid, &visimapidxid); + GetAppendOnlyEntryAuxOids(rel, NULL, NULL, &visimaprelid); AppendOnlyDeleteDesc aoDeleteDesc = palloc0(sizeof(AppendOnlyDeleteDescData)); @@ -2430,7 +2426,6 @@ appendonly_delete_init(Relation rel) AppendOnlyVisimap_Init(&aoDeleteDesc->visibilityMap, visimaprelid, - visimapidxid, RowExclusiveLock, aoDeleteDesc->appendOnlyMetaDataSnapshot); @@ -2698,7 +2693,7 @@ appendonly_insert_init(Relation rel, int segno) Assert(aoInsertDesc->fsInfo->segno == segno); GetAppendOnlyEntryAuxOids(aoInsertDesc->aoi_rel, &aoInsertDesc->segrelid, - NULL, NULL, NULL, NULL); + NULL, NULL); firstSequence = GetFastSequences(aoInsertDesc->segrelid, segno, aoInsertDesc->rowCount + 1, NUM_FAST_SEQUENCES); diff --git a/src/backend/access/appendonly/appendonlyam_handler.c b/src/backend/access/appendonly/appendonlyam_handler.c index 0136d4a850f..4be7273b4de 100644 --- a/src/backend/access/appendonly/appendonlyam_handler.c +++ b/src/backend/access/appendonly/appendonlyam_handler.c @@ -1010,7 +1010,7 @@ appendonly_multi_insert(Relation relation, TupleTableSlot **slots, int ntuples, { int64 firstSequence; Oid segrelid; - GetAppendOnlyEntryAuxOids(insertDesc->aoi_rel, &segrelid, NULL, NULL, NULL, NULL); + GetAppendOnlyEntryAuxOids(insertDesc->aoi_rel, &segrelid, NULL, NULL); firstSequence = GetFastSequences(segrelid, insertDesc->cur_segno, insertDesc->lastSequence + 1, NUM_FAST_SEQUENCES); Assert(firstSequence == insertDesc->lastSequence + 1); insertDesc->numSequences = NUM_FAST_SEQUENCES; @@ -1232,8 +1232,8 @@ appendonly_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); @@ -1632,10 +1632,9 @@ appendonly_index_build_range_scan(Relation heapRelation, * If block directory is empty, it must also be built along with the index. */ Oid blkdirrelid; - Oid blkidxrelid; GetAppendOnlyEntryAuxOids(aoscan->aos_rd, NULL, - &blkdirrelid, &blkidxrelid, NULL, NULL); + &blkdirrelid, 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 @@ -1850,7 +1849,7 @@ appendonly_relation_size(Relation rel, ForkNumber forkNumber) result = 0; GetAppendOnlyEntryAuxOids(rel, &segrelid, NULL, - NULL, NULL, NULL); + NULL); if (segrelid == InvalidOid) elog(ERROR, "could not find pg_aoseg aux table for AO table \"%s\"", @@ -1934,7 +1933,7 @@ appendonly_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)); } diff --git a/src/backend/access/appendonly/appendonlyblockdirectory.c b/src/backend/access/appendonly/appendonlyblockdirectory.c index b6a9b17991d..caee9a85edc 100644 --- a/src/backend/access/appendonly/appendonlyblockdirectory.c +++ b/src/backend/access/appendonly/appendonlyblockdirectory.c @@ -17,6 +17,7 @@ #include "access/xact.h" #include "cdb/cdbappendonlyblockdirectory.h" #include "catalog/aoblkdir.h" +#include "catalog/aocatalog.h" #include "catalog/pg_appendonly.h" #include "access/heapam.h" #include "access/genam.h" @@ -181,11 +182,10 @@ AppendOnlyBlockDirectory_Init_forSearch( Oid blkdiridxid; blockDirectory->aoRel = aoRel; - GetAppendOnlyEntryAuxOids(aoRel, NULL, &blkdirrelid, &blkdiridxid, NULL, NULL); + GetAppendOnlyEntryAuxOids(aoRel, NULL, &blkdirrelid, NULL); if (!OidIsValid(blkdirrelid)) { - Assert(!OidIsValid(blkdiridxid)); blockDirectory->blkdirRel = NULL; blockDirectory->blkdirIdx = NULL; @@ -212,6 +212,7 @@ AppendOnlyBlockDirectory_Init_forSearch( blockDirectory->blkdirRel = heap_open(blkdirrelid, AccessShareLock); + blkdiridxid = AppendonlyGetAuxIndex(blockDirectory->blkdirRel); Assert(OidIsValid(blkdiridxid)); blockDirectory->blkdirIdx = @@ -252,16 +253,11 @@ AppendOnlyBlockDirectory_Init_forUniqueChecks( snapshot->snapshot_type == SNAPSHOT_SELF); GetAppendOnlyEntryAuxOids(aoRel, - NULL, &blkdirrelid, &blkdiridxid, NULL, NULL); + NULL, &blkdirrelid, NULL); - if (!OidIsValid(blkdirrelid) || !OidIsValid(blkdiridxid)) + if (!OidIsValid(blkdirrelid)) elog(ERROR, "Could not find block directory for relation: %u", aoRel->rd_id); - ereportif(Debug_appendonly_print_blockdirectory, LOG, - (errmsg("Append-only block directory init for unique checks"), - errdetail("(aoRel = %u, blkdirrel = %u, blkdiridxrel = %u, numColumnGroups = %d)", - aoRel->rd_id, blkdirrelid, blkdiridxid, numColumnGroups))); - blockDirectory->aoRel = aoRel; blockDirectory->isAOCol = RelationIsAoCols(aoRel); @@ -277,6 +273,15 @@ AppendOnlyBlockDirectory_Init_forUniqueChecks( blockDirectory->proj = NULL; blockDirectory->blkdirRel = heap_open(blkdirrelid, AccessShareLock); + + blkdiridxid = AppendonlyGetAuxIndex(blockDirectory->blkdirRel); + Assert(OidIsValid(blkdiridxid)); + + ereportif(Debug_appendonly_print_blockdirectory, LOG, + (errmsg("Append-only block directory init for unique checks"), + errdetail("(aoRel = %u, blkdirrel = %u, blkdiridxrel = %u, numColumnGroups = %d)", + aoRel->rd_id, blkdirrelid, blkdiridxid, numColumnGroups))); + blockDirectory->blkdirIdx = index_open(blkdiridxid, AccessShareLock); init_internal(blockDirectory); @@ -309,11 +314,10 @@ AppendOnlyBlockDirectory_Init_forInsert( blockDirectory->aoRel = aoRel; blockDirectory->appendOnlyMetaDataSnapshot = appendOnlyMetaDataSnapshot; - GetAppendOnlyEntryAuxOids(aoRel, NULL, &blkdirrelid, &blkdiridxid, NULL, NULL); + GetAppendOnlyEntryAuxOids(aoRel, NULL, &blkdirrelid, NULL); if (!OidIsValid(blkdirrelid)) { - Assert(!OidIsValid(blkdiridxid)); blockDirectory->blkdirRel = NULL; blockDirectory->blkdirIdx = NULL; @@ -334,6 +338,7 @@ AppendOnlyBlockDirectory_Init_forInsert( blockDirectory->blkdirRel = heap_open(blkdirrelid, RowExclusiveLock); + blkdiridxid = AppendonlyGetAuxIndex(blockDirectory->blkdirRel); Assert(OidIsValid(blkdiridxid)); blockDirectory->blkdirIdx = @@ -378,11 +383,10 @@ AppendOnlyBlockDirectory_Init_addCol( blockDirectory->aoRel = aoRel; blockDirectory->appendOnlyMetaDataSnapshot = appendOnlyMetaDataSnapshot; - GetAppendOnlyEntryAuxOids(aoRel, NULL, &blkdirrelid, &blkdiridxid, NULL, NULL); + GetAppendOnlyEntryAuxOids(aoRel, NULL, &blkdirrelid, NULL); if (!OidIsValid(blkdirrelid)) { - Assert(!OidIsValid(blkdiridxid)); blockDirectory->blkdirRel = NULL; blockDirectory->blkdirIdx = NULL; blockDirectory->numColumnGroups = 0; @@ -410,6 +414,7 @@ AppendOnlyBlockDirectory_Init_addCol( blockDirectory->blkdirRel = heap_open(blkdirrelid, RowExclusiveLock); + blkdiridxid = AppendonlyGetAuxIndex(blockDirectory->blkdirRel); Assert(OidIsValid(blkdiridxid)); blockDirectory->blkdirIdx = @@ -1029,13 +1034,16 @@ AppendOnlyBlockDirectory_DeleteSegmentFile(Relation aoRel, Oid blkdirrelid; Oid blkdiridxid; - GetAppendOnlyEntryAuxOids(aoRel, NULL, &blkdirrelid, &blkdiridxid, NULL, NULL); + GetAppendOnlyEntryAuxOids(aoRel, NULL, &blkdirrelid, NULL); Assert(OidIsValid(blkdirrelid)); - Assert(OidIsValid(blkdiridxid)); Relation blkdirRel = table_open(blkdirrelid, RowExclusiveLock); + + blkdiridxid = AppendonlyGetAuxIndex(blkdirRel); + Assert(OidIsValid(blkdiridxid)); Relation blkdirIdx = index_open(blkdiridxid, RowExclusiveLock); + ScanKeyData scanKey; SysScanDesc indexScan; HeapTuple tuple; diff --git a/src/backend/access/appendonly/appendonlywriter.c b/src/backend/access/appendonly/appendonlywriter.c index 048ce295416..6dc3e306761 100644 --- a/src/backend/access/appendonly/appendonlywriter.c +++ b/src/backend/access/appendonly/appendonlywriter.c @@ -143,7 +143,7 @@ LockSegnoForWrite(Relation rel, int segno) appendOnlyMetaDataSnapshot = RegisterSnapshot(GetCatalogSnapshot(InvalidOid)); GetAppendOnlyEntryAuxOids(rel, - &segrelid, NULL, NULL, NULL, NULL); + &segrelid, NULL, NULL); /* * Now pick a segment that is not in use, and is not over the allowed * size threshold (90% full). @@ -435,7 +435,7 @@ choose_segno_internal(Relation rel, List *avoid_segnos, choose_segno_mode mode) } GetAppendOnlyEntryAuxOids(rel, - &segrelid, NULL, NULL, NULL, NULL); + &segrelid, NULL, NULL); /* * Now pick a segment that is not in use, and is not over the allowed @@ -695,7 +695,7 @@ choose_new_segfile(Relation rel, bool *used, List *avoid_segnos) appendOnlyMetaDataSnapshot = RegisterSnapshot(GetCatalogSnapshot(InvalidOid)); GetAppendOnlyEntryAuxOids(rel, - &segrelid, NULL, NULL, NULL, NULL); + &segrelid, NULL, NULL); UnregisterSnapshot(appendOnlyMetaDataSnapshot); InsertInitialAOCSFileSegInfo(rel, chosen_segno, diff --git a/src/backend/catalog/aocatalog.c b/src/backend/catalog/aocatalog.c index 2fbf6c050c4..7cec9817286 100644 --- a/src/backend/catalog/aocatalog.c +++ b/src/backend/catalog/aocatalog.c @@ -85,17 +85,22 @@ CreateAOAuxiliaryTable( switch(relkind) { case RELKIND_AOVISIMAP: - GetAppendOnlyEntryAuxOids(rel, NULL, - NULL, NULL, &aoauxiliary_relid, &aoauxiliary_idxid); + GetAppendOnlyEntryAuxOids(rel, + NULL, + NULL, + &aoauxiliary_relid); break; case RELKIND_AOBLOCKDIR: - GetAppendOnlyEntryAuxOids(rel, NULL, - &aoauxiliary_relid, &aoauxiliary_idxid, NULL, NULL); + GetAppendOnlyEntryAuxOids(rel, + NULL, + &aoauxiliary_relid, + NULL); break; case RELKIND_AOSEGMENTS: GetAppendOnlyEntryAuxOids(rel, - &aoauxiliary_relid, - NULL, NULL, NULL, NULL); + &aoauxiliary_relid, + NULL, + NULL); break; default: elog(ERROR, "unsupported auxiliary relkind '%c'", relkind); @@ -196,13 +201,13 @@ CreateAOAuxiliaryTable( { case RELKIND_AOVISIMAP: UpdateAppendOnlyEntryAuxOids(relOid, InvalidOid, - InvalidOid, InvalidOid, - aoauxiliary_relid, aoauxiliary_idxid); + InvalidOid, + aoauxiliary_relid); break; case RELKIND_AOBLOCKDIR: UpdateAppendOnlyEntryAuxOids(relOid, InvalidOid, - aoauxiliary_relid, aoauxiliary_idxid, - InvalidOid, InvalidOid); + aoauxiliary_relid, + InvalidOid); break; case RELKIND_AOSEGMENTS: /* Add initial entries in gp_fastsequence */ @@ -210,7 +215,6 @@ CreateAOAuxiliaryTable( UpdateAppendOnlyEntryAuxOids(relOid, aoauxiliary_relid, - InvalidOid, InvalidOid, InvalidOid, InvalidOid); break; default: diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 7e9291e2bc4..7cf3fdc37e1 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -1795,8 +1795,6 @@ heap_create_with_catalog(const char *relname, InvalidOid, InvalidOid, InvalidOid, - InvalidOid, - InvalidOid, AORelationVersion_GetLatest()); } diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index d754d97c781..de7c71ab93f 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -4211,8 +4211,8 @@ reindex_relation(Oid relid, int flags, ReindexParams *params) if ((flags & REINDEX_REL_PROCESS_TOAST) && relIsAO) GetAppendOnlyEntryAuxOids(rel, &aoseg_relid, - &aoblkdir_relid, NULL, - &aovisimap_relid, NULL); + &aoblkdir_relid, + &aovisimap_relid); /* * Close rel, but continue to hold the lock. diff --git a/src/backend/catalog/pg_appendonly.c b/src/backend/catalog/pg_appendonly.c index 2ab8ec502ce..ff3a6c2a2a1 100644 --- a/src/backend/catalog/pg_appendonly.c +++ b/src/backend/catalog/pg_appendonly.c @@ -56,9 +56,7 @@ InsertAppendOnlyEntry(Oid relid, char* compresstype, Oid segrelid, Oid blkdirrelid, - Oid blkdiridxid, Oid visimaprelid, - Oid visimapidxid, int16 version) { Relation pg_appendonly_rel; @@ -98,10 +96,7 @@ InsertAppendOnlyEntry(Oid relid, values[Anum_pg_appendonly_segfilecount- 1] = Int16GetDatum(0); values[Anum_pg_appendonly_version - 1] = Int16GetDatum(version); values[Anum_pg_appendonly_blkdirrelid - 1] = ObjectIdGetDatum(blkdirrelid); - values[Anum_pg_appendonly_blkdiridxid - 1] = ObjectIdGetDatum(blkdiridxid); values[Anum_pg_appendonly_visimaprelid - 1] = ObjectIdGetDatum(visimaprelid); - values[Anum_pg_appendonly_visimapidxid - 1] = ObjectIdGetDatum(visimapidxid); - /* * form the tuple and insert it @@ -184,9 +179,7 @@ void GetAppendOnlyEntryAuxOids(Relation rel, Oid *segrelid, Oid *blkdirrelid, - Oid *blkdiridxid, - Oid *visimaprelid, - Oid *visimapidxid) + Oid *visimaprelid) { Form_pg_appendonly aoForm; @@ -201,14 +194,8 @@ GetAppendOnlyEntryAuxOids(Relation rel, if (blkdirrelid != NULL) *blkdirrelid = aoForm->blkdirrelid; - if (blkdiridxid != NULL) - *blkdiridxid = aoForm->blkdiridxid; - if (visimaprelid != NULL) *visimaprelid = aoForm->visimaprelid; - - if (visimapidxid != NULL) - *visimapidxid = aoForm->visimapidxid; } /* @@ -239,9 +226,7 @@ void UpdateAppendOnlyEntryAuxOids(Oid relid, Oid newSegrelid, Oid newBlkdirrelid, - Oid newBlkdiridxid, - Oid newVisimaprelid, - Oid newVisimapidxid) + Oid newVisimaprelid) { Relation pg_appendonly; ScanKeyData key[1]; @@ -287,23 +272,12 @@ UpdateAppendOnlyEntryAuxOids(Oid relid, newValues[Anum_pg_appendonly_blkdirrelid - 1] = newBlkdirrelid; } - if (OidIsValid(newBlkdiridxid)) - { - replace[Anum_pg_appendonly_blkdiridxid - 1] = true; - newValues[Anum_pg_appendonly_blkdiridxid - 1] = newBlkdiridxid; - } - if (OidIsValid(newVisimaprelid)) { replace[Anum_pg_appendonly_visimaprelid - 1] = true; newValues[Anum_pg_appendonly_visimaprelid - 1] = newVisimaprelid; } - if (OidIsValid(newVisimapidxid)) - { - replace[Anum_pg_appendonly_visimapidxid - 1] = true; - newValues[Anum_pg_appendonly_visimapidxid - 1] = newVisimapidxid; - } newTuple = heap_modify_tuple(tuple, RelationGetDescr(pg_appendonly), newValues, newNulls, replace); CatalogTupleUpdate(pg_appendonly, &newTuple->t_self, newTuple); @@ -788,8 +762,7 @@ GetAppendOnlySegmentFilesCount(Relation rel) int16 result = 0; Oid segrelid = InvalidOid; - GetAppendOnlyEntryAuxOids(rel, &segrelid, NULL, - NULL, NULL, NULL); + GetAppendOnlyEntryAuxOids(rel, &segrelid, NULL, NULL); if (segrelid == InvalidOid) elog(ERROR, "could not find pg_aoseg aux table for AO table \"%s\"", RelationGetRelationName(rel)); diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 2065667ce42..4c4246dcd26 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -848,7 +848,7 @@ DefineIndex(Oid relationId, rel = table_open(relationId, NoLock); if (RelationStorageIsAO(rel)) { - GetAppendOnlyEntryAuxOids(rel, NULL, &blkdirrelid, NULL, NULL, NULL); + GetAppendOnlyEntryAuxOids(rel, NULL, &blkdirrelid, NULL); if (!OidIsValid(blkdirrelid)) lockmode = ShareRowExclusiveLock; /* Relation is AO, and has no block directory */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 573c57af8de..cb2d391e903 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -2041,8 +2041,7 @@ ao_aux_tables_safe_truncate(Relation rel) Oid aovisimap_relid = InvalidOid; GetAppendOnlyEntryAuxOids(rel, &aoseg_relid, - &aoblkdir_relid, NULL, &aovisimap_relid, - NULL); + &aoblkdir_relid, &aovisimap_relid); relid_set_new_relfilenode(aoseg_relid); relid_set_new_relfilenode(aoblkdir_relid); @@ -15814,8 +15813,8 @@ ATExecChangeOwner(Oid relationOid, Oid newOwnerId, bool recursing, LOCKMODE lock Oid visimap_relid; GetAppendOnlyEntryAuxOids(target_rel, &segrelid, - &blkdirrelid, NULL, - &visimap_relid, NULL); + &blkdirrelid, + &visimap_relid); /* If it has an AO segment table, recurse to change its * ownership */ @@ -16438,8 +16437,8 @@ ATExecSetTableSpace(Oid tableOid, Oid newTableSpace, LOCKMODE lockmode) if (RelationStorageIsAO(rel)) GetAppendOnlyEntryAuxOids(rel, &relaosegrelid, - &relaoblkdirrelid, &relaoblkdiridxid, - &relaovisimaprelid, &relaovisimapidxid); + &relaoblkdirrelid, + &relaovisimaprelid); /* Get the bitmap sub objects */ if (RelationIsBitmapIndex(rel)) @@ -16509,14 +16508,30 @@ ATExecSetTableSpace(Oid tableOid, Oid newTableSpace, LOCKMODE lockmode) if (OidIsValid(relaosegrelid)) ATExecSetTableSpace(relaosegrelid, newTableSpace, lockmode); if (OidIsValid(relaoblkdirrelid)) + { + Relation aoblkdir_rel = relation_open(relaoblkdirrelid, lockmode); + + relaoblkdiridxid = AppendonlyGetAuxIndex(aoblkdir_rel); + Assert(OidIsValid(relaoblkdiridxid)); + ATExecSetTableSpace(relaoblkdirrelid, newTableSpace, lockmode); - if (OidIsValid(relaoblkdiridxid)) ATExecSetTableSpace(relaoblkdiridxid, newTableSpace, lockmode); + + relation_close(aoblkdir_rel, lockmode); + } if (OidIsValid(relaovisimaprelid)) + { + Relation aovisimap_rel = relation_open(relaovisimaprelid, lockmode); + + relaovisimapidxid = AppendonlyGetAuxIndex(aovisimap_rel); + Assert(OidIsValid(relaovisimapidxid)); + ATExecSetTableSpace(relaovisimaprelid, newTableSpace, lockmode); - if (OidIsValid(relaovisimapidxid)) ATExecSetTableSpace(relaovisimapidxid, newTableSpace, lockmode); + relation_close(aovisimap_rel, lockmode); + } + /* * MPP-7996 - bitmap index subobjects w/Alter Table Set tablespace */ diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index c113f274b81..5c1aaf487f7 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -1160,8 +1160,8 @@ expand_vacuum_rel(VacuumRelation *vrel, int options) GetAppendOnlyEntryAuxOids(aorel, &aoseg_relid, - &aoblkdir_relid, NULL, - &aovisimap_relid, NULL); + &aoblkdir_relid, + &aovisimap_relid); /* make new VacuumRelations for each valid member of the 3 auxiliary tables */ if (OidIsValid(aoseg_relid)) @@ -2560,8 +2560,8 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params, Assert(!(params->options & VACOPT_AO_AUX_ONLY)); GetAppendOnlyEntryAuxOids(rel, &aoseg_relid, - &aoblkdir_relid, NULL, - &aovisimap_relid, NULL); + &aoblkdir_relid, + &aovisimap_relid); } /* diff --git a/src/backend/commands/vacuum_ao.c b/src/backend/commands/vacuum_ao.c index 466fe30665d..1085510f7e8 100644 --- a/src/backend/commands/vacuum_ao.c +++ b/src/backend/commands/vacuum_ao.c @@ -726,7 +726,6 @@ vacuum_appendonly_fill_stats(Relation aorel, Snapshot snapshot, int elevel, int64 hidden_tupcount; AppendOnlyVisimap visimap; Oid visimaprelid; - Oid visimapidxid; Assert(RelationStorageIsAO(aorel)); @@ -748,12 +747,11 @@ vacuum_appendonly_fill_stats(Relation aorel, Snapshot snapshot, int elevel, nblocks = (uint32)RelationGetNumberOfBlocks(aorel); GetAppendOnlyEntryAuxOids(aorel, - NULL, NULL, NULL, - &visimaprelid, &visimapidxid); + NULL, NULL, + &visimaprelid); AppendOnlyVisimap_Init(&visimap, visimaprelid, - visimapidxid, AccessShareLock, snapshot); hidden_tupcount = AppendOnlyVisimap_GetRelationHiddenTupleCount(&visimap); diff --git a/src/backend/utils/adt/dbsize.c b/src/backend/utils/adt/dbsize.c index e41dc619b89..5d73f1660b5 100644 --- a/src/backend/utils/adt/dbsize.c +++ b/src/backend/utils/adt/dbsize.c @@ -645,8 +645,8 @@ calculate_table_size(Relation rel) { Oid auxRelIds[3]; GetAppendOnlyEntryAuxOids(rel, &auxRelIds[0], - &auxRelIds[1], NULL, - &auxRelIds[2], NULL); + &auxRelIds[1], + &auxRelIds[2]); for (int i = 0; i < 3; i++) { diff --git a/src/include/access/appendonly_visimap.h b/src/include/access/appendonly_visimap.h index 1896395031a..50b155ae289 100644 --- a/src/include/access/appendonly_visimap.h +++ b/src/include/access/appendonly_visimap.h @@ -108,7 +108,6 @@ typedef struct AppendOnlyVisimapDelete void AppendOnlyVisimap_Init( AppendOnlyVisimap *visiMap, Oid visimapRelid, - Oid visimalIdxid, LOCKMODE lockmode, Snapshot appendonlyMetaDataSnapshot); @@ -134,7 +133,6 @@ int64 AppendOnlyVisimap_GetRelationHiddenTupleCount( void AppendOnlyVisimapScan_Init( AppendOnlyVisimapScan *visiMapScan, Oid visimapRelid, - Oid visimapIdxid, LOCKMODE lockmode, Snapshot appendonlyMetadataSnapshot); diff --git a/src/include/access/appendonly_visimap_store.h b/src/include/access/appendonly_visimap_store.h index f4d4e9c30a3..91f3e61abe7 100644 --- a/src/include/access/appendonly_visimap_store.h +++ b/src/include/access/appendonly_visimap_store.h @@ -56,7 +56,6 @@ typedef struct AppendOnlyVisimapStore void AppendOnlyVisimapStore_Init( AppendOnlyVisimapStore *visiMapStore, Oid visimapRelId, - Oid visimapIdxId, LOCKMODE lockmode, Snapshot snapshot, MemoryContext memoryContext); diff --git a/src/include/catalog/aocatalog.h b/src/include/catalog/aocatalog.h index 9b5f24debe8..1e5d2708506 100644 --- a/src/include/catalog/aocatalog.h +++ b/src/include/catalog/aocatalog.h @@ -19,6 +19,23 @@ #include "catalog/heap.h" #include "catalog/index.h" +/* + * Convenient function to get the index of the AO/CO auxiliary tables. + * Currently, this is only used for aoblkdir and aovisimap relations + * which have one and only one index. Asserting the same in order to + * make sure the caller knows what they are doing. + */ +static inline Oid +AppendonlyGetAuxIndex(Relation rel) +{ + List *oids; + + oids = RelationGetIndexList(rel); + Assert(oids->length == 1); + + return linitial_oid(oids); +} + extern bool CreateAOAuxiliaryTable(Relation rel, const char *auxiliaryNamePrefix, char relkind, diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h index 86910a0dada..54d9f3da5ed 100644 --- a/src/include/catalog/catversion.h +++ b/src/include/catalog/catversion.h @@ -56,6 +56,6 @@ */ /* 3yyymmddN */ -#define CATALOG_VERSION_NO 302502091 +#define CATALOG_VERSION_NO 302503261 #endif diff --git a/src/include/catalog/pg_appendonly.h b/src/include/catalog/pg_appendonly.h index d73b0661990..78616ca9f06 100644 --- a/src/include/catalog/pg_appendonly.h +++ b/src/include/catalog/pg_appendonly.h @@ -36,9 +36,7 @@ CATALOG(pg_appendonly,6105,AppendOnlyRelationId) int16 segfilecount; /* the (per seg) average total number of segment file */ int16 version; /* AO relation version see AORelationVersion for detail */ Oid blkdirrelid; /* OID of aoblkdir table; 0 if none */ - Oid blkdiridxid; /* if aoblkdir table, OID of aoblkdir index */ Oid visimaprelid; /* OID of the aovisimap table */ - Oid visimapidxid; /* OID of aovisimap index */ } FormData_pg_appendonly; /* GPDB added foreign key definitions for gpcheckcat. */ @@ -49,7 +47,7 @@ FOREIGN_KEY(relid REFERENCES pg_class(oid)); * (there are no var-length fields currentl.) */ #define APPENDONLY_TUPLE_SIZE \ - (offsetof(FormData_pg_appendonly,visimapidxid) + sizeof(Oid)) + (offsetof(FormData_pg_appendonly,visimaprelid) + sizeof(Oid)) /* ---------------- * Form_pg_appendonly corresponds to a pointer to a tuple with @@ -127,9 +125,7 @@ InsertAppendOnlyEntry(Oid relid, char* compresstype, Oid segrelid, Oid blkdirrelid, - Oid blkdiridxid, Oid visimaprelid, - Oid visimapidxid, int16 version); void @@ -150,9 +146,7 @@ void GetAppendOnlyEntryAuxOids(Relation rel, Oid *segrelid, Oid *blkdirrelid, - Oid *blkdiridxid, - Oid *visimaprelid, - Oid *visimapidxid); + Oid *visimaprelid); void GetAppendOnlyEntry(Relation rel, Form_pg_appendonly aoEntry); @@ -164,9 +158,7 @@ extern void UpdateAppendOnlyEntryAuxOids(Oid relid, Oid newSegrelid, Oid newBlkdirrelid, - Oid newBlkdiridxid, - Oid newVisimaprelid, - Oid newVisimapidxid); + Oid newVisimaprelid); extern void RemoveAppendonlyEntry(Oid relid); diff --git a/src/include/cdb/cdbaocsam.h b/src/include/cdb/cdbaocsam.h index 333f40fc639..8958e8e921c 100644 --- a/src/include/cdb/cdbaocsam.h +++ b/src/include/cdb/cdbaocsam.h @@ -65,7 +65,6 @@ typedef struct AOCSInsertDescData Oid segrelid; Oid blkdirrelid; Oid visimaprelid; - Oid visimapidxid; struct DatumStreamWrite **ds; AppendOnlyBlockDirectory blockDirectory; diff --git a/src/test/regress/expected/uao_catalog_tables.out b/src/test/regress/expected/uao_catalog_tables.out index 22ceb05072d..082e69a8bff 100644 --- a/src/test/regress/expected/uao_catalog_tables.out +++ b/src/test/regress/expected/uao_catalog_tables.out @@ -31,10 +31,10 @@ $$ LANGUAGE plpgsql; -- Verify empty visimap for uao table create table uao_table_check_empty_visimap (i int, j varchar(20), k int ) with (appendonly=true) DISTRIBUTED BY (i); insert into uao_table_check_empty_visimap values(1,'test',2); -SELECT 1 FROM pg_appendonly WHERE visimapidxid is not NULL AND visimapidxid is not NULL AND relid='uao_table_check_empty_visimap'::regclass; - ?column? ----------- - 1 +SELECT count(i.indexrelid) FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND a.relid='uao_table_check_empty_visimap'::regclass; + count +------- + 1 (1 row) -- Verify GUC select_invisible=true for uao tables diff --git a/src/test/regress/expected/uaocs_catalog_tables.out b/src/test/regress/expected/uaocs_catalog_tables.out index d7bd3dfab0b..b38c93d10b9 100644 --- a/src/test/regress/expected/uaocs_catalog_tables.out +++ b/src/test/regress/expected/uaocs_catalog_tables.out @@ -18,10 +18,10 @@ $$ LANGUAGE plpgsql; -- Verify empty visimap for uaocs table create table uaocs_table_check_empty_visimap (i int, j varchar(20), k int ) with (appendonly=true, orientation=column) DISTRIBUTED BY (i); insert into uaocs_table_check_empty_visimap values(1,'test',2); -select 1 from pg_appendonly where visimapidxid is not null and visimapidxid is not NULL and relid='uaocs_table_check_empty_visimap'::regclass; - ?column? ----------- - 1 +SELECT count(i.indexrelid) FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND a.relid='uaocs_table_check_empty_visimap'::regclass; + count +------- + 1 (1 row) -- Verify the hidden tup_count using UDF gp_aovisimap_hidden_info(oid) for uaocs relation after delete and vacuum diff --git a/src/test/regress/input/gp_tablespace.source b/src/test/regress/input/gp_tablespace.source index e7ca7263a40..2dd18f05299 100644 --- a/src/test/regress/input/gp_tablespace.source +++ b/src/test/regress/input/gp_tablespace.source @@ -21,11 +21,11 @@ BEGIN when 'blockdir' then select blkdirrelid into relation_id from pg_appendonly where relid = aotablename; when 'blockdirindex' then - select blkdiridxid into relation_id from pg_appendonly where relid = aotablename; + select i.indexrelid into relation_id from pg_appendonly a, pg_index i where a.blkdirrelid = i.indrelid and relid = aotablename; when 'visimap' then select visimaprelid into relation_id from pg_appendonly where relid = aotablename; when 'visimapindex' then - select visimapidxid into relation_id from pg_appendonly where relid = aotablename; + select i.indexrelid into relation_id from pg_appendonly a, pg_index i where a.visimaprelid = i.indrelid and relid = aotablename; else raise notice 'Invalid tabletype for has_init_file %', tabletype; return false; diff --git a/src/test/regress/input/uao_ddl/alter_ao_part_exch.source b/src/test/regress/input/uao_ddl/alter_ao_part_exch.source index e09c4a27878..a296fbd2518 100644 --- a/src/test/regress/input/uao_ddl/alter_ao_part_exch.source +++ b/src/test/regress/input/uao_ddl/alter_ao_part_exch.source @@ -26,8 +26,8 @@ insert into ao_part(col1, col2, col3) values analyze ao_part; -select count(*) FROM pg_appendonly WHERE visimapidxid is not NULL AND -visimapidxid is not NULL AND relid in (SELECT c.oid FROM pg_class c +select count(*) FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND +a.relid in (SELECT c.oid FROM pg_class c inner join pg_namespace n ON c.relnamespace = n.oid and c.relname like 'ao_part%' and n.nspname = 'alter_ao_part_exch_@amname@'); diff --git a/src/test/regress/input/uao_ddl/alter_ao_part_tables.source b/src/test/regress/input/uao_ddl/alter_ao_part_tables.source index 02acc907ed8..e01f45a30ae 100644 --- a/src/test/regress/input/uao_ddl/alter_ao_part_tables.source +++ b/src/test/regress/input/uao_ddl/alter_ao_part_tables.source @@ -144,14 +144,16 @@ select count(*) as all_tuples from sto_altap2; set gp_select_invisible=false; -- Check that visimaps were created properly -select distinct a.visimaprelid is not NULL, a.visimapidxid is not NULL - from pg_appendonly a inner join pg_class c on a.relid = c.oid and +select distinct a.visimaprelid is not NULL, i.indexrelid is not NULL + from pg_appendonly a inner join pg_class c on a.relid = c.oid + inner join pg_index i on a.visimaprelid = i.indrelid and c.relname like 'sto_alt%'; -- Drop partition table, check pg_appendonly drop table sto_altap2; -select distinct a.visimaprelid is NULL, a.visimapidxid is NULL - from pg_appendonly a inner join pg_class c on a.relid = c.oid and +select distinct a.visimaprelid is not NULL, i.indexrelid is not NULL + from pg_appendonly a inner join pg_class c on a.relid = c.oid + inner join pg_index i on a.visimaprelid = i.indrelid and c.relname like 'sto_altap2%'; -- Validate that the state needed by appendoptimized AM is correctly diff --git a/src/test/regress/input/uao_ddl/alter_ao_part_tables_splitpartition.source b/src/test/regress/input/uao_ddl/alter_ao_part_tables_splitpartition.source index 39018811bc4..c9d2f3039dc 100644 --- a/src/test/regress/input/uao_ddl/alter_ao_part_tables_splitpartition.source +++ b/src/test/regress/input/uao_ddl/alter_ao_part_tables_splitpartition.source @@ -10,8 +10,8 @@ CREATE TABLE sto_alt_uao_part_splitpartition ( PARTITION sales_Sep13 START (date '2013-09-01') INCLUSIVE END (date '2014-01-01') EXCLUSIVE); -SELECT 1 AS VisimapPresent FROM pg_appendonly WHERE visimaprelid is -not NULL AND visimapidxid is not NULL AND relid in (SELECT c.oid FROM +SELECT count(i.indexrelid) AS VisimapCount FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND +a.relid in (SELECT c.oid FROM pg_class c join pg_namespace n on c.relnamespace = n.oid and c.relname like 'sto_alt_uao_part_splitpartition%' and n.nspname = 'alter_ao_part_tables_splitpartition_@amname@'); @@ -26,8 +26,8 @@ select count(*) from sto_alt_uao_part_splitpartition; -- Alter table add default partition Alter table sto_alt_uao_part_splitpartition add default partition part_others; -select count(*) FROM pg_appendonly WHERE visimaprelid is not NULL AND -visimapidxid is not NULL AND relid in (SELECT c.oid FROM pg_class c +SELECT count(i.indexrelid) FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND +a.relid in (SELECT c.oid FROM pg_class c join pg_namespace n on c.relnamespace = n.oid and c.relname like 'sto_alt_uao_part_splitpartition%' and n.nspname = 'alter_ao_part_tables_splitpartition_@amname@'); @@ -46,8 +46,8 @@ Alter table sto_alt_uao_part_splitpartition split default partition start(date '2013-01-01') end(date '2013-03-01') into (partition p1, partition part_others); -select count(*) FROM pg_appendonly WHERE visimaprelid is not NULL AND -visimapidxid is not NULL AND relid in (SELECT c.oid FROM pg_class c +SELECT count(i.indexrelid) FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND +a.relid in (SELECT c.oid FROM pg_class c join pg_namespace n on c.relnamespace = n.oid and c.relname like 'sto_alt_uao_part_splitpartition%' and n.nspname = 'alter_ao_part_tables_splitpartition_@amname@'); diff --git a/src/test/regress/input/uao_ddl/alter_ao_table_col_ddl.source b/src/test/regress/input/uao_ddl/alter_ao_table_col_ddl.source index b7f983bce6a..7a9419ddc89 100644 --- a/src/test/regress/input/uao_ddl/alter_ao_table_col_ddl.source +++ b/src/test/regress/input/uao_ddl/alter_ao_table_col_ddl.source @@ -32,8 +32,8 @@ insert into sto_alt_uao1 values ('2_zero', 2, '2_zero', 2, 2, 2, '{2}', 2, 2, '1 select count(*) = 3 as passed from sto_alt_uao1; -- Alter table add column Alter Table sto_alt_uao1 ADD COLUMN added_col character varying(30) default 'default'; -SELECT 1 AS VisimapPresent FROM pg_appendonly WHERE visimaprelid is not NULL AND - visimapidxid is not NULL AND relid='sto_alt_uao1'::regclass; +SELECT count(i.indexrelid) = 1 AS VisimapPresent FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND + a.relid='sto_alt_uao1'::regclass; update sto_alt_uao1 set added_col = 'newly added col' where text_col = '1_zero'; select * from sto_alt_uao1 order by bigint_col; set gp_select_invisible = true; @@ -41,8 +41,8 @@ select count(*) AS all_tuples from sto_alt_uao1; set gp_select_invisible = false; -- Drop column Alter Table sto_alt_uao1 DROP COLUMN date_column; -SELECT 1 AS VisimapPresent FROM pg_appendonly WHERE visimaprelid is not NULL AND - visimapidxid is not NULL AND relid='sto_alt_uao1'::regclass; +SELECT count(i.indexrelid) = 1 AS VisimapPresent FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND + a.relid='sto_alt_uao1'::regclass; insert into sto_alt_uao1 values ('3_zero', 3, '0_zero', 3, 3, 3, '{3}', 0, 0, 0); insert into sto_alt_uao1 values ('4_zero', 4, '1_zero', 4, 4, 4, '{4}', 1, 1, 1); update sto_alt_uao1 set bigint_col = -bigint_col where text_col = '3_zero'; @@ -54,8 +54,8 @@ set gp_select_invisible = false; -- Alter column type and rename Alter Table sto_alt_uao1 ALTER COLUMN numeric_col TYPE int4; Alter Table sto_alt_uao1 RENAME COLUMN numeric_col TO int4_col; -SELECT 1 AS VisimapPresent FROM pg_appendonly WHERE visimaprelid is not NULL AND - visimapidxid is not NULL AND relid='sto_alt_uao1'::regclass; +SELECT count(i.indexrelid) = 1 AS VisimapPresent FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND + a.relid='sto_alt_uao1'::regclass; insert into sto_alt_uao1 values ('5_zero', 5, '0_zero', 5, 5, 5, '{3}', 0, 0, 0); update sto_alt_uao1 set int4_col = int4_col+100; select count(int4_col) = 5 as passed from sto_alt_uao1; diff --git a/src/test/regress/input/uao_ddl/alter_ao_table_constraint.source b/src/test/regress/input/uao_ddl/alter_ao_table_constraint.source index daea119e64c..09b26092d4a 100644 --- a/src/test/regress/input/uao_ddl/alter_ao_table_constraint.source +++ b/src/test/regress/input/uao_ddl/alter_ao_table_constraint.source @@ -9,8 +9,8 @@ CREATE TABLE sto_alt_uao2_constraint( numeric_col numeric ) DISTRIBUTED RANDOMLY; insert into sto_alt_uao2_constraint values ('1_zero', 1, '1_zero', 1); -SELECT 1 AS VisimapPresent FROM pg_appendonly WHERE visimapidxid is not NULL - AND visimapidxid is not NULL AND relid='sto_alt_uao2_constraint'::regclass; +SELECT count(i.indexrelid) = 1 AS VisimapPresent FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND + a.relid='sto_alt_uao2_constraint'::regclass; select * from sto_alt_uao2_constraint order by bigint_col; update sto_alt_uao2_constraint set numeric_col = 100 where text_col = '1_zero'; diff --git a/src/test/regress/input/uao_ddl/alter_ao_table_setdefault.source b/src/test/regress/input/uao_ddl/alter_ao_table_setdefault.source index 67ed3802183..35d1771ff8c 100644 --- a/src/test/regress/input/uao_ddl/alter_ao_table_setdefault.source +++ b/src/test/regress/input/uao_ddl/alter_ao_table_setdefault.source @@ -22,8 +22,8 @@ insert into sto_alt_uao1_default values (2, '2_zero', 2, 2, 2, '{2}', 2, 2, '1-1 -- Alter column Drop default Alter table sto_alt_uao1_default alter column text_col drop default; -SELECT 1 AS VisimapPresent FROM pg_appendonly WHERE visimaprelid is not NULL AND - visimapidxid is not NULL AND relid='sto_alt_uao1_default'::regclass; +SELECT count(i.indexrelid) = 1 AS VisimapPresent FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND + a.relid='sto_alt_uao1_default'::regclass; insert into sto_alt_uao1_default values (3, '3_zero', 3, 3, 3, '{3}', 3, 3, '1-1-2002', 3); insert into sto_alt_uao1_default values (4, '4_zero', 4, 4, 4, '{4}', 4, 4, '1-1-2002', 4,'4_zero'); select count(*) AS only_visi_tups from sto_alt_uao1_default; @@ -44,8 +44,8 @@ select * from sto_alt_uao1_default order by bigint_col; -- Alter column drop NOT NULL Alter Table sto_alt_uao1_default ALTER COLUMN int_col DROP NOT NULL, ALTER COLUMN text_col DROP NOT NULL; -SELECT 1 AS VisimapPresent FROM pg_appendonly WHERE visimaprelid is not NULL AND - visimapidxid is not NULL AND relid='sto_alt_uao1_default'::regclass; +SELECT count(i.indexrelid) = 1 AS VisimapPresent FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND + a.relid='sto_alt_uao1_default'::regclass; insert into sto_alt_uao1_default values (6, '6_zero', 6, 6, 6, '{6}', 6, 6, '1-1-2002', 6); update sto_alt_uao1_default set date_column = '2013-08-15' where text_col = '1_zero'; select * from sto_alt_uao1_default order by bigint_col; diff --git a/src/test/regress/input/uao_ddl/alter_ao_table_setstorage.source b/src/test/regress/input/uao_ddl/alter_ao_table_setstorage.source index b1dd438e46e..2a9a9d7e116 100644 --- a/src/test/regress/input/uao_ddl/alter_ao_table_setstorage.source +++ b/src/test/regress/input/uao_ddl/alter_ao_table_setstorage.source @@ -21,8 +21,8 @@ insert into sto_alt_uao1_setstorage values ('2_zero', 2, '2_zero', 2, 2, 2, '{2} -- Alter table SET STORAGE Alter Table sto_alt_uao1_setstorage ALTER char_vary_col SET STORAGE PLAIN; -SELECT 1 AS VisimapPresent FROM pg_appendonly WHERE visimapidxid is -not NULL AND visimapidxid is not NULL AND relid='sto_alt_uao1_setstorage'::regclass; +SELECT count(i.indexrelid) = 1 AS VisimapPresent FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND + a.relid='sto_alt_uao1_setstorage'::regclass; insert into sto_alt_uao1_setstorage values ('2_zero', 2, '2_zero', 2, 2, 2, '{2}', 2, 2, '1-1-2002',2); update sto_alt_uao1_setstorage set date_column = '2013-08-16' where text_col = '1_zero'; select * from sto_alt_uao1_setstorage order by bigint_col; @@ -41,8 +41,8 @@ Alter Table sto_alt_uao1_setstorage set with (reorganize='true') distributed by (bigint_col); update sto_alt_uao1_setstorage set numeric_col = -bigint_col; select * from sto_alt_uao1_setstorage; -SELECT 1 AS VisimapPresent FROM pg_appendonly WHERE visimapidxid is -not NULL AND visimapidxid is not NULL AND relid='sto_alt_uao1_setstorage'::regclass; +SELECT count(i.indexrelid) = 1 AS VisimapPresent FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND + a.relid='sto_alt_uao1_setstorage'::regclass; -- Run another reorganize to confirm that the relcache has been invalidated -- when we changed the value of this table's gp_distribution_policy. If the @@ -62,6 +62,6 @@ select * from sto_alt_uao1_setstorage; set gp_select_invisible=true; select count(*) from sto_alt_uao1_setstorage; set gp_select_invisible=false; -SELECT 1 AS VisimapPresent FROM pg_appendonly WHERE visimapidxid is -not NULL AND visimapidxid is not NULL AND relid='sto_alt_uao1_setstorage'::regclass; +SELECT count(i.indexrelid) = 1 AS VisimapPresent FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND + a.relid='sto_alt_uao1_setstorage'::regclass; COMMIT; diff --git a/src/test/regress/input/uao_ddl/alter_ao_table_statistics.source b/src/test/regress/input/uao_ddl/alter_ao_table_statistics.source index f998c683e8a..51c12e7bc5f 100644 --- a/src/test/regress/input/uao_ddl/alter_ao_table_statistics.source +++ b/src/test/regress/input/uao_ddl/alter_ao_table_statistics.source @@ -11,8 +11,8 @@ insert into sto_alt_uao2_stats values ('1_zero', 1, '1_zero', 1); select * from sto_alt_uao2_stats order by bigint_col; -- Alter column set statistics Alter table sto_alt_uao2_stats alter column bigint_col set statistics 3; -SELECT 1 AS VisimapPresent FROM pg_appendonly WHERE visimapidxid is not NULL AND - visimapidxid is not NULL AND relid='sto_alt_uao2_stats'::regclass; +SELECT count(i.indexrelid) = 1 AS VisimapPresent FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND + a.relid='sto_alt_uao2_stats'::regclass; select * from sto_alt_uao2_stats order by bigint_col; update sto_alt_uao2_stats set numeric_col = 1 where text_col = '1_zero'; insert into sto_alt_uao2_stats select i||' abc', i, 'pqr '||i, i from generate_series(1,100)i; diff --git a/src/test/regress/input/uao_ddl/analyze_ao_table_every_dml.source b/src/test/regress/input/uao_ddl/analyze_ao_table_every_dml.source index 847246ebc47..99e9426028e 100644 --- a/src/test/regress/input/uao_ddl/analyze_ao_table_every_dml.source +++ b/src/test/regress/input/uao_ddl/analyze_ao_table_every_dml.source @@ -17,8 +17,8 @@ set gp_autostats_mode=on_change; select count(*) from sto_uao_city_analyze_everydml; select relname, reltuples from pg_class where oid='sto_uao_city_analyze_everydml'::regclass; -SELECT 1 AS VisimapPresent FROM pg_appendonly WHERE visimaprelid is not NULL AND - visimapidxid is not NULL AND relid='sto_uao_city_analyze_everydml'::regclass; +SELECT count(i.indexrelid) = 1 AS VisimapPresent FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND + a.relid='sto_uao_city_analyze_everydml'::regclass; -- Copy 7 rows in table sto_uao_city_analyze_everydml COPY sto_uao_city_analyze_everydml (id, name, countrycode, district, population) FROM stdin; diff --git a/src/test/regress/input/uao_ddl/blocksize.source b/src/test/regress/input/uao_ddl/blocksize.source index 6b0d30091f5..9c556843c23 100644 --- a/src/test/regress/input/uao_ddl/blocksize.source +++ b/src/test/regress/input/uao_ddl/blocksize.source @@ -16,8 +16,8 @@ SELECT GENERATE_SERIES::numeric sno CREATE index val3_bmp_idxblocksize_upd_8k on uao_blocksize_8k using bitmap (val3); SELECT count(*) from uao_blocksize_8k; -SELECT 1 AS VisimapPresent FROM pg_appendonly WHERE visimaprelid is -not NULL AND visimapidxid is not NULL AND relid='uao_blocksize_8k'::regclass; +SELECT count(i.indexrelid) = 1 AS VisimapPresent FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND + a.relid='uao_blocksize_8k'::regclass; select 1 as block8k_present from pg_appendonly WHERE blocksize=8192 AND relid='uao_blocksize_8k'::regclass; @@ -50,9 +50,8 @@ SELECT GENERATE_SERIES::numeric sno SELECT count(*) from uao_blocksize_2048k; -SELECT 1 AS VisimapPresent FROM pg_appendonly WHERE -visimaprelid is not NULL AND visimapidxid is not NULL AND -relid='uao_blocksize_2048k'::regclass; +SELECT count(i.indexrelid) = 1 AS VisimapPresent FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND + a.relid='uao_blocksize_2048k'::regclass; select 1 as block2048k_present from pg_appendonly WHERE blocksize=2097152 AND relid='uao_blocksize_2048k'::regclass; diff --git a/src/test/regress/input/uao_ddl/compresstype.source b/src/test/regress/input/uao_ddl/compresstype.source index cabde9cd97c..56d0915a713 100644 --- a/src/test/regress/input/uao_ddl/compresstype.source +++ b/src/test/regress/input/uao_ddl/compresstype.source @@ -15,8 +15,8 @@ insert into uao_tab_compress_none values (1, 'abc', 1), (2, 'pqr', 2), (3, 'lmn', 3); delete from uao_tab_compress_none; select count(*) = 0 as passed from uao_tab_compress_none; -SELECT 1 AS VisimapPresent FROM pg_appendonly WHERE visimaprelid is -not NULL AND visimapidxid is not NULL AND relid='uao_tab_compress_none'::regclass; +SELECT count(i.indexrelid) = 1 AS VisimapPresent FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND + a.relid='uao_tab_compress_none'::regclass; -- create uao table with compress=zlib COMPRESSLEVEL=1 CREATE TABLE uao_tab_compress_zlib1 ( @@ -38,8 +38,8 @@ select count(*) from uao_tab_compress_zlib1; -- Decompress tuples select sum(length(col_text)) from uao_tab_compress_zlib1 where col_int < 1100; -SELECT 1 AS VisimapPresent FROM pg_appendonly WHERE visimaprelid is -not NULL AND visimapidxid is not NULL AND relid='uao_tab_compress_zlib1'::regclass; +SELECT count(i.indexrelid) = 1 AS VisimapPresent FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND + a.relid='uao_tab_compress_zlib1'::regclass; SELECT c.relname, c.reloptions from pg_class c join pg_namespace n on n.oid=c.relnamespace @@ -70,8 +70,8 @@ set gp_select_invisible = true; select count(*) from uao_tab_compress_zlib9; set gp_select_invisible = false; -SELECT 1 AS VisimapPresent FROM pg_appendonly WHERE visimapidxid is -not NULL AND visimapidxid is not NULL AND relid='uao_tab_compress_zlib9'::regclass; +SELECT count(i.indexrelid) = 1 AS VisimapPresent FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND + a.relid='uao_tab_compress_zlib9'::regclass; SELECT c.relname, c.reloptions from pg_class c join pg_namespace n on n.oid=c.relnamespace diff --git a/src/test/regress/input/uao_ddl/create_ao_table_500cols.source b/src/test/regress/input/uao_ddl/create_ao_table_500cols.source index 16d740442ca..55bc3e2084c 100644 --- a/src/test/regress/input/uao_ddl/create_ao_table_500cols.source +++ b/src/test/regress/input/uao_ddl/create_ao_table_500cols.source @@ -111,8 +111,8 @@ numeric(8), a493 polygon, a494 date, a495 real, a496 money, a497 cidr, a498 inet, a499 time, a500 text) DISTRIBUTED BY (id); -SELECT 1 AS VisimapPresent FROM pg_appendonly WHERE visimaprelid is not NULL AND - visimapidxid is not NULL AND relid='sto_uao_500cols'::regclass; +SELECT count(i.indexrelid) = 1 AS VisimapPresent FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND + a.relid='sto_uao_500cols'::regclass; INSERT into sto_uao_500cols (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, diff --git a/src/test/regress/input/uao_ddl/create_ao_tables.source b/src/test/regress/input/uao_ddl/create_ao_tables.source index c45f9421c8e..3ca47c8c208 100644 --- a/src/test/regress/input/uao_ddl/create_ao_tables.source +++ b/src/test/regress/input/uao_ddl/create_ao_tables.source @@ -25,13 +25,13 @@ SELECT position('pg_aoblkdir_' in relname) FROM pg_class where oid IN (SELECT blkdirrelid FROM pg_appendonly WHERE relid='sto_uao_1'::regclass); SELECT position('pg_aoblkdir_' in relname) FROM pg_class where oid IN -(SELECT blkdiridxid FROM pg_appendonly WHERE relid='sto_uao_1'::regclass); +(SELECT i.indexrelid FROM pg_appendonly a, pg_index i WHERE a.blkdirrelid = i.indrelid AND a.relid='sto_uao_1'::regclass); SELECT position('pg_aovisimap_' in relname) FROM pg_class where oid IN (SELECT visimaprelid FROM pg_appendonly WHERE relid='sto_uao_1'::regclass); SELECT position('pg_aovisimap_' in relname) FROM pg_class where oid IN -(SELECT visimapidxid FROM pg_appendonly WHERE relid='sto_uao_1'::regclass); +(SELECT i.indexrelid FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND a.relid='sto_uao_1'::regclass); insert into sto_uao_1 values (1,'aa',1001,101), (2,'bb',1002,102), (3,'aa',1003,103), @@ -190,8 +190,8 @@ delete from sto_uao_9; set gp_select_invisible=true; select count(*) from sto_uao_9; set gp_select_invisible=false; -SELECT 1 AS VisimapPresent FROM pg_appendonly WHERE visimaprelid is not NULL - AND visimapidxid is not NULL AND relid='sto_uao_9'::regclass; +SELECT count(i.indexrelid) = 1 AS VisimapPresent FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND + a.relid='sto_uao_9'::regclass; -- Delete using join delete from sto_uao_1 a using sto_uao_8 b diff --git a/src/test/regress/output/gp_tablespace.source b/src/test/regress/output/gp_tablespace.source index 604388bafd6..3b11b2ee5d1 100644 --- a/src/test/regress/output/gp_tablespace.source +++ b/src/test/regress/output/gp_tablespace.source @@ -20,11 +20,11 @@ BEGIN when 'blockdir' then select blkdirrelid into relation_id from pg_appendonly where relid = aotablename; when 'blockdirindex' then - select blkdiridxid into relation_id from pg_appendonly where relid = aotablename; + select i.indexrelid into relation_id from pg_appendonly a, pg_index i where a.blkdirrelid = i.indrelid and relid = aotablename; when 'visimap' then select visimaprelid into relation_id from pg_appendonly where relid = aotablename; when 'visimapindex' then - select visimapidxid into relation_id from pg_appendonly where relid = aotablename; + select i.indexrelid into relation_id from pg_appendonly a, pg_index i where a.visimaprelid = i.indrelid and relid = aotablename; else raise notice 'Invalid tabletype for has_init_file %', tabletype; return false; diff --git a/src/test/regress/output/uao_ddl/alter_ao_part_exch.source b/src/test/regress/output/uao_ddl/alter_ao_part_exch.source index 41ec1bef5bb..f91095e3627 100644 --- a/src/test/regress/output/uao_ddl/alter_ao_part_exch.source +++ b/src/test/regress/output/uao_ddl/alter_ao_part_exch.source @@ -23,8 +23,8 @@ insert into ao_part(col1, col2, col3) values (1, '2008-04-15', 'ao_row'), (1, '2008-04-15', 'heap'), (1, '2008-04-05', 'ao_col'), (1, '2008-05-06', 'ao_row'); analyze ao_part; -select count(*) FROM pg_appendonly WHERE visimapidxid is not NULL AND -visimapidxid is not NULL AND relid in (SELECT c.oid FROM pg_class c +select count(*) FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND +a.relid in (SELECT c.oid FROM pg_class c inner join pg_namespace n ON c.relnamespace = n.oid and c.relname like 'ao_part%' and n.nspname = 'alter_ao_part_exch_@amname@'); count diff --git a/src/test/regress/output/uao_ddl/alter_ao_part_tables.source b/src/test/regress/output/uao_ddl/alter_ao_part_tables.source index 2e01a2fdb50..cfe0809faae 100644 --- a/src/test/regress/output/uao_ddl/alter_ao_part_tables.source +++ b/src/test/regress/output/uao_ddl/alter_ao_part_tables.source @@ -388,8 +388,9 @@ select count(*) as all_tuples from sto_altap2; set gp_select_invisible=false; -- Check that visimaps were created properly -select distinct a.visimaprelid is not NULL, a.visimapidxid is not NULL - from pg_appendonly a inner join pg_class c on a.relid = c.oid and +select distinct a.visimaprelid is not NULL, i.indexrelid is not NULL + from pg_appendonly a inner join pg_class c on a.relid = c.oid + inner join pg_index i on a.visimaprelid = i.indrelid and c.relname like 'sto_alt%'; ?column? | ?column? ----------+---------- @@ -398,8 +399,9 @@ select distinct a.visimaprelid is not NULL, a.visimapidxid is not NULL -- Drop partition table, check pg_appendonly drop table sto_altap2; -select distinct a.visimaprelid is NULL, a.visimapidxid is NULL - from pg_appendonly a inner join pg_class c on a.relid = c.oid and +select distinct a.visimaprelid is not NULL, i.indexrelid is not NULL + from pg_appendonly a inner join pg_class c on a.relid = c.oid + inner join pg_index i on a.visimaprelid = i.indrelid and c.relname like 'sto_altap2%'; ?column? | ?column? ----------+---------- diff --git a/src/test/regress/output/uao_ddl/alter_ao_part_tables_splitpartition.source b/src/test/regress/output/uao_ddl/alter_ao_part_tables_splitpartition.source index 12fc4d72b46..384fcc5b180 100644 --- a/src/test/regress/output/uao_ddl/alter_ao_part_tables_splitpartition.source +++ b/src/test/regress/output/uao_ddl/alter_ao_part_tables_splitpartition.source @@ -9,17 +9,15 @@ CREATE TABLE sto_alt_uao_part_splitpartition ( PARTITION sales_Aug13 START (date '2013-08-01') INCLUSIVE, PARTITION sales_Sep13 START (date '2013-09-01') INCLUSIVE END (date '2014-01-01') EXCLUSIVE); -SELECT 1 AS VisimapPresent FROM pg_appendonly WHERE visimaprelid is -not NULL AND visimapidxid is not NULL AND relid in (SELECT c.oid FROM +SELECT count(i.indexrelid) AS VisimapCount FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND +a.relid in (SELECT c.oid FROM pg_class c join pg_namespace n on c.relnamespace = n.oid and c.relname like 'sto_alt_uao_part_splitpartition%' and n.nspname = 'alter_ao_part_tables_splitpartition_@amname@'); - visimappresent ----------------- - 1 - 1 - 1 -(3 rows) + visimapcount +------------- + 3 +(1 row) Insert into sto_alt_uao_part_splitpartition values(1,'2013-07-05',19.20); Insert into sto_alt_uao_part_splitpartition values(2,'2013-08-15',10.20); @@ -34,8 +32,8 @@ select count(*) from sto_alt_uao_part_splitpartition; -- Alter table add default partition Alter table sto_alt_uao_part_splitpartition add default partition part_others; -select count(*) FROM pg_appendonly WHERE visimaprelid is not NULL AND -visimapidxid is not NULL AND relid in (SELECT c.oid FROM pg_class c +SELECT count(i.indexrelid) FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND +a.relid in (SELECT c.oid FROM pg_class c join pg_namespace n on c.relnamespace = n.oid and c.relname like 'sto_alt_uao_part_splitpartition%' and n.nspname = 'alter_ao_part_tables_splitpartition_@amname@'); @@ -71,8 +69,8 @@ select * from sto_alt_uao_part_splitpartition; Alter table sto_alt_uao_part_splitpartition split default partition start(date '2013-01-01') end(date '2013-03-01') into (partition p1, partition part_others); -select count(*) FROM pg_appendonly WHERE visimaprelid is not NULL AND -visimapidxid is not NULL AND relid in (SELECT c.oid FROM pg_class c +SELECT count(i.indexrelid) FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND +a.relid in (SELECT c.oid FROM pg_class c join pg_namespace n on c.relnamespace = n.oid and c.relname like 'sto_alt_uao_part_splitpartition%' and n.nspname = 'alter_ao_part_tables_splitpartition_@amname@'); diff --git a/src/test/regress/output/uao_ddl/alter_ao_table_col_ddl.source b/src/test/regress/output/uao_ddl/alter_ao_table_col_ddl.source index 0ad0ae8e393..e285c0a4bba 100644 --- a/src/test/regress/output/uao_ddl/alter_ao_table_col_ddl.source +++ b/src/test/regress/output/uao_ddl/alter_ao_table_col_ddl.source @@ -46,11 +46,11 @@ select count(*) = 3 as passed from sto_alt_uao1; -- Alter table add column Alter Table sto_alt_uao1 ADD COLUMN added_col character varying(30) default 'default'; -SELECT 1 AS VisimapPresent FROM pg_appendonly WHERE visimaprelid is not NULL AND - visimapidxid is not NULL AND relid='sto_alt_uao1'::regclass; +SELECT count(i.indexrelid) = 1 AS VisimapPresent FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND + a.relid='sto_alt_uao1'::regclass; visimappresent ---------------- - 1 + t (1 row) update sto_alt_uao1 set added_col = 'newly added col' where text_col = '1_zero'; @@ -72,11 +72,11 @@ select count(*) AS all_tuples from sto_alt_uao1; set gp_select_invisible = false; -- Drop column Alter Table sto_alt_uao1 DROP COLUMN date_column; -SELECT 1 AS VisimapPresent FROM pg_appendonly WHERE visimaprelid is not NULL AND - visimapidxid is not NULL AND relid='sto_alt_uao1'::regclass; +SELECT count(i.indexrelid) = 1 AS VisimapPresent FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND + a.relid='sto_alt_uao1'::regclass; visimappresent ---------------- - 1 + t (1 row) insert into sto_alt_uao1 values ('3_zero', 3, '0_zero', 3, 3, 3, '{3}', 0, 0, 0); @@ -103,11 +103,11 @@ set gp_select_invisible = false; -- Alter column type and rename Alter Table sto_alt_uao1 ALTER COLUMN numeric_col TYPE int4; Alter Table sto_alt_uao1 RENAME COLUMN numeric_col TO int4_col; -SELECT 1 AS VisimapPresent FROM pg_appendonly WHERE visimaprelid is not NULL AND - visimapidxid is not NULL AND relid='sto_alt_uao1'::regclass; +SELECT count(i.indexrelid) = 1 AS VisimapPresent FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND + a.relid='sto_alt_uao1'::regclass; visimappresent ---------------- - 1 + t (1 row) insert into sto_alt_uao1 values ('5_zero', 5, '0_zero', 5, 5, 5, '{3}', 0, 0, 0); diff --git a/src/test/regress/output/uao_ddl/alter_ao_table_col_ddl_optimizer.source b/src/test/regress/output/uao_ddl/alter_ao_table_col_ddl_optimizer.source index 0ad0ae8e393..e285c0a4bba 100644 --- a/src/test/regress/output/uao_ddl/alter_ao_table_col_ddl_optimizer.source +++ b/src/test/regress/output/uao_ddl/alter_ao_table_col_ddl_optimizer.source @@ -46,11 +46,11 @@ select count(*) = 3 as passed from sto_alt_uao1; -- Alter table add column Alter Table sto_alt_uao1 ADD COLUMN added_col character varying(30) default 'default'; -SELECT 1 AS VisimapPresent FROM pg_appendonly WHERE visimaprelid is not NULL AND - visimapidxid is not NULL AND relid='sto_alt_uao1'::regclass; +SELECT count(i.indexrelid) = 1 AS VisimapPresent FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND + a.relid='sto_alt_uao1'::regclass; visimappresent ---------------- - 1 + t (1 row) update sto_alt_uao1 set added_col = 'newly added col' where text_col = '1_zero'; @@ -72,11 +72,11 @@ select count(*) AS all_tuples from sto_alt_uao1; set gp_select_invisible = false; -- Drop column Alter Table sto_alt_uao1 DROP COLUMN date_column; -SELECT 1 AS VisimapPresent FROM pg_appendonly WHERE visimaprelid is not NULL AND - visimapidxid is not NULL AND relid='sto_alt_uao1'::regclass; +SELECT count(i.indexrelid) = 1 AS VisimapPresent FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND + a.relid='sto_alt_uao1'::regclass; visimappresent ---------------- - 1 + t (1 row) insert into sto_alt_uao1 values ('3_zero', 3, '0_zero', 3, 3, 3, '{3}', 0, 0, 0); @@ -103,11 +103,11 @@ set gp_select_invisible = false; -- Alter column type and rename Alter Table sto_alt_uao1 ALTER COLUMN numeric_col TYPE int4; Alter Table sto_alt_uao1 RENAME COLUMN numeric_col TO int4_col; -SELECT 1 AS VisimapPresent FROM pg_appendonly WHERE visimaprelid is not NULL AND - visimapidxid is not NULL AND relid='sto_alt_uao1'::regclass; +SELECT count(i.indexrelid) = 1 AS VisimapPresent FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND + a.relid='sto_alt_uao1'::regclass; visimappresent ---------------- - 1 + t (1 row) insert into sto_alt_uao1 values ('5_zero', 5, '0_zero', 5, 5, 5, '{3}', 0, 0, 0); diff --git a/src/test/regress/output/uao_ddl/alter_ao_table_constraint.source b/src/test/regress/output/uao_ddl/alter_ao_table_constraint.source index 024e9ec7469..47640ebc2d4 100644 --- a/src/test/regress/output/uao_ddl/alter_ao_table_constraint.source +++ b/src/test/regress/output/uao_ddl/alter_ao_table_constraint.source @@ -9,11 +9,11 @@ CREATE TABLE sto_alt_uao2_constraint( numeric_col numeric ) DISTRIBUTED RANDOMLY; insert into sto_alt_uao2_constraint values ('1_zero', 1, '1_zero', 1); -SELECT 1 AS VisimapPresent FROM pg_appendonly WHERE visimapidxid is not NULL - AND visimapidxid is not NULL AND relid='sto_alt_uao2_constraint'::regclass; +SELECT count(i.indexrelid) = 1 AS VisimapPresent FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND + a.relid='sto_alt_uao2_constraint'::regclass; visimappresent ---------------- - 1 + t (1 row) select * from sto_alt_uao2_constraint order by bigint_col; diff --git a/src/test/regress/output/uao_ddl/alter_ao_table_setdefault.source b/src/test/regress/output/uao_ddl/alter_ao_table_setdefault.source index bdf0604d196..150f46be680 100644 --- a/src/test/regress/output/uao_ddl/alter_ao_table_setdefault.source +++ b/src/test/regress/output/uao_ddl/alter_ao_table_setdefault.source @@ -20,11 +20,11 @@ insert into sto_alt_uao1_default values (1, '1_zero', 1, 1, 1, '{1}', 1, 1, '1-1 insert into sto_alt_uao1_default values (2, '2_zero', 2, 2, 2, '{2}', 2, 2, '1-1-2002',2); -- Alter column Drop default Alter table sto_alt_uao1_default alter column text_col drop default; -SELECT 1 AS VisimapPresent FROM pg_appendonly WHERE visimaprelid is not NULL AND - visimapidxid is not NULL AND relid='sto_alt_uao1_default'::regclass; +SELECT count(i.indexrelid) = 1 AS VisimapPresent FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND + a.relid='sto_alt_uao1_default'::regclass; visimappresent ---------------- - 1 + t (1 row) insert into sto_alt_uao1_default values (3, '3_zero', 3, 3, 3, '{3}', 3, 3, '1-1-2002', 3); @@ -76,11 +76,11 @@ select * from sto_alt_uao1_default order by bigint_col; -- Alter column drop NOT NULL Alter Table sto_alt_uao1_default ALTER COLUMN int_col DROP NOT NULL, ALTER COLUMN text_col DROP NOT NULL; -SELECT 1 AS VisimapPresent FROM pg_appendonly WHERE visimaprelid is not NULL AND - visimapidxid is not NULL AND relid='sto_alt_uao1_default'::regclass; +SELECT count(i.indexrelid) = 1 AS VisimapPresent FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND + a.relid='sto_alt_uao1_default'::regclass; visimappresent ---------------- - 1 + t (1 row) insert into sto_alt_uao1_default values (6, '6_zero', 6, 6, 6, '{6}', 6, 6, '1-1-2002', 6); diff --git a/src/test/regress/output/uao_ddl/alter_ao_table_setstorage.source b/src/test/regress/output/uao_ddl/alter_ao_table_setstorage.source index 8b3d8e887f2..7713c5a10ea 100644 --- a/src/test/regress/output/uao_ddl/alter_ao_table_setstorage.source +++ b/src/test/regress/output/uao_ddl/alter_ao_table_setstorage.source @@ -19,11 +19,11 @@ insert into sto_alt_uao1_setstorage values ('1_zero', 1, '1_zero', 1, 1, 1, '{1} insert into sto_alt_uao1_setstorage values ('2_zero', 2, '2_zero', 2, 2, 2, '{2}', 2, 2, '1-1-2002',2); -- Alter table SET STORAGE Alter Table sto_alt_uao1_setstorage ALTER char_vary_col SET STORAGE PLAIN; -SELECT 1 AS VisimapPresent FROM pg_appendonly WHERE visimapidxid is -not NULL AND visimapidxid is not NULL AND relid='sto_alt_uao1_setstorage'::regclass; +SELECT count(i.indexrelid) = 1 AS VisimapPresent FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND + a.relid='sto_alt_uao1_setstorage'::regclass; visimappresent ---------------- - 1 + t (1 row) insert into sto_alt_uao1_setstorage values ('2_zero', 2, '2_zero', 2, 2, 2, '{2}', 2, 2, '1-1-2002',2); @@ -74,11 +74,11 @@ select * from sto_alt_uao1_setstorage; 2_zero | 2 | 2_zero | -2 | 2 | 2 | {2} | 2 | 2 | 01-01-2002 | 2 (3 rows) -SELECT 1 AS VisimapPresent FROM pg_appendonly WHERE visimapidxid is -not NULL AND visimapidxid is not NULL AND relid='sto_alt_uao1_setstorage'::regclass; +SELECT count(i.indexrelid) = 1 AS VisimapPresent FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND + a.relid='sto_alt_uao1_setstorage'::regclass; visimappresent ---------------- - 1 + t (1 row) -- Run another reorganize to confirm that the relcache has been invalidated @@ -117,11 +117,11 @@ select count(*) from sto_alt_uao1_setstorage; (1 row) set gp_select_invisible=false; -SELECT 1 AS VisimapPresent FROM pg_appendonly WHERE visimapidxid is -not NULL AND visimapidxid is not NULL AND relid='sto_alt_uao1_setstorage'::regclass; +SELECT count(i.indexrelid) = 1 AS VisimapPresent FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND + a.relid='sto_alt_uao1_setstorage'::regclass; visimappresent ---------------- - 1 + t (1 row) COMMIT; diff --git a/src/test/regress/output/uao_ddl/alter_ao_table_statistics.source b/src/test/regress/output/uao_ddl/alter_ao_table_statistics.source index d017d1ad835..b9122ae439f 100644 --- a/src/test/regress/output/uao_ddl/alter_ao_table_statistics.source +++ b/src/test/regress/output/uao_ddl/alter_ao_table_statistics.source @@ -16,11 +16,11 @@ select * from sto_alt_uao2_stats order by bigint_col; -- Alter column set statistics Alter table sto_alt_uao2_stats alter column bigint_col set statistics 3; -SELECT 1 AS VisimapPresent FROM pg_appendonly WHERE visimapidxid is not NULL AND - visimapidxid is not NULL AND relid='sto_alt_uao2_stats'::regclass; +SELECT count(i.indexrelid) = 1 AS VisimapPresent FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND + a.relid='sto_alt_uao2_stats'::regclass; visimappresent ---------------- - 1 + t (1 row) select * from sto_alt_uao2_stats order by bigint_col; diff --git a/src/test/regress/output/uao_ddl/analyze_ao_table_every_dml.source b/src/test/regress/output/uao_ddl/analyze_ao_table_every_dml.source index e9c95c5d838..35e1fe8b8f9 100644 --- a/src/test/regress/output/uao_ddl/analyze_ao_table_every_dml.source +++ b/src/test/regress/output/uao_ddl/analyze_ao_table_every_dml.source @@ -25,11 +25,11 @@ select relname, reltuples from pg_class where oid='sto_uao_city_analyze_everydml sto_uao_city_analyze_everydml | -1 (1 row) -SELECT 1 AS VisimapPresent FROM pg_appendonly WHERE visimaprelid is not NULL AND - visimapidxid is not NULL AND relid='sto_uao_city_analyze_everydml'::regclass; +SELECT count(i.indexrelid) = 1 AS VisimapPresent FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND + a.relid='sto_uao_city_analyze_everydml'::regclass; visimappresent ----------------- - 1 +------------ + t (1 row) -- Copy 7 rows in table sto_uao_city_analyze_everydml diff --git a/src/test/regress/output/uao_ddl/blocksize.source b/src/test/regress/output/uao_ddl/blocksize.source index f043e3e9efa..d33caf0d2cc 100644 --- a/src/test/regress/output/uao_ddl/blocksize.source +++ b/src/test/regress/output/uao_ddl/blocksize.source @@ -20,11 +20,11 @@ SELECT count(*) from uao_blocksize_8k; 1000 (1 row) -SELECT 1 AS VisimapPresent FROM pg_appendonly WHERE visimaprelid is -not NULL AND visimapidxid is not NULL AND relid='uao_blocksize_8k'::regclass; +SELECT count(i.indexrelid) = 1 AS VisimapPresent FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND + a.relid='uao_blocksize_8k'::regclass; visimappresent ---------------- - 1 + t (1 row) select 1 as block8k_present from pg_appendonly WHERE blocksize=8192 @@ -89,12 +89,11 @@ SELECT count(*) from uao_blocksize_2048k; 1000 (1 row) -SELECT 1 AS VisimapPresent FROM pg_appendonly WHERE -visimaprelid is not NULL AND visimapidxid is not NULL AND -relid='uao_blocksize_2048k'::regclass; +SELECT count(i.indexrelid) = 1 AS VisimapPresent FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND + a.relid='uao_blocksize_2048k'::regclass; visimappresent ---------------- - 1 + t (1 row) select 1 as block2048k_present from pg_appendonly WHERE diff --git a/src/test/regress/output/uao_ddl/compresstype.source b/src/test/regress/output/uao_ddl/compresstype.source index c1902559e32..2e54c505ad0 100644 --- a/src/test/regress/output/uao_ddl/compresstype.source +++ b/src/test/regress/output/uao_ddl/compresstype.source @@ -20,11 +20,11 @@ select count(*) = 0 as passed from uao_tab_compress_none; t (1 row) -SELECT 1 AS VisimapPresent FROM pg_appendonly WHERE visimaprelid is -not NULL AND visimapidxid is not NULL AND relid='uao_tab_compress_none'::regclass; +SELECT count(i.indexrelid) = 1 AS VisimapPresent FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND + a.relid='uao_tab_compress_none'::regclass; visimappresent ---------------- - 1 + t (1 row) -- create uao table with compress=zlib COMPRESSLEVEL=1 @@ -61,11 +61,11 @@ select sum(length(col_text)) from uao_tab_compress_zlib1 22600 (1 row) -SELECT 1 AS VisimapPresent FROM pg_appendonly WHERE visimaprelid is -not NULL AND visimapidxid is not NULL AND relid='uao_tab_compress_zlib1'::regclass; +SELECT count(i.indexrelid) = 1 AS VisimapPresent FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND + a.relid='uao_tab_compress_zlib1'::regclass; visimappresent ---------------- - 1 + t (1 row) SELECT c.relname, c.reloptions from pg_class c @@ -119,11 +119,11 @@ select count(*) from uao_tab_compress_zlib9; (1 row) set gp_select_invisible = false; -SELECT 1 AS VisimapPresent FROM pg_appendonly WHERE visimapidxid is -not NULL AND visimapidxid is not NULL AND relid='uao_tab_compress_zlib9'::regclass; +SELECT count(i.indexrelid) = 1 AS VisimapPresent FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND + a.relid='uao_tab_compress_zlib9'::regclass; visimappresent ---------------- - 1 + t (1 row) SELECT c.relname, c.reloptions from pg_class c diff --git a/src/test/regress/output/uao_ddl/create_ao_table_500cols.source b/src/test/regress/output/uao_ddl/create_ao_table_500cols.source index 29acee38a9c..633fd88ae47 100644 --- a/src/test/regress/output/uao_ddl/create_ao_table_500cols.source +++ b/src/test/regress/output/uao_ddl/create_ao_table_500cols.source @@ -110,11 +110,11 @@ lseg, a488 point, a489 double precision, a490 circle, a491 int4, a492 numeric(8), a493 polygon, a494 date, a495 real, a496 money, a497 cidr, a498 inet, a499 time, a500 text) DISTRIBUTED BY (id); -SELECT 1 AS VisimapPresent FROM pg_appendonly WHERE visimaprelid is not NULL AND - visimapidxid is not NULL AND relid='sto_uao_500cols'::regclass; +SELECT count(i.indexrelid) = 1 AS VisimapPresent FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND + a.relid='sto_uao_500cols'::regclass; visimappresent ----------------- - 1 +------------ + t (1 row) INSERT into sto_uao_500cols (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, diff --git a/src/test/regress/output/uao_ddl/create_ao_tables.source b/src/test/regress/output/uao_ddl/create_ao_tables.source index a551fda741c..1d96a541a9b 100644 --- a/src/test/regress/output/uao_ddl/create_ao_tables.source +++ b/src/test/regress/output/uao_ddl/create_ao_tables.source @@ -31,7 +31,7 @@ SELECT position('pg_aoblkdir_' in relname) FROM pg_class where oid IN (1 row) SELECT position('pg_aoblkdir_' in relname) FROM pg_class where oid IN -(SELECT blkdiridxid FROM pg_appendonly WHERE relid='sto_uao_1'::regclass); +(SELECT i.indexrelid FROM pg_appendonly a, pg_index i WHERE a.blkdirrelid = i.indrelid AND a.relid='sto_uao_1'::regclass); position ---------- 1 @@ -45,7 +45,7 @@ SELECT position('pg_aovisimap_' in relname) FROM pg_class where oid IN (1 row) SELECT position('pg_aovisimap_' in relname) FROM pg_class where oid IN -(SELECT visimapidxid FROM pg_appendonly WHERE relid='sto_uao_1'::regclass); +(SELECT i.indexrelid FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND a.relid='sto_uao_1'::regclass); position ---------- 1 @@ -289,11 +289,11 @@ select count(*) from sto_uao_9; (1 row) set gp_select_invisible=false; -SELECT 1 AS VisimapPresent FROM pg_appendonly WHERE visimaprelid is not NULL - AND visimapidxid is not NULL AND relid='sto_uao_9'::regclass; +SELECT count(i.indexrelid) = 1 AS VisimapPresent FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND + a.relid='sto_uao_9'::regclass; visimappresent ----------------- - 1 +------------ + t (1 row) -- Delete using join diff --git a/src/test/regress/sql/uao_catalog_tables.sql b/src/test/regress/sql/uao_catalog_tables.sql index 20818cb280a..1ecd64e3f2d 100644 --- a/src/test/regress/sql/uao_catalog_tables.sql +++ b/src/test/regress/sql/uao_catalog_tables.sql @@ -33,7 +33,7 @@ $$ LANGUAGE plpgsql; -- Verify empty visimap for uao table create table uao_table_check_empty_visimap (i int, j varchar(20), k int ) with (appendonly=true) DISTRIBUTED BY (i); insert into uao_table_check_empty_visimap values(1,'test',2); -SELECT 1 FROM pg_appendonly WHERE visimapidxid is not NULL AND visimapidxid is not NULL AND relid='uao_table_check_empty_visimap'::regclass; +SELECT count(i.indexrelid) FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND a.relid='uao_table_check_empty_visimap'::regclass; -- Verify GUC select_invisible=true for uao tables create table uao_table_check_select_invisible (i int, j varchar(20), k int ) with (appendonly=true) DISTRIBUTED BY (i); diff --git a/src/test/regress/sql/uaocs_catalog_tables.sql b/src/test/regress/sql/uaocs_catalog_tables.sql index b94d207bf0d..e0c46cee558 100644 --- a/src/test/regress/sql/uaocs_catalog_tables.sql +++ b/src/test/regress/sql/uaocs_catalog_tables.sql @@ -19,7 +19,7 @@ $$ LANGUAGE plpgsql; -- Verify empty visimap for uaocs table create table uaocs_table_check_empty_visimap (i int, j varchar(20), k int ) with (appendonly=true, orientation=column) DISTRIBUTED BY (i); insert into uaocs_table_check_empty_visimap values(1,'test',2); -select 1 from pg_appendonly where visimapidxid is not null and visimapidxid is not NULL and relid='uaocs_table_check_empty_visimap'::regclass; +SELECT count(i.indexrelid) FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND a.relid='uaocs_table_check_empty_visimap'::regclass; -- Verify the hidden tup_count using UDF gp_aovisimap_hidden_info(oid) for uaocs relation after delete and vacuum create table uaocs_table_check_hidden_tup_count_after_delete(i int, j varchar(20), k int ) with (appendonly=true, orientation=column) DISTRIBUTED BY (i); From 473de3dd2fd8a6760a807aa00e5f6856cac71365 Mon Sep 17 00:00:00 2001 From: reshke Date: Fri, 25 Apr 2025 13:13:08 +0000 Subject: [PATCH 3/3] resolve cherry-pick issues --- src/bin/pg_dump/pg_dump.c | 23 ++----------------- .../expected/ao_index_build_progress.out | 2 +- ...alter_ao_part_tables_splitpartition.source | 2 +- .../uao_ddl/analyze_ao_table_every_dml.source | 2 +- .../uao_ddl/create_ao_table_500cols.source | 2 +- .../output/uao_ddl/create_ao_tables.source | 2 +- 6 files changed, 7 insertions(+), 26 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index cb4b6e1db4c..e6d097c816c 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -5336,15 +5336,6 @@ create_ao_relname(char *dst, size_t len, const char *prefix, Oid auxoid) fatal("create_ao_relname: destination buffer is too short"); } -static void -create_ao_idxname(char *dst, size_t len, const char *prefix, Oid auxoid) -{ - size_t actual = snprintf(dst, len, "%s_%u_index", prefix, auxoid); - - if (actual >= len) - fatal("create_ao_idxname: destination buffer is too short"); -} - /* * GPDB: the implementation of this function has moved below, to * binary_upgrade_set_pg_class_oids_impl(), so that we can handle some of the @@ -5389,9 +5380,7 @@ binary_upgrade_set_pg_class_oids_impl(Archive *fout, Oid pg_class_bmidxoid; Oid ao_segrelid = InvalidOid; Oid ao_blkdirrelid = InvalidOid; - Oid ao_blkdiridxid = InvalidOid; Oid ao_visimaprelid = InvalidOid; - Oid ao_visimapidxid = InvalidOid; bool ao_columnstore = false; char pg_class_relkind; @@ -5402,8 +5391,8 @@ binary_upgrade_set_pg_class_oids_impl(Archive *fout, " i.indexrelid, ti.relname AS tidx_relname, " " bi.oid AS bmoid, bidx.oid AS bmidxoid, " " pgao.segrelid, pgao.columnstore, " - " pgao.blkdirrelid, pgao.blkdiridxid, " - " pgao.visimaprelid, pgao.visimapidxid " + " pgao.blkdirrelid, " + " pgao.visimaprelid " "FROM pg_catalog.pg_class c " "LEFT JOIN pg_catalog.pg_class t ON (c.reltoastrelid = t.oid) " "LEFT JOIN pg_catalog.pg_index i ON (c.reltoastrelid = i.indrelid AND i.indisvalid) " @@ -5442,9 +5431,7 @@ binary_upgrade_set_pg_class_oids_impl(Archive *fout, ao_segrelid = atooid(PQgetvalue(upgrade_res, 0, PQfnumber(upgrade_res, "segrelid"))); ao_columnstore = (PQgetvalue(upgrade_res, 0, PQfnumber(upgrade_res, "columnstore"))[0] == 't'); ao_blkdirrelid = atooid(PQgetvalue(upgrade_res, 0, PQfnumber(upgrade_res, "blkdirrelid"))); - ao_blkdiridxid = atooid(PQgetvalue(upgrade_res, 0, PQfnumber(upgrade_res, "blkdiridxid"))); ao_visimaprelid = atooid(PQgetvalue(upgrade_res, 0, PQfnumber(upgrade_res, "visimaprelid"))); - ao_visimapidxid = atooid(PQgetvalue(upgrade_res, 0, PQfnumber(upgrade_res, "visimapidxid"))); } @@ -5526,17 +5513,11 @@ binary_upgrade_set_pg_class_oids_impl(Archive *fout, create_ao_relname(ao_relname, sizeof(ao_relname), "pg_aoblkdir", pg_class_oid); binary_upgrade_set_pg_class_oids_for_ao(fout, upgrade_buffer, ao_blkdirrelid, false, ao_relname); binary_upgrade_set_type_oids_for_ao(fout, upgrade_buffer, ao_blkdirrelid, ao_relname); - - create_ao_idxname(ao_relname, sizeof(ao_relname), "pg_aoblkdir", pg_class_oid); - binary_upgrade_set_pg_class_oids_for_ao(fout, upgrade_buffer, ao_blkdiridxid, true, ao_relname); } create_ao_relname(ao_relname, sizeof(ao_relname), "pg_aovisimap", pg_class_oid); binary_upgrade_set_pg_class_oids_for_ao(fout, upgrade_buffer, ao_visimaprelid, false, ao_relname); binary_upgrade_set_type_oids_for_ao(fout, upgrade_buffer, ao_visimaprelid, ao_relname); - - create_ao_idxname(ao_relname, sizeof(ao_relname), "pg_aovisimap", pg_class_oid); - binary_upgrade_set_pg_class_oids_for_ao(fout, upgrade_buffer, ao_visimapidxid, true, ao_relname); } PQclear(upgrade_res); diff --git a/src/test/isolation2/expected/ao_index_build_progress.out b/src/test/isolation2/expected/ao_index_build_progress.out index 1048076ce9f..74a9f77b7c2 100644 --- a/src/test/isolation2/expected/ao_index_build_progress.out +++ b/src/test/isolation2/expected/ao_index_build_progress.out @@ -110,7 +110,7 @@ SELECT gp_wait_until_triggered_fault('AppendOnlyStorageRead_ReadNextBlock_succes 1U: SELECT command, phase, ((pg_stat_file(pg_relation_filepath('aoco_index_build_progress') || '.' || 129)).size + (current_setting('block_size')::int - 1)) / current_setting('block_size')::int AS col_j_blocks, blocks_total AS blocks_total_reported, blocks_done AS blocks_done_reported FROM pg_stat_progress_create_index WHERE relid = 'aoco_index_build_progress'::regclass; command | phase | col_j_blocks | blocks_total_reported | blocks_done_reported --------------+--------------------------------+--------------+-----------------------+---------------------- - CREATE INDEX | building index: scanning table | 8 | 20 | 4 + CREATE INDEX | building index: scanning table | 8 | 20 | 3 (1 row) SELECT gp_inject_fault('AppendOnlyStorageRead_ReadNextBlock_success', 'reset', dbid) FROM gp_segment_configuration WHERE content = 1 AND role = 'p'; diff --git a/src/test/regress/output/uao_ddl/alter_ao_part_tables_splitpartition.source b/src/test/regress/output/uao_ddl/alter_ao_part_tables_splitpartition.source index 384fcc5b180..f685e69ac56 100644 --- a/src/test/regress/output/uao_ddl/alter_ao_part_tables_splitpartition.source +++ b/src/test/regress/output/uao_ddl/alter_ao_part_tables_splitpartition.source @@ -15,7 +15,7 @@ pg_class c join pg_namespace n on c.relnamespace = n.oid and c.relname like 'sto_alt_uao_part_splitpartition%' and n.nspname = 'alter_ao_part_tables_splitpartition_@amname@'); visimapcount -------------- +-------------- 3 (1 row) diff --git a/src/test/regress/output/uao_ddl/analyze_ao_table_every_dml.source b/src/test/regress/output/uao_ddl/analyze_ao_table_every_dml.source index 35e1fe8b8f9..62b4cdde1f4 100644 --- a/src/test/regress/output/uao_ddl/analyze_ao_table_every_dml.source +++ b/src/test/regress/output/uao_ddl/analyze_ao_table_every_dml.source @@ -28,7 +28,7 @@ select relname, reltuples from pg_class where oid='sto_uao_city_analyze_everydml SELECT count(i.indexrelid) = 1 AS VisimapPresent FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND a.relid='sto_uao_city_analyze_everydml'::regclass; visimappresent ------------- +---------------- t (1 row) diff --git a/src/test/regress/output/uao_ddl/create_ao_table_500cols.source b/src/test/regress/output/uao_ddl/create_ao_table_500cols.source index 633fd88ae47..a3085d74e00 100644 --- a/src/test/regress/output/uao_ddl/create_ao_table_500cols.source +++ b/src/test/regress/output/uao_ddl/create_ao_table_500cols.source @@ -113,7 +113,7 @@ a498 inet, a499 time, a500 text) SELECT count(i.indexrelid) = 1 AS VisimapPresent FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND a.relid='sto_uao_500cols'::regclass; visimappresent ------------- +---------------- t (1 row) diff --git a/src/test/regress/output/uao_ddl/create_ao_tables.source b/src/test/regress/output/uao_ddl/create_ao_tables.source index 1d96a541a9b..8906923575d 100644 --- a/src/test/regress/output/uao_ddl/create_ao_tables.source +++ b/src/test/regress/output/uao_ddl/create_ao_tables.source @@ -292,7 +292,7 @@ set gp_select_invisible=false; SELECT count(i.indexrelid) = 1 AS VisimapPresent FROM pg_appendonly a, pg_index i WHERE a.visimaprelid = i.indrelid AND a.relid='sto_uao_9'::regclass; visimappresent ------------- +---------------- t (1 row)