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.39 2000/01/26 05:58:15 momjian 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
81 typedef struct ExprContext
84 TupleTableSlot *ecxt_scantuple;
85 TupleTableSlot *ecxt_innertuple;
86 TupleTableSlot *ecxt_outertuple;
87 Relation ecxt_relation;
89 ParamListInfo ecxt_param_list_info;
90 ParamExecData *ecxt_param_exec_vals; /* this is for subselects */
91 List *ecxt_range_table;
92 Datum *ecxt_aggvalues; /* precomputed values for Aggref nodes */
93 bool *ecxt_aggnulls; /* null flags for Aggref nodes */
97 * ProjectionInfo node information
99 * This is all the information needed to preform projections
100 * on a tuple. Nodes which need to do projections create one
101 * of these. In theory, when a node wants to preform a projection
102 * it should just update this information as necessary and then
103 * call ExecProject(). -cim 6/3/91
105 * targetlist target list for projection
106 * len length of target list
107 * tupValue array of pointers to projection results
108 * exprContext expression context for ExecTargetList
109 * slot slot to place projection result in
112 typedef struct ProjectionInfo
118 ExprContext *pi_exprContext;
119 TupleTableSlot *pi_slot;
125 * this class is used to store information regarding junk attributes.
126 * A junk attribute is an attribute in a tuple that is needed only for
127 * storing intermediate information in the executor, and does not belong
128 * in the tuple proper. For example, when we do a delete or replace
129 * query, the planner adds an entry to the targetlist so that the tuples
130 * returned to ExecutePlan() contain an extra attribute: the t_ctid of
131 * the tuple to be deleted/replaced. This is needed for amdelete() and
132 * amreplace(). In doing a delete this does not make much of a
133 * difference, but in doing a replace we have to make sure we disgard
134 * all the junk in a tuple before calling amreplace(). Otherwise the
135 * inserted tuple will not have the correct schema. This solves a
136 * problem with hash-join and merge-sort replace plans. -cim 10/10/90
138 * targetList: the original target list (including junk attributes).
139 * length: the length of 'targetList'.
140 * tupType: the tuple descriptor for the "original" tuple
141 * (including the junk attributes).
142 * cleanTargetList: the "clean" target list (junk attributes removed).
143 * cleanLength: the length of 'cleanTargetList'
144 * cleanTupTyp: the tuple descriptor of the "clean" tuple (with
145 * junk attributes removed).
146 * cleanMap: A map with the correspondance between the non junk
147 * attributes of the "original" tuple and the
148 * attributes of the "clean" tuple.
151 typedef struct JunkFilter
156 TupleDesc jf_tupType;
157 List *jf_cleanTargetList;
159 TupleDesc jf_cleanTupType;
160 AttrNumber *jf_cleanMap;
166 * direction direction of the scan
168 * range_table array of scan relation information
170 * result_relation_information for update queries
172 * into_relation_descriptor relation being retrieved "into"
174 * param_list_info information needed to transform
175 * Param nodes into Const nodes
177 * BaseId during InitPlan(), each node is
178 * given a number. this is the next
179 * number to be assigned.
181 * tupleTable this is a pointer to an array
182 * of pointers to tuples used by
183 * the executor at any given moment.
185 * junkFilter contains information used to
186 * extract junk attributes from a tuple.
187 * (see JunkFilter above)
189 * refcount local buffer refcounts used in
190 * an ExecMain cycle. this is introduced
191 * to avoid ExecStart's unpinning each
192 * other's buffers when called recursively
195 typedef struct EState
198 ScanDirection es_direction;
199 Snapshot es_snapshot;
200 List *es_range_table;
201 RelationInfo *es_result_relation_info;
202 List **es_result_relation_constraints;
203 Relation es_into_relation_descriptor;
204 ParamListInfo es_param_list_info;
205 ParamExecData *es_param_exec_vals; /* this is for subselects */
207 TupleTable es_tupleTable;
208 JunkFilter *es_junkFilter;
209 uint32 es_processed; /* # of tuples processed */
210 Oid es_lastoid; /* last oid processed (by INSERT) */
211 List *es_rowMark; /* not good place, but there is no other */
212 /* Below is to re-evaluate plan qual in READ COMMITTED mode */
213 struct Plan *es_origPlan;
214 Pointer es_evalPlanQual;
215 bool *es_evTupleNull;
216 HeapTuple *es_evTuple;
221 * Executor Type information needed by plannodes.h
223 *| Note: the bogus classes CommonState and CommonScanState exist only
224 *| because our inheritance system only allows single inheritance
225 *| and we have to have unique slot names. Hence two or more
226 *| classes which want to have a common slot must ALL inherit
227 *| the slot from some other class. (This is a big hack to
228 *| allow our classes to share slot names..)
231 *| the class Result and the class NestLoop nodes both want
232 *| a slot called "OuterTuple" so they both have to inherit
233 *| it from some other class. In this case they inherit
234 *| it from CommonState. "CommonState" and "CommonScanState" are
235 *| the best names I could come up with for this sort of
238 *| As a result, many classes have extra slots which they
239 *| don't use. These slots are denoted (unused) in the
240 *| comment preceeding the class definition. If you
241 *| comes up with a better idea of a way of doing things
242 *| along these lines, then feel free to make your idea
243 *| known to me.. -cim 10/15/89
247 /* ----------------------------------------------------------------
248 * Common Executor State Information
249 * ----------------------------------------------------------------
252 /* BaseNode removed -- base_id moved into CommonState - jolly */
255 * CommonState information
257 *| this is a bogus class used to hold slots so other
258 *| nodes can inherit them...
260 * OuterTupleSlot pointer to slot containing current "outer" tuple
261 * ResultTupleSlot pointer to slot in tuple table for projected tuple
262 * ExprContext node's current expression context
263 * ProjInfo info this node uses to form tuple projections
264 * NumScanAttributes size of ScanAttributes array
265 * ScanAttributes attribute numbers of interest in this tuple
269 typedef struct CommonState
271 NodeTag type; /* its first field is NodeTag */
273 TupleTableSlot *cs_OuterTupleSlot;
274 TupleTableSlot *cs_ResultTupleSlot;
275 ExprContext *cs_ExprContext;
276 ProjectionInfo *cs_ProjInfo;
277 bool cs_TupFromTlist;
281 /* ----------------------------------------------------------------
282 * Control Node State Information
283 * ----------------------------------------------------------------
287 * ResultState information
289 * done flag which tells us to quit when we
290 * have already returned a constant tuple.
292 * CommonState information
294 * OuterTupleSlot pointer to slot containing current "outer" tuple
295 * ResultTupleSlot pointer to slot in tuple table for projected tuple
296 * ExprContext node's current expression context
297 * ProjInfo info this node uses to form tuple projections
298 * NumScanAttributes size of ScanAttributes array
299 * ScanAttributes attribute numbers of interest in this tuple
302 typedef struct ResultState
304 CommonState cstate; /* its first field is NodeTag */
310 * AppendState information
312 * append nodes have this field "unionplans" which is this
313 * list of plans to execute in sequence.. these variables
314 * keep track of things..
316 * whichplan which plan is being executed
317 * nplans how many plans are in the list
318 * initialized array of ExecInitNode() results
319 * rtentries range table for the current plan
320 * result_relation_info_list array of each subplan's result relation info
321 * junkFilter_list array of each subplan's junk filter
323 * CommonState information
325 * OuterTupleSlot pointer to slot containing current "outer" tuple
326 * ResultTupleSlot pointer to slot in tuple table for projected tuple
327 * ExprContext node's current expression context
328 * ProjInfo info this node uses to form tuple projections
329 * NumScanAttributes size of ScanAttributes array
330 * ScanAttributes attribute numbers of interest in this tuple
333 typedef struct AppendState
335 CommonState cstate; /* its first field is NodeTag */
338 bool *as_initialized;
340 List *as_result_relation_info_list;
341 List *as_junkFilter_list;
344 /* ----------------------------------------------------------------
345 * Scan State Information
346 * ----------------------------------------------------------------
350 * CommonScanState information
352 * CommonScanState is a class like CommonState, but is used more
353 * by the nodes like SeqScan and Sort which want to
354 * keep track of an underlying relation.
356 * currentRelation relation being scanned
357 * currentScanDesc current scan descriptor for scan
358 * ScanTupleSlot pointer to slot in tuple table holding scan tuple
360 * CommonState information
362 * OuterTupleSlot pointer to slot containing current "outer" tuple
363 * ResultTupleSlot pointer to slot in tuple table for projected tuple
364 * ExprContext node's current expression context
365 * ProjInfo info this node uses to form tuple projections
366 * NumScanAttributes size of ScanAttributes array
367 * ScanAttributes attribute numbers of interest in this tuple
370 typedef struct CommonScanState
372 CommonState cstate; /* its first field is NodeTag */
373 Relation css_currentRelation;
374 HeapScanDesc css_currentScanDesc;
375 TupleTableSlot *css_ScanTupleSlot;
379 * IndexScanState information
381 *| index scans don't use CommonScanState because
382 *| the underlying AM abstractions for heap scans and
383 *| index scans are too different.. It would be nice
384 *| if the current abstraction was more useful but ... -cim 10/15/89
386 * IndexPtr current index in use
387 * NumIndices number of indices in this scan
388 * ScanKeys Skey structures to scan index rels
389 * NumScanKeys array of no of keys in each Skey struct
390 * RuntimeKeyInfo array of array of flags for Skeys evaled at runtime
391 * RelationDescs ptr to array of relation descriptors
392 * ScanDescs ptr to array of scan descriptors
394 * CommonState information
396 * OuterTupleSlot pointer to slot containing current "outer" tuple
397 * ResultTupleSlot pointer to slot in tuple table for projected tuple
398 * ExprContext node's current expression context
399 * ProjInfo info this node uses to form tuple projections
400 * NumScanAttributes size of ScanAttributes array
401 * ScanAttributes attribute numbers of interest in this tuple
404 typedef struct IndexScanState
406 CommonState cstate; /* its first field is NodeTag */
409 int iss_MarkIndexPtr;
410 ScanKey *iss_ScanKeys;
411 int *iss_NumScanKeys;
412 Pointer iss_RuntimeKeyInfo;
413 RelationPtr iss_RelationDescs;
414 IndexScanDescPtr iss_ScanDescs;
415 HeapTupleData iss_htup;
419 * TidScanState information
421 *| tid scans don't use CommonScanState because
422 *| the underlying AM abstractions for heap scans and
423 *| tid scans are too different.. It would be nice
424 *| if the current abstraction was more useful but ... -cim 10/15/89
426 * TidPtr current tid in use
427 * NumTids number of tids in this scan
428 * tidList evaluated item pointers
430 * CommonState information
432 * OuterTupleSlot pointer to slot containing current "outer" tuple
433 * ResultTupleSlot pointer to slot in tuple table for projected tuple
434 * ExprContext node's current expression context
435 * ProjInfo info this node uses to form tuple projections
436 * NumScanAttributes size of ScanAttributes array
437 * ScanAttributes attribute numbers of interest in this tuple
440 typedef struct TidScanState
442 CommonState cstate; /* its first field is NodeTag */
446 ItemPointer *tss_TidList;
447 HeapTupleData tss_htup;
450 /* ----------------------------------------------------------------
451 * Join State Information
452 * ----------------------------------------------------------------
456 * JoinState information
458 * CommonState information
460 * OuterTupleSlot pointer to slot containing current "outer" tuple
461 * ResultTupleSlot pointer to slot in tuple table for projected tuple
462 * ExprContext node's current expression context
463 * ProjInfo info this node uses to form tuple projections
464 * NumScanAttributes size of ScanAttributes array
465 * ScanAttributes attribute numbers of interest in this tuple
468 typedef CommonState JoinState;
471 * NestLoopState information
473 * PortalFlag Set to enable portals to work.
475 * JoinState information
477 * CommonState information
479 * OuterTupleSlot pointer to slot containing current "outer" tuple
480 * ResultTupleSlot pointer to slot in tuple table for projected tuple
481 * ExprContext node's current expression context
482 * ProjInfo info this node uses to form tuple projections
483 * NumScanAttributes size of ScanAttributes array
484 * ScanAttributes attribute numbers of interest in this tuple
487 typedef struct NestLoopState
489 JoinState jstate; /* its first field is NodeTag */
494 * MergeJoinState information
496 * OuterSkipQual outerKey1 < innerKey1 ...
497 * InnerSkipQual outerKey1 > innerKey1 ...
498 * JoinState current "state" of join. see executor.h
499 * MarkedTupleSlot pointer to slot in tuple table for marked tuple
501 * JoinState information
503 * CommonState information
505 * OuterTupleSlot pointer to slot containing current "outer" tuple
506 * ResultTupleSlot pointer to slot in tuple table for projected tuple
507 * ExprContext node's current expression context
508 * ProjInfo info this node uses to form tuple projections
509 * NumScanAttributes size of ScanAttributes array
510 * ScanAttributes attribute numbers of interest in this tuple
513 typedef struct MergeJoinState
515 JoinState jstate; /* its first field is NodeTag */
516 List *mj_OuterSkipQual;
517 List *mj_InnerSkipQual;
519 TupleTableSlot *mj_MarkedTupleSlot;
523 * HashJoinState information
525 * hj_HashTable hash table for the hashjoin
526 * hj_CurBucketNo bucket# for current outer tuple
527 * hj_CurTuple last inner tuple matched to current outer
528 * tuple, or NULL if starting search
529 * (CurBucketNo and CurTuple are meaningless
530 * unless OuterTupleSlot is nonempty!)
531 * hj_InnerHashKey the inner hash key in the hashjoin condition
532 * hj_OuterTupleSlot tuple slot for outer tuples
533 * hj_HashTupleSlot tuple slot for hashed tuples
535 * JoinState information
537 * CommonState information
539 * OuterTupleSlot pointer to slot containing current "outer" tuple
540 * ResultTupleSlot pointer to slot in tuple table for projected tuple
541 * ExprContext node's current expression context
542 * ProjInfo info this node uses to form tuple projections
543 * NumScanAttributes size of ScanAttributes array
544 * ScanAttributes attribute numbers of interest in this tuple
547 typedef struct HashJoinState
549 JoinState jstate; /* its first field is NodeTag */
550 HashJoinTable hj_HashTable;
552 HashJoinTuple hj_CurTuple;
553 Var *hj_InnerHashKey;
554 TupleTableSlot *hj_OuterTupleSlot;
555 TupleTableSlot *hj_HashTupleSlot;
559 /* ----------------------------------------------------------------
560 * Materialization State Information
561 * ----------------------------------------------------------------
565 * MaterialState information
567 * materialize nodes are used to materialize the results
568 * of a subplan into a temporary relation.
570 * Flag indicated whether subplan has been materialized
571 * TempRelation temporary relation containing result of executing
574 * CommonScanState information
576 * currentRelation relation descriptor of sorted relation
577 * currentScanDesc current scan descriptor for scan
578 * ScanTupleSlot pointer to slot in tuple table holding scan tuple
580 * CommonState information
582 * OuterTupleSlot pointer to slot containing current "outer" tuple
583 * ResultTupleSlot pointer to slot in tuple table for projected tuple
584 * ExprContext node's current expression context
585 * ProjInfo info this node uses to form tuple projections
586 * NumScanAttributes size of ScanAttributes array
587 * ScanAttributes attribute numbers of interest in this tuple
590 typedef struct MaterialState
592 CommonScanState csstate; /* its first field is NodeTag */
594 Relation mat_TempRelation;
597 /* ---------------------
598 * AggregateState information
600 * Note: the associated ExprContext contains ecxt_aggvalues and ecxt_aggnulls
601 * arrays, which hold the computed agg values for the current input group
602 * during evaluation of an Agg node's output tuple(s).
603 * -------------------------
605 typedef struct AggStatePerAggData *AggStatePerAgg; /* private in nodeAgg.c */
607 typedef struct AggState
609 CommonScanState csstate; /* its first field is NodeTag */
610 List *aggs; /* all Aggref nodes in targetlist & quals */
611 int numaggs; /* length of list (could be zero!) */
612 AggStatePerAgg peragg; /* per-Aggref working state */
613 bool agg_done; /* indicates completion of Agg scan */
616 /* ---------------------
617 * GroupState information
619 * -------------------------
621 typedef struct GroupState
623 CommonScanState csstate; /* its first field is NodeTag */
624 bool grp_useFirstTuple; /* first tuple not processed yet */
626 HeapTuple grp_firstTuple;
630 * SortState information
632 * sort_Done indicates whether sort has been performed yet
633 * sort_Keys scan key structures describing the sort keys
634 * tuplesortstate private state of tuplesort.c
636 * CommonScanState information
638 * currentRelation relation descriptor of sorted relation
639 * currentScanDesc current scan descriptor for scan
640 * ScanTupleSlot pointer to slot in tuple table holding scan tuple
642 * CommonState information
644 * OuterTupleSlot pointer to slot containing current "outer" tuple
645 * ResultTupleSlot pointer to slot in tuple table for projected tuple
646 * ExprContext node's current expression context
647 * ProjInfo info this node uses to form tuple projections
648 * NumScanAttributes size of ScanAttributes array
649 * ScanAttributes attribute numbers of interest in this tuple
652 typedef struct SortState
654 CommonScanState csstate; /* its first field is NodeTag */
657 void *tuplesortstate;
661 * UniqueState information
663 * Unique nodes are used "on top of" sort nodes to discard
664 * duplicate tuples returned from the sort phase. Basically
665 * all it does is compare the current tuple from the subplan
666 * with the previously fetched tuple stored in OuterTuple and
667 * if the two are identical, then we just fetch another tuple
668 * from the sort and try again.
670 * CommonState information
672 * OuterTupleSlot pointer to slot containing current "outer" tuple
673 * ResultTupleSlot pointer to slot in tuple table for projected tuple
674 * ExprContext node's current expression context
675 * ProjInfo info this node uses to form tuple projections
676 * NumScanAttributes size of ScanAttributes array
677 * ScanAttributes attribute numbers of interest in this tuple
680 typedef CommonState UniqueState;
684 * HashState information
686 * hashtable hash table for the hashjoin
688 * CommonState information
690 * OuterTupleSlot pointer to slot containing current "outer" tuple
691 * ResultTupleSlot pointer to slot in tuple table for projected tuple
692 * ExprContext node's current expression context
693 * ProjInfo info this node uses to form tuple projections
694 * NumScanAttributes size of ScanAttributes array
695 * ScanAttributes attribute numbers of interest in this tuple
698 typedef struct HashState
700 CommonState cstate; /* its first field is NodeTag */
701 HashJoinTable hashtable;
705 /* -----------------------
706 * TeeState information
707 * leftPlace : next item in the queue unseen by the left parent
708 * rightPlace : next item in the queue unseen by the right parent
709 * lastPlace : last item in the queue
710 * bufferRelname : name of the relation used as the buffer queue
711 * bufferRel : the relation used as the buffer queue
712 * mcxt : for now, tee's have their own memory context
713 * may be cleaned up later if portals are cleaned up
715 * initially, a Tee starts with [left/right]Place variables set to -1.
716 * on cleanup, queue is free'd when both leftPlace and rightPlace = -1
717 * -------------------------
719 typedef struct TeeState
721 CommonState cstate; /* its first field is NodeTag */
725 char *tee_bufferRelname;
726 Relation tee_bufferRel;
727 MemoryContext tee_mcxt;
728 HeapScanDesc tee_leftScanDesc,
734 #endif /* EXECNODES_H */