PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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
ParallelIndexScanDescData
ParallelIndexScanDesc
 
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

#define IndexScanIsValid (   scan)    PointerIsValid(scan)

Definition at line 128 of file genam.h.

Typedef Documentation

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

Definition at line 83 of file genam.h.

Definition at line 86 of file genam.h.

Definition at line 89 of file genam.h.

Definition at line 87 of file genam.h.

Enumeration Type Documentation

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

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

Definition at line 171 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, NULL, 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().

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

Referenced by check_exclusion_or_unique_constraint(), copy_heap_data(), ExecInitIndexOnlyScan(), ExecInitIndexScan(), get_actual_variable_range(), 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:90
Relation heapRelation
Definition: relscan.h:88
static IndexScanDesc index_beginscan_internal(Relation indexRelation, int nkeys, int norderbys, Snapshot snapshot, ParallelIndexScanDesc pscan, bool temp_snap)
Definition: indexam.c:268
#define NULL
Definition: c.h:226
IndexScanDesc index_beginscan_bitmap ( Relation  indexRelation,
Snapshot  snapshot,
int  nkeys 
)

Definition at line 247 of file indexam.c.

References index_beginscan_internal(), NULL, 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:90
static IndexScanDesc index_beginscan_internal(Relation indexRelation, int nkeys, int norderbys, Snapshot snapshot, ParallelIndexScanDesc pscan, bool temp_snap)
Definition: indexam.c:268
#define NULL
Definition: c.h:226
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:2072
Snapshot RegisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:858
Snapshot xs_snapshot
Definition: relscan.h:90
char ps_snapshot_data[FLEXIBLE_ARRAY_MEMBER]
Definition: relscan.h:141
Relation heapRelation
Definition: relscan.h:88
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:671
#define RelationGetRelid(relation)
Definition: rel.h:413
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:177
#define CHECK_REL_PROCEDURE(pname)
Definition: indexam.c:112
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:49
bool index_can_return ( Relation  indexRelation,
int  attno 
)

Definition at line 783 of file indexam.c.

References IndexAmRoutine::amcanreturn, NULL, 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:177
#define NULL
Definition: c.h:226
amcanreturn_function amcanreturn
Definition: amapi.h:203
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(), 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:116
void RelationClose(Relation relation)
Definition: relcache.c:2155
#define MAX_LOCKMODES
Definition: lock.h:86
#define Assert(condition)
Definition: c.h:671
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:90
#define InvalidBuffer
Definition: buf.h:25
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3292
struct IndexAmRoutine * rd_amroutine
Definition: rel.h:177
#define CHECK_SCAN_PROCEDURE(pname)
Definition: indexam.c:119
Relation indexRelation
Definition: relscan.h:89
void RelationDecrementReferenceCount(Relation rel)
Definition: relcache.c:2135
Buffer xs_cbuf
Definition: relscan.h:113
bool xs_temp_snap
Definition: relscan.h:96
amendscan_function amendscan
Definition: amapi.h:212
void IndexScanEnd(IndexScanDesc scan)
Definition: genam.c:144
void UnregisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:900
#define SCAN_CHECKS
Definition: indexam.c:105
#define BufferIsValid(bufnum)
Definition: bufmgr.h:114
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(), NULL, 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:90
Relation indexRelation
Definition: relscan.h:89
Relation heapRelation
Definition: relscan.h:88
bool heap_hot_search_buffer(ItemPointer tid, Relation relation, Buffer buffer, Snapshot snapshot, HeapTuple heapTuple, bool *all_dead, bool first_call)
Definition: heapam.c:1984
Buffer xs_cbuf
Definition: relscan.h:113
ItemPointerData t_self
Definition: htup.h:65
#define pgstat_count_heap_fetch(rel)
Definition: pgstat.h:1150
bool xactStartedInRecovery
Definition: relscan.h:101
bool xs_continue_hot
Definition: relscan.h:129
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:3529
#define NULL
Definition: c.h:226
#define IsMVCCSnapshot(snapshot)
Definition: tqual.h:31
HeapTupleData xs_ctup
Definition: relscan.h:112
Buffer ReleaseAndReadBuffer(Buffer buffer, Relation relation, BlockNumber blockNum)
Definition: bufmgr.c:1508
bool kill_prior_tuple
Definition: relscan.h:99
#define BUFFER_LOCK_SHARE
Definition: bufmgr.h:88
void heap_page_prune_opt(Relation relation, Buffer buffer)
Definition: pruneheap.c:75
#define ItemPointerGetBlockNumber(pointer)
Definition: itemptr.h:66
int Buffer
Definition: buf.h:23
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:177
#define CHECK_SCAN_PROCEDURE(pname)
Definition: indexam.c:119
Relation indexRelation
Definition: relscan.h:89
amgetbitmap_function amgetbitmap
Definition: amapi.h:211
#define SCAN_CHECKS
Definition: indexam.c:105
#define pgstat_count_index_tuples(rel, n)
Definition: pgstat.h:1160
bool kill_prior_tuple
Definition: relscan.h:99
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, NULL, 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:113
ItemPointerData t_self
Definition: htup.h:65
HeapTuple index_fetch_heap(IndexScanDesc scan)
Definition: indexam.c:583
bool xs_continue_hot
Definition: relscan.h:129
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
HeapTupleData xs_ctup
Definition: relscan.h:112
#define BufferIsValid(bufnum)
Definition: bufmgr.h:114
BlockNumber BufferGetBlockNumber(Buffer buffer)
Definition: bufmgr.c:2588
#define ItemPointerGetBlockNumber(pointer)
Definition: itemptr.h:66
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, NULL, 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, though we pay no attention
539  * 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:3292
struct IndexAmRoutine * rd_amroutine
Definition: rel.h:177
#define CHECK_SCAN_PROCEDURE(pname)
Definition: indexam.c:119
Relation indexRelation
Definition: relscan.h:89
Buffer xs_cbuf
Definition: relscan.h:113
ItemPointerData t_self
Definition: htup.h:65
TransactionId RecentGlobalXmin
Definition: snapmgr.c:166
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
HeapTupleData xs_ctup
Definition: relscan.h:112
#define SCAN_CHECKS
Definition: indexam.c:105
#define BufferIsValid(bufnum)
Definition: bufmgr.h:114
#define pgstat_count_index_tuples(rel, n)
Definition: pgstat.h:1160
bool kill_prior_tuple
Definition: relscan.h:99
#define TransactionIdIsValid(xid)
Definition: transam.h:41
RegProcedure index_getprocid ( Relation  irel,
AttrNumber  attnum,
uint16  procnum 
)

Definition at line 821 of file indexam.c.

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

Referenced by _hash_metapinit(), 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:392
struct IndexAmRoutine * rd_amroutine
Definition: rel.h:177
unsigned short uint16
Definition: c.h:264
RegProcedure * rd_support
Definition: rel.h:180
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
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, NULL, 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:53
uint16 amsupport
Definition: amapi.h:169
FmgrInfo * rd_supportinfo
Definition: rel.h:181
regproc RegProcedure
Definition: c.h:392
struct IndexAmRoutine * rd_amroutine
Definition: rel.h:177
unsigned short uint16
Definition: c.h:264
#define ERROR
Definition: elog.h:43
#define RegProcedureIsValid(p)
Definition: c.h:536
#define RelationGetRelationName(relation)
Definition: rel.h:433
void fmgr_info_cxt(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt)
Definition: fmgr.c:169
RegProcedure * rd_support
Definition: rel.h:180
#define InvalidOid
Definition: postgres_ext.h:36
Oid fn_oid
Definition: fmgr.h:56
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
MemoryContext rd_indexcxt
Definition: rel.h:175
#define elog
Definition: elog.h:219
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, NULL, 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:4243
struct IndexAmRoutine * rd_amroutine
Definition: rel.h:177
#define CHECK_REL_PROCEDURE(pname)
Definition: indexam.c:112
#define NULL
Definition: c.h:226
static Datum values[MAXATTR]
Definition: bootstrap.c:162
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:177
#define CHECK_SCAN_PROCEDURE(pname)
Definition: indexam.c:119
Relation indexRelation
Definition: relscan.h:89
#define SCAN_CHECKS
Definition: indexam.c:105
ammarkpos_function ammarkpos
Definition: amapi.h:213
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_page_items(), brin_summarize_new_values(), 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:113
#define ERROR
Definition: elog.h:43
#define RelationGetRelationName(relation)
Definition: rel.h:433
#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:1117
void index_parallelrescan ( IndexScanDesc  scan)

Definition at line 481 of file indexam.c.

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

Referenced by ExecReScanIndexOnlyScan(), and ExecReScanIndexScan().

482 {
483  SCAN_CHECKS;
484 
485  /* amparallelrescan is optional; assume no-op if not provided by AM */
488 }
amparallelrescan_function amparallelrescan
Definition: amapi.h:219
struct IndexAmRoutine * rd_amroutine
Definition: rel.h:177
Relation indexRelation
Definition: relscan.h:89
#define NULL
Definition: c.h:226
#define SCAN_CHECKS
Definition: indexam.c:105
Size index_parallelscan_estimate ( Relation  indexrel,
Snapshot  snapshot 
)

Definition at line 417 of file indexam.c.

References add_size(), IndexAmRoutine::amestimateparallelscan, EstimateSnapshotSpace(), MAXALIGN, NULL, 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:1992
Size add_size(Size s1, Size s2)
Definition: shmem.c:475
#define NULL
Definition: c.h:226
size_t Size
Definition: c.h:353
#define MAXALIGN(LEN)
Definition: c.h:584
#define offsetof(type, field)
Definition: c.h:551
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, NULL, 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:141
void SerializeSnapshot(Snapshot snapshot, char *start_address)
Definition: snapmgr.c:2016
#define OffsetToPointer(base, offset)
Definition: c.h:531
Size EstimateSnapshotSpace(Snapshot snap)
Definition: snapmgr.c:1992
Size add_size(Size s1, Size s2)
Definition: shmem.c:475
#define NULL
Definition: c.h:226
size_t Size
Definition: c.h:353
#define MAXALIGN(LEN)
Definition: c.h:584
#define RelationGetRelid(relation)
Definition: rel.h:413
#define offsetof(type, field)
Definition: c.h:551
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(), ExecInitIndexOnlyScan(), ExecInitIndexScan(), ExecReScanBitmapIndexScan(), ExecReScanIndexOnlyScan(), ExecReScanIndexScan(), get_actual_variable_range(), 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:3292
struct IndexAmRoutine * rd_amroutine
Definition: rel.h:177
#define CHECK_SCAN_PROCEDURE(pname)
Definition: indexam.c:119
Relation indexRelation
Definition: relscan.h:89
Buffer xs_cbuf
Definition: relscan.h:113
bool xs_continue_hot
Definition: relscan.h:129
amrescan_function amrescan
Definition: amapi.h:209
#define Assert(condition)
Definition: c.h:671
#define SCAN_CHECKS
Definition: indexam.c:105
#define BufferIsValid(bufnum)
Definition: bufmgr.h:114
bool kill_prior_tuple
Definition: relscan.h:99
int numberOfOrderBys
Definition: relscan.h:92
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:90
struct IndexAmRoutine * rd_amroutine
Definition: rel.h:177
#define CHECK_SCAN_PROCEDURE(pname)
Definition: indexam.c:119
Relation indexRelation
Definition: relscan.h:89
bool xs_continue_hot
Definition: relscan.h:129
#define Assert(condition)
Definition: c.h:671
#define IsMVCCSnapshot(snapshot)
Definition: tqual.h:31
#define SCAN_CHECKS
Definition: indexam.c:105
bool kill_prior_tuple
Definition: relscan.h:99
amrestrpos_function amrestrpos
Definition: amapi.h:214
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:177
#define CHECK_REL_PROCEDURE(pname)
Definition: indexam.c:112
amvacuumcleanup_function amvacuumcleanup
Definition: amapi.h:202
void IndexScanEnd ( IndexScanDesc  scan)

Definition at line 144 of file genam.c.

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

Referenced by index_endscan().

145 {
146  if (scan->keyData != NULL)
147  pfree(scan->keyData);
148  if (scan->orderByData != NULL)
149  pfree(scan->orderByData);
150 
151  pfree(scan);
152 }
void pfree(void *pointer)
Definition: mcxt.c:992
ScanKey orderByData
Definition: relscan.h:94
#define NULL
Definition: c.h:226
ScanKey keyData
Definition: relscan.h:93
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, NULL, 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_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 
124  scan->xs_ctup.t_data = NULL;
125  scan->xs_cbuf = InvalidBuffer;
126  scan->xs_continue_hot = false;
127 
128  return scan;
129 }
bool TransactionStartedDuringRecovery(void)
Definition: xact.c:870
IndexTuple xs_itup
Definition: relscan.h:108
Snapshot xs_snapshot
Definition: relscan.h:90
#define InvalidBuffer
Definition: buf.h:25
TupleDesc xs_itupdesc
Definition: relscan.h:109
bool ignore_killed_tuples
Definition: relscan.h:100
Relation indexRelation
Definition: relscan.h:89
HeapTupleHeader t_data
Definition: htup.h:67
Relation heapRelation
Definition: relscan.h:88
Buffer xs_cbuf
Definition: relscan.h:113
ItemPointerData t_self
Definition: htup.h:65
bool xactStartedInRecovery
Definition: relscan.h:101
ScanKeyData * ScanKey
Definition: skey.h:75
bool xs_continue_hot
Definition: relscan.h:129
#define InvalidSnapshot
Definition: snapshot.h:25
ScanKey orderByData
Definition: relscan.h:94
bool xs_want_itup
Definition: relscan.h:95
#define NULL
Definition: c.h:226
HeapTupleData xs_ctup
Definition: relscan.h:112
ScanKey keyData
Definition: relscan.h:93
#define ItemPointerSetInvalid(pointer)
Definition: itemptr.h:131
void * palloc(Size size)
Definition: mcxt.c:891
bool kill_prior_tuple
Definition: relscan.h:99
int numberOfOrderBys
Definition: relscan.h:92
struct IndexScanDescData * IndexScanDesc
Definition: genam.h:86
SysScanDesc systable_beginscan ( Relation  heapRelation,
Oid  indexId,
bool  indexOK,
Snapshot  snapshot,
int  nkeys,
ScanKey  key 
)

Definition at line 322 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, NULL, 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(), 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_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(), 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(), regclassin(), regoperin(), regprocin(), regtypein(), relation_has_policies(), RelationBuildRowSecurity(), RelationBuildRuleLock(), RelationBuildTriggers(), RelationBuildTupleDesc(), RelationGetExclusionInfo(), RelationGetFKeyList(), RelationGetIndexList(), RelationRemoveInheritance(), RelidByRelfilenode(), RemoveAmOpEntryById(), RemoveAmProcEntryById(), RemoveAttrDefault(), RemoveAttrDefaultById(), RemoveCollationById(), RemoveDefaultACLById(), RemoveExtensionById(), RemoveInheritance(), RemovePolicyById(), RemoveRewriteRuleById(), RemoveRoleFromObjectACL(), RemoveRoleFromObjectPolicy(), RemoveStatistics(), RemoveTriggerById(), RemoveTSConfigurationById(), rename_policy(), renametrig(), replorigin_create(), ScanPgRelation(), SearchCatCache(), SearchCatCacheList(), 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().

327 {
328  SysScanDesc sysscan;
329  Relation irel;
330 
331  if (indexOK &&
333  !ReindexIsProcessingIndex(indexId))
334  irel = index_open(indexId, AccessShareLock);
335  else
336  irel = NULL;
337 
338  sysscan = (SysScanDesc) palloc(sizeof(SysScanDescData));
339 
340  sysscan->heap_rel = heapRelation;
341  sysscan->irel = irel;
342 
343  if (snapshot == NULL)
344  {
345  Oid relid = RelationGetRelid(heapRelation);
346 
347  snapshot = RegisterSnapshot(GetCatalogSnapshot(relid));
348  sysscan->snapshot = snapshot;
349  }
350  else
351  {
352  /* Caller is responsible for any snapshot. */
353  sysscan->snapshot = NULL;
354  }
355 
356  if (irel)
357  {
358  int i;
359 
360  /* Change attribute numbers to be index column numbers. */
361  for (i = 0; i < nkeys; i++)
362  {
363  int j;
364 
365  for (j = 0; j < irel->rd_index->indnatts; j++)
366  {
367  if (key[i].sk_attno == irel->rd_index->indkey.values[j])
368  {
369  key[i].sk_attno = j + 1;
370  break;
371  }
372  }
373  if (j == irel->rd_index->indnatts)
374  elog(ERROR, "column is not in index");
375  }
376 
377  sysscan->iscan = index_beginscan(heapRelation, irel,
378  snapshot, nkeys, 0);
379  index_rescan(sysscan->iscan, key, nkeys, NULL, 0);
380  sysscan->scan = NULL;
381  }
382  else
383  {
384  /*
385  * We disallow synchronized scans when forced to use a heapscan on a
386  * catalog. In most cases the desired rows are near the front, so
387  * that the unpredictable start point of a syncscan is a serious
388  * disadvantage; and there are no compensating advantages, because
389  * it's unlikely that such scans will occur in parallel.
390  */
391  sysscan->scan = heap_beginscan_strat(heapRelation, snapshot,
392  nkeys, key,
393  true, false);
394  sysscan->iscan = NULL;
395  }
396 
397  return sysscan;
398 }
Relation irel
Definition: relscan.h:148
Snapshot snapshot
Definition: relscan.h:151
struct SysScanDescData * SysScanDesc
Definition: genam.h:87
Relation heap_rel
Definition: relscan.h:147
Snapshot RegisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:858
Snapshot GetCatalogSnapshot(Oid relid)
Definition: snapmgr.c:436
#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:73
unsigned int Oid
Definition: postgres_ext.h:31
IndexScanDesc iscan
Definition: relscan.h:150
Form_pg_index rd_index
Definition: rel.h:155
#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:1412
#define NULL
Definition: c.h:226
HeapScanDesc scan
Definition: relscan.h:149
void * palloc(Size size)
Definition: mcxt.c:891
int i
#define elog
Definition: elog.h:219
bool ReindexIsProcessingIndex(Oid indexOid)
Definition: index.c:3687
#define RelationGetRelid(relation)
Definition: rel.h:413
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
SysScanDesc systable_beginscan_ordered ( Relation  heapRelation,
Relation  indexRelation,
Snapshot  snapshot,
int  nkeys,
ScanKey  key 
)

Definition at line 527 of file genam.c.

References elog, ERROR, GetCatalogSnapshot(), SysScanDescData::heap_rel, i, IgnoreSystemIndexes, index_beginscan(), index_rescan(), SysScanDescData::irel, SysScanDescData::iscan, NULL, 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().

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

Definition at line 493 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(), 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_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(), 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(), regclassin(), regoperin(), regprocin(), regtypein(), relation_has_policies(), RelationBuildRowSecurity(), RelationBuildRuleLock(), RelationBuildTriggers(), RelationBuildTupleDesc(), RelationGetExclusionInfo(), RelationGetFKeyList(), RelationGetIndexList(), RelationRemoveInheritance(), RelidByRelfilenode(), RemoveAmOpEntryById(), RemoveAmProcEntryById(), RemoveAttrDefault(), RemoveAttrDefaultById(), RemoveCollationById(), RemoveDefaultACLById(), RemoveExtensionById(), RemoveInheritance(), RemovePolicyById(), RemoveRewriteRuleById(), RemoveRoleFromObjectACL(), RemoveRoleFromObjectPolicy(), RemoveStatistics(), RemoveTriggerById(), RemoveTSConfigurationById(), rename_policy(), renametrig(), replorigin_create(), ScanPgRelation(), SearchCatCache(), SearchCatCacheList(), 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().

494 {
495  if (sysscan->irel)
496  {
497  index_endscan(sysscan->iscan);
498  index_close(sysscan->irel, AccessShareLock);
499  }
500  else
501  heap_endscan(sysscan->scan);
502 
503  if (sysscan->snapshot)
504  UnregisterSnapshot(sysscan->snapshot);
505 
506  pfree(sysscan);
507 }
Relation irel
Definition: relscan.h:148
Snapshot snapshot
Definition: relscan.h:151
void heap_endscan(HeapScanDesc scan)
Definition: heapam.c:1581
#define AccessShareLock
Definition: lockdefs.h:36
IndexScanDesc iscan
Definition: relscan.h:150
void pfree(void *pointer)
Definition: mcxt.c:992
void index_endscan(IndexScanDesc scan)
Definition: indexam.c:340
void UnregisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:900
HeapScanDesc scan
Definition: relscan.h:149
void index_close(Relation relation, LOCKMODE lockmode)
Definition: indexam.c:176
void systable_endscan_ordered ( SysScanDesc  sysscan)

Definition at line 608 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().

609 {
610  Assert(sysscan->irel);
611  index_endscan(sysscan->iscan);
612  if (sysscan->snapshot)
613  UnregisterSnapshot(sysscan->snapshot);
614  pfree(sysscan);
615 }
Relation irel
Definition: relscan.h:148
Snapshot snapshot
Definition: relscan.h:151
IndexScanDesc iscan
Definition: relscan.h:150
void pfree(void *pointer)
Definition: mcxt.c:992
void index_endscan(IndexScanDesc scan)
Definition: indexam.c:340
void UnregisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:900
#define Assert(condition)
Definition: c.h:671
HeapTuple systable_getnext ( SysScanDesc  sysscan)

Definition at line 410 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(), 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_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(), 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(), regclassin(), regoperin(), regprocin(), regtypein(), relation_has_policies(), RelationBuildRowSecurity(), RelationBuildRuleLock(), RelationBuildTriggers(), RelationBuildTupleDesc(), RelationGetExclusionInfo(), RelationGetFKeyList(), RelationGetIndexList(), RelationRemoveInheritance(), RelidByRelfilenode(), RemoveAmOpEntryById(), RemoveAmProcEntryById(), RemoveAttrDefault(), RemoveAttrDefaultById(), RemoveCollationById(), RemoveDefaultACLById(), RemoveExtensionById(), RemoveInheritance(), RemovePolicyById(), RemoveRewriteRuleById(), RemoveRoleFromObjectACL(), RemoveRoleFromObjectPolicy(), RemoveStatistics(), RemoveTriggerById(), RemoveTSConfigurationById(), rename_policy(), renametrig(), replorigin_create(), ScanPgRelation(), SearchCatCache(), SearchCatCacheList(), 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().

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

Definition at line 591 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().

592 {
593  HeapTuple htup;
594 
595  Assert(sysscan->irel);
596  htup = index_getnext(sysscan->iscan, direction);
597  /* See notes in systable_getnext */
598  if (htup && sysscan->iscan->xs_recheck)
599  elog(ERROR, "system catalog scans with lossy index conditions are not implemented");
600 
601  return htup;
602 }
Relation irel
Definition: relscan.h:148
IndexScanDesc iscan
Definition: relscan.h:150
#define ERROR
Definition: elog.h:43
#define Assert(condition)
Definition: c.h:671
#define elog
Definition: elog.h:219
HeapTuple index_getnext(IndexScanDesc scan, ScanDirection direction)
Definition: indexam.c:659
bool systable_recheck_tuple ( SysScanDesc  sysscan,
HeapTuple  tup 
)

Definition at line 448 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().

449 {
450  Snapshot freshsnap;
451  bool result;
452 
453  /*
454  * Trust that LockBuffer() and HeapTupleSatisfiesMVCC() do not themselves
455  * acquire snapshots, so we need not register the snapshot. Those
456  * facilities are too low-level to have any business scanning tables.
457  */
458  freshsnap = GetCatalogSnapshot(RelationGetRelid(sysscan->heap_rel));
459 
460  if (sysscan->irel)
461  {
462  IndexScanDesc scan = sysscan->iscan;
463 
465  Assert(tup == &scan->xs_ctup);
466  Assert(BufferIsValid(scan->xs_cbuf));
467  /* must hold a buffer lock to call HeapTupleSatisfiesVisibility */
469  result = HeapTupleSatisfiesVisibility(tup, freshsnap, scan->xs_cbuf);
471  }
472  else
473  {
474  HeapScanDesc scan = sysscan->scan;
475 
477  Assert(tup == &scan->rs_ctup);
478  Assert(BufferIsValid(scan->rs_cbuf));
479  /* must hold a buffer lock to call HeapTupleSatisfiesVisibility */
481  result = HeapTupleSatisfiesVisibility(tup, freshsnap, scan->rs_cbuf);
483  }
484  return result;
485 }
Relation irel
Definition: relscan.h:148
#define BUFFER_LOCK_UNLOCK
Definition: bufmgr.h:87
Relation heap_rel
Definition: relscan.h:147
Snapshot GetCatalogSnapshot(Oid relid)
Definition: snapmgr.c:436
Snapshot xs_snapshot
Definition: relscan.h:90
IndexScanDesc iscan
Definition: relscan.h:150
#define HeapTupleSatisfiesVisibility(tuple, snapshot, buffer)
Definition: tqual.h:45
HeapTupleData rs_ctup
Definition: relscan.h:68
Buffer xs_cbuf
Definition: relscan.h:113
Snapshot rs_snapshot
Definition: relscan.h:48
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:3529
Buffer rs_cbuf
Definition: relscan.h:70
#define Assert(condition)
Definition: c.h:671
#define IsMVCCSnapshot(snapshot)
Definition: tqual.h:31
HeapTupleData xs_ctup
Definition: relscan.h:112
#define BufferIsValid(bufnum)
Definition: bufmgr.h:114
HeapScanDesc scan
Definition: relscan.h:149
#define BUFFER_LOCK_SHARE
Definition: bufmgr.h:88
#define RelationGetRelid(relation)
Definition: rel.h:413