PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
spi_priv.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * spi_priv.h
4  * Server Programming Interface private declarations
5  *
6  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  * src/include/executor/spi_priv.h
10  *
11  *-------------------------------------------------------------------------
12  */
13 #ifndef SPI_PRIV_H
14 #define SPI_PRIV_H
15 
16 #include "executor/spi.h"
17 
18 
19 #define _SPI_PLAN_MAGIC 569278163
20 
21 typedef struct
22 {
23  /* current results */
24  uint64 processed; /* by Executor */
26  SPITupleTable *tuptable; /* tuptable currently being built */
27 
28  /* resources of this execution context */
29  slist_head tuptables; /* list of all live SPITupleTables */
30  MemoryContext procCxt; /* procedure context */
31  MemoryContext execCxt; /* executor context */
32  MemoryContext savedcxt; /* context of SPI_connect's caller */
33  SubTransactionId connectSubid; /* ID of connecting subtransaction */
35 
36 /*
37  * SPI plans have three states: saved, unsaved, or temporary.
38  *
39  * Ordinarily, the _SPI_plan struct itself as well as the argtypes array
40  * are in a dedicated memory context identified by plancxt (which can be
41  * really small). All the other subsidiary state is in plancache entries
42  * identified by plancache_list (note: the list cells themselves are in
43  * plancxt).
44  *
45  * In an unsaved plan, the plancxt as well as the plancache entries' contexts
46  * are children of the SPI procedure context, so they'll all disappear at
47  * function exit. plancache.c also knows that the plancache entries are
48  * "unsaved", so it doesn't link them into its global list; hence they do
49  * not respond to inval events. This is OK since we are presumably holding
50  * adequate locks to prevent other backends from messing with the tables.
51  *
52  * For a saved plan, the plancxt is made a child of CacheMemoryContext
53  * since it should persist until explicitly destroyed. Likewise, the
54  * plancache entries will be under CacheMemoryContext since we tell
55  * plancache.c to save them. We rely on plancache.c to keep the cache
56  * entries up-to-date as needed in the face of invalidation events.
57  *
58  * There are also "temporary" SPI plans, in which the _SPI_plan struct is
59  * not even palloc'd but just exists in some function's local variable.
60  * The plancache entries are unsaved and exist under the SPI executor context,
61  * while additional data such as argtypes and list cells is loose in the SPI
62  * executor context. Such plans can be identified by having plancxt == NULL.
63  *
64  * We can also have "one-shot" SPI plans (which are typically temporary,
65  * as described above). These are meant to be executed once and discarded,
66  * and various optimizations are made on the assumption of single use.
67  * Note in particular that the CachedPlanSources within such an SPI plan
68  * are not "complete" until execution.
69  *
70  * Note: if the original query string contained only whitespace and comments,
71  * the plancache_list will be NIL and so there is no place to store the
72  * query string. We don't care about that, but we do care about the
73  * argument type array, which is why it's seemingly-redundantly stored.
74  */
75 typedef struct _SPI_plan
76 {
77  int magic; /* should equal _SPI_PLAN_MAGIC */
78  bool saved; /* saved or unsaved plan? */
79  bool oneshot; /* one-shot plan? */
80  List *plancache_list; /* one CachedPlanSource per parsetree */
81  MemoryContext plancxt; /* Context containing _SPI_plan and data */
82  int cursor_options; /* Cursor options used for planning */
83  int nargs; /* number of plan arguments */
84  Oid *argtypes; /* Argument types (NULL if nargs is 0) */
85  ParserSetupHook parserSetup; /* alternative parameter spec method */
87 } _SPI_plan;
88 
89 #endif /* SPI_PRIV_H */
Oid * argtypes
Definition: spi_priv.h:84
List * plancache_list
Definition: spi_priv.h:80
int magic
Definition: spi_priv.h:77
uint32 SubTransactionId
Definition: c.h:398
unsigned int Oid
Definition: postgres_ext.h:31
SubTransactionId connectSubid
Definition: spi_priv.h:33
SPITupleTable * tuptable
Definition: spi_priv.h:26
void(* ParserSetupHook)(struct ParseState *pstate, void *arg)
Definition: params.h:66
MemoryContext savedcxt
Definition: spi_priv.h:32
MemoryContext plancxt
Definition: spi_priv.h:81
MemoryContext procCxt
Definition: spi_priv.h:30
MemoryContext execCxt
Definition: spi_priv.h:31
bool saved
Definition: spi_priv.h:78
int nargs
Definition: spi_priv.h:83
uint64 processed
Definition: spi_priv.h:24
ParserSetupHook parserSetup
Definition: spi_priv.h:85
bool oneshot
Definition: spi_priv.h:79
struct _SPI_plan _SPI_plan
void * parserSetupArg
Definition: spi_priv.h:86
int cursor_options
Definition: spi_priv.h:82
Definition: pg_list.h:45
slist_head tuptables
Definition: spi_priv.h:29