/*-------------------------------------------------------------------------
*
- * relscan.h--
- * POSTGRES internal relation scan descriptor definitions.
+ * relscan.h
+ * POSTGRES relation scan descriptor definitions.
*
*
- * Copyright (c) 1994, Regents of the University of California
+ * Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: relscan.h,v 1.8 1997/09/08 21:50:56 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/access/relscan.h,v 1.36 2004/08/29 04:13:03 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef RELSCAN_H
#define RELSCAN_H
-#include <utils/tqual.h>
-#include <storage/buf.h>
-#include <utils/rel.h>
+#include "access/skey.h"
+#include "utils/tqual.h"
-typedef ItemPointerData MarkData;
typedef struct HeapScanDescData
{
- Relation rs_rd; /* pointer to relation descriptor */
- HeapTuple rs_ptup; /* previous tuple in scan */
- HeapTuple rs_ctup; /* current tuple in scan */
- HeapTuple rs_ntup; /* next tuple in scan */
- Buffer rs_pbuf; /* previous buffer in scan */
- Buffer rs_cbuf; /* current buffer in scan */
- Buffer rs_nbuf; /* next buffer in scan */
- ItemPointerData rs_mptid; /* marked previous tid */
- ItemPointerData rs_mctid; /* marked current tid */
- ItemPointerData rs_mntid; /* marked next tid */
- ItemPointerData rs_mcd; /* marked current delta XXX ??? */
- bool rs_atend; /* restart scan at end? */
- TimeQual rs_tr; /* time qualification */
- uint16 rs_cdelta; /* current delta in chain */
- uint16 rs_nkeys; /* number of attributes in keys */
- ScanKey rs_key; /* key descriptors */
+ /* scan parameters */
+ Relation rs_rd; /* heap relation descriptor */
+ Snapshot rs_snapshot; /* snapshot to see */
+ int rs_nkeys; /* number of scan keys */
+ ScanKey rs_key; /* array of scan key descriptors */
+ BlockNumber rs_nblocks; /* number of blocks to scan */
+
+ /* scan current state */
+ HeapTupleData rs_ctup; /* current tuple in scan, if any */
+ Buffer rs_cbuf; /* current buffer in scan, if any */
+ /* NB: if rs_cbuf is not InvalidBuffer, we hold a pin on that buffer */
+ ItemPointerData rs_mctid; /* marked scan position, if any */
+
+ PgStat_Info rs_pgstat_info; /* statistics collector hook */
} HeapScanDescData;
typedef HeapScanDescData *HeapScanDesc;
+
typedef struct IndexScanDescData
{
- Relation relation; /* relation descriptor */
- void *opaque; /* am-specific slot */
- ItemPointerData previousItemData; /* previous index pointer */
+ /* scan parameters */
+ Relation heapRelation; /* heap relation descriptor, or NULL */
+ Relation indexRelation; /* index relation descriptor */
+ Snapshot xs_snapshot; /* snapshot to see */
+ int numberOfKeys; /* number of scan keys */
+ ScanKey keyData; /* array of scan key descriptors */
+
+ /* signaling to index AM about killing index tuples */
+ bool kill_prior_tuple; /* last-returned tuple is dead */
+ bool ignore_killed_tuples; /* do not return killed entries */
+
+ /* set by index AM if scan keys satisfy index's uniqueness constraint */
+ bool keys_are_unique;
+
+ /* scan current state */
+ bool got_tuple; /* true after successful index_getnext */
+ void *opaque; /* access-method-specific info */
ItemPointerData currentItemData; /* current index pointer */
- ItemPointerData nextItemData; /* next index pointer */
- MarkData previousMarkData; /* marked previous pointer */
- MarkData currentMarkData;/* marked current pointer */
- MarkData nextMarkData; /* marked next pointer */
- uint8 flags; /* scan position flags */
- bool scanFromEnd; /* restart scan at end? */
- uint16 numberOfKeys; /* number of key attributes */
- ScanKey keyData; /* key descriptor */
+ ItemPointerData currentMarkData; /* marked position, if any */
+
+ /*
+ * xs_ctup/xs_cbuf are valid after a successful index_getnext. After
+ * index_getnext_indexitem, xs_ctup.t_self contains the heap tuple TID
+ * from the index entry, but its other fields are not valid.
+ */
+ HeapTupleData xs_ctup; /* current heap tuple, if any */
+ Buffer xs_cbuf; /* current heap buffer in scan, if any */
+ /* NB: if xs_cbuf is not InvalidBuffer, we hold a pin on that buffer */
+
+ FmgrInfo fn_getnext; /* cached lookup info for AM's getnext fn */
+
+ /*
+ * If keys_are_unique and got_tuple are both true, we stop calling the
+ * index AM; it is then necessary for index_getnext to keep track of
+ * the logical scan position for itself. It does that using
+ * unique_tuple_pos: -1 = before row, 0 = on row, +1 = after row.
+ */
+ int unique_tuple_pos; /* logical position */
+ int unique_tuple_mark; /* logical marked position */
+
+ PgStat_Info xs_pgstat_info; /* statistics collector hook */
} IndexScanDescData;
typedef IndexScanDescData *IndexScanDesc;
+
/* ----------------
* IndexScanDescPtr is used in the executor where we have to
* keep track of several index scans when using several indices
typedef IndexScanDesc *IndexScanDescPtr;
/*
- * HeapScanIsValid --
+ * HeapScanIsValid
* True iff the heap scan is valid.
*/
#define HeapScanIsValid(scan) PointerIsValid(scan)
/*
- * IndexScanIsValid --
+ * IndexScanIsValid
* True iff the index scan is valid.
*/
#define IndexScanIsValid(scan) PointerIsValid(scan)
-#endif /* RELSCAN_H */
+#endif /* RELSCAN_H */