1 /*-------------------------------------------------------------------------
4 * definitions for executor state nodes
7 * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * $Id: execnodes.h,v 1.43 2000/07/12 02:37:32 tgl Exp $
12 *-------------------------------------------------------------------------
17 #include "access/funcindex.h"
18 #include "access/relscan.h"
19 #include "access/sdir.h"
20 #include "executor/hashjoin.h"
21 #include "executor/tuptable.h"
22 #include "nodes/params.h"
23 #include "nodes/primnodes.h"
26 * IndexInfo information
28 * this class holds the information saying what attributes
29 * are the key attributes for this index. -cim 10/15/89
31 * NumKeyAttributes number of key attributes for this index
32 * KeyAttributeNumbers array of attribute numbers used as keys
33 * Predicate partial-index predicate for this index
36 typedef struct IndexInfo
39 int ii_NumKeyAttributes;
40 AttrNumber *ii_KeyAttributeNumbers;
41 FuncIndexInfoPtr ii_FuncIndexInfo;
46 * RelationInfo information
48 * whenever we update an existing relation, we have to
49 * update indices on the relation. The RelationInfo class
50 * is used to hold all the information on result relations,
51 * including indices.. -cim 10/15/89
53 * RangeTableIndex result relation's range table index
54 * RelationDesc relation descriptor for result relation
55 * NumIndices number indices existing on result relation
56 * IndexRelationDescs array of relation descriptors for indices
57 * IndexRelationInfo array of key/attr info for indices
60 typedef struct RelationInfo
63 Index ri_RangeTableIndex;
64 Relation ri_RelationDesc;
66 RelationPtr ri_IndexRelationDescs;
67 IndexInfo **ri_IndexRelationInfo;
73 * This class holds the "current context" information
74 * needed to evaluate expressions for doing tuple qualifications
75 * and tuple projections. For example, if an expression refers
76 * to an attribute in the current inner tuple then we need to know
77 * what the current inner tuple is and so we look at the expression
80 * There are two memory contexts associated with an ExprContext:
81 * * ecxt_per_query_memory is a relatively long-lived context (such as
82 * TransactionCommandContext); typically it's the same context the
83 * ExprContext node itself is allocated in. This context can be
84 * used for purposes such as storing operator/function fcache nodes.
85 * * ecxt_per_tuple_memory is a short-term context for expression results.
86 * As the name suggests, it will typically be reset once per tuple,
87 * before we begin to evaluate expressions for that tuple. Each
88 * ExprContext normally has its very own per-tuple memory context.
89 * CurrentMemoryContext should be set to ecxt_per_tuple_memory before
90 * calling ExecEvalExpr() --- see ExecEvalExprSwitchContext().
93 typedef struct ExprContext
96 /* Tuples that Var nodes in expression may refer to */
97 TupleTableSlot *ecxt_scantuple;
98 TupleTableSlot *ecxt_innertuple;
99 TupleTableSlot *ecxt_outertuple;
100 /* Memory contexts for expression evaluation --- see notes above */
101 MemoryContext ecxt_per_query_memory;
102 MemoryContext ecxt_per_tuple_memory;
103 /* Values to substitute for Param nodes in expression */
104 ParamExecData *ecxt_param_exec_vals; /* for PARAM_EXEC params */
105 ParamListInfo ecxt_param_list_info; /* for other param types */
106 /* Values to substitute for Aggref nodes in expression */
107 Datum *ecxt_aggvalues; /* precomputed values for Aggref nodes */
108 bool *ecxt_aggnulls; /* null flags for Aggref nodes */
109 /* Range table that Vars in expression refer to --- seldom needed */
110 List *ecxt_range_table;
114 * ProjectionInfo node information
116 * This is all the information needed to perform projections
117 * on a tuple. Nodes which need to do projections create one
118 * of these. In theory, when a node wants to perform a projection
119 * it should just update this information as necessary and then
120 * call ExecProject(). -cim 6/3/91
122 * targetlist target list for projection
123 * len length of target list
124 * tupValue array of pointers to projection results
125 * exprContext expression context for ExecTargetList
126 * slot slot to place projection result in
129 typedef struct ProjectionInfo
135 ExprContext *pi_exprContext;
136 TupleTableSlot *pi_slot;
142 * This class is used to store information regarding junk attributes.
143 * A junk attribute is an attribute in a tuple that is needed only for
144 * storing intermediate information in the executor, and does not belong
145 * in emitted tuples. For example, when we do an UPDATE query,
146 * the planner adds a "junk" entry to the targetlist so that the tuples
147 * returned to ExecutePlan() contain an extra attribute: the ctid of
148 * the tuple to be updated. This is needed to do the update, but we
149 * don't want the ctid to be part of the stored new tuple! So, we
150 * apply a "junk filter" to remove the junk attributes and form the
153 * targetList: the original target list (including junk attributes).
154 * length: the length of 'targetList'.
155 * tupType: the tuple descriptor for the "original" tuple
156 * (including the junk attributes).
157 * cleanTargetList: the "clean" target list (junk attributes removed).
158 * cleanLength: the length of 'cleanTargetList'
159 * cleanTupTyp: the tuple descriptor of the "clean" tuple (with
160 * junk attributes removed).
161 * cleanMap: A map with the correspondance between the non junk
162 * attributes of the "original" tuple and the
163 * attributes of the "clean" tuple.
166 typedef struct JunkFilter
171 TupleDesc jf_tupType;
172 List *jf_cleanTargetList;
174 TupleDesc jf_cleanTupType;
175 AttrNumber *jf_cleanMap;
181 * direction direction of the scan
183 * range_table array of scan relation information
185 * result_relation_information for update queries
187 * into_relation_descriptor relation being retrieved "into"
189 * param_list_info information needed to transform
190 * Param nodes into Const nodes
192 * tupleTable this is a pointer to an array
193 * of pointers to tuples used by
194 * the executor at any given moment.
196 * junkFilter contains information used to
197 * extract junk attributes from a tuple.
198 * (see JunkFilter above)
201 typedef struct EState
204 ScanDirection es_direction;
205 Snapshot es_snapshot;
206 List *es_range_table;
207 RelationInfo *es_result_relation_info;
208 List **es_result_relation_constraints;
209 Relation es_into_relation_descriptor;
210 ParamListInfo es_param_list_info;
211 ParamExecData *es_param_exec_vals; /* this is for subselects */
212 TupleTable es_tupleTable;
213 JunkFilter *es_junkFilter;
214 uint32 es_processed; /* # of tuples processed */
215 Oid es_lastoid; /* last oid processed (by INSERT) */
216 List *es_rowMark; /* not good place, but there is no other */
217 /* Below is to re-evaluate plan qual in READ COMMITTED mode */
218 struct Plan *es_origPlan;
219 Pointer es_evalPlanQual;
220 bool *es_evTupleNull;
221 HeapTuple *es_evTuple;
226 * Executor Type information needed by plannodes.h
228 *| Note: the bogus classes CommonState and CommonScanState exist only
229 *| because our inheritance system only allows single inheritance
230 *| and we have to have unique slot names. Hence two or more
231 *| classes which want to have a common slot must ALL inherit
232 *| the slot from some other class. (This is a big hack to
233 *| allow our classes to share slot names..)
236 *| the class Result and the class NestLoop nodes both want
237 *| a slot called "OuterTuple" so they both have to inherit
238 *| it from some other class. In this case they inherit
239 *| it from CommonState. "CommonState" and "CommonScanState" are
240 *| the best names I could come up with for this sort of
243 *| As a result, many classes have extra slots which they
244 *| don't use. These slots are denoted (unused) in the
245 *| comment preceeding the class definition. If you
246 *| comes up with a better idea of a way of doing things
247 *| along these lines, then feel free to make your idea
248 *| known to me.. -cim 10/15/89
252 /* ----------------------------------------------------------------
253 * Common Executor State Information
254 * ----------------------------------------------------------------
258 * CommonState information
260 * Superclass for all executor node-state object types.
262 * OuterTupleSlot pointer to slot containing current "outer" tuple
263 * ResultTupleSlot pointer to slot in tuple table for projected tuple
264 * ExprContext node's expression-evaluation context
265 * ProjInfo info this node uses to form tuple projections
266 * TupFromTlist state flag used by some node types (why kept here?)
269 typedef struct CommonState
271 NodeTag type; /* its first field is NodeTag */
272 TupleTableSlot *cs_OuterTupleSlot;
273 TupleTableSlot *cs_ResultTupleSlot;
274 ExprContext *cs_ExprContext;
275 ProjectionInfo *cs_ProjInfo;
276 bool cs_TupFromTlist;
280 /* ----------------------------------------------------------------
281 * Control Node State Information
282 * ----------------------------------------------------------------
286 * ResultState information
288 * done flag which tells us to quit when we
289 * have already returned a constant tuple.
292 typedef struct ResultState
294 CommonState cstate; /* its first field is NodeTag */
300 * AppendState information
302 * append nodes have this field "unionplans" which is this
303 * list of plans to execute in sequence.. these variables
304 * keep track of things..
306 * whichplan which plan is being executed
307 * nplans how many plans are in the list
308 * initialized array of ExecInitNode() results
309 * rtentries range table for the current plan
310 * result_relation_info_list array of each subplan's result relation info
311 * junkFilter_list array of each subplan's junk filter
314 typedef struct AppendState
316 CommonState cstate; /* its first field is NodeTag */
319 bool *as_initialized;
321 List *as_result_relation_info_list;
322 List *as_junkFilter_list;
325 /* ----------------------------------------------------------------
326 * Scan State Information
327 * ----------------------------------------------------------------
331 * CommonScanState information
333 * CommonScanState extends CommonState for node types that represent
334 * scans of an underlying relation. It can also be used for nodes
335 * that scan the output of an underlying plan node --- in that case,
336 * only ScanTupleSlot is actually useful, and it refers to the tuple
337 * retrieved from the subplan.
339 * currentRelation relation being scanned (NULL if none)
340 * currentScanDesc current scan descriptor for scan (NULL if none)
341 * ScanTupleSlot pointer to slot in tuple table holding scan tuple
344 typedef struct CommonScanState
346 CommonState cstate; /* its first field is NodeTag */
347 Relation css_currentRelation;
348 HeapScanDesc css_currentScanDesc;
349 TupleTableSlot *css_ScanTupleSlot;
353 * SeqScan uses a bare CommonScanState as its state item, since it needs
354 * no additional fields.
358 * IndexScanState information
360 * Note that an IndexScan node *also* has a CommonScanState state item.
361 * IndexScanState stores the info needed specifically for indexing.
362 * There's probably no good reason why this is a separate node type
363 * rather than an extension of CommonScanState.
365 * NumIndices number of indices in this scan
366 * IndexPtr current index in use
367 * ScanKeys Skey structures to scan index rels
368 * NumScanKeys array of no of keys in each Skey struct
369 * RuntimeKeyInfo array of array of flags for Skeys evaled at runtime
370 * RuntimeContext expr context for evaling runtime Skeys
371 * RelationDescs ptr to array of relation descriptors
372 * ScanDescs ptr to array of scan descriptors
375 typedef struct IndexScanState
380 int iss_MarkIndexPtr;
381 ScanKey *iss_ScanKeys;
382 int *iss_NumScanKeys;
383 int **iss_RuntimeKeyInfo;
384 ExprContext *iss_RuntimeContext;
385 RelationPtr iss_RelationDescs;
386 IndexScanDescPtr iss_ScanDescs;
387 HeapTupleData iss_htup;
391 * TidScanState information
393 * Note that a TidScan node *also* has a CommonScanState state item.
394 * There's probably no good reason why this is a separate node type
395 * rather than an extension of CommonScanState.
397 * NumTids number of tids in this scan
398 * TidPtr current tid in use
399 * TidList evaluated item pointers
402 typedef struct TidScanState
408 ItemPointer *tss_TidList;
409 HeapTupleData tss_htup;
412 /* ----------------------------------------------------------------
413 * Join State Information
414 * ----------------------------------------------------------------
418 * JoinState information
420 * Superclass for state items of join nodes.
421 * Currently this is the same as CommonState.
424 typedef CommonState JoinState;
427 * NestLoopState information
430 typedef struct NestLoopState
432 JoinState jstate; /* its first field is NodeTag */
436 * MergeJoinState information
438 * OuterSkipQual outerKey1 < innerKey1 ...
439 * InnerSkipQual outerKey1 > innerKey1 ...
440 * JoinState current "state" of join. see executor.h
441 * MarkedTupleSlot pointer to slot in tuple table for marked tuple
444 typedef struct MergeJoinState
446 JoinState jstate; /* its first field is NodeTag */
447 List *mj_OuterSkipQual;
448 List *mj_InnerSkipQual;
450 TupleTableSlot *mj_MarkedTupleSlot;
454 * HashJoinState information
456 * hj_HashTable hash table for the hashjoin
457 * hj_CurBucketNo bucket# for current outer tuple
458 * hj_CurTuple last inner tuple matched to current outer
459 * tuple, or NULL if starting search
460 * (CurBucketNo and CurTuple are meaningless
461 * unless OuterTupleSlot is nonempty!)
462 * hj_InnerHashKey the inner hash key in the hashjoin condition
463 * hj_OuterTupleSlot tuple slot for outer tuples
464 * hj_HashTupleSlot tuple slot for hashed tuples
467 typedef struct HashJoinState
469 JoinState jstate; /* its first field is NodeTag */
470 HashJoinTable hj_HashTable;
472 HashJoinTuple hj_CurTuple;
473 Node *hj_InnerHashKey;
474 TupleTableSlot *hj_OuterTupleSlot;
475 TupleTableSlot *hj_HashTupleSlot;
479 /* ----------------------------------------------------------------
480 * Materialization State Information
481 * ----------------------------------------------------------------
485 * MaterialState information
487 * materialize nodes are used to materialize the results
488 * of a subplan into a temporary file.
490 * csstate.css_ScanTupleSlot refers to output of underlying plan.
492 * tuplestorestate private state of tuplestore.c
495 typedef struct MaterialState
497 CommonScanState csstate; /* its first field is NodeTag */
498 void *tuplestorestate;
501 /* ---------------------
502 * AggregateState information
504 * csstate.css_ScanTupleSlot refers to output of underlying plan.
506 * Note: the associated ExprContext contains ecxt_aggvalues and ecxt_aggnulls
507 * arrays, which hold the computed agg values for the current input group
508 * during evaluation of an Agg node's output tuple(s).
509 * -------------------------
511 typedef struct AggStatePerAggData *AggStatePerAgg; /* private in nodeAgg.c */
513 typedef struct AggState
515 CommonScanState csstate; /* its first field is NodeTag */
516 List *aggs; /* all Aggref nodes in targetlist & quals */
517 int numaggs; /* length of list (could be zero!) */
518 AggStatePerAgg peragg; /* per-Aggref working state */
519 MemoryContext tup_cxt; /* context for per-output-tuple expressions */
520 MemoryContext agg_cxt[2]; /* pair of expression eval memory contexts */
521 int which_cxt; /* 0 or 1, indicates current agg_cxt */
522 bool agg_done; /* indicates completion of Agg scan */
525 /* ---------------------
526 * GroupState information
527 * -------------------------
529 typedef struct GroupState
531 CommonScanState csstate; /* its first field is NodeTag */
532 FmgrInfo *eqfunctions; /* per-field lookup data for equality fns */
533 bool grp_useFirstTuple; /* first tuple not processed yet */
535 HeapTuple grp_firstTuple;
539 * SortState information
541 * sort_Done indicates whether sort has been performed yet
542 * sort_Keys scan key structures describing the sort keys
543 * tuplesortstate private state of tuplesort.c
546 typedef struct SortState
548 CommonScanState csstate; /* its first field is NodeTag */
551 void *tuplesortstate;
555 * UniqueState information
557 * Unique nodes are used "on top of" sort nodes to discard
558 * duplicate tuples returned from the sort phase. Basically
559 * all it does is compare the current tuple from the subplan
560 * with the previously fetched tuple stored in priorTuple.
561 * If the two are identical in all interesting fields, then
562 * we just fetch another tuple from the sort and try again.
565 typedef struct UniqueState
567 CommonState cstate; /* its first field is NodeTag */
568 FmgrInfo *eqfunctions; /* per-field lookup data for equality fns */
569 HeapTuple priorTuple; /* most recently returned tuple, or NULL */
570 MemoryContext tempContext; /* short-term context for comparisons */
575 * HashState information
577 * hashtable hash table for the hashjoin
580 typedef struct HashState
582 CommonState cstate; /* its first field is NodeTag */
583 HashJoinTable hashtable;
587 /* -----------------------
588 * TeeState information
589 * leftPlace : next item in the queue unseen by the left parent
590 * rightPlace : next item in the queue unseen by the right parent
591 * lastPlace : last item in the queue
592 * bufferRelname : name of the relation used as the buffer queue
593 * bufferRel : the relation used as the buffer queue
594 * mcxt : for now, tee's have their own memory context
595 * may be cleaned up later if portals are cleaned up
597 * initially, a Tee starts with [left/right]Place variables set to -1.
598 * on cleanup, queue is free'd when both leftPlace and rightPlace = -1
599 * -------------------------
601 typedef struct TeeState
603 CommonState cstate; /* its first field is NodeTag */
607 char *tee_bufferRelname;
608 Relation tee_bufferRel;
609 MemoryContext tee_mcxt;
610 HeapScanDesc tee_leftScanDesc,
616 #endif /* EXECNODES_H */