PostgreSQL Source Code  git master
indexam.c File Reference
#include "postgres.h"
#include "access/amapi.h"
#include "access/heapam.h"
#include "access/relscan.h"
#include "access/tableam.h"
#include "access/transam.h"
#include "access/xlog.h"
#include "catalog/index.h"
#include "catalog/pg_type.h"
#include "pgstat.h"
#include "storage/bufmgr.h"
#include "storage/lmgr.h"
#include "storage/predicate.h"
#include "utils/snapmgr.h"
Include dependency graph for indexam.c:

Go to the source code of this file.

Macros

#define RELATION_CHECKS
 
#define SCAN_CHECKS
 
#define CHECK_REL_PROCEDURE(pname)
 
#define CHECK_SCAN_PROCEDURE(pname)
 

Functions

static IndexScanDesc index_beginscan_internal (Relation indexRelation, int nkeys, int norderbys, Snapshot snapshot, ParallelIndexScanDesc pscan, bool temp_snap)
 
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, 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 indexRelation, Snapshot snapshot)
 
void index_parallelscan_initialize (Relation heapRelation, Relation indexRelation, 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)
 
bool index_fetch_heap (IndexScanDesc scan, TupleTableSlot *slot)
 
bool index_getnext_slot (IndexScanDesc scan, ScanDirection direction, TupleTableSlot *slot)
 
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)
 
void index_store_float8_orderby_distances (IndexScanDesc scan, Oid *orderByTypes, double *distances, bool recheckOrderBy)
 

Macro Definition Documentation

◆ CHECK_REL_PROCEDURE

#define CHECK_REL_PROCEDURE (   pname)
Value:
do { \
if (indexRelation->rd_indam->pname == NULL) \
elog(ERROR, "function %s is not defined for index %s", \
CppAsString(pname), RelationGetRelationName(indexRelation)); \
} while(0)
#define ERROR
Definition: elog.h:43
#define RelationGetRelationName(relation)
Definition: rel.h:448
#define CppAsString(identifier)
Definition: c.h:223

Definition at line 87 of file indexam.c.

Referenced by index_beginscan_internal(), index_bulk_delete(), index_insert(), and index_vacuum_cleanup().

◆ CHECK_SCAN_PROCEDURE

#define CHECK_SCAN_PROCEDURE (   pname)
Value:
do { \
if (scan->indexRelation->rd_indam->pname == NULL) \
elog(ERROR, "function %s is not defined for index %s", \
CppAsString(pname), RelationGetRelationName(scan->indexRelation)); \
} while(0)
#define ERROR
Definition: elog.h:43
#define RelationGetRelationName(relation)
Definition: rel.h:448
#define CppAsString(identifier)
Definition: c.h:223

Definition at line 94 of file indexam.c.

Referenced by index_endscan(), index_getbitmap(), index_getnext_tid(), index_markpos(), index_rescan(), and index_restrpos().

◆ RELATION_CHECKS

#define RELATION_CHECKS
Value:
( \
AssertMacro(RelationIsValid(indexRelation)), \
AssertMacro(PointerIsValid(indexRelation->rd_indam)), \
AssertMacro(!ReindexIsProcessingIndex(RelationGetRelid(indexRelation))) \
)
#define RelationIsValid(relation)
Definition: rel.h:387
bool ReindexIsProcessingIndex(Oid indexOid)
Definition: index.c:3645
#define PointerIsValid(pointer)
Definition: c.h:626
#define RelationGetRelid(relation)
Definition: rel.h:414

Definition at line 73 of file indexam.c.

Referenced by index_beginscan_internal(), index_bulk_delete(), index_can_return(), index_insert(), index_parallelscan_estimate(), index_parallelscan_initialize(), and index_vacuum_cleanup().

◆ SCAN_CHECKS

#define SCAN_CHECKS
Value:
( \
AssertMacro(IndexScanIsValid(scan)), \
AssertMacro(RelationIsValid(scan->indexRelation)), \
AssertMacro(PointerIsValid(scan->indexRelation->rd_indam)) \
)
#define RelationIsValid(relation)
Definition: rel.h:387
#define IndexScanIsValid(scan)
Definition: genam.h:129
#define PointerIsValid(pointer)
Definition: c.h:626

Definition at line 80 of file indexam.c.

Referenced by index_endscan(), index_getbitmap(), index_getnext_tid(), index_markpos(), index_parallelrescan(), index_rescan(), and index_restrpos().

Function Documentation

◆ index_beginscan()

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

Definition at line 197 of file indexam.c.

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

Referenced by check_exclusion_or_unique_constraint(), get_actual_variable_endpoint(), heapam_relation_copy_for_cluster(), IndexNext(), IndexNextWithReorder(), IndexOnlyNext(), RelationFindReplTupleByIndex(), systable_beginscan(), and systable_beginscan_ordered().

201 {
202  IndexScanDesc scan;
203 
204  scan = index_beginscan_internal(indexRelation, nkeys, norderbys, snapshot, NULL, false);
205 
206  /*
207  * Save additional parameters into the scandesc. Everything else was set
208  * up by RelationGetIndexScan.
209  */
210  scan->heapRelation = heapRelation;
211  scan->xs_snapshot = snapshot;
212 
213  /* prepare to fetch index matches from table */
214  scan->xs_heapfetch = table_index_fetch_begin(heapRelation);
215 
216  return scan;
217 }
static IndexFetchTableData * table_index_fetch_begin(Relation rel)
Definition: tableam.h:934
struct SnapshotData * xs_snapshot
Definition: relscan.h:104
Relation heapRelation
Definition: relscan.h:102
static IndexScanDesc index_beginscan_internal(Relation indexRelation, int nkeys, int norderbys, Snapshot snapshot, ParallelIndexScanDesc pscan, bool temp_snap)
Definition: indexam.c:247
IndexFetchTableData * xs_heapfetch
Definition: relscan.h:135

◆ index_beginscan_bitmap()

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

Definition at line 226 of file indexam.c.

References index_beginscan_internal(), and IndexScanDescData::xs_snapshot.

Referenced by ExecInitBitmapIndexScan().

229 {
230  IndexScanDesc scan;
231 
232  scan = index_beginscan_internal(indexRelation, nkeys, 0, snapshot, NULL, false);
233 
234  /*
235  * Save additional parameters into the scandesc. Everything else was set
236  * up by RelationGetIndexScan.
237  */
238  scan->xs_snapshot = snapshot;
239 
240  return scan;
241 }
struct SnapshotData * xs_snapshot
Definition: relscan.h:104
static IndexScanDesc index_beginscan_internal(Relation indexRelation, int nkeys, int norderbys, Snapshot snapshot, ParallelIndexScanDesc pscan, bool temp_snap)
Definition: indexam.c:247

◆ index_beginscan_internal()

static IndexScanDesc index_beginscan_internal ( Relation  indexRelation,
int  nkeys,
int  norderbys,
Snapshot  snapshot,
ParallelIndexScanDesc  pscan,
bool  temp_snap 
)
static

Definition at line 247 of file indexam.c.

References IndexAmRoutine::ambeginscan, IndexAmRoutine::ampredlocks, CHECK_REL_PROCEDURE, IndexScanDescData::parallel_scan, PredicateLockRelation(), RelationData::rd_indam, RELATION_CHECKS, RelationIncrementReferenceCount(), and IndexScanDescData::xs_temp_snap.

Referenced by index_beginscan(), index_beginscan_bitmap(), and index_beginscan_parallel().

250 {
251  IndexScanDesc scan;
252 
254  CHECK_REL_PROCEDURE(ambeginscan);
255 
256  if (!(indexRelation->rd_indam->ampredlocks))
257  PredicateLockRelation(indexRelation, snapshot);
258 
259  /*
260  * We hold a reference count to the relcache entry throughout the scan.
261  */
262  RelationIncrementReferenceCount(indexRelation);
263 
264  /*
265  * Tell the AM to open a scan.
266  */
267  scan = indexRelation->rd_indam->ambeginscan(indexRelation, nkeys,
268  norderbys);
269  /* Initialize information for parallel scan. */
270  scan->parallel_scan = pscan;
271  scan->xs_temp_snap = temp_snap;
272 
273  return scan;
274 }
ambeginscan_function ambeginscan
Definition: amapi.h:221
struct IndexAmRoutine * rd_indam
Definition: rel.h:165
#define RELATION_CHECKS
Definition: indexam.c:73
void PredicateLockRelation(Relation relation, Snapshot snapshot)
Definition: predicate.c:2503
bool ampredlocks
Definition: amapi.h:195
#define CHECK_REL_PROCEDURE(pname)
Definition: indexam.c:87
struct ParallelIndexScanDescData * parallel_scan
Definition: relscan.h:151
void RelationIncrementReferenceCount(Relation rel)
Definition: relcache.c:2057

◆ index_beginscan_parallel()

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

Definition at line 476 of file indexam.c.

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

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

478 {
479  Snapshot snapshot;
480  IndexScanDesc scan;
481 
482  Assert(RelationGetRelid(heaprel) == pscan->ps_relid);
483  snapshot = RestoreSnapshot(pscan->ps_snapshot_data);
484  RegisterSnapshot(snapshot);
485  scan = index_beginscan_internal(indexrel, nkeys, norderbys, snapshot,
486  pscan, true);
487 
488  /*
489  * Save additional parameters into the scandesc. Everything else was set
490  * up by index_beginscan_internal.
491  */
492  scan->heapRelation = heaprel;
493  scan->xs_snapshot = snapshot;
494 
495  /* prepare to fetch index matches from table */
496  scan->xs_heapfetch = table_index_fetch_begin(heaprel);
497 
498  return scan;
499 }
Snapshot RestoreSnapshot(char *start_address)
Definition: snapmgr.c:2131
Snapshot RegisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:865
static IndexFetchTableData * table_index_fetch_begin(Relation rel)
Definition: tableam.h:934
struct SnapshotData * xs_snapshot
Definition: relscan.h:104
char ps_snapshot_data[FLEXIBLE_ARRAY_MEMBER]
Definition: relscan.h:160
Relation heapRelation
Definition: relscan.h:102
static IndexScanDesc index_beginscan_internal(Relation indexRelation, int nkeys, int norderbys, Snapshot snapshot, ParallelIndexScanDesc pscan, bool temp_snap)
Definition: indexam.c:247
#define Assert(condition)
Definition: c.h:732
IndexFetchTableData * xs_heapfetch
Definition: relscan.h:135
#define RelationGetRelid(relation)
Definition: rel.h:414

◆ index_bulk_delete()

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

Definition at line 682 of file indexam.c.

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

Referenced by lazy_vacuum_index(), and validate_index().

686 {
687  Relation indexRelation = info->index;
688 
690  CHECK_REL_PROCEDURE(ambulkdelete);
691 
692  return indexRelation->rd_indam->ambulkdelete(info, stats,
693  callback, callback_state);
694 }
struct IndexAmRoutine * rd_indam
Definition: rel.h:165
ambulkdelete_function ambulkdelete
Definition: amapi.h:213
#define RELATION_CHECKS
Definition: indexam.c:73
Relation index
Definition: genam.h:46
#define CHECK_REL_PROCEDURE(pname)
Definition: indexam.c:87
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 722 of file indexam.c.

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

Referenced by get_relation_info(), and indexam_property().

723 {
725 
726  /* amcanreturn is optional; assume false if not provided by AM */
727  if (indexRelation->rd_indam->amcanreturn == NULL)
728  return false;
729 
730  return indexRelation->rd_indam->amcanreturn(indexRelation, attno);
731 }
struct IndexAmRoutine * rd_indam
Definition: rel.h:165
#define RELATION_CHECKS
Definition: indexam.c:73
amcanreturn_function amcanreturn
Definition: amapi.h:215

◆ index_close()

void index_close ( Relation  relation,
LOCKMODE  lockmode 
)

Definition at line 152 of file indexam.c.

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

Referenced by _bt_parallel_build_main(), ATExecAddIndex(), ATExecAddIndexConstraint(), ATExecDetachPartition(), ATExecReplicaIdentity(), AttachPartitionEnsureIndexes(), brin_page_items(), brincostestimate(), bt_index_check_internal(), build_indices(), BuildEventTriggerCache(), check_index_is_clusterable(), CheckIndexCompatible(), close_lo_relation(), copy_table_data(), DefineIndex(), DefineRelation(), 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_concurrently_build(), index_concurrently_create_copy(), index_concurrently_set_dead(), index_create(), index_drop(), indexam_property(), infer_arbiter_indexes(), InitCatCachePhase2(), lookup_ts_config_cache(), pg_nextoid(), pgstathashindex(), plan_create_index_workers(), refresh_by_match_merge(), reindex_index(), ReindexIndex(), ReindexRelationConcurrently(), RelationFindReplTupleByIndex(), RelationGetIndexAttrBitmap(), RelationTruncateIndexes(), systable_endscan(), toast_close_indexes(), transformTableLikeClause(), TryReuseIndex(), unique_key_recheck(), vac_close_indexes(), vac_open_indexes(), and validate_index().

153 {
154  LockRelId relid = relation->rd_lockInfo.lockRelId;
155 
156  Assert(lockmode >= NoLock && lockmode < MAX_LOCKMODES);
157 
158  /* The relcache does the real work... */
159  RelationClose(relation);
160 
161  if (lockmode != NoLock)
162  UnlockRelationId(&relid, lockmode);
163 }
LockRelId lockRelId
Definition: rel.h:44
void UnlockRelationId(LockRelId *relid, LOCKMODE lockmode)
Definition: lmgr.c:184
Definition: rel.h:36
#define NoLock
Definition: lockdefs.h:34
LockInfoData rd_lockInfo
Definition: rel.h:87
void RelationClose(Relation relation)
Definition: relcache.c:2090
#define MAX_LOCKMODES
Definition: lock.h:85
#define Assert(condition)
Definition: c.h:732

◆ index_endscan()

void index_endscan ( IndexScanDesc  scan)

Definition at line 315 of file indexam.c.

References IndexAmRoutine::amendscan, CHECK_SCAN_PROCEDURE, IndexScanDescData::indexRelation, IndexScanEnd(), RelationData::rd_indam, RelationDecrementReferenceCount(), SCAN_CHECKS, table_index_fetch_end(), UnregisterSnapshot(), IndexScanDescData::xs_heapfetch, IndexScanDescData::xs_snapshot, and IndexScanDescData::xs_temp_snap.

Referenced by check_exclusion_or_unique_constraint(), ExecEndBitmapIndexScan(), ExecEndIndexOnlyScan(), ExecEndIndexScan(), get_actual_variable_endpoint(), heapam_relation_copy_for_cluster(), RelationFindReplTupleByIndex(), systable_endscan(), and systable_endscan_ordered().

316 {
317  SCAN_CHECKS;
318  CHECK_SCAN_PROCEDURE(amendscan);
319 
320  /* Release resources (like buffer pins) from table accesses */
321  if (scan->xs_heapfetch)
322  {
324  scan->xs_heapfetch = NULL;
325  }
326 
327  /* End the AM's scan */
328  scan->indexRelation->rd_indam->amendscan(scan);
329 
330  /* Release index refcount acquired by index_beginscan */
332 
333  if (scan->xs_temp_snap)
335 
336  /* Release the scan data structure itself */
337  IndexScanEnd(scan);
338 }
struct IndexAmRoutine * rd_indam
Definition: rel.h:165
struct SnapshotData * xs_snapshot
Definition: relscan.h:104
#define CHECK_SCAN_PROCEDURE(pname)
Definition: indexam.c:94
Relation indexRelation
Definition: relscan.h:103
void RelationDecrementReferenceCount(Relation rel)
Definition: relcache.c:2070
amendscan_function amendscan
Definition: amapi.h:225
void IndexScanEnd(IndexScanDesc scan)
Definition: genam.c:144
void UnregisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:907
IndexFetchTableData * xs_heapfetch
Definition: relscan.h:135
#define SCAN_CHECKS
Definition: indexam.c:80
static void table_index_fetch_end(struct IndexFetchTableData *scan)
Definition: tableam.h:953

◆ index_fetch_heap()

bool index_fetch_heap ( IndexScanDesc  scan,
TupleTableSlot slot 
)

Definition at line 566 of file indexam.c.

References IndexScanDescData::indexRelation, IndexScanDescData::kill_prior_tuple, pgstat_count_heap_fetch, table_index_fetch_tuple(), IndexScanDescData::xactStartedInRecovery, IndexScanDescData::xs_heap_continue, IndexScanDescData::xs_heapfetch, IndexScanDescData::xs_heaptid, and IndexScanDescData::xs_snapshot.

Referenced by get_actual_variable_endpoint(), index_getnext_slot(), and IndexOnlyNext().

567 {
568  bool all_dead = false;
569  bool found;
570 
571  found = table_index_fetch_tuple(scan->xs_heapfetch, &scan->xs_heaptid,
572  scan->xs_snapshot, slot,
573  &scan->xs_heap_continue, &all_dead);
574 
575  if (found)
577 
578  /*
579  * If we scanned a whole HOT chain and found only dead tuples, tell index
580  * AM to kill its entry for that TID (this will take effect in the next
581  * amgettuple call, in index_getnext_tid). We do not do this when in
582  * recovery because it may violate MVCC to do so. See comments in
583  * RelationGetIndexScan().
584  */
585  if (!scan->xactStartedInRecovery)
586  scan->kill_prior_tuple = all_dead;
587 
588  return found;
589 }
struct SnapshotData * xs_snapshot
Definition: relscan.h:104
Relation indexRelation
Definition: relscan.h:103
#define pgstat_count_heap_fetch(rel)
Definition: pgstat.h:1369
ItemPointerData xs_heaptid
Definition: relscan.h:132
bool xactStartedInRecovery
Definition: relscan.h:115
static bool table_index_fetch_tuple(struct IndexFetchTableData *scan, ItemPointer tid, Snapshot snapshot, TupleTableSlot *slot, bool *call_again, bool *all_dead)
Definition: tableam.h:981
IndexFetchTableData * xs_heapfetch
Definition: relscan.h:135
bool xs_heap_continue
Definition: relscan.h:133
bool kill_prior_tuple
Definition: relscan.h:113

◆ index_getbitmap()

int64 index_getbitmap ( IndexScanDesc  scan,
TIDBitmap bitmap 
)

Definition at line 652 of file indexam.c.

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

Referenced by MultiExecBitmapIndexScan().

653 {
654  int64 ntids;
655 
656  SCAN_CHECKS;
657  CHECK_SCAN_PROCEDURE(amgetbitmap);
658 
659  /* just make sure this is false... */
660  scan->kill_prior_tuple = false;
661 
662  /*
663  * have the am's getbitmap proc do all the work.
664  */
665  ntids = scan->indexRelation->rd_indam->amgetbitmap(scan, bitmap);
666 
668 
669  return ntids;
670 }
struct IndexAmRoutine * rd_indam
Definition: rel.h:165
#define CHECK_SCAN_PROCEDURE(pname)
Definition: indexam.c:94
Relation indexRelation
Definition: relscan.h:103
amgetbitmap_function amgetbitmap
Definition: amapi.h:224
#define SCAN_CHECKS
Definition: indexam.c:80
#define pgstat_count_index_tuples(rel, n)
Definition: pgstat.h:1379
bool kill_prior_tuple
Definition: relscan.h:113

◆ index_getnext_slot()

bool index_getnext_slot ( IndexScanDesc  scan,
ScanDirection  direction,
TupleTableSlot slot 
)

Definition at line 607 of file indexam.c.

References Assert, index_fetch_heap(), index_getnext_tid(), ItemPointerEquals(), ItemPointerIsValid, IndexScanDescData::xs_heap_continue, and IndexScanDescData::xs_heaptid.

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

608 {
609  for (;;)
610  {
611  if (!scan->xs_heap_continue)
612  {
613  ItemPointer tid;
614 
615  /* Time to fetch the next TID from the index */
616  tid = index_getnext_tid(scan, direction);
617 
618  /* If we're out of index entries, we're done */
619  if (tid == NULL)
620  break;
621 
622  Assert(ItemPointerEquals(tid, &scan->xs_heaptid));
623  }
624 
625  /*
626  * Fetch the next (or only) visible heap tuple for this index entry.
627  * If we don't find anything, loop around and grab the next TID from
628  * the index.
629  */
631  if (index_fetch_heap(scan, slot))
632  return true;
633  }
634 
635  return false;
636 }
#define ItemPointerIsValid(pointer)
Definition: itemptr.h:82
ItemPointer index_getnext_tid(IndexScanDesc scan, ScanDirection direction)
Definition: indexam.c:509
ItemPointerData xs_heaptid
Definition: relscan.h:132
#define Assert(condition)
Definition: c.h:732
bool xs_heap_continue
Definition: relscan.h:133
bool ItemPointerEquals(ItemPointer pointer1, ItemPointer pointer2)
Definition: itemptr.c:29
bool index_fetch_heap(IndexScanDesc scan, TupleTableSlot *slot)
Definition: indexam.c:566

◆ index_getnext_tid()

ItemPointer index_getnext_tid ( IndexScanDesc  scan,
ScanDirection  direction 
)

Definition at line 509 of file indexam.c.

References IndexAmRoutine::amgettuple, Assert, CHECK_SCAN_PROCEDURE, IndexScanDescData::indexRelation, ItemPointerIsValid, IndexScanDescData::kill_prior_tuple, pgstat_count_index_tuples, RelationData::rd_indam, RecentGlobalXmin, SCAN_CHECKS, table_index_fetch_reset(), TransactionIdIsValid, IndexScanDescData::xs_heap_continue, IndexScanDescData::xs_heapfetch, and IndexScanDescData::xs_heaptid.

Referenced by get_actual_variable_endpoint(), index_getnext_slot(), and IndexOnlyNext().

510 {
511  bool found;
512 
513  SCAN_CHECKS;
514  CHECK_SCAN_PROCEDURE(amgettuple);
515 
517 
518  /*
519  * The AM's amgettuple proc finds the next index entry matching the scan
520  * keys, and puts the TID into scan->xs_heaptid. It should also set
521  * scan->xs_recheck and possibly scan->xs_itup/scan->xs_hitup, though we
522  * pay no attention to those fields here.
523  */
524  found = scan->indexRelation->rd_indam->amgettuple(scan, direction);
525 
526  /* Reset kill flag immediately for safety */
527  scan->kill_prior_tuple = false;
528  scan->xs_heap_continue = false;
529 
530  /* If we're out of index entries, we're done */
531  if (!found)
532  {
533  /* release resources (like buffer pins) from table accesses */
534  if (scan->xs_heapfetch)
536 
537  return NULL;
538  }
540 
542 
543  /* Return the TID of the tuple we found. */
544  return &scan->xs_heaptid;
545 }
#define ItemPointerIsValid(pointer)
Definition: itemptr.h:82
struct IndexAmRoutine * rd_indam
Definition: rel.h:165
amgettuple_function amgettuple
Definition: amapi.h:223
#define CHECK_SCAN_PROCEDURE(pname)
Definition: indexam.c:94
Relation indexRelation
Definition: relscan.h:103
ItemPointerData xs_heaptid
Definition: relscan.h:132
TransactionId RecentGlobalXmin
Definition: snapmgr.c:168
static void table_index_fetch_reset(struct IndexFetchTableData *scan)
Definition: tableam.h:944
#define Assert(condition)
Definition: c.h:732
IndexFetchTableData * xs_heapfetch
Definition: relscan.h:135
#define SCAN_CHECKS
Definition: indexam.c:80
bool xs_heap_continue
Definition: relscan.h:133
#define pgstat_count_index_tuples(rel, n)
Definition: pgstat.h:1379
bool kill_prior_tuple
Definition: relscan.h:113
#define TransactionIdIsValid(xid)
Definition: transam.h:41

◆ index_getprocid()

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

Definition at line 760 of file indexam.c.

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

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

763 {
764  RegProcedure *loc;
765  int nproc;
766  int procindex;
767 
768  nproc = irel->rd_indam->amsupport;
769 
770  Assert(procnum > 0 && procnum <= (uint16) nproc);
771 
772  procindex = (nproc * (attnum - 1)) + (procnum - 1);
773 
774  loc = irel->rd_support;
775 
776  Assert(loc != NULL);
777 
778  return loc[procindex];
779 }
struct IndexAmRoutine * rd_indam
Definition: rel.h:165
uint16 amsupport
Definition: amapi.h:173
regproc RegProcedure
Definition: c.h:505
unsigned short uint16
Definition: c.h:357
RegProcedure * rd_support
Definition: rel.h:168
int16 attnum
Definition: pg_attribute.h:79
#define Assert(condition)
Definition: c.h:732

◆ index_getprocinfo()

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

Definition at line 794 of file indexam.c.

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

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

797 {
798  FmgrInfo *locinfo;
799  int nproc;
800  int procindex;
801 
802  nproc = irel->rd_indam->amsupport;
803 
804  Assert(procnum > 0 && procnum <= (uint16) nproc);
805 
806  procindex = (nproc * (attnum - 1)) + (procnum - 1);
807 
808  locinfo = irel->rd_supportinfo;
809 
810  Assert(locinfo != NULL);
811 
812  locinfo += procindex;
813 
814  /* Initialize the lookup info if first time through */
815  if (locinfo->fn_oid == InvalidOid)
816  {
817  RegProcedure *loc = irel->rd_support;
818  RegProcedure procId;
819 
820  Assert(loc != NULL);
821 
822  procId = loc[procindex];
823 
824  /*
825  * Complain if function was not found during IndexSupportInitialize.
826  * This should not happen unless the system tables contain bogus
827  * entries for the index opclass. (If an AM wants to allow a support
828  * function to be optional, it can use index_getprocid.)
829  */
830  if (!RegProcedureIsValid(procId))
831  elog(ERROR, "missing support function %d for attribute %d of index \"%s\"",
832  procnum, attnum, RelationGetRelationName(irel));
833 
834  fmgr_info_cxt(procId, locinfo, irel->rd_indexcxt);
835  }
836 
837  return locinfo;
838 }
struct IndexAmRoutine * rd_indam
Definition: rel.h:165
Definition: fmgr.h:56
uint16 amsupport
Definition: amapi.h:173
FmgrInfo * rd_supportinfo
Definition: rel.h:169
regproc RegProcedure
Definition: c.h:505
unsigned short uint16
Definition: c.h:357
#define ERROR
Definition: elog.h:43
#define RegProcedureIsValid(p)
Definition: c.h:640
#define RelationGetRelationName(relation)
Definition: rel.h:448
void fmgr_info_cxt(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt)
Definition: fmgr.c:134
RegProcedure * rd_support
Definition: rel.h:168
#define InvalidOid
Definition: postgres_ext.h:36
int16 attnum
Definition: pg_attribute.h:79
Oid fn_oid
Definition: fmgr.h:59
#define Assert(condition)
Definition: c.h:732
#define elog(elevel,...)
Definition: elog.h:226
MemoryContext rd_indexcxt
Definition: rel.h:163

◆ index_insert()

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

Definition at line 170 of file indexam.c.

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

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

177 {
179  CHECK_REL_PROCEDURE(aminsert);
180 
181  if (!(indexRelation->rd_indam->ampredlocks))
182  CheckForSerializableConflictIn(indexRelation,
183  (HeapTuple) NULL,
184  InvalidBuffer);
185 
186  return indexRelation->rd_indam->aminsert(indexRelation, values, isnull,
187  heap_t_ctid, heapRelation,
188  checkUnique, indexInfo);
189 }
struct IndexAmRoutine * rd_indam
Definition: rel.h:165
#define RELATION_CHECKS
Definition: indexam.c:73
#define InvalidBuffer
Definition: buf.h:25
bool ampredlocks
Definition: amapi.h:195
aminsert_function aminsert
Definition: amapi.h:212
void CheckForSerializableConflictIn(Relation relation, HeapTuple tuple, Buffer buffer)
Definition: predicate.c:4442
#define CHECK_REL_PROCEDURE(pname)
Definition: indexam.c:87
static Datum values[MAXATTR]
Definition: bootstrap.c:167

◆ index_markpos()

void index_markpos ( IndexScanDesc  scan)

Definition at line 345 of file indexam.c.

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

Referenced by ExecIndexMarkPos(), and ExecIndexOnlyMarkPos().

346 {
347  SCAN_CHECKS;
348  CHECK_SCAN_PROCEDURE(ammarkpos);
349 
350  scan->indexRelation->rd_indam->ammarkpos(scan);
351 }
struct IndexAmRoutine * rd_indam
Definition: rel.h:165
#define CHECK_SCAN_PROCEDURE(pname)
Definition: indexam.c:94
Relation indexRelation
Definition: relscan.h:103
#define SCAN_CHECKS
Definition: indexam.c:80
ammarkpos_function ammarkpos
Definition: amapi.h:226

◆ index_open()

Relation index_open ( Oid  relationId,
LOCKMODE  lockmode 
)

Definition at line 126 of file indexam.c.

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

Referenced by _bt_parallel_build_main(), ATExecAddIndex(), ATExecAddIndexConstraint(), ATExecDetachPartition(), ATExecReplicaIdentity(), AttachPartitionEnsureIndexes(), brin_desummarize_range(), brin_page_items(), brin_summarize_range(), brincostestimate(), bt_index_check_internal(), build_indices(), BuildEventTriggerCache(), check_index_is_clusterable(), CheckIndexCompatible(), copy_table_data(), DefineIndex(), DefineRelation(), 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_concurrently_build(), index_concurrently_create_copy(), index_concurrently_set_dead(), index_drop(), indexam_property(), infer_arbiter_indexes(), InitCatCachePhase2(), lookup_ts_config_cache(), open_lo_relation(), pg_nextoid(), pgstathashindex(), plan_create_index_workers(), refresh_by_match_merge(), reindex_index(), ReindexIndex(), ReindexRelationConcurrently(), RelationFindReplTupleByIndex(), RelationGetIndexAttrBitmap(), RelationTruncateIndexes(), systable_beginscan(), toast_open_indexes(), transformIndexConstraint(), transformTableLikeClause(), TryReuseIndex(), unique_key_recheck(), vac_open_indexes(), and validate_index().

127 {
128  Relation r;
129 
130  r = relation_open(relationId, lockmode);
131 
132  if (r->rd_rel->relkind != RELKIND_INDEX &&
133  r->rd_rel->relkind != RELKIND_PARTITIONED_INDEX)
134  ereport(ERROR,
135  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
136  errmsg("\"%s\" is not an index",
138 
139  return r;
140 }
int errcode(int sqlerrcode)
Definition: elog.c:570
Form_pg_class rd_rel
Definition: rel.h:84
#define ERROR
Definition: elog.h:43
Relation relation_open(Oid relationId, LOCKMODE lockmode)
Definition: relation.c:48
#define RelationGetRelationName(relation)
Definition: rel.h:448
#define ereport(elevel, rest)
Definition: elog.h:141
int errmsg(const char *fmt,...)
Definition: elog.c:784

◆ index_parallelrescan()

void index_parallelrescan ( IndexScanDesc  scan)

Definition at line 458 of file indexam.c.

References IndexAmRoutine::amparallelrescan, IndexScanDescData::indexRelation, RelationData::rd_indam, SCAN_CHECKS, table_index_fetch_reset(), and IndexScanDescData::xs_heapfetch.

Referenced by ExecIndexOnlyScanReInitializeDSM(), and ExecIndexScanReInitializeDSM().

459 {
460  SCAN_CHECKS;
461 
462  if (scan->xs_heapfetch)
464 
465  /* amparallelrescan is optional; assume no-op if not provided by AM */
466  if (scan->indexRelation->rd_indam->amparallelrescan != NULL)
468 }
struct IndexAmRoutine * rd_indam
Definition: rel.h:165
amparallelrescan_function amparallelrescan
Definition: amapi.h:232
Relation indexRelation
Definition: relscan.h:103
static void table_index_fetch_reset(struct IndexFetchTableData *scan)
Definition: tableam.h:944
IndexFetchTableData * xs_heapfetch
Definition: relscan.h:135
#define SCAN_CHECKS
Definition: indexam.c:80

◆ index_parallelscan_estimate()

Size index_parallelscan_estimate ( Relation  indexRelation,
Snapshot  snapshot 
)

Definition at line 394 of file indexam.c.

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

Referenced by ExecIndexOnlyScanEstimate(), and ExecIndexScanEstimate().

395 {
396  Size nbytes;
397 
399 
400  nbytes = offsetof(ParallelIndexScanDescData, ps_snapshot_data);
401  nbytes = add_size(nbytes, EstimateSnapshotSpace(snapshot));
402  nbytes = MAXALIGN(nbytes);
403 
404  /*
405  * If amestimateparallelscan is not provided, assume there is no
406  * AM-specific data needed. (It's hard to believe that could work, but
407  * it's easy enough to cater to it here.)
408  */
409  if (indexRelation->rd_indam->amestimateparallelscan != NULL)
410  nbytes = add_size(nbytes,
411  indexRelation->rd_indam->amestimateparallelscan());
412 
413  return nbytes;
414 }
struct IndexAmRoutine * rd_indam
Definition: rel.h:165
#define RELATION_CHECKS
Definition: indexam.c:73
Size EstimateSnapshotSpace(Snapshot snap)
Definition: snapmgr.c:2048
Size add_size(Size s1, Size s2)
Definition: shmem.c:475
size_t Size
Definition: c.h:466
#define MAXALIGN(LEN)
Definition: c.h:685
amestimateparallelscan_function amestimateparallelscan
Definition: amapi.h:230
#define offsetof(type, field)
Definition: c.h:655

◆ index_parallelscan_initialize()

void index_parallelscan_initialize ( Relation  heapRelation,
Relation  indexRelation,
Snapshot  snapshot,
ParallelIndexScanDesc  target 
)

Definition at line 427 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_indam, RELATION_CHECKS, RelationGetRelid, and SerializeSnapshot().

Referenced by ExecIndexOnlyScanInitializeDSM(), and ExecIndexScanInitializeDSM().

429 {
430  Size offset;
431 
433 
434  offset = add_size(offsetof(ParallelIndexScanDescData, ps_snapshot_data),
435  EstimateSnapshotSpace(snapshot));
436  offset = MAXALIGN(offset);
437 
438  target->ps_relid = RelationGetRelid(heapRelation);
439  target->ps_indexid = RelationGetRelid(indexRelation);
440  target->ps_offset = offset;
441  SerializeSnapshot(snapshot, target->ps_snapshot_data);
442 
443  /* aminitparallelscan is optional; assume no-op if not provided by AM */
444  if (indexRelation->rd_indam->aminitparallelscan != NULL)
445  {
446  void *amtarget;
447 
448  amtarget = OffsetToPointer(target, offset);
449  indexRelation->rd_indam->aminitparallelscan(amtarget);
450  }
451 }
struct IndexAmRoutine * rd_indam
Definition: rel.h:165
#define RELATION_CHECKS
Definition: indexam.c:73
char ps_snapshot_data[FLEXIBLE_ARRAY_MEMBER]
Definition: relscan.h:160
void SerializeSnapshot(Snapshot snapshot, char *start_address)
Definition: snapmgr.c:2072
#define OffsetToPointer(base, offset)
Definition: c.h:635
Size EstimateSnapshotSpace(Snapshot snap)
Definition: snapmgr.c:2048
Size add_size(Size s1, Size s2)
Definition: shmem.c:475
size_t Size
Definition: c.h:466
#define MAXALIGN(LEN)
Definition: c.h:685
#define RelationGetRelid(relation)
Definition: rel.h:414
#define offsetof(type, field)
Definition: c.h:655
aminitparallelscan_function aminitparallelscan
Definition: amapi.h:231

◆ index_rescan()

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

Definition at line 289 of file indexam.c.

References IndexAmRoutine::amrescan, Assert, CHECK_SCAN_PROCEDURE, IndexScanDescData::indexRelation, IndexScanDescData::kill_prior_tuple, IndexScanDescData::numberOfKeys, IndexScanDescData::numberOfOrderBys, RelationData::rd_indam, SCAN_CHECKS, table_index_fetch_reset(), IndexScanDescData::xs_heap_continue, and IndexScanDescData::xs_heapfetch.

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

292 {
293  SCAN_CHECKS;
294  CHECK_SCAN_PROCEDURE(amrescan);
295 
296  Assert(nkeys == scan->numberOfKeys);
297  Assert(norderbys == scan->numberOfOrderBys);
298 
299  /* Release resources (like buffer pins) from table accesses */
300  if (scan->xs_heapfetch)
302 
303  scan->kill_prior_tuple = false; /* for safety */
304  scan->xs_heap_continue = false;
305 
306  scan->indexRelation->rd_indam->amrescan(scan, keys, nkeys,
307  orderbys, norderbys);
308 }
struct IndexAmRoutine * rd_indam
Definition: rel.h:165
#define CHECK_SCAN_PROCEDURE(pname)
Definition: indexam.c:94
Relation indexRelation
Definition: relscan.h:103
amrescan_function amrescan
Definition: amapi.h:222
static void table_index_fetch_reset(struct IndexFetchTableData *scan)
Definition: tableam.h:944
#define Assert(condition)
Definition: c.h:732
IndexFetchTableData * xs_heapfetch
Definition: relscan.h:135
#define SCAN_CHECKS
Definition: indexam.c:80
bool xs_heap_continue
Definition: relscan.h:133
bool kill_prior_tuple
Definition: relscan.h:113
int numberOfOrderBys
Definition: relscan.h:106

◆ index_restrpos()

void index_restrpos ( IndexScanDesc  scan)

Definition at line 369 of file indexam.c.

References IndexAmRoutine::amrestrpos, Assert, CHECK_SCAN_PROCEDURE, IndexScanDescData::indexRelation, IsMVCCSnapshot, IndexScanDescData::kill_prior_tuple, RelationData::rd_indam, SCAN_CHECKS, table_index_fetch_reset(), IndexScanDescData::xs_heap_continue, IndexScanDescData::xs_heapfetch, and IndexScanDescData::xs_snapshot.

Referenced by ExecIndexOnlyRestrPos(), and ExecIndexRestrPos().

370 {
372 
373  SCAN_CHECKS;
374  CHECK_SCAN_PROCEDURE(amrestrpos);
375 
376  /* release resources (like buffer pins) from table accesses */
377  if (scan->xs_heapfetch)
379 
380  scan->kill_prior_tuple = false; /* for safety */
381  scan->xs_heap_continue = false;
382 
383  scan->indexRelation->rd_indam->amrestrpos(scan);
384 }
struct IndexAmRoutine * rd_indam
Definition: rel.h:165
struct SnapshotData * xs_snapshot
Definition: relscan.h:104
#define CHECK_SCAN_PROCEDURE(pname)
Definition: indexam.c:94
Relation indexRelation
Definition: relscan.h:103
#define IsMVCCSnapshot(snapshot)
Definition: snapmgr.h:98
static void table_index_fetch_reset(struct IndexFetchTableData *scan)
Definition: tableam.h:944
#define Assert(condition)
Definition: c.h:732
IndexFetchTableData * xs_heapfetch
Definition: relscan.h:135
#define SCAN_CHECKS
Definition: indexam.c:80
bool xs_heap_continue
Definition: relscan.h:133
bool kill_prior_tuple
Definition: relscan.h:113
amrestrpos_function amrestrpos
Definition: amapi.h:227

◆ index_store_float8_orderby_distances()

void index_store_float8_orderby_distances ( IndexScanDesc  scan,
Oid orderByTypes,
double *  distances,
bool  recheckOrderBy 
)

Definition at line 849 of file indexam.c.

References Assert, DatumGetPointer, elog, ERROR, Float4GetDatum(), Float8GetDatum(), i, IndexScanDescData::numberOfOrderBys, pfree(), IndexScanDescData::xs_orderbynulls, IndexScanDescData::xs_orderbyvals, and IndexScanDescData::xs_recheckorderby.

Referenced by getNextNearest(), and spggettuple().

851 {
852  int i;
853 
854  scan->xs_recheckorderby = recheckOrderBy;
855 
856  if (!distances)
857  {
858  Assert(!scan->xs_recheckorderby);
859 
860  for (i = 0; i < scan->numberOfOrderBys; i++)
861  {
862  scan->xs_orderbyvals[i] = (Datum) 0;
863  scan->xs_orderbynulls[i] = true;
864  }
865 
866  return;
867  }
868 
869  for (i = 0; i < scan->numberOfOrderBys; i++)
870  {
871  if (orderByTypes[i] == FLOAT8OID)
872  {
873 #ifndef USE_FLOAT8_BYVAL
874  /* must free any old value to avoid memory leakage */
875  if (!scan->xs_orderbynulls[i])
877 #endif
878  scan->xs_orderbyvals[i] = Float8GetDatum(distances[i]);
879  scan->xs_orderbynulls[i] = false;
880  }
881  else if (orderByTypes[i] == FLOAT4OID)
882  {
883  /* convert distance function's result to ORDER BY type */
884 #ifndef USE_FLOAT4_BYVAL
885  /* must free any old value to avoid memory leakage */
886  if (!scan->xs_orderbynulls[i])
888 #endif
889  scan->xs_orderbyvals[i] = Float4GetDatum((float4) distances[i]);
890  scan->xs_orderbynulls[i] = false;
891  }
892  else
893  {
894  /*
895  * If the ordering operator's return value is anything else, we
896  * don't know how to convert the float8 bound calculated by the
897  * distance function to that. The executor won't actually need
898  * the order by values we return here, if there are no lossy
899  * results, so only insist on converting if the *recheck flag is
900  * set.
901  */
902  if (scan->xs_recheckorderby)
903  elog(ERROR, "ORDER BY operator must return float8 or float4 if the distance function is lossy");
904  scan->xs_orderbynulls[i] = true;
905  }
906  }
907 }
Datum * xs_orderbyvals
Definition: relscan.h:146
bool xs_recheckorderby
Definition: relscan.h:148
Datum Float8GetDatum(float8 X)
Definition: fmgr.c:1723
bool * xs_orderbynulls
Definition: relscan.h:147
void pfree(void *pointer)
Definition: mcxt.c:1031
#define ERROR
Definition: elog.h:43
Datum Float4GetDatum(float4 X)
Definition: fmgr.c:1711
float float4
Definition: c.h:490
uintptr_t Datum
Definition: postgres.h:367
#define Assert(condition)
Definition: c.h:732
#define DatumGetPointer(X)
Definition: postgres.h:549
#define elog(elevel,...)
Definition: elog.h:226
int i
int numberOfOrderBys
Definition: relscan.h:106

◆ index_vacuum_cleanup()

IndexBulkDeleteResult* index_vacuum_cleanup ( IndexVacuumInfo info,
IndexBulkDeleteResult stats 
)

Definition at line 703 of file indexam.c.

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

Referenced by do_analyze_rel(), and lazy_cleanup_index().

705 {
706  Relation indexRelation = info->index;
707 
709  CHECK_REL_PROCEDURE(amvacuumcleanup);
710 
711  return indexRelation->rd_indam->amvacuumcleanup(info, stats);
712 }
struct IndexAmRoutine * rd_indam
Definition: rel.h:165
#define RELATION_CHECKS
Definition: indexam.c:73
Relation index
Definition: genam.h:46
#define CHECK_REL_PROCEDURE(pname)
Definition: indexam.c:87
amvacuumcleanup_function amvacuumcleanup
Definition: amapi.h:214