relscan.h 3.7 KB
Newer Older
1 2
/*-------------------------------------------------------------------------
 *
3
 * relscan.h
4
 *	  POSTGRES relation scan descriptor definitions.
5 6
 *
 *
7
 * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
Bruce Momjian's avatar
Add:  
Bruce Momjian committed
8
 * Portions Copyright (c) 1994, Regents of the University of California
9
 *
10
 * $PostgreSQL: pgsql/src/include/access/relscan.h,v 1.39 2005/05/27 23:31:21 tgl Exp $
11 12 13
 *
 *-------------------------------------------------------------------------
 */
14
#ifndef RELSCAN_H
15 16
#define RELSCAN_H

17
#include "access/skey.h"
18
#include "utils/tqual.h"
19 20


21 22
typedef struct HeapScanDescData
{
23 24 25 26 27
	/* 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 */
28
	BlockNumber rs_nblocks;		/* number of blocks to scan */
29 30

	/* scan current state */
31 32 33
	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 */
34
	ItemPointerData rs_mctid;	/* marked scan position, if any */
35

36
	PgStat_Info rs_pgstat_info; /* statistics collector hook */
37
} HeapScanDescData;
38 39 40

typedef HeapScanDescData *HeapScanDesc;

41 42
/*
 * We use the same IndexScanDescData structure for both amgettuple-based
43 44
 * and amgetmulti-based index scans.  Some fields are only relevant in
 * amgettuple-based scans.
45
 */
46 47
typedef struct IndexScanDescData
{
48 49 50 51 52 53
	/* 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 */
54
	bool		is_multiscan;	/* TRUE = using amgetmulti */
55

56 57 58 59 60 61 62
	/* 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;

63
	/* scan current state */
64
	bool		got_tuple;		/* true after successful index_getnext */
65
	void	   *opaque;			/* access-method-specific info */
66
	ItemPointerData currentItemData;	/* current index pointer */
67
	ItemPointerData currentMarkData;	/* marked position, if any */
Bruce Momjian's avatar
Bruce Momjian committed
68

69
	/*
Bruce Momjian's avatar
Bruce Momjian committed
70 71 72
	 * 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.
73 74 75 76 77
	 */
	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 */

78 79 80 81 82 83
	/*
	 * 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.
	 */
Bruce Momjian's avatar
Bruce Momjian committed
84 85
	int			unique_tuple_pos;		/* logical position */
	int			unique_tuple_mark;		/* logical marked position */
86

87
	PgStat_Info xs_pgstat_info; /* statistics collector hook */
88
} IndexScanDescData;
89

90
typedef IndexScanDescData *IndexScanDesc;
91

92

93
/* ----------------
94 95 96
 *		IndexScanDescPtr is used in the executor where we have to
 *		keep track of several index scans when using several indices
 *		- cim 9/10/89
97 98
 * ----------------
 */
99
typedef IndexScanDesc *IndexScanDescPtr;
100 101

/*
Bruce Momjian's avatar
Bruce Momjian committed
102
 * HeapScanIsValid
103
 *		True iff the heap scan is valid.
104
 */
105
#define HeapScanIsValid(scan) PointerIsValid(scan)
106 107

/*
Bruce Momjian's avatar
Bruce Momjian committed
108
 * IndexScanIsValid
109
 *		True iff the index scan is valid.
110 111
 */
#define IndexScanIsValid(scan) PointerIsValid(scan)
112

113
#endif   /* RELSCAN_H */