Fix xslt_process() to ensure that it inserts a NULL terminator after the
[PostgreSQL.git] / src / include / nodes / execnodes.h
blob4b16723bde6435e987788bc1e1b07efb9baa34c3
1 /*-------------------------------------------------------------------------
3 * execnodes.h
4 * definitions for executor state nodes
7 * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * $PostgreSQL$
12 *-------------------------------------------------------------------------
14 #ifndef EXECNODES_H
15 #define EXECNODES_H
17 #include "access/genam.h"
18 #include "access/heapam.h"
19 #include "access/skey.h"
20 #include "nodes/params.h"
21 #include "nodes/plannodes.h"
22 #include "nodes/tidbitmap.h"
23 #include "utils/hsearch.h"
24 #include "utils/rel.h"
25 #include "utils/snapshot.h"
26 #include "utils/tuplestore.h"
29 /* ----------------
30 * IndexInfo information
32 * this struct holds the information needed to construct new index
33 * entries for a particular index. Used for both index_build and
34 * retail creation of index entries.
36 * NumIndexAttrs number of columns in this index
37 * KeyAttrNumbers underlying-rel attribute numbers used as keys
38 * (zeroes indicate expressions)
39 * Expressions expr trees for expression entries, or NIL if none
40 * ExpressionsState exec state for expressions, or NIL if none
41 * Predicate partial-index predicate, or NIL if none
42 * PredicateState exec state for predicate, or NIL if none
43 * Unique is it a unique index?
44 * ReadyForInserts is it valid for inserts?
45 * Concurrent are we doing a concurrent index build?
46 * BrokenHotChain did we detect any broken HOT chains?
48 * ii_Concurrent and ii_BrokenHotChain are used only during index build;
49 * they're conventionally set to false otherwise.
50 * ----------------
52 typedef struct IndexInfo
54 NodeTag type;
55 int ii_NumIndexAttrs;
56 AttrNumber ii_KeyAttrNumbers[INDEX_MAX_KEYS];
57 List *ii_Expressions; /* list of Expr */
58 List *ii_ExpressionsState; /* list of ExprState */
59 List *ii_Predicate; /* list of Expr */
60 List *ii_PredicateState; /* list of ExprState */
61 bool ii_Unique;
62 bool ii_ReadyForInserts;
63 bool ii_Concurrent;
64 bool ii_BrokenHotChain;
65 } IndexInfo;
67 /* ----------------
68 * ExprContext_CB
70 * List of callbacks to be called at ExprContext shutdown.
71 * ----------------
73 typedef void (*ExprContextCallbackFunction) (Datum arg);
75 typedef struct ExprContext_CB
77 struct ExprContext_CB *next;
78 ExprContextCallbackFunction function;
79 Datum arg;
80 } ExprContext_CB;
82 /* ----------------
83 * ExprContext
85 * This class holds the "current context" information
86 * needed to evaluate expressions for doing tuple qualifications
87 * and tuple projections. For example, if an expression refers
88 * to an attribute in the current inner tuple then we need to know
89 * what the current inner tuple is and so we look at the expression
90 * context.
92 * There are two memory contexts associated with an ExprContext:
93 * * ecxt_per_query_memory is a query-lifespan context, typically the same
94 * context the ExprContext node itself is allocated in. This context
95 * can be used for purposes such as storing function call cache info.
96 * * ecxt_per_tuple_memory is a short-term context for expression results.
97 * As the name suggests, it will typically be reset once per tuple,
98 * before we begin to evaluate expressions for that tuple. Each
99 * ExprContext normally has its very own per-tuple memory context.
101 * CurrentMemoryContext should be set to ecxt_per_tuple_memory before
102 * calling ExecEvalExpr() --- see ExecEvalExprSwitchContext().
103 * ----------------
105 typedef struct ExprContext
107 NodeTag type;
109 /* Tuples that Var nodes in expression may refer to */
110 TupleTableSlot *ecxt_scantuple;
111 TupleTableSlot *ecxt_innertuple;
112 TupleTableSlot *ecxt_outertuple;
114 /* Memory contexts for expression evaluation --- see notes above */
115 MemoryContext ecxt_per_query_memory;
116 MemoryContext ecxt_per_tuple_memory;
118 /* Values to substitute for Param nodes in expression */
119 ParamExecData *ecxt_param_exec_vals; /* for PARAM_EXEC params */
120 ParamListInfo ecxt_param_list_info; /* for other param types */
123 * Values to substitute for Aggref nodes in the expressions of an Agg
124 * node, or for WindowFunc nodes within a WindowAgg node.
126 Datum *ecxt_aggvalues; /* precomputed values for aggs/windowfuncs */
127 bool *ecxt_aggnulls; /* null flags for aggs/windowfuncs */
129 /* Value to substitute for CaseTestExpr nodes in expression */
130 Datum caseValue_datum;
131 bool caseValue_isNull;
133 /* Value to substitute for CoerceToDomainValue nodes in expression */
134 Datum domainValue_datum;
135 bool domainValue_isNull;
137 /* Link to containing EState (NULL if a standalone ExprContext) */
138 struct EState *ecxt_estate;
140 /* Functions to call back when ExprContext is shut down */
141 ExprContext_CB *ecxt_callbacks;
142 } ExprContext;
145 * Set-result status returned by ExecEvalExpr()
147 typedef enum
149 ExprSingleResult, /* expression does not return a set */
150 ExprMultipleResult, /* this result is an element of a set */
151 ExprEndResult /* there are no more elements in the set */
152 } ExprDoneCond;
155 * Return modes for functions returning sets. Note values must be chosen
156 * as separate bits so that a bitmask can be formed to indicate supported
157 * modes. SFRM_Materialize_Random and SFRM_Materialize_Preferred are
158 * auxiliary flags about SFRM_Materialize mode, rather than separate modes.
160 typedef enum
162 SFRM_ValuePerCall = 0x01, /* one value returned per call */
163 SFRM_Materialize = 0x02, /* result set instantiated in Tuplestore */
164 SFRM_Materialize_Random = 0x04, /* Tuplestore needs randomAccess */
165 SFRM_Materialize_Preferred = 0x08 /* caller prefers Tuplestore */
166 } SetFunctionReturnMode;
169 * When calling a function that might return a set (multiple rows),
170 * a node of this type is passed as fcinfo->resultinfo to allow
171 * return status to be passed back. A function returning set should
172 * raise an error if no such resultinfo is provided.
174 typedef struct ReturnSetInfo
176 NodeTag type;
177 /* values set by caller: */
178 ExprContext *econtext; /* context function is being called in */
179 TupleDesc expectedDesc; /* tuple descriptor expected by caller */
180 int allowedModes; /* bitmask: return modes caller can handle */
181 /* result status from function (but pre-initialized by caller): */
182 SetFunctionReturnMode returnMode; /* actual return mode */
183 ExprDoneCond isDone; /* status for ValuePerCall mode */
184 /* fields filled by function in Materialize return mode: */
185 Tuplestorestate *setResult; /* holds the complete returned tuple set */
186 TupleDesc setDesc; /* actual descriptor for returned tuples */
187 } ReturnSetInfo;
189 /* ----------------
190 * ProjectionInfo node information
192 * This is all the information needed to perform projections ---
193 * that is, form new tuples by evaluation of targetlist expressions.
194 * Nodes which need to do projections create one of these.
196 * ExecProject() evaluates the tlist, forms a tuple, and stores it
197 * in the given slot. Note that the result will be a "virtual" tuple
198 * unless ExecMaterializeSlot() is then called to force it to be
199 * converted to a physical tuple. The slot must have a tupledesc
200 * that matches the output of the tlist!
202 * The planner very often produces tlists that consist entirely of
203 * simple Var references (lower levels of a plan tree almost always
204 * look like that). And top-level tlists are often mostly Vars too.
205 * We therefore optimize execution of simple-Var tlist entries.
206 * The pi_targetlist list actually contains only the tlist entries that
207 * aren't simple Vars, while those that are Vars are processed using the
208 * varSlotOffsets/varNumbers/varOutputCols arrays.
210 * The lastXXXVar fields are used to optimize fetching of fields from
211 * input tuples: they let us do a slot_getsomeattrs() call to ensure
212 * that all needed attributes are extracted in one pass.
214 * targetlist target list for projection (non-Var expressions only)
215 * exprContext expression context in which to evaluate targetlist
216 * slot slot to place projection result in
217 * itemIsDone workspace array for ExecProject
218 * directMap true if varOutputCols[] is an identity map
219 * numSimpleVars number of simple Vars found in original tlist
220 * varSlotOffsets array indicating which slot each simple Var is from
221 * varNumbers array containing input attr numbers of simple Vars
222 * varOutputCols array containing output attr numbers of simple Vars
223 * lastInnerVar highest attnum from inner tuple slot (0 if none)
224 * lastOuterVar highest attnum from outer tuple slot (0 if none)
225 * lastScanVar highest attnum from scan tuple slot (0 if none)
226 * ----------------
228 typedef struct ProjectionInfo
230 NodeTag type;
231 List *pi_targetlist;
232 ExprContext *pi_exprContext;
233 TupleTableSlot *pi_slot;
234 ExprDoneCond *pi_itemIsDone;
235 bool pi_directMap;
236 int pi_numSimpleVars;
237 int *pi_varSlotOffsets;
238 int *pi_varNumbers;
239 int *pi_varOutputCols;
240 int pi_lastInnerVar;
241 int pi_lastOuterVar;
242 int pi_lastScanVar;
243 } ProjectionInfo;
245 /* ----------------
246 * JunkFilter
248 * This class is used to store information regarding junk attributes.
249 * A junk attribute is an attribute in a tuple that is needed only for
250 * storing intermediate information in the executor, and does not belong
251 * in emitted tuples. For example, when we do an UPDATE query,
252 * the planner adds a "junk" entry to the targetlist so that the tuples
253 * returned to ExecutePlan() contain an extra attribute: the ctid of
254 * the tuple to be updated. This is needed to do the update, but we
255 * don't want the ctid to be part of the stored new tuple! So, we
256 * apply a "junk filter" to remove the junk attributes and form the
257 * real output tuple. The junkfilter code also provides routines to
258 * extract the values of the junk attribute(s) from the input tuple.
260 * targetList: the original target list (including junk attributes).
261 * cleanTupType: the tuple descriptor for the "clean" tuple (with
262 * junk attributes removed).
263 * cleanMap: A map with the correspondence between the non-junk
264 * attribute numbers of the "original" tuple and the
265 * attribute numbers of the "clean" tuple.
266 * resultSlot: tuple slot used to hold cleaned tuple.
267 * junkAttNo: not used by junkfilter code. Can be used by caller
268 * to remember the attno of a specific junk attribute
269 * (execMain.c stores the "ctid" attno here).
270 * ----------------
272 typedef struct JunkFilter
274 NodeTag type;
275 List *jf_targetList;
276 TupleDesc jf_cleanTupType;
277 AttrNumber *jf_cleanMap;
278 TupleTableSlot *jf_resultSlot;
279 AttrNumber jf_junkAttNo;
280 } JunkFilter;
282 /* ----------------
283 * ResultRelInfo information
285 * Whenever we update an existing relation, we have to
286 * update indices on the relation, and perhaps also fire triggers.
287 * The ResultRelInfo class is used to hold all the information needed
288 * about a result relation, including indices.. -cim 10/15/89
290 * RangeTableIndex result relation's range table index
291 * RelationDesc relation descriptor for result relation
292 * NumIndices # of indices existing on result relation
293 * IndexRelationDescs array of relation descriptors for indices
294 * IndexRelationInfo array of key/attr info for indices
295 * TrigDesc triggers to be fired, if any
296 * TrigFunctions cached lookup info for trigger functions
297 * TrigInstrument optional runtime measurements for triggers
298 * ConstraintExprs array of constraint-checking expr states
299 * junkFilter for removing junk attributes from tuples
300 * projectReturning for computing a RETURNING list
301 * ----------------
303 typedef struct ResultRelInfo
305 NodeTag type;
306 Index ri_RangeTableIndex;
307 Relation ri_RelationDesc;
308 int ri_NumIndices;
309 RelationPtr ri_IndexRelationDescs;
310 IndexInfo **ri_IndexRelationInfo;
311 TriggerDesc *ri_TrigDesc;
312 FmgrInfo *ri_TrigFunctions;
313 struct Instrumentation *ri_TrigInstrument;
314 List **ri_ConstraintExprs;
315 JunkFilter *ri_junkFilter;
316 ProjectionInfo *ri_projectReturning;
317 } ResultRelInfo;
319 /* ----------------
320 * EState information
322 * Master working state for an Executor invocation
323 * ----------------
325 typedef struct EState
327 NodeTag type;
329 /* Basic state for all query types: */
330 ScanDirection es_direction; /* current scan direction */
331 Snapshot es_snapshot; /* time qual to use */
332 Snapshot es_crosscheck_snapshot; /* crosscheck time qual for RI */
333 List *es_range_table; /* List of RangeTblEntry */
335 /* If query can insert/delete tuples, the command ID to mark them with */
336 CommandId es_output_cid;
338 /* Info about target table for insert/update/delete queries: */
339 ResultRelInfo *es_result_relations; /* array of ResultRelInfos */
340 int es_num_result_relations; /* length of array */
341 ResultRelInfo *es_result_relation_info; /* currently active array elt */
342 JunkFilter *es_junkFilter; /* currently active junk filter */
344 /* Stuff used for firing triggers: */
345 List *es_trig_target_relations; /* trigger-only ResultRelInfos */
346 TupleTableSlot *es_trig_tuple_slot; /* for trigger output tuples */
348 /* Parameter info: */
349 ParamListInfo es_param_list_info; /* values of external params */
350 ParamExecData *es_param_exec_vals; /* values of internal params */
352 /* Other working state: */
353 MemoryContext es_query_cxt; /* per-query context in which EState lives */
355 TupleTable es_tupleTable; /* Array of TupleTableSlots */
357 uint32 es_processed; /* # of tuples processed */
358 Oid es_lastoid; /* last oid processed (by INSERT) */
359 List *es_rowMarks; /* not good place, but there is no other */
361 bool es_instrument; /* true requests runtime instrumentation */
362 bool es_select_into; /* true if doing SELECT INTO */
363 bool es_into_oids; /* true to generate OIDs in SELECT INTO */
365 List *es_exprcontexts; /* List of ExprContexts within EState */
367 List *es_subplanstates; /* List of PlanState for SubPlans */
370 * this ExprContext is for per-output-tuple operations, such as constraint
371 * checks and index-value computations. It will be reset for each output
372 * tuple. Note that it will be created only if needed.
374 ExprContext *es_per_tuple_exprcontext;
376 /* Below is to re-evaluate plan qual in READ COMMITTED mode */
377 PlannedStmt *es_plannedstmt; /* link to top of plan tree */
378 struct evalPlanQual *es_evalPlanQual; /* chain of PlanQual states */
379 bool *es_evTupleNull; /* local array of EPQ status */
380 HeapTuple *es_evTuple; /* shared array of EPQ substitute tuples */
381 bool es_useEvalPlan; /* evaluating EPQ tuples? */
382 } EState;
386 * es_rowMarks is a list of these structs. See RowMarkClause for details
387 * about rti and prti. toidAttno is not used in a "plain" rowmark.
389 typedef struct ExecRowMark
391 Relation relation; /* opened and RowShareLock'd relation */
392 Index rti; /* its range table index */
393 Index prti; /* parent range table index, if child */
394 bool forUpdate; /* true = FOR UPDATE, false = FOR SHARE */
395 bool noWait; /* NOWAIT option */
396 AttrNumber ctidAttNo; /* resno of its ctid junk attribute */
397 AttrNumber toidAttNo; /* resno of tableoid junk attribute, if any */
398 ItemPointerData curCtid; /* ctid of currently locked tuple, if any */
399 } ExecRowMark;
402 /* ----------------------------------------------------------------
403 * Tuple Hash Tables
405 * All-in-memory tuple hash tables are used for a number of purposes.
407 * Note: tab_hash_funcs are for the key datatype(s) stored in the table,
408 * and tab_eq_funcs are non-cross-type equality operators for those types.
409 * Normally these are the only functions used, but FindTupleHashEntry()
410 * supports searching a hashtable using cross-data-type hashing. For that,
411 * the caller must supply hash functions for the LHS datatype as well as
412 * the cross-type equality operators to use. in_hash_funcs and cur_eq_funcs
413 * are set to point to the caller's function arrays while doing such a search.
414 * During LookupTupleHashEntry(), they point to tab_hash_funcs and
415 * tab_eq_funcs respectively.
416 * ----------------------------------------------------------------
418 typedef struct TupleHashEntryData *TupleHashEntry;
419 typedef struct TupleHashTableData *TupleHashTable;
421 typedef struct TupleHashEntryData
423 /* firstTuple must be the first field in this struct! */
424 MinimalTuple firstTuple; /* copy of first tuple in this group */
425 /* there may be additional data beyond the end of this struct */
426 } TupleHashEntryData; /* VARIABLE LENGTH STRUCT */
428 typedef struct TupleHashTableData
430 HTAB *hashtab; /* underlying dynahash table */
431 int numCols; /* number of columns in lookup key */
432 AttrNumber *keyColIdx; /* attr numbers of key columns */
433 FmgrInfo *tab_hash_funcs; /* hash functions for table datatype(s) */
434 FmgrInfo *tab_eq_funcs; /* equality functions for table datatype(s) */
435 MemoryContext tablecxt; /* memory context containing table */
436 MemoryContext tempcxt; /* context for function evaluations */
437 Size entrysize; /* actual size to make each hash entry */
438 TupleTableSlot *tableslot; /* slot for referencing table entries */
439 /* The following fields are set transiently for each table search: */
440 TupleTableSlot *inputslot; /* current input tuple's slot */
441 FmgrInfo *in_hash_funcs; /* hash functions for input datatype(s) */
442 FmgrInfo *cur_eq_funcs; /* equality functions for input vs. table */
443 } TupleHashTableData;
445 typedef HASH_SEQ_STATUS TupleHashIterator;
448 * Use InitTupleHashIterator/TermTupleHashIterator for a read/write scan.
449 * Use ResetTupleHashIterator if the table can be frozen (in this case no
450 * explicit scan termination is needed).
452 #define InitTupleHashIterator(htable, iter) \
453 hash_seq_init(iter, (htable)->hashtab)
454 #define TermTupleHashIterator(iter) \
455 hash_seq_term(iter)
456 #define ResetTupleHashIterator(htable, iter) \
457 do { \
458 hash_freeze((htable)->hashtab); \
459 hash_seq_init(iter, (htable)->hashtab); \
460 } while (0)
461 #define ScanTupleHashTable(iter) \
462 ((TupleHashEntry) hash_seq_search(iter))
465 /* ----------------------------------------------------------------
466 * Expression State Trees
468 * Each executable expression tree has a parallel ExprState tree.
470 * Unlike PlanState, there is not an exact one-for-one correspondence between
471 * ExprState node types and Expr node types. Many Expr node types have no
472 * need for node-type-specific run-time state, and so they can use plain
473 * ExprState or GenericExprState as their associated ExprState node type.
474 * ----------------------------------------------------------------
477 /* ----------------
478 * ExprState node
480 * ExprState is the common superclass for all ExprState-type nodes.
482 * It can also be instantiated directly for leaf Expr nodes that need no
483 * local run-time state (such as Var, Const, or Param).
485 * To save on dispatch overhead, each ExprState node contains a function
486 * pointer to the routine to execute to evaluate the node.
487 * ----------------
490 typedef struct ExprState ExprState;
492 typedef Datum (*ExprStateEvalFunc) (ExprState *expression,
493 ExprContext *econtext,
494 bool *isNull,
495 ExprDoneCond *isDone);
497 struct ExprState
499 NodeTag type;
500 Expr *expr; /* associated Expr node */
501 ExprStateEvalFunc evalfunc; /* routine to run to execute node */
504 /* ----------------
505 * GenericExprState node
507 * This is used for Expr node types that need no local run-time state,
508 * but have one child Expr node.
509 * ----------------
511 typedef struct GenericExprState
513 ExprState xprstate;
514 ExprState *arg; /* state of my child node */
515 } GenericExprState;
517 /* ----------------
518 * AggrefExprState node
519 * ----------------
521 typedef struct AggrefExprState
523 ExprState xprstate;
524 List *args; /* states of argument expressions */
525 int aggno; /* ID number for agg within its plan node */
526 } AggrefExprState;
528 /* ----------------
529 * WindowFuncExprState node
530 * ----------------
532 typedef struct WindowFuncExprState
534 ExprState xprstate;
535 List *args; /* states of argument expressions */
536 int wfuncno; /* ID number for wfunc within its plan node */
537 } WindowFuncExprState;
539 /* ----------------
540 * ArrayRefExprState node
542 * Note: array types can be fixed-length (typlen > 0), but only when the
543 * element type is itself fixed-length. Otherwise they are varlena structures
544 * and have typlen = -1. In any case, an array type is never pass-by-value.
545 * ----------------
547 typedef struct ArrayRefExprState
549 ExprState xprstate;
550 List *refupperindexpr; /* states for child nodes */
551 List *reflowerindexpr;
552 ExprState *refexpr;
553 ExprState *refassgnexpr;
554 int16 refattrlength; /* typlen of array type */
555 int16 refelemlength; /* typlen of the array element type */
556 bool refelembyval; /* is the element type pass-by-value? */
557 char refelemalign; /* typalign of the element type */
558 } ArrayRefExprState;
560 /* ----------------
561 * FuncExprState node
563 * Although named for FuncExpr, this is also used for OpExpr, DistinctExpr,
564 * and NullIf nodes; be careful to check what xprstate.expr is actually
565 * pointing at!
566 * ----------------
568 typedef struct FuncExprState
570 ExprState xprstate;
571 List *args; /* states of argument expressions */
574 * Function manager's lookup info for the target function. If func.fn_oid
575 * is InvalidOid, we haven't initialized it yet (nor any of the following
576 * fields).
578 FmgrInfo func;
581 * For a set-returning function (SRF) that returns a tuplestore, we keep
582 * the tuplestore here and dole out the result rows one at a time. The
583 * slot holds the row currently being returned.
585 Tuplestorestate *funcResultStore;
586 TupleTableSlot *funcResultSlot;
589 * In some cases we need to compute a tuple descriptor for the function's
590 * output. If so, it's stored here.
592 TupleDesc funcResultDesc;
593 bool funcReturnsTuple; /* valid when funcResultDesc isn't
594 * NULL */
597 * We need to store argument values across calls when evaluating a SRF
598 * that uses value-per-call mode.
600 * setArgsValid is true when we are evaluating a set-valued function and
601 * we are in the middle of a call series; we want to pass the same
602 * argument values to the function again (and again, until it returns
603 * ExprEndResult).
605 bool setArgsValid;
608 * Flag to remember whether we found a set-valued argument to the
609 * function. This causes the function result to be a set as well. Valid
610 * only when setArgsValid is true or funcResultStore isn't NULL.
612 bool setHasSetArg; /* some argument returns a set */
615 * Flag to remember whether we have registered a shutdown callback for
616 * this FuncExprState. We do so only if funcResultStore or setArgsValid
617 * has been set at least once (since all the callback is for is to release
618 * the tuplestore or clear setArgsValid).
620 bool shutdown_reg; /* a shutdown callback is registered */
623 * Current argument data for a set-valued function; contains valid data
624 * only if setArgsValid is true.
626 FunctionCallInfoData setArgs;
627 } FuncExprState;
629 /* ----------------
630 * ScalarArrayOpExprState node
632 * This is a FuncExprState plus some additional data.
633 * ----------------
635 typedef struct ScalarArrayOpExprState
637 FuncExprState fxprstate;
638 /* Cached info about array element type */
639 Oid element_type;
640 int16 typlen;
641 bool typbyval;
642 char typalign;
643 } ScalarArrayOpExprState;
645 /* ----------------
646 * BoolExprState node
647 * ----------------
649 typedef struct BoolExprState
651 ExprState xprstate;
652 List *args; /* states of argument expression(s) */
653 } BoolExprState;
655 /* ----------------
656 * SubPlanState node
657 * ----------------
659 typedef struct SubPlanState
661 ExprState xprstate;
662 struct PlanState *planstate; /* subselect plan's state tree */
663 ExprState *testexpr; /* state of combining expression */
664 List *args; /* states of argument expression(s) */
665 HeapTuple curTuple; /* copy of most recent tuple from subplan */
666 /* these are used when hashing the subselect's output: */
667 ProjectionInfo *projLeft; /* for projecting lefthand exprs */
668 ProjectionInfo *projRight; /* for projecting subselect output */
669 TupleHashTable hashtable; /* hash table for no-nulls subselect rows */
670 TupleHashTable hashnulls; /* hash table for rows with null(s) */
671 bool havehashrows; /* TRUE if hashtable is not empty */
672 bool havenullrows; /* TRUE if hashnulls is not empty */
673 MemoryContext tablecxt; /* memory context containing tables */
674 ExprContext *innerecontext; /* working context for comparisons */
675 AttrNumber *keyColIdx; /* control data for hash tables */
676 FmgrInfo *tab_hash_funcs; /* hash functions for table datatype(s) */
677 FmgrInfo *tab_eq_funcs; /* equality functions for table datatype(s) */
678 FmgrInfo *lhs_hash_funcs; /* hash functions for lefthand datatype(s) */
679 FmgrInfo *cur_eq_funcs; /* equality functions for LHS vs. table */
680 } SubPlanState;
682 /* ----------------
683 * AlternativeSubPlanState node
684 * ----------------
686 typedef struct AlternativeSubPlanState
688 ExprState xprstate;
689 List *subplans; /* states of alternative subplans */
690 int active; /* list index of the one we're using */
691 } AlternativeSubPlanState;
693 /* ----------------
694 * FieldSelectState node
695 * ----------------
697 typedef struct FieldSelectState
699 ExprState xprstate;
700 ExprState *arg; /* input expression */
701 TupleDesc argdesc; /* tupdesc for most recent input */
702 } FieldSelectState;
704 /* ----------------
705 * FieldStoreState node
706 * ----------------
708 typedef struct FieldStoreState
710 ExprState xprstate;
711 ExprState *arg; /* input tuple value */
712 List *newvals; /* new value(s) for field(s) */
713 TupleDesc argdesc; /* tupdesc for most recent input */
714 } FieldStoreState;
716 /* ----------------
717 * CoerceViaIOState node
718 * ----------------
720 typedef struct CoerceViaIOState
722 ExprState xprstate;
723 ExprState *arg; /* input expression */
724 FmgrInfo outfunc; /* lookup info for source output function */
725 FmgrInfo infunc; /* lookup info for result input function */
726 Oid intypioparam; /* argument needed for input function */
727 } CoerceViaIOState;
729 /* ----------------
730 * ArrayCoerceExprState node
731 * ----------------
733 typedef struct ArrayCoerceExprState
735 ExprState xprstate;
736 ExprState *arg; /* input array value */
737 Oid resultelemtype; /* element type of result array */
738 FmgrInfo elemfunc; /* lookup info for element coercion function */
739 /* use struct pointer to avoid including array.h here */
740 struct ArrayMapState *amstate; /* workspace for array_map */
741 } ArrayCoerceExprState;
743 /* ----------------
744 * ConvertRowtypeExprState node
745 * ----------------
747 typedef struct ConvertRowtypeExprState
749 ExprState xprstate;
750 ExprState *arg; /* input tuple value */
751 TupleDesc indesc; /* tupdesc for source rowtype */
752 TupleDesc outdesc; /* tupdesc for result rowtype */
753 AttrNumber *attrMap; /* indexes of input fields, or 0 for null */
754 Datum *invalues; /* workspace for deconstructing source */
755 bool *inisnull;
756 Datum *outvalues; /* workspace for constructing result */
757 bool *outisnull;
758 } ConvertRowtypeExprState;
760 /* ----------------
761 * CaseExprState node
762 * ----------------
764 typedef struct CaseExprState
766 ExprState xprstate;
767 ExprState *arg; /* implicit equality comparison argument */
768 List *args; /* the arguments (list of WHEN clauses) */
769 ExprState *defresult; /* the default result (ELSE clause) */
770 } CaseExprState;
772 /* ----------------
773 * CaseWhenState node
774 * ----------------
776 typedef struct CaseWhenState
778 ExprState xprstate;
779 ExprState *expr; /* condition expression */
780 ExprState *result; /* substitution result */
781 } CaseWhenState;
783 /* ----------------
784 * ArrayExprState node
786 * Note: ARRAY[] expressions always produce varlena arrays, never fixed-length
787 * arrays.
788 * ----------------
790 typedef struct ArrayExprState
792 ExprState xprstate;
793 List *elements; /* states for child nodes */
794 int16 elemlength; /* typlen of the array element type */
795 bool elembyval; /* is the element type pass-by-value? */
796 char elemalign; /* typalign of the element type */
797 } ArrayExprState;
799 /* ----------------
800 * RowExprState node
801 * ----------------
803 typedef struct RowExprState
805 ExprState xprstate;
806 List *args; /* the arguments */
807 TupleDesc tupdesc; /* descriptor for result tuples */
808 } RowExprState;
810 /* ----------------
811 * RowCompareExprState node
812 * ----------------
814 typedef struct RowCompareExprState
816 ExprState xprstate;
817 List *largs; /* the left-hand input arguments */
818 List *rargs; /* the right-hand input arguments */
819 FmgrInfo *funcs; /* array of comparison function info */
820 } RowCompareExprState;
822 /* ----------------
823 * CoalesceExprState node
824 * ----------------
826 typedef struct CoalesceExprState
828 ExprState xprstate;
829 List *args; /* the arguments */
830 } CoalesceExprState;
832 /* ----------------
833 * MinMaxExprState node
834 * ----------------
836 typedef struct MinMaxExprState
838 ExprState xprstate;
839 List *args; /* the arguments */
840 FmgrInfo cfunc; /* lookup info for comparison func */
841 } MinMaxExprState;
843 /* ----------------
844 * XmlExprState node
845 * ----------------
847 typedef struct XmlExprState
849 ExprState xprstate;
850 List *named_args; /* ExprStates for named arguments */
851 List *args; /* ExprStates for other arguments */
852 } XmlExprState;
854 /* ----------------
855 * NullTestState node
856 * ----------------
858 typedef struct NullTestState
860 ExprState xprstate;
861 ExprState *arg; /* input expression */
862 bool argisrow; /* T if input is of a composite type */
863 /* used only if argisrow: */
864 TupleDesc argdesc; /* tupdesc for most recent input */
865 } NullTestState;
867 /* ----------------
868 * CoerceToDomainState node
869 * ----------------
871 typedef struct CoerceToDomainState
873 ExprState xprstate;
874 ExprState *arg; /* input expression */
875 /* Cached list of constraints that need to be checked */
876 List *constraints; /* list of DomainConstraintState nodes */
877 } CoerceToDomainState;
880 * DomainConstraintState - one item to check during CoerceToDomain
882 * Note: this is just a Node, and not an ExprState, because it has no
883 * corresponding Expr to link to. Nonetheless it is part of an ExprState
884 * tree, so we give it a name following the xxxState convention.
886 typedef enum DomainConstraintType
888 DOM_CONSTRAINT_NOTNULL,
889 DOM_CONSTRAINT_CHECK
890 } DomainConstraintType;
892 typedef struct DomainConstraintState
894 NodeTag type;
895 DomainConstraintType constrainttype; /* constraint type */
896 char *name; /* name of constraint (for error msgs) */
897 ExprState *check_expr; /* for CHECK, a boolean expression */
898 } DomainConstraintState;
901 /* ----------------------------------------------------------------
902 * Executor State Trees
904 * An executing query has a PlanState tree paralleling the Plan tree
905 * that describes the plan.
906 * ----------------------------------------------------------------
909 /* ----------------
910 * PlanState node
912 * We never actually instantiate any PlanState nodes; this is just the common
913 * abstract superclass for all PlanState-type nodes.
914 * ----------------
916 typedef struct PlanState
918 NodeTag type;
920 Plan *plan; /* associated Plan node */
922 EState *state; /* at execution time, states of individual
923 * nodes point to one EState for the whole
924 * top-level plan */
926 struct Instrumentation *instrument; /* Optional runtime stats for this
927 * plan node */
930 * Common structural data for all Plan types. These links to subsidiary
931 * state trees parallel links in the associated plan tree (except for the
932 * subPlan list, which does not exist in the plan tree).
934 List *targetlist; /* target list to be computed at this node */
935 List *qual; /* implicitly-ANDed qual conditions */
936 struct PlanState *lefttree; /* input plan tree(s) */
937 struct PlanState *righttree;
938 List *initPlan; /* Init SubPlanState nodes (un-correlated expr
939 * subselects) */
940 List *subPlan; /* SubPlanState nodes in my expressions */
943 * State for management of parameter-change-driven rescanning
945 Bitmapset *chgParam; /* set of IDs of changed Params */
948 * Other run-time state needed by most if not all node types.
950 TupleTableSlot *ps_ResultTupleSlot; /* slot for my result tuples */
951 ExprContext *ps_ExprContext; /* node's expression-evaluation context */
952 ProjectionInfo *ps_ProjInfo; /* info for doing tuple projection */
953 bool ps_TupFromTlist;/* state flag for processing set-valued
954 * functions in targetlist */
955 } PlanState;
957 /* ----------------
958 * these are are defined to avoid confusion problems with "left"
959 * and "right" and "inner" and "outer". The convention is that
960 * the "left" plan is the "outer" plan and the "right" plan is
961 * the inner plan, but these make the code more readable.
962 * ----------------
964 #define innerPlanState(node) (((PlanState *)(node))->righttree)
965 #define outerPlanState(node) (((PlanState *)(node))->lefttree)
968 /* ----------------
969 * ResultState information
970 * ----------------
972 typedef struct ResultState
974 PlanState ps; /* its first field is NodeTag */
975 ExprState *resconstantqual;
976 bool rs_done; /* are we done? */
977 bool rs_checkqual; /* do we need to check the qual? */
978 } ResultState;
980 /* ----------------
981 * AppendState information
983 * nplans how many plans are in the list
984 * whichplan which plan is being executed (0 .. n-1)
985 * firstplan first plan to execute (usually 0)
986 * lastplan last plan to execute (usually n-1)
987 * ----------------
989 typedef struct AppendState
991 PlanState ps; /* its first field is NodeTag */
992 PlanState **appendplans; /* array of PlanStates for my inputs */
993 int as_nplans;
994 int as_whichplan;
995 int as_firstplan;
996 int as_lastplan;
997 } AppendState;
999 /* ----------------
1000 * RecursiveUnionState information
1002 * RecursiveUnionState is used for performing a recursive union.
1004 * recursing T when we're done scanning the non-recursive term
1005 * intermediate_empty T if intermediate_table is currently empty
1006 * working_table working table (to be scanned by recursive term)
1007 * intermediate_table current recursive output (next generation of WT)
1008 * ----------------
1010 typedef struct RecursiveUnionState
1012 PlanState ps; /* its first field is NodeTag */
1013 bool recursing;
1014 bool intermediate_empty;
1015 Tuplestorestate *working_table;
1016 Tuplestorestate *intermediate_table;
1017 /* Remaining fields are unused in UNION ALL case */
1018 FmgrInfo *eqfunctions; /* per-grouping-field equality fns */
1019 FmgrInfo *hashfunctions; /* per-grouping-field hash fns */
1020 MemoryContext tempContext; /* short-term context for comparisons */
1021 TupleHashTable hashtable; /* hash table for tuples already seen */
1022 MemoryContext tableContext; /* memory context containing hash table */
1023 } RecursiveUnionState;
1025 /* ----------------
1026 * BitmapAndState information
1027 * ----------------
1029 typedef struct BitmapAndState
1031 PlanState ps; /* its first field is NodeTag */
1032 PlanState **bitmapplans; /* array of PlanStates for my inputs */
1033 int nplans; /* number of input plans */
1034 } BitmapAndState;
1036 /* ----------------
1037 * BitmapOrState information
1038 * ----------------
1040 typedef struct BitmapOrState
1042 PlanState ps; /* its first field is NodeTag */
1043 PlanState **bitmapplans; /* array of PlanStates for my inputs */
1044 int nplans; /* number of input plans */
1045 } BitmapOrState;
1047 /* ----------------------------------------------------------------
1048 * Scan State Information
1049 * ----------------------------------------------------------------
1052 /* ----------------
1053 * ScanState information
1055 * ScanState extends PlanState for node types that represent
1056 * scans of an underlying relation. It can also be used for nodes
1057 * that scan the output of an underlying plan node --- in that case,
1058 * only ScanTupleSlot is actually useful, and it refers to the tuple
1059 * retrieved from the subplan.
1061 * currentRelation relation being scanned (NULL if none)
1062 * currentScanDesc current scan descriptor for scan (NULL if none)
1063 * ScanTupleSlot pointer to slot in tuple table holding scan tuple
1064 * ----------------
1066 typedef struct ScanState
1068 PlanState ps; /* its first field is NodeTag */
1069 Relation ss_currentRelation;
1070 HeapScanDesc ss_currentScanDesc;
1071 TupleTableSlot *ss_ScanTupleSlot;
1072 } ScanState;
1075 * SeqScan uses a bare ScanState as its state node, since it needs
1076 * no additional fields.
1078 typedef ScanState SeqScanState;
1081 * These structs store information about index quals that don't have simple
1082 * constant right-hand sides. See comments for ExecIndexBuildScanKeys()
1083 * for discussion.
1085 typedef struct
1087 ScanKey scan_key; /* scankey to put value into */
1088 ExprState *key_expr; /* expr to evaluate to get value */
1089 } IndexRuntimeKeyInfo;
1091 typedef struct
1093 ScanKey scan_key; /* scankey to put value into */
1094 ExprState *array_expr; /* expr to evaluate to get array value */
1095 int next_elem; /* next array element to use */
1096 int num_elems; /* number of elems in current array value */
1097 Datum *elem_values; /* array of num_elems Datums */
1098 bool *elem_nulls; /* array of num_elems is-null flags */
1099 } IndexArrayKeyInfo;
1101 /* ----------------
1102 * IndexScanState information
1104 * indexqualorig execution state for indexqualorig expressions
1105 * ScanKeys Skey structures to scan index rel
1106 * NumScanKeys number of Skey structs
1107 * RuntimeKeys info about Skeys that must be evaluated at runtime
1108 * NumRuntimeKeys number of RuntimeKeys structs
1109 * RuntimeKeysReady true if runtime Skeys have been computed
1110 * RuntimeContext expr context for evaling runtime Skeys
1111 * RelationDesc index relation descriptor
1112 * ScanDesc index scan descriptor
1113 * ----------------
1115 typedef struct IndexScanState
1117 ScanState ss; /* its first field is NodeTag */
1118 List *indexqualorig;
1119 ScanKey iss_ScanKeys;
1120 int iss_NumScanKeys;
1121 IndexRuntimeKeyInfo *iss_RuntimeKeys;
1122 int iss_NumRuntimeKeys;
1123 bool iss_RuntimeKeysReady;
1124 ExprContext *iss_RuntimeContext;
1125 Relation iss_RelationDesc;
1126 IndexScanDesc iss_ScanDesc;
1127 } IndexScanState;
1129 /* ----------------
1130 * BitmapIndexScanState information
1132 * result bitmap to return output into, or NULL
1133 * ScanKeys Skey structures to scan index rel
1134 * NumScanKeys number of Skey structs
1135 * RuntimeKeys info about Skeys that must be evaluated at runtime
1136 * NumRuntimeKeys number of RuntimeKeys structs
1137 * ArrayKeys info about Skeys that come from ScalarArrayOpExprs
1138 * NumArrayKeys number of ArrayKeys structs
1139 * RuntimeKeysReady true if runtime Skeys have been computed
1140 * RuntimeContext expr context for evaling runtime Skeys
1141 * RelationDesc index relation descriptor
1142 * ScanDesc index scan descriptor
1143 * ----------------
1145 typedef struct BitmapIndexScanState
1147 ScanState ss; /* its first field is NodeTag */
1148 TIDBitmap *biss_result;
1149 ScanKey biss_ScanKeys;
1150 int biss_NumScanKeys;
1151 IndexRuntimeKeyInfo *biss_RuntimeKeys;
1152 int biss_NumRuntimeKeys;
1153 IndexArrayKeyInfo *biss_ArrayKeys;
1154 int biss_NumArrayKeys;
1155 bool biss_RuntimeKeysReady;
1156 ExprContext *biss_RuntimeContext;
1157 Relation biss_RelationDesc;
1158 IndexScanDesc biss_ScanDesc;
1159 } BitmapIndexScanState;
1161 /* ----------------
1162 * BitmapHeapScanState information
1164 * bitmapqualorig execution state for bitmapqualorig expressions
1165 * tbm bitmap obtained from child index scan(s)
1166 * tbmiterator iterator for scanning current pages
1167 * tbmres current-page data
1168 * prefetch_iterator iterator for prefetching ahead of current page
1169 * prefetch_pages # pages prefetch iterator is ahead of current
1170 * prefetch_target target prefetch distance
1171 * ----------------
1173 typedef struct BitmapHeapScanState
1175 ScanState ss; /* its first field is NodeTag */
1176 List *bitmapqualorig;
1177 TIDBitmap *tbm;
1178 TBMIterator *tbmiterator;
1179 TBMIterateResult *tbmres;
1180 TBMIterator *prefetch_iterator;
1181 int prefetch_pages;
1182 int prefetch_target;
1183 } BitmapHeapScanState;
1185 /* ----------------
1186 * TidScanState information
1188 * isCurrentOf scan has a CurrentOfExpr qual
1189 * NumTids number of tids in this scan
1190 * TidPtr index of currently fetched tid
1191 * TidList evaluated item pointers (array of size NumTids)
1192 * ----------------
1194 typedef struct TidScanState
1196 ScanState ss; /* its first field is NodeTag */
1197 List *tss_tidquals; /* list of ExprState nodes */
1198 bool tss_isCurrentOf;
1199 int tss_NumTids;
1200 int tss_TidPtr;
1201 int tss_MarkTidPtr;
1202 ItemPointerData *tss_TidList;
1203 HeapTupleData tss_htup;
1204 } TidScanState;
1206 /* ----------------
1207 * SubqueryScanState information
1209 * SubqueryScanState is used for scanning a sub-query in the range table.
1210 * ScanTupleSlot references the current output tuple of the sub-query.
1211 * ----------------
1213 typedef struct SubqueryScanState
1215 ScanState ss; /* its first field is NodeTag */
1216 PlanState *subplan;
1217 } SubqueryScanState;
1219 /* ----------------
1220 * FunctionScanState information
1222 * Function nodes are used to scan the results of a
1223 * function appearing in FROM (typically a function returning set).
1225 * eflags node's capability flags
1226 * tupdesc expected return tuple description
1227 * tuplestorestate private state of tuplestore.c
1228 * funcexpr state for function expression being evaluated
1229 * ----------------
1231 typedef struct FunctionScanState
1233 ScanState ss; /* its first field is NodeTag */
1234 int eflags;
1235 TupleDesc tupdesc;
1236 Tuplestorestate *tuplestorestate;
1237 ExprState *funcexpr;
1238 } FunctionScanState;
1240 /* ----------------
1241 * ValuesScanState information
1243 * ValuesScan nodes are used to scan the results of a VALUES list
1245 * rowcontext per-expression-list context
1246 * exprlists array of expression lists being evaluated
1247 * array_len size of array
1248 * curr_idx current array index (0-based)
1249 * marked_idx marked position (for mark/restore)
1251 * Note: ss.ps.ps_ExprContext is used to evaluate any qual or projection
1252 * expressions attached to the node. We create a second ExprContext,
1253 * rowcontext, in which to build the executor expression state for each
1254 * Values sublist. Resetting this context lets us get rid of expression
1255 * state for each row, avoiding major memory leakage over a long values list.
1256 * ----------------
1258 typedef struct ValuesScanState
1260 ScanState ss; /* its first field is NodeTag */
1261 ExprContext *rowcontext;
1262 List **exprlists;
1263 int array_len;
1264 int curr_idx;
1265 int marked_idx;
1266 } ValuesScanState;
1268 /* ----------------
1269 * CteScanState information
1271 * CteScan nodes are used to scan a CommonTableExpr query.
1273 * Multiple CteScan nodes can read out from the same CTE query. We use
1274 * a tuplestore to hold rows that have been read from the CTE query but
1275 * not yet consumed by all readers.
1276 * ----------------
1278 typedef struct CteScanState
1280 ScanState ss; /* its first field is NodeTag */
1281 int eflags; /* capability flags to pass to tuplestore */
1282 int readptr; /* index of my tuplestore read pointer */
1283 PlanState *cteplanstate; /* PlanState for the CTE query itself */
1284 /* Link to the "leader" CteScanState (possibly this same node) */
1285 struct CteScanState *leader;
1286 /* The remaining fields are only valid in the "leader" CteScanState */
1287 Tuplestorestate *cte_table; /* rows already read from the CTE query */
1288 bool eof_cte; /* reached end of CTE query? */
1289 } CteScanState;
1291 /* ----------------
1292 * WorkTableScanState information
1294 * WorkTableScan nodes are used to scan the work table created by
1295 * a RecursiveUnion node. We locate the RecursiveUnion node
1296 * during executor startup.
1297 * ----------------
1299 typedef struct WorkTableScanState
1301 ScanState ss; /* its first field is NodeTag */
1302 RecursiveUnionState *rustate;
1303 } WorkTableScanState;
1305 /* ----------------------------------------------------------------
1306 * Join State Information
1307 * ----------------------------------------------------------------
1310 /* ----------------
1311 * JoinState information
1313 * Superclass for state nodes of join plans.
1314 * ----------------
1316 typedef struct JoinState
1318 PlanState ps;
1319 JoinType jointype;
1320 List *joinqual; /* JOIN quals (in addition to ps.qual) */
1321 } JoinState;
1323 /* ----------------
1324 * NestLoopState information
1326 * NeedNewOuter true if need new outer tuple on next call
1327 * MatchedOuter true if found a join match for current outer tuple
1328 * NullInnerTupleSlot prepared null tuple for left outer joins
1329 * ----------------
1331 typedef struct NestLoopState
1333 JoinState js; /* its first field is NodeTag */
1334 bool nl_NeedNewOuter;
1335 bool nl_MatchedOuter;
1336 TupleTableSlot *nl_NullInnerTupleSlot;
1337 } NestLoopState;
1339 /* ----------------
1340 * MergeJoinState information
1342 * NumClauses number of mergejoinable join clauses
1343 * Clauses info for each mergejoinable clause
1344 * JoinState current "state" of join. see execdefs.h
1345 * ExtraMarks true to issue extra Mark operations on inner scan
1346 * FillOuter true if should emit unjoined outer tuples anyway
1347 * FillInner true if should emit unjoined inner tuples anyway
1348 * MatchedOuter true if found a join match for current outer tuple
1349 * MatchedInner true if found a join match for current inner tuple
1350 * OuterTupleSlot slot in tuple table for cur outer tuple
1351 * InnerTupleSlot slot in tuple table for cur inner tuple
1352 * MarkedTupleSlot slot in tuple table for marked tuple
1353 * NullOuterTupleSlot prepared null tuple for right outer joins
1354 * NullInnerTupleSlot prepared null tuple for left outer joins
1355 * OuterEContext workspace for computing outer tuple's join values
1356 * InnerEContext workspace for computing inner tuple's join values
1357 * ----------------
1359 /* private in nodeMergejoin.c: */
1360 typedef struct MergeJoinClauseData *MergeJoinClause;
1362 typedef struct MergeJoinState
1364 JoinState js; /* its first field is NodeTag */
1365 int mj_NumClauses;
1366 MergeJoinClause mj_Clauses; /* array of length mj_NumClauses */
1367 int mj_JoinState;
1368 bool mj_ExtraMarks;
1369 bool mj_FillOuter;
1370 bool mj_FillInner;
1371 bool mj_MatchedOuter;
1372 bool mj_MatchedInner;
1373 TupleTableSlot *mj_OuterTupleSlot;
1374 TupleTableSlot *mj_InnerTupleSlot;
1375 TupleTableSlot *mj_MarkedTupleSlot;
1376 TupleTableSlot *mj_NullOuterTupleSlot;
1377 TupleTableSlot *mj_NullInnerTupleSlot;
1378 ExprContext *mj_OuterEContext;
1379 ExprContext *mj_InnerEContext;
1380 } MergeJoinState;
1382 /* ----------------
1383 * HashJoinState information
1385 * hj_HashTable hash table for the hashjoin
1386 * (NULL if table not built yet)
1387 * hj_CurHashValue hash value for current outer tuple
1388 * hj_CurBucketNo regular bucket# for current outer tuple
1389 * hj_CurSkewBucketNo skew bucket# for current outer tuple
1390 * hj_CurTuple last inner tuple matched to current outer
1391 * tuple, or NULL if starting search
1392 * (hj_CurXXX variables are undefined if
1393 * OuterTupleSlot is empty!)
1394 * hj_OuterHashKeys the outer hash keys in the hashjoin condition
1395 * hj_InnerHashKeys the inner hash keys in the hashjoin condition
1396 * hj_HashOperators the join operators in the hashjoin condition
1397 * hj_OuterTupleSlot tuple slot for outer tuples
1398 * hj_HashTupleSlot tuple slot for hashed tuples
1399 * hj_NullInnerTupleSlot prepared null tuple for left outer joins
1400 * hj_FirstOuterTupleSlot first tuple retrieved from outer plan
1401 * hj_NeedNewOuter true if need new outer tuple on next call
1402 * hj_MatchedOuter true if found a join match for current outer
1403 * hj_OuterNotEmpty true if outer relation known not empty
1404 * ----------------
1407 /* these structs are defined in executor/hashjoin.h: */
1408 typedef struct HashJoinTupleData *HashJoinTuple;
1409 typedef struct HashJoinTableData *HashJoinTable;
1411 typedef struct HashJoinState
1413 JoinState js; /* its first field is NodeTag */
1414 List *hashclauses; /* list of ExprState nodes */
1415 HashJoinTable hj_HashTable;
1416 uint32 hj_CurHashValue;
1417 int hj_CurBucketNo;
1418 int hj_CurSkewBucketNo;
1419 HashJoinTuple hj_CurTuple;
1420 List *hj_OuterHashKeys; /* list of ExprState nodes */
1421 List *hj_InnerHashKeys; /* list of ExprState nodes */
1422 List *hj_HashOperators; /* list of operator OIDs */
1423 TupleTableSlot *hj_OuterTupleSlot;
1424 TupleTableSlot *hj_HashTupleSlot;
1425 TupleTableSlot *hj_NullInnerTupleSlot;
1426 TupleTableSlot *hj_FirstOuterTupleSlot;
1427 bool hj_NeedNewOuter;
1428 bool hj_MatchedOuter;
1429 bool hj_OuterNotEmpty;
1430 } HashJoinState;
1433 /* ----------------------------------------------------------------
1434 * Materialization State Information
1435 * ----------------------------------------------------------------
1438 /* ----------------
1439 * MaterialState information
1441 * materialize nodes are used to materialize the results
1442 * of a subplan into a temporary file.
1444 * ss.ss_ScanTupleSlot refers to output of underlying plan.
1445 * ----------------
1447 typedef struct MaterialState
1449 ScanState ss; /* its first field is NodeTag */
1450 int eflags; /* capability flags to pass to tuplestore */
1451 bool eof_underlying; /* reached end of underlying plan? */
1452 Tuplestorestate *tuplestorestate;
1453 } MaterialState;
1455 /* ----------------
1456 * SortState information
1457 * ----------------
1459 typedef struct SortState
1461 ScanState ss; /* its first field is NodeTag */
1462 bool randomAccess; /* need random access to sort output? */
1463 bool bounded; /* is the result set bounded? */
1464 int64 bound; /* if bounded, how many tuples are needed */
1465 bool sort_Done; /* sort completed yet? */
1466 bool bounded_Done; /* value of bounded we did the sort with */
1467 int64 bound_Done; /* value of bound we did the sort with */
1468 void *tuplesortstate; /* private state of tuplesort.c */
1469 } SortState;
1471 /* ---------------------
1472 * GroupState information
1473 * -------------------------
1475 typedef struct GroupState
1477 ScanState ss; /* its first field is NodeTag */
1478 FmgrInfo *eqfunctions; /* per-field lookup data for equality fns */
1479 bool grp_done; /* indicates completion of Group scan */
1480 } GroupState;
1482 /* ---------------------
1483 * AggState information
1485 * ss.ss_ScanTupleSlot refers to output of underlying plan.
1487 * Note: ss.ps.ps_ExprContext contains ecxt_aggvalues and
1488 * ecxt_aggnulls arrays, which hold the computed agg values for the current
1489 * input group during evaluation of an Agg node's output tuple(s). We
1490 * create a second ExprContext, tmpcontext, in which to evaluate input
1491 * expressions and run the aggregate transition functions.
1492 * -------------------------
1494 /* these structs are private in nodeAgg.c: */
1495 typedef struct AggStatePerAggData *AggStatePerAgg;
1496 typedef struct AggStatePerGroupData *AggStatePerGroup;
1498 typedef struct AggState
1500 ScanState ss; /* its first field is NodeTag */
1501 List *aggs; /* all Aggref nodes in targetlist & quals */
1502 int numaggs; /* length of list (could be zero!) */
1503 FmgrInfo *eqfunctions; /* per-grouping-field equality fns */
1504 FmgrInfo *hashfunctions; /* per-grouping-field hash fns */
1505 AggStatePerAgg peragg; /* per-Aggref information */
1506 MemoryContext aggcontext; /* memory context for long-lived data */
1507 ExprContext *tmpcontext; /* econtext for input expressions */
1508 bool agg_done; /* indicates completion of Agg scan */
1509 /* these fields are used in AGG_PLAIN and AGG_SORTED modes: */
1510 AggStatePerGroup pergroup; /* per-Aggref-per-group working state */
1511 HeapTuple grp_firstTuple; /* copy of first tuple of current group */
1512 /* these fields are used in AGG_HASHED mode: */
1513 TupleHashTable hashtable; /* hash table with one entry per group */
1514 TupleTableSlot *hashslot; /* slot for loading hash table */
1515 List *hash_needed; /* list of columns needed in hash table */
1516 bool table_filled; /* hash table filled yet? */
1517 TupleHashIterator hashiter; /* for iterating through hash table */
1518 } AggState;
1520 /* ----------------
1521 * WindowAggState information
1522 * ----------------
1524 /* these structs are private in nodeWindowAgg.c: */
1525 typedef struct WindowStatePerFuncData *WindowStatePerFunc;
1526 typedef struct WindowStatePerAggData *WindowStatePerAgg;
1528 typedef struct WindowAggState
1530 ScanState ss; /* its first field is NodeTag */
1532 /* these fields are filled in by ExecInitExpr: */
1533 List *funcs; /* all WindowFunc nodes in targetlist */
1534 int numfuncs; /* total number of window functions */
1535 int numaggs; /* number that are plain aggregates */
1537 WindowStatePerFunc perfunc; /* per-window-function information */
1538 WindowStatePerAgg peragg; /* per-plain-aggregate information */
1539 FmgrInfo *partEqfunctions; /* equality funcs for partition columns */
1540 FmgrInfo *ordEqfunctions; /* equality funcs for ordering columns */
1541 Tuplestorestate *buffer; /* stores rows of current partition */
1542 int current_ptr; /* read pointer # for current */
1543 int agg_ptr; /* read pointer # for aggregates */
1544 int64 spooled_rows; /* total # of rows in buffer */
1545 int64 currentpos; /* position of current row in partition */
1546 int64 frametailpos; /* current frame tail position */
1547 int64 aggregatedupto; /* rows before this one are aggregated */
1549 MemoryContext wincontext; /* context for partition-lifespan data */
1550 ExprContext *tmpcontext; /* short-term evaluation context */
1552 bool all_done; /* true if the scan is finished */
1553 bool partition_spooled; /* true if all tuples in current
1554 * partition have been spooled into
1555 * tuplestore */
1556 bool more_partitions;/* true if there's more partitions after this
1557 * one */
1558 bool frametail_valid;/* true if frametailpos is known up to date
1559 * for current row */
1561 TupleTableSlot *first_part_slot; /* first tuple of current or next
1562 * partition */
1564 /* temporary slots for tuples fetched back from tuplestore */
1565 TupleTableSlot *agg_row_slot;
1566 TupleTableSlot *temp_slot_1;
1567 TupleTableSlot *temp_slot_2;
1568 } WindowAggState;
1570 /* ----------------
1571 * UniqueState information
1573 * Unique nodes are used "on top of" sort nodes to discard
1574 * duplicate tuples returned from the sort phase. Basically
1575 * all it does is compare the current tuple from the subplan
1576 * with the previously fetched tuple (stored in its result slot).
1577 * If the two are identical in all interesting fields, then
1578 * we just fetch another tuple from the sort and try again.
1579 * ----------------
1581 typedef struct UniqueState
1583 PlanState ps; /* its first field is NodeTag */
1584 FmgrInfo *eqfunctions; /* per-field lookup data for equality fns */
1585 MemoryContext tempContext; /* short-term context for comparisons */
1586 } UniqueState;
1588 /* ----------------
1589 * HashState information
1590 * ----------------
1592 typedef struct HashState
1594 PlanState ps; /* its first field is NodeTag */
1595 HashJoinTable hashtable; /* hash table for the hashjoin */
1596 List *hashkeys; /* list of ExprState nodes */
1597 /* hashkeys is same as parent's hj_InnerHashKeys */
1598 } HashState;
1600 /* ----------------
1601 * SetOpState information
1603 * Even in "sorted" mode, SetOp nodes are more complex than a simple
1604 * Unique, since we have to count how many duplicates to return. But
1605 * we also support hashing, so this is really more like a cut-down
1606 * form of Agg.
1607 * ----------------
1609 /* this struct is private in nodeSetOp.c: */
1610 typedef struct SetOpStatePerGroupData *SetOpStatePerGroup;
1612 typedef struct SetOpState
1614 PlanState ps; /* its first field is NodeTag */
1615 FmgrInfo *eqfunctions; /* per-grouping-field equality fns */
1616 FmgrInfo *hashfunctions; /* per-grouping-field hash fns */
1617 bool setop_done; /* indicates completion of output scan */
1618 long numOutput; /* number of dups left to output */
1619 MemoryContext tempContext; /* short-term context for comparisons */
1620 /* these fields are used in SETOP_SORTED mode: */
1621 SetOpStatePerGroup pergroup; /* per-group working state */
1622 HeapTuple grp_firstTuple; /* copy of first tuple of current group */
1623 /* these fields are used in SETOP_HASHED mode: */
1624 TupleHashTable hashtable; /* hash table with one entry per group */
1625 MemoryContext tableContext; /* memory context containing hash table */
1626 bool table_filled; /* hash table filled yet? */
1627 TupleHashIterator hashiter; /* for iterating through hash table */
1628 } SetOpState;
1630 /* ----------------
1631 * LimitState information
1633 * Limit nodes are used to enforce LIMIT/OFFSET clauses.
1634 * They just select the desired subrange of their subplan's output.
1636 * offset is the number of initial tuples to skip (0 does nothing).
1637 * count is the number of tuples to return after skipping the offset tuples.
1638 * If no limit count was specified, count is undefined and noCount is true.
1639 * When lstate == LIMIT_INITIAL, offset/count/noCount haven't been set yet.
1640 * ----------------
1642 typedef enum
1644 LIMIT_INITIAL, /* initial state for LIMIT node */
1645 LIMIT_RESCAN, /* rescan after recomputing parameters */
1646 LIMIT_EMPTY, /* there are no returnable rows */
1647 LIMIT_INWINDOW, /* have returned a row in the window */
1648 LIMIT_SUBPLANEOF, /* at EOF of subplan (within window) */
1649 LIMIT_WINDOWEND, /* stepped off end of window */
1650 LIMIT_WINDOWSTART /* stepped off beginning of window */
1651 } LimitStateCond;
1653 typedef struct LimitState
1655 PlanState ps; /* its first field is NodeTag */
1656 ExprState *limitOffset; /* OFFSET parameter, or NULL if none */
1657 ExprState *limitCount; /* COUNT parameter, or NULL if none */
1658 int64 offset; /* current OFFSET value */
1659 int64 count; /* current COUNT, if any */
1660 bool noCount; /* if true, ignore count */
1661 LimitStateCond lstate; /* state machine status, as above */
1662 int64 position; /* 1-based index of last tuple returned */
1663 TupleTableSlot *subSlot; /* tuple last obtained from subplan */
1664 } LimitState;
1666 #endif /* EXECNODES_H */