1 /*-------------------------------------------------------------------------
4 * POSTGRES portal definitions.
6 * A portal is an abstraction which represents the execution state of
7 * a running query (specifically, a CURSOR).
9 * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
10 * Portions Copyright (c) 1994, Regents of the University of California
12 * $Id: portal.h,v 1.41 2003/04/29 03:21:30 tgl Exp $
14 *-------------------------------------------------------------------------
19 #include "executor/execdesc.h"
20 #include "nodes/memnodes.h"
21 #include "utils/tuplestore.h"
24 * We support three kinds of scroll behavior:
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.
30 * (2) NO SCROLL was specified: don't allow any backward fetches.
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.
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
46 typedef struct PortalData *Portal;
48 typedef struct PortalData
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 */
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
78 * True iff portal is valid.
80 #define PortalIsValid(p) PointerIsValid(p)
83 * Access macros for Portal ... use these in preference to field access.
85 #define PortalGetQueryDesc(portal) ((portal)->queryDesc)
86 #define PortalGetHeapMemory(portal) ((portal)->heap)
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);