]> granicus.if.org Git - postgresql/blob - src/include/access/relscan.h
bd1a9a4c3f83496b45bf38245fd3d73b2630645d
[postgresql] / src / include / access / relscan.h
1 /*-------------------------------------------------------------------------
2  *
3  * relscan.h
4  *        POSTGRES relation scan descriptor definitions.
5  *
6  *
7  * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * $PostgreSQL: pgsql/src/include/access/relscan.h,v 1.51 2007/01/05 22:19:51 momjian Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef RELSCAN_H
15 #define RELSCAN_H
16
17 #include "access/skey.h"
18 #include "storage/bufpage.h"
19 #include "utils/tqual.h"
20
21
22 typedef struct HeapScanDescData
23 {
24         /* scan parameters */
25         Relation        rs_rd;                  /* heap relation descriptor */
26         Snapshot        rs_snapshot;    /* snapshot to see */
27         int                     rs_nkeys;               /* number of scan keys */
28         ScanKey         rs_key;                 /* array of scan key descriptors */
29         BlockNumber rs_nblocks;         /* number of blocks to scan */
30         bool            rs_pageatatime; /* verify visibility page-at-a-time? */
31
32         /* scan current state */
33         bool            rs_inited;              /* false = scan not init'd yet */
34         HeapTupleData rs_ctup;          /* current tuple in scan, if any */
35         BlockNumber rs_cblock;          /* current block # in scan, if any */
36         Buffer          rs_cbuf;                /* current buffer in scan, if any */
37         /* NB: if rs_cbuf is not InvalidBuffer, we hold a pin on that buffer */
38         ItemPointerData rs_mctid;       /* marked scan position, if any */
39
40         PgStat_Info rs_pgstat_info; /* statistics collector hook */
41
42         /* these fields only used in page-at-a-time mode */
43         int                     rs_cindex;              /* current tuple's index in vistuples */
44         int                     rs_mindex;              /* marked tuple's saved index */
45         int                     rs_ntuples;             /* number of visible tuples on page */
46         OffsetNumber rs_vistuples[MaxHeapTuplesPerPage];        /* their offsets */
47 } HeapScanDescData;
48
49 typedef HeapScanDescData *HeapScanDesc;
50
51 /*
52  * We use the same IndexScanDescData structure for both amgettuple-based
53  * and amgetmulti-based index scans.  Some fields are only relevant in
54  * amgettuple-based scans.
55  */
56 typedef struct IndexScanDescData
57 {
58         /* scan parameters */
59         Relation        heapRelation;   /* heap relation descriptor, or NULL */
60         Relation        indexRelation;  /* index relation descriptor */
61         Snapshot        xs_snapshot;    /* snapshot to see */
62         int                     numberOfKeys;   /* number of scan keys */
63         ScanKey         keyData;                /* array of scan key descriptors */
64         bool            is_multiscan;   /* TRUE = using amgetmulti */
65
66         /* signaling to index AM about killing index tuples */
67         bool            kill_prior_tuple;               /* last-returned tuple is dead */
68         bool            ignore_killed_tuples;   /* do not return killed entries */
69
70         /* index access method's private state */
71         void       *opaque;                     /* access-method-specific info */
72         /* these fields are used by some but not all AMs: */
73         ItemPointerData currentItemData;        /* current index pointer */
74         ItemPointerData currentMarkData;        /* marked position, if any */
75
76         /*
77          * xs_ctup/xs_cbuf are valid after a successful index_getnext. After
78          * index_getnext_indexitem, xs_ctup.t_self contains the heap tuple TID
79          * from the index entry, but its other fields are not valid.
80          */
81         HeapTupleData xs_ctup;          /* current heap tuple, if any */
82         Buffer          xs_cbuf;                /* current heap buffer in scan, if any */
83         /* NB: if xs_cbuf is not InvalidBuffer, we hold a pin on that buffer */
84
85         PgStat_Info xs_pgstat_info; /* statistics collector hook */
86 } IndexScanDescData;
87
88 typedef IndexScanDescData *IndexScanDesc;
89
90
91 /*
92  * HeapScanIsValid
93  *              True iff the heap scan is valid.
94  */
95 #define HeapScanIsValid(scan) PointerIsValid(scan)
96
97 /*
98  * IndexScanIsValid
99  *              True iff the index scan is valid.
100  */
101 #define IndexScanIsValid(scan) PointerIsValid(scan)
102
103 #endif   /* RELSCAN_H */