]> granicus.if.org Git - postgresql/blob - src/include/utils/portal.h
Code review for holdable-cursors patch. Fix error recovery, memory
[postgresql] / src / include / utils / portal.h
1 /*-------------------------------------------------------------------------
2  *
3  * portal.h
4  *        POSTGRES portal definitions.
5  *
6  * A portal is an abstraction which represents the execution state of
7  * a running query (specifically, a CURSOR).
8  *
9  * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
10  * Portions Copyright (c) 1994, Regents of the University of California
11  *
12  * $Id: portal.h,v 1.41 2003/04/29 03:21:30 tgl Exp $
13  *
14  *-------------------------------------------------------------------------
15  */
16 #ifndef PORTAL_H
17 #define PORTAL_H
18
19 #include "executor/execdesc.h"
20 #include "nodes/memnodes.h"
21 #include "utils/tuplestore.h"
22
23 /*
24  * We support three kinds of scroll behavior:
25  *
26  * (1) Neither NO SCROLL nor SCROLL was specified: to remain backward
27  *     compatible, we allow backward fetches here, unless it would
28  *     impose additional runtime overhead to do so.
29  *
30  * (2) NO SCROLL was specified: don't allow any backward fetches.
31  *
32  * (3) SCROLL was specified: allow all kinds of backward fetches, even
33  *     if we need to take a slight performance hit to do so.
34  *
35  * Case #1 is converted to #2 or #3 by looking at the query itself and
36  * determining if scrollability can be supported without additional
37  * overhead.
38  */
39 typedef enum
40 {
41         DEFAULT_SCROLL,
42         DISABLE_SCROLL,
43         ENABLE_SCROLL
44 } ScrollType;
45
46 typedef struct PortalData *Portal;
47
48 typedef struct PortalData
49 {
50         char       *name;                       /* Portal's name */
51         MemoryContext heap;                     /* subsidiary memory */
52         QueryDesc  *queryDesc;          /* Info about query associated with portal */
53         void            (*cleanup) (Portal portal, bool isError);       /* Cleanup hook */
54         ScrollType      scrollType;             /* Allow backward fetches? */
55         bool            executorRunning;        /* T if we need to call ExecutorEnd */
56         bool            holdOpen;               /* hold open after xact ends? */
57         TransactionId createXact;       /* the xid of the creating xact */
58         Tuplestorestate *holdStore;     /* store for holdable cursors */
59         MemoryContext holdContext;  /* memory containing holdStore */
60
61         /*
62          * atStart, atEnd and portalPos indicate the current cursor position.
63          * portalPos is zero before the first row, N after fetching N'th row of
64          * query.  After we run off the end, portalPos = # of rows in query, and
65          * atEnd is true.  If portalPos overflows, set posOverflow (this causes
66          * us to stop relying on its value for navigation).  Note that atStart
67          * implies portalPos == 0, but not the reverse (portalPos could have
68          * overflowed).
69          */
70         bool            atStart;
71         bool            atEnd;
72         bool            posOverflow;
73         long            portalPos;
74 } PortalData;
75
76 /*
77  * PortalIsValid
78  *              True iff portal is valid.
79  */
80 #define PortalIsValid(p) PointerIsValid(p)
81
82 /*
83  * Access macros for Portal ... use these in preference to field access.
84  */
85 #define PortalGetQueryDesc(portal)      ((portal)->queryDesc)
86 #define PortalGetHeapMemory(portal) ((portal)->heap)
87
88
89 extern void EnablePortalManager(void);
90 extern void AtEOXact_portals(bool isCommit);
91 extern Portal CreatePortal(const char *name);
92 extern void PortalDrop(Portal portal, bool isError);
93 extern Portal GetPortalByName(const char *name);
94 extern void PortalSetQuery(Portal portal, QueryDesc *queryDesc);
95 extern void PersistHoldablePortal(Portal portal);
96
97 #endif   /* PORTAL_H */