PostgreSQL Source Code  git master
genam.h File Reference
#include "access/sdir.h"
#include "access/skey.h"
#include "nodes/tidbitmap.h"
#include "storage/lockdefs.h"
#include "utils/relcache.h"
#include "utils/snapshot.h"
Include dependency graph for genam.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  IndexBuildResult
 
struct  IndexVacuumInfo
 
struct  IndexBulkDeleteResult
 

Macros

#define IndexScanIsValid(scan)   PointerIsValid(scan)
 

Typedefs

typedef struct IndexBuildResult IndexBuildResult
 
typedef struct IndexVacuumInfo IndexVacuumInfo
 
typedef struct IndexBulkDeleteResult IndexBulkDeleteResult
 
typedef bool(* IndexBulkDeleteCallback) (ItemPointer itemptr, void *state)
 
typedef struct IndexScanDescDataIndexScanDesc
 
typedef struct SysScanDescDataSysScanDesc
 
typedef struct ParallelIndexScanDescDataParallelIndexScanDesc
 
typedef enum IndexUniqueCheck IndexUniqueCheck
 

Enumerations

enum  IndexUniqueCheck { UNIQUE_CHECK_NO, UNIQUE_CHECK_YES, UNIQUE_CHECK_PARTIAL, UNIQUE_CHECK_EXISTING }
 

Functions

Relation index_open (Oid relationId, LOCKMODE lockmode)
 
void index_close (Relation relation, LOCKMODE lockmode)
 
bool index_insert (Relation indexRelation, Datum *values, bool *isnull, ItemPointer heap_t_ctid, Relation heapRelation, IndexUniqueCheck checkUnique, struct IndexInfo *indexInfo)
 
IndexScanDesc index_beginscan (Relation heapRelation, Relation indexRelation, Snapshot snapshot, int nkeys, int norderbys)
 
IndexScanDesc index_beginscan_bitmap (Relation indexRelation, Snapshot snapshot, int nkeys)
 
void index_rescan (IndexScanDesc scan, ScanKey keys, int nkeys, ScanKey orderbys, int norderbys)
 
void index_endscan (IndexScanDesc scan)
 
void index_markpos (IndexScanDesc scan)
 
void index_restrpos (IndexScanDesc scan)
 
Size index_parallelscan_estimate (Relation indexrel, Snapshot snapshot)
 
void index_parallelscan_initialize (Relation heaprel, Relation indexrel, Snapshot snapshot, ParallelIndexScanDesc target)
 
void index_parallelrescan (IndexScanDesc scan)
 
IndexScanDesc index_beginscan_parallel (Relation heaprel, Relation indexrel, int nkeys, int norderbys, ParallelIndexScanDesc pscan)
 
ItemPointer index_getnext_tid (IndexScanDesc scan, ScanDirection direction)
 
HeapTuple index_fetch_heap (IndexScanDesc scan)
 
HeapTuple index_getnext (IndexScanDesc scan, ScanDirection direction)
 
int64 index_getbitmap (IndexScanDesc scan, TIDBitmap *bitmap)
 
IndexBulkDeleteResultindex_bulk_delete (IndexVacuumInfo *info, IndexBulkDeleteResult *stats, IndexBulkDeleteCallback callback, void *callback_state)
 
IndexBulkDeleteResultindex_vacuum_cleanup (IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
 
bool index_can_return (Relation indexRelation, int attno)
 
RegProcedure index_getprocid (Relation irel, AttrNumber attnum, uint16 procnum)
 
FmgrInfoindex_getprocinfo (Relation irel, AttrNumber attnum, uint16 procnum)
 
IndexScanDesc RelationGetIndexScan (Relation indexRelation, int nkeys, int norderbys)
 
void IndexScanEnd (IndexScanDesc scan)
 
char * BuildIndexValueDescription (Relation indexRelation, Datum *values, bool *isnull)
 
SysScanDesc systable_beginscan (Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
 
HeapTuple systable_getnext (SysScanDesc sysscan)
 
bool systable_recheck_tuple (SysScanDesc sysscan, HeapTuple tup)
 
void systable_endscan (SysScanDesc sysscan)
 
SysScanDesc systable_beginscan_ordered (Relation heapRelation, Relation indexRelation, Snapshot snapshot, int nkeys, ScanKey key)
 
HeapTuple systable_getnext_ordered (SysScanDesc sysscan, ScanDirection direction)
 
void systable_endscan_ordered (SysScanDesc sysscan)
 

Macro Definition Documentation

◆ IndexScanIsValid

#define IndexScanIsValid (   scan)    PointerIsValid(scan)

Definition at line 128 of file genam.h.

Typedef Documentation

◆ IndexBuildResult

◆ IndexBulkDeleteCallback

typedef bool(* IndexBulkDeleteCallback) (ItemPointer itemptr, void *state)

Definition at line 83 of file genam.h.

◆ IndexBulkDeleteResult

◆ IndexScanDesc

Definition at line 86 of file genam.h.

◆ IndexUniqueCheck

◆ IndexVacuumInfo

◆ ParallelIndexScanDesc

Definition at line 89 of file genam.h.

◆ SysScanDesc

Definition at line 87 of file genam.h.

Enumeration Type Documentation

◆ IndexUniqueCheck

Enumerator
UNIQUE_CHECK_NO 
UNIQUE_CHECK_YES 
UNIQUE_CHECK_PARTIAL 
UNIQUE_CHECK_EXISTING 

Definition at line 111 of file genam.h.

112 {
113  UNIQUE_CHECK_NO, /* Don't do any uniqueness checking */
114  UNIQUE_CHECK_YES, /* Enforce uniqueness at insertion time */
115  UNIQUE_CHECK_PARTIAL, /* Test uniqueness, but no error */
116  UNIQUE_CHECK_EXISTING /* Check if existing tuple is unique */
IndexUniqueCheck
Definition: genam.h:111

Function Documentation

◆ BuildIndexValueDescription()

char* BuildIndexValueDescription ( Relation  indexRelation,
Datum values,
bool isnull 
)

Definition at line 177 of file genam.c.

References ACL_SELECT, ACLCHECK_OK, appendStringInfo(), appendStringInfoChar(), appendStringInfoString(), Assert, buf, check_enable_rls(), StringInfoData::data, elog, ERROR, GETSTRUCT, getTypeOutputInfo(), GetUserId(), HeapTupleIsValid, i, INDEXRELID, initStringInfo(), InvalidAttrNumber, InvalidOid, ObjectIdGetDatum, OidOutputFunctionCall(), pg_attribute_aclcheck(), pg_class_aclcheck(), pg_get_indexdef_columns(), RelationData::rd_opcintype, RelationData::rd_rel, RelationGetRelid, ReleaseSysCache(), RLS_ENABLED, SearchSysCache1(), and val.

Referenced by _bt_check_unique(), check_exclusion_or_unique_constraint(), and comparetup_index_btree().

179 {
181  Form_pg_index idxrec;
182  HeapTuple ht_idx;
183  int natts = indexRelation->rd_rel->relnatts;
184  int i;
185  int keyno;
186  Oid indexrelid = RelationGetRelid(indexRelation);
187  Oid indrelid;
188  AclResult aclresult;
189 
190  /*
191  * Check permissions- if the user does not have access to view all of the
192  * key columns then return NULL to avoid leaking data.
193  *
194  * First check if RLS is enabled for the relation. If so, return NULL to
195  * avoid leaking data.
196  *
197  * Next we need to check table-level SELECT access and then, if there is
198  * no access there, check column-level permissions.
199  */
200 
201  /*
202  * Fetch the pg_index tuple by the Oid of the index
203  */
204  ht_idx = SearchSysCache1(INDEXRELID, ObjectIdGetDatum(indexrelid));
205  if (!HeapTupleIsValid(ht_idx))
206  elog(ERROR, "cache lookup failed for index %u", indexrelid);
207  idxrec = (Form_pg_index) GETSTRUCT(ht_idx);
208 
209  indrelid = idxrec->indrelid;
210  Assert(indexrelid == idxrec->indexrelid);
211 
212  /* RLS check- if RLS is enabled then we don't return anything. */
213  if (check_enable_rls(indrelid, InvalidOid, true) == RLS_ENABLED)
214  {
215  ReleaseSysCache(ht_idx);
216  return NULL;
217  }
218 
219  /* Table-level SELECT is enough, if the user has it */
220  aclresult = pg_class_aclcheck(indrelid, GetUserId(), ACL_SELECT);
221  if (aclresult != ACLCHECK_OK)
222  {
223  /*
224  * No table-level access, so step through the columns in the index and
225  * make sure the user has SELECT rights on all of them.
226  */
227  for (keyno = 0; keyno < idxrec->indnatts; keyno++)
228  {
229  AttrNumber attnum = idxrec->indkey.values[keyno];
230 
231  /*
232  * Note that if attnum == InvalidAttrNumber, then this is an index
233  * based on an expression and we return no detail rather than try
234  * to figure out what column(s) the expression includes and if the
235  * user has SELECT rights on them.
236  */
237  if (attnum == InvalidAttrNumber ||
238  pg_attribute_aclcheck(indrelid, attnum, GetUserId(),
240  {
241  /* No access, so clean up and return */
242  ReleaseSysCache(ht_idx);
243  return NULL;
244  }
245  }
246  }
247  ReleaseSysCache(ht_idx);
248 
249  initStringInfo(&buf);
250  appendStringInfo(&buf, "(%s)=(",
251  pg_get_indexdef_columns(indexrelid, true));
252 
253  for (i = 0; i < natts; i++)
254  {
255  char *val;
256 
257  if (isnull[i])
258  val = "null";
259  else
260  {
261  Oid foutoid;
262  bool typisvarlena;
263 
264  /*
265  * The provided data is not necessarily of the type stored in the
266  * index; rather it is of the index opclass's input type. So look
267  * at rd_opcintype not the index tupdesc.
268  *
269  * Note: this is a bit shaky for opclasses that have pseudotype
270  * input types such as ANYARRAY or RECORD. Currently, the
271  * typoutput functions associated with the pseudotypes will work
272  * okay, but we might have to try harder in future.
273  */
274  getTypeOutputInfo(indexRelation->rd_opcintype[i],
275  &foutoid, &typisvarlena);
276  val = OidOutputFunctionCall(foutoid, values[i]);
277  }
278 
279  if (i > 0)
280  appendStringInfoString(&buf, ", ");
281  appendStringInfoString(&buf, val);
282  }
283 
284  appendStringInfoChar(&buf, ')');
285 
286  return buf.data;
287 }
void getTypeOutputInfo(Oid type, Oid *typOutput, bool *typIsVarlena)
Definition: lsyscache.c:2646
#define GETSTRUCT(TUP)
Definition: htup_details.h:661
AclResult pg_attribute_aclcheck(Oid table_oid, AttrNumber attnum, Oid roleid, AclMode mode)
Definition: aclchk.c:4308
Oid GetUserId(void)
Definition: miscinit.c:284
char * pg_get_indexdef_columns(Oid indexrelid, bool pretty)
Definition: ruleutils.c:1131
Form_pg_class rd_rel
Definition: rel.h:114
unsigned int Oid
Definition: postgres_ext.h:31
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:78
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:157
static char * buf
Definition: pg_test_fsync.c:67
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:169
void initStringInfo(StringInfo str)
Definition: stringinfo.c:46
FormData_pg_index * Form_pg_index
Definition: pg_index.h:67
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1112
AclResult
Definition: acl.h:178
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1160
#define ACL_SELECT
Definition: parsenodes.h:73
#define InvalidOid
Definition: postgres_ext.h:36
int check_enable_rls(Oid relid, Oid checkAsUser, bool noError)
Definition: rls.c:53
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define Assert(condition)
Definition: c.h:670
#define InvalidAttrNumber
Definition: attnum.h:23
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4422
static Datum values[MAXATTR]
Definition: bootstrap.c:164
char * OidOutputFunctionCall(Oid functionId, Datum val)
Definition: fmgr.c:1742
int i
#define elog
Definition: elog.h:219
Oid * rd_opcintype
Definition: rel.h:183
int16 AttrNumber
Definition: attnum.h:21
#define RelationGetRelid(relation)
Definition: rel.h:425
long val
Definition: informix.c:689

◆ index_beginscan()

IndexScanDesc index_beginscan ( Relation  heapRelation,
Relation  indexRelation,
Snapshot  snapshot,
int  nkeys,
int  norderbys 
)

Definition at line 221 of file indexam.c.

References IndexScanDescData::heapRelation, index_beginscan_internal(), and IndexScanDescData::xs_snapshot.

Referenced by check_exclusion_or_unique_constraint(), copy_heap_data(), get_actual_variable_range(), IndexNext(), IndexNextWithReorder(), IndexOnlyNext(), RelationFindReplTupleByIndex(), systable_beginscan(), and systable_beginscan_ordered().

225 {
226  IndexScanDesc scan;
227 
228  scan = index_beginscan_internal(indexRelation, nkeys, norderbys, snapshot, NULL, false);
229 
230  /*
231  * Save additional parameters into the scandesc. Everything else was set
232  * up by RelationGetIndexScan.
233  */
234  scan->heapRelation = heapRelation;
235  scan->xs_snapshot = snapshot;
236 
237  return scan;
238 }
Snapshot xs_snapshot
Definition: relscan.h:91
Relation heapRelation
Definition: relscan.h:89
static IndexScanDesc index_beginscan_internal(Relation indexRelation, int nkeys, int norderbys, Snapshot snapshot, ParallelIndexScanDesc pscan, bool temp_snap)
Definition: indexam.c:268

◆ index_beginscan_bitmap()

IndexScanDesc index_beginscan_bitmap ( Relation  indexRelation,
Snapshot  snapshot,
int  nkeys 
)

Definition at line 247 of file indexam.c.

References index_beginscan_internal(), and IndexScanDescData::xs_snapshot.

Referenced by ExecInitBitmapIndexScan().

250 {
251  IndexScanDesc scan;
252 
253  scan = index_beginscan_internal(indexRelation, nkeys, 0, snapshot, NULL, false);
254 
255  /*
256  * Save additional parameters into the scandesc. Everything else was set
257  * up by RelationGetIndexScan.
258  */
259  scan->xs_snapshot = snapshot;
260 
261  return scan;
262 }
Snapshot xs_snapshot
Definition: relscan.h:91
static IndexScanDesc index_beginscan_internal(Relation indexRelation, int nkeys, int norderbys, Snapshot snapshot, ParallelIndexScanDesc pscan, bool temp_snap)
Definition: indexam.c:268

◆ index_beginscan_parallel()

IndexScanDesc index_beginscan_parallel ( Relation  heaprel,
Relation  indexrel,
int  nkeys,
int  norderbys,
ParallelIndexScanDesc  pscan 
)

Definition at line 496 of file indexam.c.

References Assert, IndexScanDescData::heapRelation, index_beginscan_internal(), ParallelIndexScanDescData::ps_relid, ParallelIndexScanDescData::ps_snapshot_data, RegisterSnapshot(), RelationGetRelid, RestoreSnapshot(), and IndexScanDescData::xs_snapshot.

Referenced by ExecIndexOnlyScanInitializeDSM(), ExecIndexOnlyScanInitializeWorker(), ExecIndexScanInitializeDSM(), and ExecIndexScanInitializeWorker().

498 {
499  Snapshot snapshot;
500  IndexScanDesc scan;
501 
502  Assert(RelationGetRelid(heaprel) == pscan->ps_relid);
503  snapshot = RestoreSnapshot(pscan->ps_snapshot_data);
504  RegisterSnapshot(snapshot);
505  scan = index_beginscan_internal(indexrel, nkeys, norderbys, snapshot,
506  pscan, true);
507 
508  /*
509  * Save additional parameters into the scandesc. Everything else was set
510  * up by index_beginscan_internal.
511  */
512  scan->heapRelation = heaprel;
513  scan->xs_snapshot = snapshot;
514 
515  return scan;
516 }
Snapshot RestoreSnapshot(char *start_address)
Definition: snapmgr.c:2129
Snapshot RegisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:863
Snapshot xs_snapshot
Definition: relscan.h:91
char ps_snapshot_data[FLEXIBLE_ARRAY_MEMBER]
Definition: relscan.h:149
Relation heapRelation
Definition: relscan.h:89
static IndexScanDesc index_beginscan_internal(Relation indexRelation, int nkeys, int norderbys, Snapshot snapshot, ParallelIndexScanDesc pscan, bool temp_snap)
Definition: indexam.c:268
#define Assert(condition)
Definition: c.h:670
#define RelationGetRelid(relation)
Definition: rel.h:425

◆ index_bulk_delete()

IndexBulkDeleteResult* index_bulk_delete ( IndexVacuumInfo info,
IndexBulkDeleteResult stats,
IndexBulkDeleteCallback  callback,
void *  callback_state 
)

Definition at line 743 of file indexam.c.

References IndexAmRoutine::ambulkdelete, CHECK_REL_PROCEDURE, IndexVacuumInfo::index, RelationData::rd_amroutine, and RELATION_CHECKS.

Referenced by lazy_vacuum_index(), and validate_index().

747 {
748  Relation indexRelation = info->index;
749 
751  CHECK_REL_PROCEDURE(ambulkdelete);
752 
753  return indexRelation->rd_amroutine->ambulkdelete(info, stats,
754  callback, callback_state);
755 }
ambulkdelete_function ambulkdelete
Definition: amapi.h:201
#define RELATION_CHECKS
Definition: indexam.c:98
Relation index
Definition: genam.h:46
struct IndexAmRoutine * rd_amroutine
Definition: rel.h:181
#define CHECK_REL_PROCEDURE(pname)
Definition: indexam.c:112
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:48

◆ index_can_return()

bool index_can_return ( Relation  indexRelation,
int  attno 
)

Definition at line 783 of file indexam.c.

References IndexAmRoutine::amcanreturn, RelationData::rd_amroutine, and RELATION_CHECKS.

Referenced by get_relation_info(), and indexam_property().

784 {
786 
787  /* amcanreturn is optional; assume false if not provided by AM */
788  if (indexRelation->rd_amroutine->amcanreturn == NULL)
789  return false;
790 
791  return indexRelation->rd_amroutine->amcanreturn(indexRelation, attno);
792 }
#define RELATION_CHECKS
Definition: indexam.c:98
struct IndexAmRoutine * rd_amroutine
Definition: rel.h:181
amcanreturn_function amcanreturn
Definition: amapi.h:203

◆ index_close()

void index_close ( Relation  relation,
LOCKMODE  lockmode 
)

Definition at line 176 of file indexam.c.

References Assert, LockInfoData::lockRelId, MAX_LOCKMODES, NoLock, RelationData::rd_lockInfo, RelationClose(), and UnlockRelationId().

Referenced by ATExecAddIndex(), ATExecAddIndexConstraint(), ATExecReplicaIdentity(), brin_page_items(), brincostestimate(), bt_index_check_internal(), build_indices(), BuildEventTriggerCache(), check_index_is_clusterable(), CheckIndexCompatible(), close_lo_relation(), copy_heap_data(), DefineIndex(), enum_endpoint(), enum_range_internal(), ExecCloseIndices(), ExecEndBitmapIndexScan(), ExecEndIndexOnlyScan(), ExecEndIndexScan(), ExecRefreshMatView(), get_actual_variable_range(), get_relation_info(), gin_clean_pending_list(), gincostestimate(), hash_bitmap_info(), index_create(), index_drop(), indexam_property(), infer_arbiter_indexes(), InitCatCachePhase2(), lookup_ts_config_cache(), pgstathashindex(), refresh_by_match_merge(), reindex_index(), ReindexIndex(), RelationFindReplTupleByIndex(), RelationGetIndexAttrBitmap(), RelationTruncateIndexes(), systable_endscan(), toast_close_indexes(), transformTableLikeClause(), TryReuseIndex(), unique_key_recheck(), vac_close_indexes(), vac_open_indexes(), and validate_index().

177 {
178  LockRelId relid = relation->rd_lockInfo.lockRelId;
179 
180  Assert(lockmode >= NoLock && lockmode < MAX_LOCKMODES);
181 
182  /* The relcache does the real work... */
183  RelationClose(relation);
184 
185  if (lockmode != NoLock)
186  UnlockRelationId(&relid, lockmode);
187 }
LockRelId lockRelId
Definition: rel.h:44
void UnlockRelationId(LockRelId *relid, LOCKMODE lockmode)
Definition: lmgr.c:167
Definition: rel.h:36
#define NoLock
Definition: lockdefs.h:34
LockInfoData rd_lockInfo
Definition: rel.h:117
void RelationClose(Relation relation)
Definition: relcache.c:2167
#define MAX_LOCKMODES
Definition: lock.h:85
#define Assert(condition)
Definition: c.h:670

◆ index_endscan()

void index_endscan ( IndexScanDesc  scan)

Definition at line 340 of file indexam.c.

References IndexAmRoutine::amendscan, BufferIsValid, CHECK_SCAN_PROCEDURE, IndexScanDescData::indexRelation, IndexScanEnd(), InvalidBuffer, RelationData::rd_amroutine, RelationDecrementReferenceCount(), ReleaseBuffer(), SCAN_CHECKS, UnregisterSnapshot(), IndexScanDescData::xs_cbuf, IndexScanDescData::xs_snapshot, and IndexScanDescData::xs_temp_snap.

Referenced by check_exclusion_or_unique_constraint(), copy_heap_data(), ExecEndBitmapIndexScan(), ExecEndIndexOnlyScan(), ExecEndIndexScan(), get_actual_variable_range(), RelationFindReplTupleByIndex(), systable_endscan(), and systable_endscan_ordered().

341 {
342  SCAN_CHECKS;
343  CHECK_SCAN_PROCEDURE(amendscan);
344 
345  /* Release any held pin on a heap page */
346  if (BufferIsValid(scan->xs_cbuf))
347  {
348  ReleaseBuffer(scan->xs_cbuf);
349  scan->xs_cbuf = InvalidBuffer;
350  }
351 
352  /* End the AM's scan */
353  scan->indexRelation->rd_amroutine->amendscan(scan);
354 
355  /* Release index refcount acquired by index_beginscan */
357 
358  if (scan->xs_temp_snap)
360 
361  /* Release the scan data structure itself */
362  IndexScanEnd(scan);
363 }
Snapshot xs_snapshot
Definition: relscan.h:91
#define InvalidBuffer
Definition: buf.h:25
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3309
struct IndexAmRoutine * rd_amroutine
Definition: rel.h:181
#define CHECK_SCAN_PROCEDURE(pname)
Definition: indexam.c:119
Relation indexRelation
Definition: relscan.h:90
void RelationDecrementReferenceCount(Relation rel)
Definition: relcache.c:2147
Buffer xs_cbuf
Definition: relscan.h:121
bool xs_temp_snap
Definition: relscan.h:97
amendscan_function amendscan
Definition: amapi.h:212
void IndexScanEnd(IndexScanDesc scan)
Definition: genam.c:146
void UnregisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:905
#define SCAN_CHECKS
Definition: indexam.c:105
#define BufferIsValid(bufnum)
Definition: bufmgr.h:114

◆ index_fetch_heap()

HeapTuple index_fetch_heap ( IndexScanDesc  scan)

Definition at line 583 of file indexam.c.

References BUFFER_LOCK_SHARE, BUFFER_LOCK_UNLOCK, heap_hot_search_buffer(), heap_page_prune_opt(), IndexScanDescData::heapRelation, IndexScanDescData::indexRelation, IsMVCCSnapshot, ItemPointerGetBlockNumber, IndexScanDescData::kill_prior_tuple, LockBuffer(), pgstat_count_heap_fetch, ReleaseAndReadBuffer(), HeapTupleData::t_self, IndexScanDescData::xactStartedInRecovery, IndexScanDescData::xs_cbuf, IndexScanDescData::xs_continue_hot, IndexScanDescData::xs_ctup, and IndexScanDescData::xs_snapshot.

Referenced by index_getnext(), and IndexOnlyNext().

584 {
585  ItemPointer tid = &scan->xs_ctup.t_self;
586  bool all_dead = false;
587  bool got_heap_tuple;
588 
589  /* We can skip the buffer-switching logic if we're in mid-HOT chain. */
590  if (!scan->xs_continue_hot)
591  {
592  /* Switch to correct buffer if we don't have it already */
593  Buffer prev_buf = scan->xs_cbuf;
594 
595  scan->xs_cbuf = ReleaseAndReadBuffer(scan->xs_cbuf,
596  scan->heapRelation,
598 
599  /*
600  * Prune page, but only if we weren't already on this page
601  */
602  if (prev_buf != scan->xs_cbuf)
604  }
605 
606  /* Obtain share-lock on the buffer so we can examine visibility */
608  got_heap_tuple = heap_hot_search_buffer(tid, scan->heapRelation,
609  scan->xs_cbuf,
610  scan->xs_snapshot,
611  &scan->xs_ctup,
612  &all_dead,
613  !scan->xs_continue_hot);
615 
616  if (got_heap_tuple)
617  {
618  /*
619  * Only in a non-MVCC snapshot can more than one member of the HOT
620  * chain be visible.
621  */
624  return &scan->xs_ctup;
625  }
626 
627  /* We've reached the end of the HOT chain. */
628  scan->xs_continue_hot = false;
629 
630  /*
631  * If we scanned a whole HOT chain and found only dead tuples, tell index
632  * AM to kill its entry for that TID (this will take effect in the next
633  * amgettuple call, in index_getnext_tid). We do not do this when in
634  * recovery because it may violate MVCC to do so. See comments in
635  * RelationGetIndexScan().
636  */
637  if (!scan->xactStartedInRecovery)
638  scan->kill_prior_tuple = all_dead;
639 
640  return NULL;
641 }
#define BUFFER_LOCK_UNLOCK
Definition: bufmgr.h:87
Snapshot xs_snapshot
Definition: relscan.h:91
Relation indexRelation
Definition: relscan.h:90
Relation heapRelation
Definition: relscan.h:89
bool heap_hot_search_buffer(ItemPointer tid, Relation relation, Buffer buffer, Snapshot snapshot, HeapTuple heapTuple, bool *all_dead, bool first_call)
Definition: heapam.c:2011
Buffer xs_cbuf
Definition: relscan.h:121
ItemPointerData t_self
Definition: htup.h:65
#define pgstat_count_heap_fetch(rel)
Definition: pgstat.h:1270
bool xactStartedInRecovery
Definition: relscan.h:102
bool xs_continue_hot
Definition: relscan.h:137
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:3546
#define IsMVCCSnapshot(snapshot)
Definition: tqual.h:31
HeapTupleData xs_ctup
Definition: relscan.h:120
Buffer ReleaseAndReadBuffer(Buffer buffer, Relation relation, BlockNumber blockNum)
Definition: bufmgr.c:1513
bool kill_prior_tuple
Definition: relscan.h:100
#define BUFFER_LOCK_SHARE
Definition: bufmgr.h:88
void heap_page_prune_opt(Relation relation, Buffer buffer)
Definition: pruneheap.c:74
#define ItemPointerGetBlockNumber(pointer)
Definition: itemptr.h:76
int Buffer
Definition: buf.h:23

◆ index_getbitmap()

int64 index_getbitmap ( IndexScanDesc  scan,
TIDBitmap bitmap 
)

Definition at line 713 of file indexam.c.

References IndexAmRoutine::amgetbitmap, CHECK_SCAN_PROCEDURE, IndexScanDescData::indexRelation, IndexScanDescData::kill_prior_tuple, pgstat_count_index_tuples, RelationData::rd_amroutine, and SCAN_CHECKS.

Referenced by MultiExecBitmapIndexScan().

714 {
715  int64 ntids;
716 
717  SCAN_CHECKS;
718  CHECK_SCAN_PROCEDURE(amgetbitmap);
719 
720  /* just make sure this is false... */
721  scan->kill_prior_tuple = false;
722 
723  /*
724  * have the am's getbitmap proc do all the work.
725  */
726  ntids = scan->indexRelation->rd_amroutine->amgetbitmap(scan, bitmap);
727 
729 
730  return ntids;
731 }
struct IndexAmRoutine * rd_amroutine
Definition: rel.h:181
#define CHECK_SCAN_PROCEDURE(pname)
Definition: indexam.c:119
Relation indexRelation
Definition: relscan.h:90
amgetbitmap_function amgetbitmap
Definition: amapi.h:211
#define SCAN_CHECKS
Definition: indexam.c:105
#define pgstat_count_index_tuples(rel, n)
Definition: pgstat.h:1280
bool kill_prior_tuple
Definition: relscan.h:100

◆ index_getnext()

HeapTuple index_getnext ( IndexScanDesc  scan,
ScanDirection  direction 
)

Definition at line 659 of file indexam.c.

References Assert, BufferGetBlockNumber(), BufferIsValid, index_fetch_heap(), index_getnext_tid(), ItemPointerGetBlockNumber, HeapTupleData::t_self, IndexScanDescData::xs_cbuf, IndexScanDescData::xs_continue_hot, and IndexScanDescData::xs_ctup.

Referenced by check_exclusion_or_unique_constraint(), copy_heap_data(), get_actual_variable_range(), IndexNext(), IndexNextWithReorder(), RelationFindReplTupleByIndex(), systable_getnext(), and systable_getnext_ordered().

660 {
661  HeapTuple heapTuple;
662  ItemPointer tid;
663 
664  for (;;)
665  {
666  if (scan->xs_continue_hot)
667  {
668  /*
669  * We are resuming scan of a HOT chain after having returned an
670  * earlier member. Must still hold pin on current heap page.
671  */
672  Assert(BufferIsValid(scan->xs_cbuf));
675  }
676  else
677  {
678  /* Time to fetch the next TID from the index */
679  tid = index_getnext_tid(scan, direction);
680 
681  /* If we're out of index entries, we're done */
682  if (tid == NULL)
683  break;
684  }
685 
686  /*
687  * Fetch the next (or only) visible heap tuple for this index entry.
688  * If we don't find anything, loop around and grab the next TID from
689  * the index.
690  */
691  heapTuple = index_fetch_heap(scan);
692  if (heapTuple != NULL)
693  return heapTuple;
694  }
695 
696  return NULL; /* failure exit */
697 }
ItemPointer index_getnext_tid(IndexScanDesc scan, ScanDirection direction)
Definition: indexam.c:526
Buffer xs_cbuf
Definition: relscan.h:121
ItemPointerData t_self
Definition: htup.h:65
HeapTuple index_fetch_heap(IndexScanDesc scan)
Definition: indexam.c:583
bool xs_continue_hot
Definition: relscan.h:137
#define Assert(condition)
Definition: c.h:670
HeapTupleData xs_ctup
Definition: relscan.h:120
#define BufferIsValid(bufnum)
Definition: bufmgr.h:114
BlockNumber BufferGetBlockNumber(Buffer buffer)
Definition: bufmgr.c:2605
#define ItemPointerGetBlockNumber(pointer)
Definition: itemptr.h:76

◆ index_getnext_tid()

ItemPointer index_getnext_tid ( IndexScanDesc  scan,
ScanDirection  direction 
)

Definition at line 526 of file indexam.c.

References IndexAmRoutine::amgettuple, Assert, BufferIsValid, CHECK_SCAN_PROCEDURE, IndexScanDescData::indexRelation, InvalidBuffer, IndexScanDescData::kill_prior_tuple, pgstat_count_index_tuples, RelationData::rd_amroutine, RecentGlobalXmin, ReleaseBuffer(), SCAN_CHECKS, HeapTupleData::t_self, TransactionIdIsValid, IndexScanDescData::xs_cbuf, and IndexScanDescData::xs_ctup.

Referenced by index_getnext(), and IndexOnlyNext().

527 {
528  bool found;
529 
530  SCAN_CHECKS;
531  CHECK_SCAN_PROCEDURE(amgettuple);
532 
534 
535  /*
536  * The AM's amgettuple proc finds the next index entry matching the scan
537  * keys, and puts the TID into scan->xs_ctup.t_self. It should also set
538  * scan->xs_recheck and possibly scan->xs_itup/scan->xs_hitup, though we
539  * pay no attention to those fields here.
540  */
541  found = scan->indexRelation->rd_amroutine->amgettuple(scan, direction);
542 
543  /* Reset kill flag immediately for safety */
544  scan->kill_prior_tuple = false;
545 
546  /* If we're out of index entries, we're done */
547  if (!found)
548  {
549  /* ... but first, release any held pin on a heap page */
550  if (BufferIsValid(scan->xs_cbuf))
551  {
552  ReleaseBuffer(scan->xs_cbuf);
553  scan->xs_cbuf = InvalidBuffer;
554  }
555  return NULL;
556  }
557 
559 
560  /* Return the TID of the tuple we found. */
561  return &scan->xs_ctup.t_self;
562 }
amgettuple_function amgettuple
Definition: amapi.h:210
#define InvalidBuffer
Definition: buf.h:25
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3309
struct IndexAmRoutine * rd_amroutine
Definition: rel.h:181
#define CHECK_SCAN_PROCEDURE(pname)
Definition: indexam.c:119
Relation indexRelation
Definition: relscan.h:90
Buffer xs_cbuf
Definition: relscan.h:121
ItemPointerData t_self
Definition: htup.h:65
TransactionId RecentGlobalXmin
Definition: snapmgr.c:166
#define Assert(condition)
Definition: c.h:670
HeapTupleData xs_ctup
Definition: relscan.h:120
#define SCAN_CHECKS
Definition: indexam.c:105
#define BufferIsValid(bufnum)
Definition: bufmgr.h:114
#define pgstat_count_index_tuples(rel, n)
Definition: pgstat.h:1280
bool kill_prior_tuple
Definition: relscan.h:100
#define TransactionIdIsValid(xid)
Definition: transam.h:41

◆ index_getprocid()

RegProcedure index_getprocid ( Relation  irel,
AttrNumber  attnum,
uint16  procnum 
)

Definition at line 821 of file indexam.c.

References IndexAmRoutine::amsupport, Assert, RelationData::rd_amroutine, and RelationData::rd_support.

Referenced by _hash_init(), gistcanreturn(), inclusion_get_procinfo(), initGinState(), and initGISTstate().

824 {
825  RegProcedure *loc;
826  int nproc;
827  int procindex;
828 
829  nproc = irel->rd_amroutine->amsupport;
830 
831  Assert(procnum > 0 && procnum <= (uint16) nproc);
832 
833  procindex = (nproc * (attnum - 1)) + (procnum - 1);
834 
835  loc = irel->rd_support;
836 
837  Assert(loc != NULL);
838 
839  return loc[procindex];
840 }
uint16 amsupport
Definition: amapi.h:169
regproc RegProcedure
Definition: c.h:443
struct IndexAmRoutine * rd_amroutine
Definition: rel.h:181
unsigned short uint16
Definition: c.h:295
RegProcedure * rd_support
Definition: rel.h:184
#define Assert(condition)
Definition: c.h:670

◆ index_getprocinfo()

FmgrInfo* index_getprocinfo ( Relation  irel,
AttrNumber  attnum,
uint16  procnum 
)

Definition at line 855 of file indexam.c.

References IndexAmRoutine::amsupport, Assert, elog, ERROR, fmgr_info_cxt(), FmgrInfo::fn_oid, InvalidOid, RelationData::rd_amroutine, RelationData::rd_indexcxt, RelationData::rd_support, RelationData::rd_supportinfo, RegProcedureIsValid, and RelationGetRelationName.

Referenced by _bt_first(), _bt_mkscankey(), _bt_mkscankey_nodata(), _hash_datum2hashkey(), brin_build_desc(), brinbuildCallback(), bringetbitmap(), brininsert(), doPickSplit(), inclusion_get_procinfo(), initBloomState(), initGinState(), initGISTstate(), spgdoinsert(), spgGetCache(), spgLeafTest(), spgWalk(), and union_tuples().

858 {
859  FmgrInfo *locinfo;
860  int nproc;
861  int procindex;
862 
863  nproc = irel->rd_amroutine->amsupport;
864 
865  Assert(procnum > 0 && procnum <= (uint16) nproc);
866 
867  procindex = (nproc * (attnum - 1)) + (procnum - 1);
868 
869  locinfo = irel->rd_supportinfo;
870 
871  Assert(locinfo != NULL);
872 
873  locinfo += procindex;
874 
875  /* Initialize the lookup info if first time through */
876  if (locinfo->fn_oid == InvalidOid)
877  {
878  RegProcedure *loc = irel->rd_support;
879  RegProcedure procId;
880 
881  Assert(loc != NULL);
882 
883  procId = loc[procindex];
884 
885  /*
886  * Complain if function was not found during IndexSupportInitialize.
887  * This should not happen unless the system tables contain bogus
888  * entries for the index opclass. (If an AM wants to allow a support
889  * function to be optional, it can use index_getprocid.)
890  */
891  if (!RegProcedureIsValid(procId))
892  elog(ERROR, "missing support function %d for attribute %d of index \"%s\"",
893  procnum, attnum, RelationGetRelationName(irel));
894 
895  fmgr_info_cxt(procId, locinfo, irel->rd_indexcxt);
896  }
897 
898  return locinfo;
899 }
Definition: fmgr.h:56
uint16 amsupport
Definition: amapi.h:169
FmgrInfo * rd_supportinfo
Definition: rel.h:185
regproc RegProcedure
Definition: c.h:443
struct IndexAmRoutine * rd_amroutine
Definition: rel.h:181
unsigned short uint16
Definition: c.h:295
#define ERROR
Definition: elog.h:43
#define RegProcedureIsValid(p)
Definition: c.h:578
#define RelationGetRelationName(relation)
Definition: rel.h:445
void fmgr_info_cxt(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt)
Definition: fmgr.c:132
RegProcedure * rd_support
Definition: rel.h:184
#define InvalidOid
Definition: postgres_ext.h:36
Oid fn_oid
Definition: fmgr.h:59
#define Assert(condition)
Definition: c.h:670
MemoryContext rd_indexcxt
Definition: rel.h:179
#define elog
Definition: elog.h:219

◆ index_insert()

bool index_insert ( Relation  indexRelation,
Datum values,
bool isnull,
ItemPointer  heap_t_ctid,
Relation  heapRelation,
IndexUniqueCheck  checkUnique,
struct IndexInfo indexInfo 
)

Definition at line 194 of file indexam.c.

References IndexAmRoutine::aminsert, IndexAmRoutine::ampredlocks, CHECK_REL_PROCEDURE, CheckForSerializableConflictIn(), InvalidBuffer, RelationData::rd_amroutine, and RELATION_CHECKS.

Referenced by CatalogIndexInsert(), ExecInsertIndexTuples(), toast_save_datum(), unique_key_recheck(), and validate_index_heapscan().

201 {
203  CHECK_REL_PROCEDURE(aminsert);
204 
205  if (!(indexRelation->rd_amroutine->ampredlocks))
206  CheckForSerializableConflictIn(indexRelation,
207  (HeapTuple) NULL,
208  InvalidBuffer);
209 
210  return indexRelation->rd_amroutine->aminsert(indexRelation, values, isnull,
211  heap_t_ctid, heapRelation,
212  checkUnique, indexInfo);
213 }
#define RELATION_CHECKS
Definition: indexam.c:98
#define InvalidBuffer
Definition: buf.h:25
bool ampredlocks
Definition: amapi.h:191
aminsert_function aminsert
Definition: amapi.h:200
void CheckForSerializableConflictIn(Relation relation, HeapTuple tuple, Buffer buffer)
Definition: predicate.c:4326
struct IndexAmRoutine * rd_amroutine
Definition: rel.h:181
#define CHECK_REL_PROCEDURE(pname)
Definition: indexam.c:112
static Datum values[MAXATTR]
Definition: bootstrap.c:164

◆ index_markpos()

void index_markpos ( IndexScanDesc  scan)

Definition at line 370 of file indexam.c.

References IndexAmRoutine::ammarkpos, CHECK_SCAN_PROCEDURE, IndexScanDescData::indexRelation, RelationData::rd_amroutine, and SCAN_CHECKS.

Referenced by ExecIndexMarkPos(), and ExecIndexOnlyMarkPos().

371 {
372  SCAN_CHECKS;
373  CHECK_SCAN_PROCEDURE(ammarkpos);
374 
375  scan->indexRelation->rd_amroutine->ammarkpos(scan);
376 }
struct IndexAmRoutine * rd_amroutine
Definition: rel.h:181
#define CHECK_SCAN_PROCEDURE(pname)
Definition: indexam.c:119
Relation indexRelation
Definition: relscan.h:90
#define SCAN_CHECKS
Definition: indexam.c:105
ammarkpos_function ammarkpos
Definition: amapi.h:213

◆ index_open()

Relation index_open ( Oid  relationId,
LOCKMODE  lockmode 
)

Definition at line 151 of file indexam.c.

References ereport, errcode(), errmsg(), ERROR, RelationData::rd_rel, relation_open(), RelationGetRelationName, and RELKIND_INDEX.

Referenced by ATExecAddIndex(), ATExecAddIndexConstraint(), ATExecReplicaIdentity(), brin_desummarize_range(), brin_page_items(), brin_summarize_range(), brincostestimate(), bt_index_check_internal(), build_indices(), BuildEventTriggerCache(), check_index_is_clusterable(), CheckIndexCompatible(), copy_heap_data(), DefineIndex(), enum_endpoint(), enum_range_internal(), ExecInitBitmapIndexScan(), ExecInitIndexOnlyScan(), ExecInitIndexScan(), ExecOpenIndices(), ExecRefreshMatView(), get_actual_variable_range(), get_relation_info(), gin_clean_pending_list(), gincostestimate(), hash_bitmap_info(), index_drop(), indexam_property(), infer_arbiter_indexes(), InitCatCachePhase2(), lookup_ts_config_cache(), open_lo_relation(), pgstathashindex(), refresh_by_match_merge(), reindex_index(), ReindexIndex(), RelationFindReplTupleByIndex(), RelationGetIndexAttrBitmap(), RelationTruncateIndexes(), systable_beginscan(), toast_open_indexes(), transformIndexConstraint(), transformTableLikeClause(), TryReuseIndex(), unique_key_recheck(), vac_open_indexes(), and validate_index().

152 {
153  Relation r;
154 
155  r = relation_open(relationId, lockmode);
156 
157  if (r->rd_rel->relkind != RELKIND_INDEX)
158  ereport(ERROR,
159  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
160  errmsg("\"%s\" is not an index",
162 
163  return r;
164 }
int errcode(int sqlerrcode)
Definition: elog.c:575
Form_pg_class rd_rel
Definition: rel.h:114
#define ERROR
Definition: elog.h:43
#define RelationGetRelationName(relation)
Definition: rel.h:445
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define RELKIND_INDEX
Definition: pg_class.h:161
Relation relation_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1120

◆ index_parallelrescan()

void index_parallelrescan ( IndexScanDesc  scan)

Definition at line 481 of file indexam.c.

References IndexAmRoutine::amparallelrescan, IndexScanDescData::indexRelation, RelationData::rd_amroutine, and SCAN_CHECKS.

Referenced by ExecIndexOnlyScanReInitializeDSM(), and ExecIndexScanReInitializeDSM().

482 {
483  SCAN_CHECKS;
484 
485  /* amparallelrescan is optional; assume no-op if not provided by AM */
486  if (scan->indexRelation->rd_amroutine->amparallelrescan != NULL)
488 }
amparallelrescan_function amparallelrescan
Definition: amapi.h:219
struct IndexAmRoutine * rd_amroutine
Definition: rel.h:181
Relation indexRelation
Definition: relscan.h:90
#define SCAN_CHECKS
Definition: indexam.c:105

◆ index_parallelscan_estimate()

Size index_parallelscan_estimate ( Relation  indexrel,
Snapshot  snapshot 
)

Definition at line 417 of file indexam.c.

References add_size(), IndexAmRoutine::amestimateparallelscan, EstimateSnapshotSpace(), MAXALIGN, offsetof, RelationData::rd_amroutine, and RELATION_CHECKS.

Referenced by ExecIndexOnlyScanEstimate(), and ExecIndexScanEstimate().

418 {
419  Size nbytes;
420 
422 
423  nbytes = offsetof(ParallelIndexScanDescData, ps_snapshot_data);
424  nbytes = add_size(nbytes, EstimateSnapshotSpace(snapshot));
425  nbytes = MAXALIGN(nbytes);
426 
427  /*
428  * If amestimateparallelscan is not provided, assume there is no
429  * AM-specific data needed. (It's hard to believe that could work, but
430  * it's easy enough to cater to it here.)
431  */
432  if (indexRelation->rd_amroutine->amestimateparallelscan != NULL)
433  nbytes = add_size(nbytes,
434  indexRelation->rd_amroutine->amestimateparallelscan());
435 
436  return nbytes;
437 }
#define RELATION_CHECKS
Definition: indexam.c:98
Size EstimateSnapshotSpace(Snapshot snap)
Definition: snapmgr.c:2046
Size add_size(Size s1, Size s2)
Definition: shmem.c:475
size_t Size
Definition: c.h:404
#define MAXALIGN(LEN)
Definition: c.h:623
#define offsetof(type, field)
Definition: c.h:593

◆ index_parallelscan_initialize()

void index_parallelscan_initialize ( Relation  heaprel,
Relation  indexrel,
Snapshot  snapshot,
ParallelIndexScanDesc  target 
)

Definition at line 450 of file indexam.c.

References add_size(), IndexAmRoutine::aminitparallelscan, EstimateSnapshotSpace(), MAXALIGN, offsetof, OffsetToPointer, ParallelIndexScanDescData::ps_indexid, ParallelIndexScanDescData::ps_offset, ParallelIndexScanDescData::ps_relid, ParallelIndexScanDescData::ps_snapshot_data, RelationData::rd_amroutine, RELATION_CHECKS, RelationGetRelid, and SerializeSnapshot().

Referenced by ExecIndexOnlyScanInitializeDSM(), and ExecIndexScanInitializeDSM().

452 {
453  Size offset;
454 
456 
457  offset = add_size(offsetof(ParallelIndexScanDescData, ps_snapshot_data),
458  EstimateSnapshotSpace(snapshot));
459  offset = MAXALIGN(offset);
460 
461  target->ps_relid = RelationGetRelid(heapRelation);
462  target->ps_indexid = RelationGetRelid(indexRelation);
463  target->ps_offset = offset;
464  SerializeSnapshot(snapshot, target->ps_snapshot_data);
465 
466  /* aminitparallelscan is optional; assume no-op if not provided by AM */
467  if (indexRelation->rd_amroutine->aminitparallelscan != NULL)
468  {
469  void *amtarget;
470 
471  amtarget = OffsetToPointer(target, offset);
472  indexRelation->rd_amroutine->aminitparallelscan(amtarget);
473  }
474 }
#define RELATION_CHECKS
Definition: indexam.c:98
char ps_snapshot_data[FLEXIBLE_ARRAY_MEMBER]
Definition: relscan.h:149
void SerializeSnapshot(Snapshot snapshot, char *start_address)
Definition: snapmgr.c:2070
#define OffsetToPointer(base, offset)
Definition: c.h:573
Size EstimateSnapshotSpace(Snapshot snap)
Definition: snapmgr.c:2046
Size add_size(Size s1, Size s2)
Definition: shmem.c:475
size_t Size
Definition: c.h:404
#define MAXALIGN(LEN)
Definition: c.h:623
#define RelationGetRelid(relation)
Definition: rel.h:425
#define offsetof(type, field)
Definition: c.h:593

◆ index_rescan()

void index_rescan ( IndexScanDesc  scan,
ScanKey  keys,
int  nkeys,
ScanKey  orderbys,
int  norderbys 
)

Definition at line 310 of file indexam.c.

References IndexAmRoutine::amrescan, Assert, BufferIsValid, CHECK_SCAN_PROCEDURE, IndexScanDescData::indexRelation, InvalidBuffer, IndexScanDescData::kill_prior_tuple, IndexScanDescData::numberOfKeys, IndexScanDescData::numberOfOrderBys, RelationData::rd_amroutine, ReleaseBuffer(), SCAN_CHECKS, IndexScanDescData::xs_cbuf, and IndexScanDescData::xs_continue_hot.

Referenced by check_exclusion_or_unique_constraint(), copy_heap_data(), ExecIndexOnlyScanInitializeDSM(), ExecIndexOnlyScanInitializeWorker(), ExecIndexScanInitializeDSM(), ExecIndexScanInitializeWorker(), ExecInitBitmapIndexScan(), ExecReScanBitmapIndexScan(), ExecReScanIndexOnlyScan(), ExecReScanIndexScan(), get_actual_variable_range(), IndexNext(), IndexNextWithReorder(), IndexOnlyNext(), MultiExecBitmapIndexScan(), RelationFindReplTupleByIndex(), systable_beginscan(), and systable_beginscan_ordered().

313 {
314  SCAN_CHECKS;
315  CHECK_SCAN_PROCEDURE(amrescan);
316 
317  Assert(nkeys == scan->numberOfKeys);
318  Assert(norderbys == scan->numberOfOrderBys);
319 
320  /* Release any held pin on a heap page */
321  if (BufferIsValid(scan->xs_cbuf))
322  {
323  ReleaseBuffer(scan->xs_cbuf);
324  scan->xs_cbuf = InvalidBuffer;
325  }
326 
327  scan->xs_continue_hot = false;
328 
329  scan->kill_prior_tuple = false; /* for safety */
330 
331  scan->indexRelation->rd_amroutine->amrescan(scan, keys, nkeys,
332  orderbys, norderbys);
333 }
#define InvalidBuffer
Definition: buf.h:25
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3309
struct IndexAmRoutine * rd_amroutine
Definition: rel.h:181
#define CHECK_SCAN_PROCEDURE(pname)
Definition: indexam.c:119
Relation indexRelation
Definition: relscan.h:90
Buffer xs_cbuf
Definition: relscan.h:121
bool xs_continue_hot
Definition: relscan.h:137
amrescan_function amrescan
Definition: amapi.h:209
#define Assert(condition)
Definition: c.h:670
#define SCAN_CHECKS
Definition: indexam.c:105
#define BufferIsValid(bufnum)
Definition: bufmgr.h:114
bool kill_prior_tuple
Definition: relscan.h:100
int numberOfOrderBys
Definition: relscan.h:93

◆ index_restrpos()

void index_restrpos ( IndexScanDesc  scan)

Definition at line 395 of file indexam.c.

References IndexAmRoutine::amrestrpos, Assert, CHECK_SCAN_PROCEDURE, IndexScanDescData::indexRelation, IsMVCCSnapshot, IndexScanDescData::kill_prior_tuple, RelationData::rd_amroutine, SCAN_CHECKS, IndexScanDescData::xs_continue_hot, and IndexScanDescData::xs_snapshot.

Referenced by ExecIndexOnlyRestrPos(), and ExecIndexRestrPos().

396 {
398 
399  SCAN_CHECKS;
400  CHECK_SCAN_PROCEDURE(amrestrpos);
401 
402  scan->xs_continue_hot = false;
403 
404  scan->kill_prior_tuple = false; /* for safety */
405 
406  scan->indexRelation->rd_amroutine->amrestrpos(scan);
407 }
Snapshot xs_snapshot
Definition: relscan.h:91
struct IndexAmRoutine * rd_amroutine
Definition: rel.h:181
#define CHECK_SCAN_PROCEDURE(pname)
Definition: indexam.c:119
Relation indexRelation
Definition: relscan.h:90
bool xs_continue_hot
Definition: relscan.h:137
#define Assert(condition)
Definition: c.h:670
#define IsMVCCSnapshot(snapshot)
Definition: tqual.h:31
#define SCAN_CHECKS
Definition: indexam.c:105
bool kill_prior_tuple
Definition: relscan.h:100
amrestrpos_function amrestrpos
Definition: amapi.h:214

◆ index_vacuum_cleanup()

IndexBulkDeleteResult* index_vacuum_cleanup ( IndexVacuumInfo info,
IndexBulkDeleteResult stats 
)

Definition at line 764 of file indexam.c.

References IndexAmRoutine::amvacuumcleanup, CHECK_REL_PROCEDURE, IndexVacuumInfo::index, RelationData::rd_amroutine, and RELATION_CHECKS.

Referenced by do_analyze_rel(), and lazy_cleanup_index().

766 {
767  Relation indexRelation = info->index;
768 
770  CHECK_REL_PROCEDURE(amvacuumcleanup);
771 
772  return indexRelation->rd_amroutine->amvacuumcleanup(info, stats);
773 }
#define RELATION_CHECKS
Definition: indexam.c:98
Relation index
Definition: genam.h:46
struct IndexAmRoutine * rd_amroutine
Definition: rel.h:181
#define CHECK_REL_PROCEDURE(pname)
Definition: indexam.c:112
amvacuumcleanup_function amvacuumcleanup
Definition: amapi.h:202

◆ IndexScanEnd()

void IndexScanEnd ( IndexScanDesc  scan)

Definition at line 146 of file genam.c.

References IndexScanDescData::keyData, IndexScanDescData::orderByData, and pfree().

Referenced by index_endscan().

147 {
148  if (scan->keyData != NULL)
149  pfree(scan->keyData);
150  if (scan->orderByData != NULL)
151  pfree(scan->orderByData);
152 
153  pfree(scan);
154 }
void pfree(void *pointer)
Definition: mcxt.c:949
ScanKey orderByData
Definition: relscan.h:95
ScanKey keyData
Definition: relscan.h:94

◆ RelationGetIndexScan()

IndexScanDesc RelationGetIndexScan ( Relation  indexRelation,
int  nkeys,
int  norderbys 
)

Definition at line 78 of file genam.c.

References IndexScanDescData::heapRelation, IndexScanDescData::ignore_killed_tuples, IndexScanDescData::indexRelation, InvalidBuffer, InvalidSnapshot, ItemPointerSetInvalid, IndexScanDescData::keyData, IndexScanDescData::kill_prior_tuple, IndexScanDescData::numberOfKeys, IndexScanDescData::numberOfOrderBys, IndexScanDescData::opaque, IndexScanDescData::orderByData, palloc(), HeapTupleData::t_data, HeapTupleData::t_self, TransactionStartedDuringRecovery(), IndexScanDescData::xactStartedInRecovery, IndexScanDescData::xs_cbuf, IndexScanDescData::xs_continue_hot, IndexScanDescData::xs_ctup, IndexScanDescData::xs_hitup, IndexScanDescData::xs_hitupdesc, IndexScanDescData::xs_itup, IndexScanDescData::xs_itupdesc, IndexScanDescData::xs_snapshot, and IndexScanDescData::xs_want_itup.

Referenced by blbeginscan(), brinbeginscan(), btbeginscan(), ginbeginscan(), gistbeginscan(), hashbeginscan(), and spgbeginscan().

79 {
80  IndexScanDesc scan;
81 
82  scan = (IndexScanDesc) palloc(sizeof(IndexScanDescData));
83 
84  scan->heapRelation = NULL; /* may be set later */
85  scan->indexRelation = indexRelation;
86  scan->xs_snapshot = InvalidSnapshot; /* caller must initialize this */
87  scan->numberOfKeys = nkeys;
88  scan->numberOfOrderBys = norderbys;
89 
90  /*
91  * We allocate key workspace here, but it won't get filled until amrescan.
92  */
93  if (nkeys > 0)
94  scan->keyData = (ScanKey) palloc(sizeof(ScanKeyData) * nkeys);
95  else
96  scan->keyData = NULL;
97  if (norderbys > 0)
98  scan->orderByData = (ScanKey) palloc(sizeof(ScanKeyData) * norderbys);
99  else
100  scan->orderByData = NULL;
101 
102  scan->xs_want_itup = false; /* may be set later */
103 
104  /*
105  * During recovery we ignore killed tuples and don't bother to kill them
106  * either. We do this because the xmin on the primary node could easily be
107  * later than the xmin on the standby node, so that what the primary
108  * thinks is killed is supposed to be visible on standby. So for correct
109  * MVCC for queries during recovery we must ignore these hints and check
110  * all tuples. Do *not* set ignore_killed_tuples to true when running in a
111  * transaction that was started during recovery. xactStartedInRecovery
112  * should not be altered by index AMs.
113  */
114  scan->kill_prior_tuple = false;
117 
118  scan->opaque = NULL;
119 
120  scan->xs_itup = NULL;
121  scan->xs_itupdesc = NULL;
122  scan->xs_hitup = NULL;
123  scan->xs_hitupdesc = NULL;
124 
126  scan->xs_ctup.t_data = NULL;
127  scan->xs_cbuf = InvalidBuffer;
128  scan->xs_continue_hot = false;
129 
130  return scan;
131 }
bool TransactionStartedDuringRecovery(void)
Definition: xact.c:864
IndexTuple xs_itup
Definition: relscan.h:114
Snapshot xs_snapshot
Definition: relscan.h:91
#define InvalidBuffer
Definition: buf.h:25
TupleDesc xs_itupdesc
Definition: relscan.h:115
TupleDesc xs_hitupdesc
Definition: relscan.h:117
bool ignore_killed_tuples
Definition: relscan.h:101
Relation indexRelation
Definition: relscan.h:90
HeapTupleHeader t_data
Definition: htup.h:67
Relation heapRelation
Definition: relscan.h:89
Buffer xs_cbuf
Definition: relscan.h:121
ItemPointerData t_self
Definition: htup.h:65
bool xactStartedInRecovery
Definition: relscan.h:102
ScanKeyData * ScanKey
Definition: skey.h:75
bool xs_continue_hot
Definition: relscan.h:137
#define InvalidSnapshot
Definition: snapshot.h:25
ScanKey orderByData
Definition: relscan.h:95
bool xs_want_itup
Definition: relscan.h:96
HeapTupleData xs_ctup
Definition: relscan.h:120
ScanKey keyData
Definition: relscan.h:94
#define ItemPointerSetInvalid(pointer)
Definition: itemptr.h:150
void * palloc(Size size)
Definition: mcxt.c:848
HeapTuple xs_hitup
Definition: relscan.h:116
bool kill_prior_tuple
Definition: relscan.h:100
int numberOfOrderBys
Definition: relscan.h:93
struct IndexScanDescData * IndexScanDesc
Definition: genam.h:86

◆ systable_beginscan()

SysScanDesc systable_beginscan ( Relation  heapRelation,
Oid  indexId,
bool  indexOK,
Snapshot  snapshot,
int  nkeys,
ScanKey  key 
)

Definition at line 328 of file genam.c.

References AccessShareLock, elog, ERROR, GetCatalogSnapshot(), heap_beginscan_strat(), SysScanDescData::heap_rel, i, IgnoreSystemIndexes, index_beginscan(), index_open(), index_rescan(), SysScanDescData::irel, SysScanDescData::iscan, palloc(), RelationData::rd_index, RegisterSnapshot(), ReindexIsProcessingIndex(), RelationGetRelid, SysScanDescData::scan, ScanKeyData::sk_attno, and SysScanDescData::snapshot.

Referenced by AfterTriggerSetState(), AlterConstraintNamespaces(), AlterDatabase(), AlterDatabaseOwner(), AlterDomainDropConstraint(), AlterDomainValidateConstraint(), AlterExtensionNamespace(), AlterPolicy(), AlterSeqNamespaces(), AlterSetting(), ApplyExtensionUpdates(), ApplySetting(), ATExecAddOf(), ATExecAlterColumnType(), ATExecAlterConstraint(), ATExecAttachPartition(), ATExecDropConstraint(), ATExecValidateConstraint(), ATPrepChangePersistence(), AttrDefaultFetch(), change_owner_fix_column_acls(), change_owner_recurse_to_sequences(), changeDependencyFor(), CheckConstraintFetch(), checkSharedDependencies(), ChooseConstraintName(), ConstraintNameIsUsed(), copyTemplateDependencies(), CountDBSubscriptions(), CreateComments(), CreateInheritance(), CreatePolicy(), CreateSharedComments(), CreateTrigger(), DefineOpClass(), DefineTSConfiguration(), DeleteAttributeTuples(), DeleteComments(), deleteDependencyRecordsFor(), deleteDependencyRecordsForClass(), DeleteInitPrivs(), deleteOneObject(), DeleteSecurityLabel(), DeleteSharedComments(), DeleteSharedSecurityLabel(), DeleteSystemAttributeTuples(), drop_parent_dependency(), DropCastById(), DropConfigurationMapping(), dropDatabaseDependencies(), DropRole(), DropTransformById(), EnableDisableTrigger(), EnumValuesDelete(), exec_object_restorecon(), ExecAlterExtensionStmt(), ExecGrant_Largeobject(), extension_config_remove(), fetch_statentries_for_relation(), find_composite_type_dependencies(), find_inheritance_children(), find_language_template(), findDependentObjects(), get_catalog_object_by_oid(), get_constraint_index(), get_database_oid(), get_db_info(), get_domain_constraint_oid(), get_extension_name(), get_extension_oid(), get_extension_schema(), get_index_constraint(), get_object_address_attrdef(), get_partition_parent(), get_pkey_attnames(), get_primary_key_attnos(), get_relation_constraint_attnos(), get_relation_constraint_oid(), get_relation_policy_oid(), get_rels_with_domain(), get_trigger_oid(), GetAllTablesPublications(), GetComment(), GetDatabaseTuple(), GetDatabaseTupleByOid(), GetDefaultOpClass(), getExtensionOfObject(), GetNewOidWithIndex(), getObjectDescription(), getObjectIdentityParts(), getOwnedSequences(), GetPublicationRelations(), GetSecurityLabel(), GetSharedSecurityLabel(), GetSubscriptionNotReadyRelations(), GetSubscriptionRelations(), has_superclass(), heap_truncate_find_FKs(), isObjectPinned(), isSharedObjectPinned(), LargeObjectDrop(), LargeObjectExists(), load_domaintype_info(), load_enum_cache_data(), LookupOpclassInfo(), makeConfigurationDependencies(), MakeConfigurationMapping(), MergeConstraintsIntoExisting(), MergeWithExistingConstraint(), movedb(), myLargeObjectExists(), pg_extension_config_dump(), pg_extension_ownercheck(), pg_get_constraintdef_worker(), pg_get_serial_sequence(), pg_get_triggerdef_worker(), pg_largeobject_aclmask_snapshot(), pg_largeobject_ownercheck(), RangeDelete(), recordExtensionInitPrivWorker(), recordExtObjInitPriv(), relation_has_policies(), RelationBuildRowSecurity(), RelationBuildRuleLock(), RelationBuildTriggers(), RelationBuildTupleDesc(), RelationGetExclusionInfo(), RelationGetFKeyList(), RelationGetIndexList(), RelationGetStatExtList(), RelationRemoveInheritance(), RelidByRelfilenode(), RemoveAmOpEntryById(), RemoveAmProcEntryById(), RemoveAttrDefault(), RemoveAttrDefaultById(), RemoveCollationById(), RemoveDefaultACLById(), RemoveExtensionById(), RemoveInheritance(), RemovePolicyById(), RemoveRewriteRuleById(), RemoveRoleFromObjectACL(), RemoveRoleFromObjectPolicy(), RemoveStatistics(), RemoveTriggerById(), RemoveTSConfigurationById(), rename_policy(), renametrig(), replorigin_create(), ScanPgRelation(), SearchCatCacheList(), SearchCatCacheMiss(), sepgsql_attribute_post_create(), sepgsql_database_post_create(), sepgsql_proc_post_create(), sepgsql_proc_setattr(), sepgsql_relation_post_create(), sepgsql_relation_setattr(), sepgsql_relation_setattr_extra(), sepgsql_schema_post_create(), sequenceIsOwned(), SetSecurityLabel(), SetSharedSecurityLabel(), shdepChangeDep(), shdepDropDependency(), shdepDropOwned(), shdepReassignOwned(), toastrel_valueid_exists(), typeInheritsFrom(), and vac_update_datfrozenxid().

333 {
334  SysScanDesc sysscan;
335  Relation irel;
336 
337  if (indexOK &&
339  !ReindexIsProcessingIndex(indexId))
340  irel = index_open(indexId, AccessShareLock);
341  else
342  irel = NULL;
343 
344  sysscan = (SysScanDesc) palloc(sizeof(SysScanDescData));
345 
346  sysscan->heap_rel = heapRelation;
347  sysscan->irel = irel;
348 
349  if (snapshot == NULL)
350  {
351  Oid relid = RelationGetRelid(heapRelation);
352 
353  snapshot = RegisterSnapshot(GetCatalogSnapshot(relid));
354  sysscan->snapshot = snapshot;
355  }
356  else
357  {
358  /* Caller is responsible for any snapshot. */
359  sysscan->snapshot = NULL;
360  }
361 
362  if (irel)
363  {
364  int i;
365 
366  /* Change attribute numbers to be index column numbers. */
367  for (i = 0; i < nkeys; i++)
368  {
369  int j;
370 
371  for (j = 0; j < irel->rd_index->indnatts; j++)
372  {
373  if (key[i].sk_attno == irel->rd_index->indkey.values[j])
374  {
375  key[i].sk_attno = j + 1;
376  break;
377  }
378  }
379  if (j == irel->rd_index->indnatts)
380  elog(ERROR, "column is not in index");
381  }
382 
383  sysscan->iscan = index_beginscan(heapRelation, irel,
384  snapshot, nkeys, 0);
385  index_rescan(sysscan->iscan, key, nkeys, NULL, 0);
386  sysscan->scan = NULL;
387  }
388  else
389  {
390  /*
391  * We disallow synchronized scans when forced to use a heapscan on a
392  * catalog. In most cases the desired rows are near the front, so
393  * that the unpredictable start point of a syncscan is a serious
394  * disadvantage; and there are no compensating advantages, because
395  * it's unlikely that such scans will occur in parallel.
396  */
397  sysscan->scan = heap_beginscan_strat(heapRelation, snapshot,
398  nkeys, key,
399  true, false);
400  sysscan->iscan = NULL;
401  }
402 
403  return sysscan;
404 }
Relation irel
Definition: relscan.h:156
Snapshot snapshot
Definition: relscan.h:159
struct SysScanDescData * SysScanDesc
Definition: genam.h:87
Relation heap_rel
Definition: relscan.h:155
Snapshot RegisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:863
Snapshot GetCatalogSnapshot(Oid relid)
Definition: snapmgr.c:440
#define AccessShareLock
Definition: lockdefs.h:36
void index_rescan(IndexScanDesc scan, ScanKey keys, int nkeys, ScanKey orderbys, int norderbys)
Definition: indexam.c:310
bool IgnoreSystemIndexes
Definition: miscinit.c:74
unsigned int Oid
Definition: postgres_ext.h:31
IndexScanDesc iscan
Definition: relscan.h:158
Form_pg_index rd_index
Definition: rel.h:159
#define ERROR
Definition: elog.h:43
HeapScanDesc heap_beginscan_strat(Relation relation, Snapshot snapshot, int nkeys, ScanKey key, bool allow_strat, bool allow_sync)
Definition: heapam.c:1415
HeapScanDesc scan
Definition: relscan.h:157
void * palloc(Size size)
Definition: mcxt.c:848
int i
#define elog
Definition: elog.h:219
bool ReindexIsProcessingIndex(Oid indexOid)
Definition: index.c:3690
#define RelationGetRelid(relation)
Definition: rel.h:425
Relation index_open(Oid relationId, LOCKMODE lockmode)
Definition: indexam.c:151
AttrNumber sk_attno
Definition: skey.h:67
IndexScanDesc index_beginscan(Relation heapRelation, Relation indexRelation, Snapshot snapshot, int nkeys, int norderbys)
Definition: indexam.c:221

◆ systable_beginscan_ordered()

SysScanDesc systable_beginscan_ordered ( Relation  heapRelation,
Relation  indexRelation,
Snapshot  snapshot,
int  nkeys,
ScanKey  key 
)

Definition at line 533 of file genam.c.

References elog, ERROR, GetCatalogSnapshot(), SysScanDescData::heap_rel, i, IgnoreSystemIndexes, index_beginscan(), index_rescan(), SysScanDescData::irel, SysScanDescData::iscan, palloc(), RelationData::rd_index, RegisterSnapshot(), ReindexIsProcessingIndex(), RelationGetRelationName, RelationGetRelid, SysScanDescData::scan, ScanKeyData::sk_attno, SysScanDescData::snapshot, and WARNING.

Referenced by BuildEventTriggerCache(), enum_endpoint(), enum_range_internal(), inv_getsize(), inv_read(), inv_truncate(), inv_write(), lookup_ts_config_cache(), toast_delete_datum(), toast_fetch_datum(), and toast_fetch_datum_slice().

537 {
538  SysScanDesc sysscan;
539  int i;
540 
541  /* REINDEX can probably be a hard error here ... */
542  if (ReindexIsProcessingIndex(RelationGetRelid(indexRelation)))
543  elog(ERROR, "cannot do ordered scan on index \"%s\", because it is being reindexed",
544  RelationGetRelationName(indexRelation));
545  /* ... but we only throw a warning about violating IgnoreSystemIndexes */
547  elog(WARNING, "using index \"%s\" despite IgnoreSystemIndexes",
548  RelationGetRelationName(indexRelation));
549 
550  sysscan = (SysScanDesc) palloc(sizeof(SysScanDescData));
551 
552  sysscan->heap_rel = heapRelation;
553  sysscan->irel = indexRelation;
554 
555  if (snapshot == NULL)
556  {
557  Oid relid = RelationGetRelid(heapRelation);
558 
559  snapshot = RegisterSnapshot(GetCatalogSnapshot(relid));
560  sysscan->snapshot = snapshot;
561  }
562  else
563  {
564  /* Caller is responsible for any snapshot. */
565  sysscan->snapshot = NULL;
566  }
567 
568  /* Change attribute numbers to be index column numbers. */
569  for (i = 0; i < nkeys; i++)
570  {
571  int j;
572 
573  for (j = 0; j < indexRelation->rd_index->indnatts; j++)
574  {
575  if (key[i].sk_attno == indexRelation->rd_index->indkey.values[j])
576  {
577  key[i].sk_attno = j + 1;
578  break;
579  }
580  }
581  if (j == indexRelation->rd_index->indnatts)
582  elog(ERROR, "column is not in index");
583  }
584 
585  sysscan->iscan = index_beginscan(heapRelation, indexRelation,
586  snapshot, nkeys, 0);
587  index_rescan(sysscan->iscan, key, nkeys, NULL, 0);
588  sysscan->scan = NULL;
589 
590  return sysscan;
591 }
Relation irel
Definition: relscan.h:156
Snapshot snapshot
Definition: relscan.h:159
struct SysScanDescData * SysScanDesc
Definition: genam.h:87
Relation heap_rel
Definition: relscan.h:155
Snapshot RegisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:863
Snapshot GetCatalogSnapshot(Oid relid)
Definition: snapmgr.c:440
void index_rescan(IndexScanDesc scan, ScanKey keys, int nkeys, ScanKey orderbys, int norderbys)
Definition: indexam.c:310
bool IgnoreSystemIndexes
Definition: miscinit.c:74
unsigned int Oid
Definition: postgres_ext.h:31
IndexScanDesc iscan
Definition: relscan.h:158
Form_pg_index rd_index
Definition: rel.h:159
#define ERROR
Definition: elog.h:43
#define RelationGetRelationName(relation)
Definition: rel.h:445
#define WARNING
Definition: elog.h:40
HeapScanDesc scan
Definition: relscan.h:157
void * palloc(Size size)
Definition: mcxt.c:848
int i
#define elog
Definition: elog.h:219
bool ReindexIsProcessingIndex(Oid indexOid)
Definition: index.c:3690
#define RelationGetRelid(relation)
Definition: rel.h:425
AttrNumber sk_attno
Definition: skey.h:67
IndexScanDesc index_beginscan(Relation heapRelation, Relation indexRelation, Snapshot snapshot, int nkeys, int norderbys)
Definition: indexam.c:221

◆ systable_endscan()

void systable_endscan ( SysScanDesc  sysscan)

Definition at line 499 of file genam.c.

References AccessShareLock, heap_endscan(), index_close(), index_endscan(), SysScanDescData::irel, SysScanDescData::iscan, pfree(), SysScanDescData::scan, SysScanDescData::snapshot, and UnregisterSnapshot().

Referenced by AfterTriggerSetState(), AlterConstraintNamespaces(), AlterDatabase(), AlterDatabaseOwner(), AlterDomainDropConstraint(), AlterDomainValidateConstraint(), AlterExtensionNamespace(), AlterPolicy(), AlterSeqNamespaces(), AlterSetting(), ApplyExtensionUpdates(), ApplySetting(), ATExecAddOf(), ATExecAlterColumnType(), ATExecAlterConstraint(), ATExecAttachPartition(), ATExecDropConstraint(), ATExecValidateConstraint(), ATPrepChangePersistence(), AttrDefaultFetch(), change_owner_fix_column_acls(), change_owner_recurse_to_sequences(), changeDependencyFor(), CheckConstraintFetch(), checkSharedDependencies(), ChooseConstraintName(), ConstraintNameIsUsed(), copyTemplateDependencies(), CountDBSubscriptions(), CreateComments(), CreateInheritance(), CreatePolicy(), CreateSharedComments(), CreateTrigger(), DefineOpClass(), DefineTSConfiguration(), DeleteAttributeTuples(), DeleteComments(), deleteDependencyRecordsFor(), deleteDependencyRecordsForClass(), DeleteInitPrivs(), deleteOneObject(), DeleteSecurityLabel(), DeleteSharedComments(), DeleteSharedSecurityLabel(), DeleteSystemAttributeTuples(), drop_parent_dependency(), DropCastById(), DropConfigurationMapping(), dropDatabaseDependencies(), DropRole(), DropTransformById(), EnableDisableTrigger(), EnumValuesDelete(), exec_object_restorecon(), ExecAlterExtensionStmt(), ExecGrant_Largeobject(), extension_config_remove(), fetch_statentries_for_relation(), find_composite_type_dependencies(), find_inheritance_children(), find_language_template(), findDependentObjects(), get_catalog_object_by_oid(), get_constraint_index(), get_database_oid(), get_db_info(), get_domain_constraint_oid(), get_extension_name(), get_extension_oid(), get_extension_schema(), get_index_constraint(), get_object_address_attrdef(), get_partition_parent(), get_pkey_attnames(), get_primary_key_attnos(), get_relation_constraint_attnos(), get_relation_constraint_oid(), get_relation_policy_oid(), get_rels_with_domain(), get_trigger_oid(), GetAllTablesPublications(), GetComment(), GetDatabaseTuple(), GetDatabaseTupleByOid(), GetDefaultOpClass(), getExtensionOfObject(), GetNewOidWithIndex(), getObjectDescription(), getObjectIdentityParts(), getOwnedSequences(), GetPublicationRelations(), GetSecurityLabel(), GetSharedSecurityLabel(), GetSubscriptionNotReadyRelations(), GetSubscriptionRelations(), has_superclass(), heap_truncate_find_FKs(), isObjectPinned(), isSharedObjectPinned(), LargeObjectDrop(), LargeObjectExists(), load_domaintype_info(), load_enum_cache_data(), LookupOpclassInfo(), makeConfigurationDependencies(), MakeConfigurationMapping(), MergeConstraintsIntoExisting(), MergeWithExistingConstraint(), movedb(), myLargeObjectExists(), pg_extension_config_dump(), pg_extension_ownercheck(), pg_get_constraintdef_worker(), pg_get_serial_sequence(), pg_get_triggerdef_worker(), pg_largeobject_aclmask_snapshot(), pg_largeobject_ownercheck(), RangeDelete(), recordExtensionInitPrivWorker(), recordExtObjInitPriv(), relation_has_policies(), RelationBuildRowSecurity(), RelationBuildRuleLock(), RelationBuildTriggers(), RelationBuildTupleDesc(), RelationGetExclusionInfo(), RelationGetFKeyList(), RelationGetIndexList(), RelationGetStatExtList(), RelationRemoveInheritance(), RelidByRelfilenode(), RemoveAmOpEntryById(), RemoveAmProcEntryById(), RemoveAttrDefault(), RemoveAttrDefaultById(), RemoveCollationById(), RemoveDefaultACLById(), RemoveExtensionById(), RemoveInheritance(), RemovePolicyById(), RemoveRewriteRuleById(), RemoveRoleFromObjectACL(), RemoveRoleFromObjectPolicy(), RemoveStatistics(), RemoveTriggerById(), RemoveTSConfigurationById(), rename_policy(), renametrig(), replorigin_create(), ScanPgRelation(), SearchCatCacheList(), SearchCatCacheMiss(), sepgsql_attribute_post_create(), sepgsql_database_post_create(), sepgsql_proc_post_create(), sepgsql_proc_setattr(), sepgsql_relation_post_create(), sepgsql_relation_setattr(), sepgsql_relation_setattr_extra(), sepgsql_schema_post_create(), sequenceIsOwned(), SetSecurityLabel(), SetSharedSecurityLabel(), shdepChangeDep(), shdepDropDependency(), shdepDropOwned(), shdepReassignOwned(), toastrel_valueid_exists(), typeInheritsFrom(), and vac_update_datfrozenxid().

500 {
501  if (sysscan->irel)
502  {
503  index_endscan(sysscan->iscan);
504  index_close(sysscan->irel, AccessShareLock);
505  }
506  else
507  heap_endscan(sysscan->scan);
508 
509  if (sysscan->snapshot)
510  UnregisterSnapshot(sysscan->snapshot);
511 
512  pfree(sysscan);
513 }
Relation irel
Definition: relscan.h:156
Snapshot snapshot
Definition: relscan.h:159
void heap_endscan(HeapScanDesc scan)
Definition: heapam.c:1565
#define AccessShareLock
Definition: lockdefs.h:36
IndexScanDesc iscan
Definition: relscan.h:158
void pfree(void *pointer)
Definition: mcxt.c:949
void index_endscan(IndexScanDesc scan)
Definition: indexam.c:340
void UnregisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:905
HeapScanDesc scan
Definition: relscan.h:157
void index_close(Relation relation, LOCKMODE lockmode)
Definition: indexam.c:176

◆ systable_endscan_ordered()

void systable_endscan_ordered ( SysScanDesc  sysscan)

Definition at line 614 of file genam.c.

References Assert, index_endscan(), SysScanDescData::irel, SysScanDescData::iscan, pfree(), SysScanDescData::snapshot, and UnregisterSnapshot().

Referenced by BuildEventTriggerCache(), enum_endpoint(), enum_range_internal(), inv_getsize(), inv_read(), inv_truncate(), inv_write(), lookup_ts_config_cache(), toast_delete_datum(), toast_fetch_datum(), and toast_fetch_datum_slice().

615 {
616  Assert(sysscan->irel);
617  index_endscan(sysscan->iscan);
618  if (sysscan->snapshot)
619  UnregisterSnapshot(sysscan->snapshot);
620  pfree(sysscan);
621 }
Relation irel
Definition: relscan.h:156
Snapshot snapshot
Definition: relscan.h:159
IndexScanDesc iscan
Definition: relscan.h:158
void pfree(void *pointer)
Definition: mcxt.c:949
void index_endscan(IndexScanDesc scan)
Definition: indexam.c:340
void UnregisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:905
#define Assert(condition)
Definition: c.h:670

◆ systable_getnext()

HeapTuple systable_getnext ( SysScanDesc  sysscan)

Definition at line 416 of file genam.c.

References elog, ERROR, ForwardScanDirection, heap_getnext(), index_getnext(), SysScanDescData::irel, SysScanDescData::iscan, SysScanDescData::scan, and IndexScanDescData::xs_recheck.

Referenced by AfterTriggerSetState(), AlterConstraintNamespaces(), AlterDatabase(), AlterDatabaseOwner(), AlterDomainDropConstraint(), AlterDomainValidateConstraint(), AlterExtensionNamespace(), AlterPolicy(), AlterSeqNamespaces(), AlterSetting(), ApplyExtensionUpdates(), ApplySetting(), ATExecAddOf(), ATExecAlterColumnType(), ATExecAlterConstraint(), ATExecAttachPartition(), ATExecDropConstraint(), ATExecValidateConstraint(), ATPrepChangePersistence(), AttrDefaultFetch(), change_owner_fix_column_acls(), change_owner_recurse_to_sequences(), changeDependencyFor(), CheckConstraintFetch(), checkSharedDependencies(), ChooseConstraintName(), ConstraintNameIsUsed(), copyTemplateDependencies(), CountDBSubscriptions(), CreateComments(), CreateInheritance(), CreatePolicy(), CreateSharedComments(), CreateTrigger(), DefineOpClass(), DefineTSConfiguration(), DeleteAttributeTuples(), DeleteComments(), deleteDependencyRecordsFor(), deleteDependencyRecordsForClass(), DeleteInitPrivs(), deleteOneObject(), DeleteSecurityLabel(), DeleteSharedComments(), DeleteSharedSecurityLabel(), DeleteSystemAttributeTuples(), drop_parent_dependency(), DropCastById(), DropConfigurationMapping(), dropDatabaseDependencies(), DropRole(), DropTransformById(), EnableDisableTrigger(), EnumValuesDelete(), exec_object_restorecon(), ExecAlterExtensionStmt(), ExecGrant_Largeobject(), extension_config_remove(), fetch_statentries_for_relation(), find_composite_type_dependencies(), find_inheritance_children(), find_language_template(), findDependentObjects(), get_catalog_object_by_oid(), get_constraint_index(), get_database_oid(), get_db_info(), get_domain_constraint_oid(), get_extension_name(), get_extension_oid(), get_extension_schema(), get_index_constraint(), get_object_address_attrdef(), get_partition_parent(), get_pkey_attnames(), get_primary_key_attnos(), get_relation_constraint_attnos(), get_relation_constraint_oid(), get_relation_policy_oid(), get_rels_with_domain(), get_trigger_oid(), GetAllTablesPublications(), GetComment(), GetDatabaseTuple(), GetDatabaseTupleByOid(), GetDefaultOpClass(), getExtensionOfObject(), GetNewOidWithIndex(), getObjectDescription(), getObjectIdentityParts(), getOwnedSequences(), GetPublicationRelations(), GetSecurityLabel(), GetSharedSecurityLabel(), GetSubscriptionNotReadyRelations(), GetSubscriptionRelations(), has_superclass(), heap_truncate_find_FKs(), isObjectPinned(), isSharedObjectPinned(), LargeObjectDrop(), LargeObjectExists(), load_domaintype_info(), load_enum_cache_data(), LookupOpclassInfo(), makeConfigurationDependencies(), MakeConfigurationMapping(), MergeConstraintsIntoExisting(), MergeWithExistingConstraint(), movedb(), myLargeObjectExists(), pg_extension_config_dump(), pg_extension_ownercheck(), pg_get_constraintdef_worker(), pg_get_serial_sequence(), pg_get_triggerdef_worker(), pg_largeobject_aclmask_snapshot(), pg_largeobject_ownercheck(), RangeDelete(), recordExtensionInitPrivWorker(), recordExtObjInitPriv(), relation_has_policies(), RelationBuildRowSecurity(), RelationBuildRuleLock(), RelationBuildTriggers(), RelationBuildTupleDesc(), RelationGetExclusionInfo(), RelationGetFKeyList(), RelationGetIndexList(), RelationGetStatExtList(), RelationRemoveInheritance(), RelidByRelfilenode(), RemoveAmOpEntryById(), RemoveAmProcEntryById(), RemoveAttrDefault(), RemoveAttrDefaultById(), RemoveCollationById(), RemoveDefaultACLById(), RemoveExtensionById(), RemoveInheritance(), RemovePolicyById(), RemoveRewriteRuleById(), RemoveRoleFromObjectACL(), RemoveRoleFromObjectPolicy(), RemoveStatistics(), RemoveTriggerById(), RemoveTSConfigurationById(), rename_policy(), renametrig(), replorigin_create(), ScanPgRelation(), SearchCatCacheList(), SearchCatCacheMiss(), sepgsql_attribute_post_create(), sepgsql_database_post_create(), sepgsql_proc_post_create(), sepgsql_proc_setattr(), sepgsql_relation_post_create(), sepgsql_relation_setattr(), sepgsql_relation_setattr_extra(), sepgsql_schema_post_create(), sequenceIsOwned(), SetSecurityLabel(), SetSharedSecurityLabel(), shdepChangeDep(), shdepDropDependency(), shdepDropOwned(), shdepReassignOwned(), toastrel_valueid_exists(), typeInheritsFrom(), and vac_update_datfrozenxid().

417 {
418  HeapTuple htup;
419 
420  if (sysscan->irel)
421  {
422  htup = index_getnext(sysscan->iscan, ForwardScanDirection);
423 
424  /*
425  * We currently don't need to support lossy index operators for any
426  * system catalog scan. It could be done here, using the scan keys to
427  * drive the operator calls, if we arranged to save the heap attnums
428  * during systable_beginscan(); this is practical because we still
429  * wouldn't need to support indexes on expressions.
430  */
431  if (htup && sysscan->iscan->xs_recheck)
432  elog(ERROR, "system catalog scans with lossy index conditions are not implemented");
433  }
434  else
435  htup = heap_getnext(sysscan->scan, ForwardScanDirection);
436 
437  return htup;
438 }
Relation irel
Definition: relscan.h:156
IndexScanDesc iscan
Definition: relscan.h:158
#define ERROR
Definition: elog.h:43
HeapTuple heap_getnext(HeapScanDesc scan, ScanDirection direction)
Definition: heapam.c:1808
HeapScanDesc scan
Definition: relscan.h:157
#define elog
Definition: elog.h:219
HeapTuple index_getnext(IndexScanDesc scan, ScanDirection direction)
Definition: indexam.c:659

◆ systable_getnext_ordered()

HeapTuple systable_getnext_ordered ( SysScanDesc  sysscan,
ScanDirection  direction 
)

Definition at line 597 of file genam.c.

References Assert, elog, ERROR, index_getnext(), SysScanDescData::irel, SysScanDescData::iscan, and IndexScanDescData::xs_recheck.

Referenced by BuildEventTriggerCache(), enum_endpoint(), enum_range_internal(), inv_getsize(), inv_read(), inv_truncate(), inv_write(), lookup_ts_config_cache(), toast_delete_datum(), toast_fetch_datum(), and toast_fetch_datum_slice().

598 {
599  HeapTuple htup;
600 
601  Assert(sysscan->irel);
602  htup = index_getnext(sysscan->iscan, direction);
603  /* See notes in systable_getnext */
604  if (htup && sysscan->iscan->xs_recheck)
605  elog(ERROR, "system catalog scans with lossy index conditions are not implemented");
606 
607  return htup;
608 }
Relation irel
Definition: relscan.h:156
IndexScanDesc iscan
Definition: relscan.h:158
#define ERROR
Definition: elog.h:43
#define Assert(condition)
Definition: c.h:670
#define elog
Definition: elog.h:219
HeapTuple index_getnext(IndexScanDesc scan, ScanDirection direction)
Definition: indexam.c:659

◆ systable_recheck_tuple()

bool systable_recheck_tuple ( SysScanDesc  sysscan,
HeapTuple  tup 
)

Definition at line 454 of file genam.c.

References Assert, BUFFER_LOCK_SHARE, BUFFER_LOCK_UNLOCK, BufferIsValid, GetCatalogSnapshot(), SysScanDescData::heap_rel, HeapTupleSatisfiesVisibility, SysScanDescData::irel, SysScanDescData::iscan, IsMVCCSnapshot, LockBuffer(), RelationGetRelid, HeapScanDescData::rs_cbuf, HeapScanDescData::rs_ctup, HeapScanDescData::rs_snapshot, SysScanDescData::scan, IndexScanDescData::xs_cbuf, IndexScanDescData::xs_ctup, and IndexScanDescData::xs_snapshot.

Referenced by findDependentObjects().

455 {
456  Snapshot freshsnap;
457  bool result;
458 
459  /*
460  * Trust that LockBuffer() and HeapTupleSatisfiesMVCC() do not themselves
461  * acquire snapshots, so we need not register the snapshot. Those
462  * facilities are too low-level to have any business scanning tables.
463  */
464  freshsnap = GetCatalogSnapshot(RelationGetRelid(sysscan->heap_rel));
465 
466  if (sysscan->irel)
467  {
468  IndexScanDesc scan = sysscan->iscan;
469 
471  Assert(tup == &scan->xs_ctup);
472  Assert(BufferIsValid(scan->xs_cbuf));
473  /* must hold a buffer lock to call HeapTupleSatisfiesVisibility */
475  result = HeapTupleSatisfiesVisibility(tup, freshsnap, scan->xs_cbuf);
477  }
478  else
479  {
480  HeapScanDesc scan = sysscan->scan;
481 
483  Assert(tup == &scan->rs_ctup);
484  Assert(BufferIsValid(scan->rs_cbuf));
485  /* must hold a buffer lock to call HeapTupleSatisfiesVisibility */
487  result = HeapTupleSatisfiesVisibility(tup, freshsnap, scan->rs_cbuf);
489  }
490  return result;
491 }
Relation irel
Definition: relscan.h:156
#define BUFFER_LOCK_UNLOCK
Definition: bufmgr.h:87
Relation heap_rel
Definition: relscan.h:155
Snapshot GetCatalogSnapshot(Oid relid)
Definition: snapmgr.c:440
Snapshot xs_snapshot
Definition: relscan.h:91
IndexScanDesc iscan
Definition: relscan.h:158
#define HeapTupleSatisfiesVisibility(tuple, snapshot, buffer)
Definition: tqual.h:45
HeapTupleData rs_ctup
Definition: relscan.h:69
Buffer xs_cbuf
Definition: relscan.h:121
Snapshot rs_snapshot
Definition: relscan.h:49
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:3546
Buffer rs_cbuf
Definition: relscan.h:71
#define Assert(condition)
Definition: c.h:670
#define IsMVCCSnapshot(snapshot)
Definition: tqual.h:31
HeapTupleData xs_ctup
Definition: relscan.h:120
#define BufferIsValid(bufnum)
Definition: bufmgr.h:114
HeapScanDesc scan
Definition: relscan.h:157
#define BUFFER_LOCK_SHARE
Definition: bufmgr.h:88
#define RelationGetRelid(relation)
Definition: rel.h:425