sysscan->snapshot = NULL;
}
+ /*
+ * If CheckXidAlive is set then set a flag to indicate that system table
+ * scan is in-progress. See detailed comments in xact.c where these
+ * variables are declared.
+ */
+ if (TransactionIdIsValid(CheckXidAlive))
+ bsysscan = true;
+
if (irel)
{
int i;
sysscan->iscan = NULL;
}
- /*
- * If CheckXidAlive is set then set a flag to indicate that system table
- * scan is in-progress. See detailed comments in xact.c where these
- * variables are declared.
- */
- if (TransactionIdIsValid(CheckXidAlive))
- bsysscan = true;
-
return sysscan;
}
elog(ERROR, "column is not in index");
}
- sysscan->iscan = index_beginscan(heapRelation, indexRelation,
- snapshot, NULL, nkeys, 0);
- index_rescan(sysscan->iscan, idxkey, nkeys, NULL, 0);
- sysscan->scan = NULL;
-
- pfree(idxkey);
-
/*
* If CheckXidAlive is set then set a flag to indicate that system table
* scan is in-progress. See detailed comments in xact.c where these
if (TransactionIdIsValid(CheckXidAlive))
bsysscan = true;
+ sysscan->iscan = index_beginscan(heapRelation, indexRelation,
+ snapshot, NULL, nkeys, 0);
+ index_rescan(sysscan->iscan, idxkey, nkeys, NULL, 0);
+ sysscan->scan = NULL;
+
+ pfree(idxkey);
+
return sysscan;
}
Oid relid = RelationGetRelid(relation);
Snapshot snapshot = RegisterSnapshot(GetCatalogSnapshot(relid));
- return relation->rd_tableam->scan_begin(relation, snapshot, nkeys, key,
- NULL, flags);
+ return table_beginscan_common(relation, snapshot, nkeys, key,
+ NULL, flags);
}
snapshot = SnapshotAny;
}
- return relation->rd_tableam->scan_begin(relation, snapshot, 0, NULL,
- pscan, flags);
+ return table_beginscan_common(relation, snapshot, 0, NULL,
+ pscan, flags);
}
TableScanDesc
snapshot = SnapshotAny;
}
- sscan = relation->rd_tableam->scan_begin(relation, snapshot, 0, NULL,
- pscan, flags);
+ sscan = table_beginscan_common(relation, snapshot, 0, NULL,
+ pscan, flags);
return sscan;
}
Relation rel = scan->rs_rd;
const TableAmRoutine *tableam = rel->rd_tableam;
- /*
- * We don't expect direct calls to table_tuple_get_latest_tid with valid
- * CheckXidAlive for catalog or regular tables. See detailed comments in
- * xact.c where these variables are declared.
- */
- if (unlikely(TransactionIdIsValid(CheckXidAlive) && !bsysscan))
- elog(ERROR, "unexpected table_tuple_get_latest_tid call during logical decoding");
-
/*
* Since this can be called with user-supplied TID, don't trust the input
* too much.
* ----------------------------------------------------------------------------
*/
+/*
+ * A wrapper around the Table Access Method scan_begin callback, to centralize
+ * error checking. All calls to ->scan_begin() should go through this
+ * function.
+ */
+static TableScanDesc
+table_beginscan_common(Relation rel, Snapshot snapshot, int nkeys,
+ ScanKeyData *key, ParallelTableScanDesc pscan,
+ uint32 flags)
+{
+ /*
+ * We don't allow scans to be started while CheckXidAlive is set, except
+ * via systable_beginscan() et al. See detailed comments in xact.c where
+ * these variables are declared.
+ */
+ if (unlikely(TransactionIdIsValid(CheckXidAlive) && !bsysscan))
+ elog(ERROR, "scan started during logical decoding");
+
+ return rel->rd_tableam->scan_begin(rel, snapshot, nkeys, key, pscan, flags);
+}
+
/*
* Start a scan of `rel`. Returned tuples pass a visibility test of
* `snapshot`, and if nkeys != 0, the results are filtered by those scan keys.
uint32 flags = SO_TYPE_SEQSCAN |
SO_ALLOW_STRAT | SO_ALLOW_SYNC | SO_ALLOW_PAGEMODE;
- return rel->rd_tableam->scan_begin(rel, snapshot, nkeys, key, NULL, flags);
+ return table_beginscan_common(rel, snapshot, nkeys, key, NULL, flags);
}
/*
if (allow_sync)
flags |= SO_ALLOW_SYNC;
- return rel->rd_tableam->scan_begin(rel, snapshot, nkeys, key, NULL, flags);
+ return table_beginscan_common(rel, snapshot, nkeys, key, NULL, flags);
}
/*
{
uint32 flags = SO_TYPE_BITMAPSCAN | SO_ALLOW_PAGEMODE;
- return rel->rd_tableam->scan_begin(rel, snapshot, nkeys, key,
- NULL, flags);
+ return table_beginscan_common(rel, snapshot, nkeys, key, NULL, flags);
}
/*
if (allow_pagemode)
flags |= SO_ALLOW_PAGEMODE;
- return rel->rd_tableam->scan_begin(rel, snapshot, nkeys, key, NULL, flags);
+ return table_beginscan_common(rel, snapshot, nkeys, key, NULL, flags);
}
/*
{
uint32 flags = SO_TYPE_TIDSCAN;
- return rel->rd_tableam->scan_begin(rel, snapshot, 0, NULL, NULL, flags);
+ return table_beginscan_common(rel, snapshot, 0, NULL, NULL, flags);
}
/*
{
uint32 flags = SO_TYPE_ANALYZE;
- return rel->rd_tableam->scan_begin(rel, NULL, 0, NULL, NULL, flags);
+ return table_beginscan_common(rel, NULL, 0, NULL, NULL, flags);
}
/*
Assert(direction == ForwardScanDirection ||
direction == BackwardScanDirection);
- /*
- * We don't expect direct calls to table_scan_getnextslot with valid
- * CheckXidAlive for catalog or regular tables. See detailed comments in
- * xact.c where these variables are declared.
- */
- if (unlikely(TransactionIdIsValid(CheckXidAlive) && !bsysscan))
- elog(ERROR, "unexpected table_scan_getnextslot call during logical decoding");
-
return sscan->rs_rd->rd_tableam->scan_getnextslot(sscan, direction, slot);
}
TableScanDesc sscan;
uint32 flags = SO_TYPE_TIDRANGESCAN | SO_ALLOW_PAGEMODE;
- sscan = rel->rd_tableam->scan_begin(rel, snapshot, 0, NULL, NULL, flags);
+ sscan = table_beginscan_common(rel, snapshot, 0, NULL, NULL, flags);
/* Set the range of TIDs to scan */
sscan->rs_rd->rd_tableam->scan_set_tidrange(sscan, mintid, maxtid);
static inline IndexFetchTableData *
table_index_fetch_begin(Relation rel)
{
+ /*
+ * We don't allow scans to be started while CheckXidAlive is set, except
+ * via systable_beginscan() et al. See detailed comments in xact.c where
+ * these variables are declared.
+ */
+ if (unlikely(TransactionIdIsValid(CheckXidAlive) && !bsysscan))
+ elog(ERROR, "scan started during logical decoding");
+
return rel->rd_tableam->index_fetch_begin(rel);
}
TupleTableSlot *slot,
bool *call_again, bool *all_dead)
{
- /*
- * We don't expect direct calls to table_index_fetch_tuple with valid
- * CheckXidAlive for catalog or regular tables. See detailed comments in
- * xact.c where these variables are declared.
- */
- if (unlikely(TransactionIdIsValid(CheckXidAlive) && !bsysscan))
- elog(ERROR, "unexpected table_index_fetch_tuple call during logical decoding");
-
return scan->rel->rd_tableam->index_fetch_tuple(scan, tid, snapshot,
slot, call_again,
all_dead);
uint64 *lossy_pages,
uint64 *exact_pages)
{
- /*
- * We don't expect direct calls to table_scan_bitmap_next_tuple with valid
- * CheckXidAlive for catalog or regular tables. See detailed comments in
- * xact.c where these variables are declared.
- */
- if (unlikely(TransactionIdIsValid(CheckXidAlive) && !bsysscan))
- elog(ERROR, "unexpected table_scan_bitmap_next_tuple call during logical decoding");
-
return scan->rs_rd->rd_tableam->scan_bitmap_next_tuple(scan,
slot,
recheck,
table_scan_sample_next_block(TableScanDesc scan,
SampleScanState *scanstate)
{
- /*
- * We don't expect direct calls to table_scan_sample_next_block with valid
- * CheckXidAlive for catalog or regular tables. See detailed comments in
- * xact.c where these variables are declared.
- */
- if (unlikely(TransactionIdIsValid(CheckXidAlive) && !bsysscan))
- elog(ERROR, "unexpected table_scan_sample_next_block call during logical decoding");
return scan->rs_rd->rd_tableam->scan_sample_next_block(scan, scanstate);
}
SampleScanState *scanstate,
TupleTableSlot *slot)
{
- /*
- * We don't expect direct calls to table_scan_sample_next_tuple with valid
- * CheckXidAlive for catalog or regular tables. See detailed comments in
- * xact.c where these variables are declared.
- */
- if (unlikely(TransactionIdIsValid(CheckXidAlive) && !bsysscan))
- elog(ERROR, "unexpected table_scan_sample_next_tuple call during logical decoding");
return scan->rs_rd->rd_tableam->scan_sample_next_tuple(scan, scanstate,
slot);
}