Skip to content

Commit b6e9971

Browse files
soumyadeep2007yjhjstz
authored andcommitted
ao/co index build scans: Only use SnapshotAny
We can simply use SnapshotAny for AO/CO index build scans because: i) We don't support concurrent index builds on AO/CO tables. ii) No AO/CO tables are created during bootstrap.
1 parent 41b93ee commit b6e9971

2 files changed

Lines changed: 6 additions & 89 deletions

File tree

src/backend/access/aocs/aocsam_handler.c

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1696,8 +1696,6 @@ aoco_index_build_range_scan(Relation heapRelation,
16961696
EState *estate;
16971697
ExprContext *econtext;
16981698
Snapshot snapshot;
1699-
bool need_unregister_snapshot = false;
1700-
TransactionId OldestXmin;
17011699
AOCSFileSegInfo **seginfo = NULL;
17021700
int32 segfile_count;
17031701
int64 total_blockcount = 0;
@@ -1743,34 +1741,15 @@ aoco_index_build_range_scan(Relation heapRelation,
17431741
/* Set up execution state for predicate, if any. */
17441742
predicate = ExecPrepareQual(indexInfo->ii_Predicate, estate);
17451743

1746-
/*
1747-
* Prepare for scan of the base relation. In a normal index build, we use
1748-
* SnapshotAny because we must retrieve all tuples and do our own time
1749-
* qual checks (because we have to index RECENTLY_DEAD tuples). In a
1750-
* concurrent build, or during bootstrap, we take a regular MVCC snapshot
1751-
* and index whatever's live according to that.
1752-
*/
1753-
OldestXmin = InvalidTransactionId;
1754-
1755-
/* okay to ignore lazy VACUUMs here */
1756-
if (!IsBootstrapProcessingMode() && !indexInfo->ii_Concurrent)
1757-
OldestXmin = GetOldestNonRemovableTransactionId(heapRelation);
1758-
17591744
if (!scan)
17601745
{
17611746
/*
17621747
* Serial index build.
17631748
*
1764-
* Must begin our own heap scan in this case. We may also need to
1765-
* register a snapshot whose lifetime is under our direct control.
1749+
* XXX: We always use SnapshotAny here. An MVCC snapshot and oldest xmin
1750+
* calculation is necessary to support indexes built CONCURRENTLY.
17661751
*/
1767-
if (!TransactionIdIsValid(OldestXmin))
1768-
{
1769-
snapshot = RegisterSnapshot(GetTransactionSnapshot());
1770-
need_unregister_snapshot = true;
1771-
}
1772-
else
1773-
snapshot = SnapshotAny;
1752+
snapshot = SnapshotAny;
17741753

17751754
scan = table_beginscan_strat(heapRelation, /* relation */
17761755
snapshot, /* snapshot */
@@ -1864,23 +1843,6 @@ aoco_index_build_range_scan(Relation heapRelation,
18641843
total_blockcount);
18651844
}
18661845

1867-
1868-
/*
1869-
* GPDB_14_MERGE_FIXME
1870-
* Same as in appendonly_handler.c:
1871-
* Need to check the comments here as GetOldestXmin() has been removed.
1872-
*/
1873-
/*
1874-
* Must call GetOldestXmin() with SnapshotAny. Should never call
1875-
* GetOldestXmin() with MVCC snapshot. (It's especially worth checking
1876-
* this for parallel builds, since ambuild routines that support parallel
1877-
* builds must work these details out for themselves.)
1878-
*/
1879-
Assert(snapshot == SnapshotAny || IsMVCCSnapshot(snapshot));
1880-
Assert(snapshot == SnapshotAny ? TransactionIdIsValid(OldestXmin) :
1881-
!TransactionIdIsValid(OldestXmin));
1882-
Assert(snapshot == SnapshotAny || !anyvisible);
1883-
18841846
/* set our scan endpoints */
18851847
if (!allow_sync)
18861848
{
@@ -2006,10 +1968,6 @@ aoco_index_build_range_scan(Relation heapRelation,
20061968

20071969
table_endscan(scan);
20081970

2009-
/* we can now forget our snapshot, if set and registered by us */
2010-
if (need_unregister_snapshot)
2011-
UnregisterSnapshot(snapshot);
2012-
20131971
ExecDropSingleTupleTableSlot(slot);
20141972

20151973
FreeExecutorState(estate);

src/backend/access/appendonly/appendonlyam_handler.c

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,8 +1567,6 @@ appendonly_index_build_range_scan(Relation heapRelation,
15671567
EState *estate;
15681568
ExprContext *econtext;
15691569
Snapshot snapshot;
1570-
bool need_unregister_snapshot = false;
1571-
TransactionId OldestXmin;
15721570
FileSegInfo **seginfo = NULL;
15731571
int segfile_count;
15741572
int64 total_blockcount = 0;
@@ -1612,35 +1610,15 @@ appendonly_index_build_range_scan(Relation heapRelation,
16121610
/* Set up execution state for predicate, if any. */
16131611
predicate = ExecPrepareQual(indexInfo->ii_Predicate, estate);
16141612

1615-
/*
1616-
* Prepare for scan of the base relation. In a normal index build, we use
1617-
* SnapshotAny because we must retrieve all tuples and do our own time
1618-
* qual checks (because we have to index RECENTLY_DEAD tuples). In a
1619-
* concurrent build, or during bootstrap, we take a regular MVCC snapshot
1620-
* and index whatever's live according to that.
1621-
*/
1622-
OldestXmin = InvalidTransactionId;
1623-
1624-
/* okay to ignore lazy VACUUMs here */
1625-
if (!IsBootstrapProcessingMode() && !indexInfo->ii_Concurrent)
1626-
OldestXmin = GetOldestNonRemovableTransactionId(heapRelation);
1627-
16281613
if (!scan)
16291614
{
16301615
/*
16311616
* Serial index build.
16321617
*
1633-
* Must begin our own heap scan in this case. We may also need to
1634-
* register a snapshot whose lifetime is under our direct control.
1618+
* XXX: We always use SnapshotAny here. An MVCC snapshot and oldest xmin
1619+
* calculation is necessary to support indexes built CONCURRENTLY.
16351620
*/
1636-
if (!TransactionIdIsValid(OldestXmin))
1637-
{
1638-
snapshot = RegisterSnapshot(GetTransactionSnapshot());
1639-
need_unregister_snapshot = true;
1640-
}
1641-
else
1642-
snapshot = SnapshotAny;
1643-
1621+
snapshot = SnapshotAny;
16441622
scan = table_beginscan_strat(heapRelation, /* relation */
16451623
snapshot, /* snapshot */
16461624
0, /* number of keys */
@@ -1708,21 +1686,6 @@ appendonly_index_build_range_scan(Relation heapRelation,
17081686
pgstat_progress_update_param(PROGRESS_SCAN_BLOCKS_TOTAL, total_blockcount);
17091687
}
17101688

1711-
/*
1712-
* GPDB_14_MERGE_FIXME
1713-
* Need to check the comments here as GetOldestXmin() has been removed.
1714-
*/
1715-
/*
1716-
* Must call GetOldestXmin() with SnapshotAny. Should never call
1717-
* GetOldestXmin() with MVCC snapshot. (It's especially worth checking
1718-
* this for parallel builds, since ambuild routines that support parallel
1719-
* builds must work these details out for themselves.)
1720-
*/
1721-
Assert(snapshot == SnapshotAny || IsMVCCSnapshot(snapshot));
1722-
Assert(snapshot == SnapshotAny ? TransactionIdIsValid(OldestXmin) :
1723-
!TransactionIdIsValid(OldestXmin));
1724-
Assert(snapshot == SnapshotAny || !anyvisible);
1725-
17261689
/* set our scan endpoints */
17271690
if (!allow_sync)
17281691
{
@@ -1828,10 +1791,6 @@ appendonly_index_build_range_scan(Relation heapRelation,
18281791

18291792
table_endscan(scan);
18301793

1831-
/* we can now forget our snapshot, if set and registered by us */
1832-
if (need_unregister_snapshot)
1833-
UnregisterSnapshot(snapshot);
1834-
18351794
ExecDropSingleTupleTableSlot(slot);
18361795

18371796
FreeExecutorState(estate);

0 commit comments

Comments
 (0)