1 /*-------------------------------------------------------------------------
4 * definitions for executor state nodes
7 * Copyright (c) 1994, Regents of the University of California
9 * $Id: execnodes.h,v 1.18 1998/09/01 04:36:35 momjian Exp $
11 *-------------------------------------------------------------------------
16 #include <nodes/memnodes.h>
17 #include <nodes/primnodes.h>
18 #include <executor/hashjoin.h>
19 #include <access/relscan.h>
20 #include <access/sdir.h>
21 #include <nodes/params.h>
22 #include <executor/tuptable.h>
23 #include <access/funcindex.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_values; /* precomputed values for aggreg */
93 char *ecxt_nulls; /* null flags for aggreg values */
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 Relation es_into_relation_descriptor;
203 ParamListInfo es_param_list_info;
204 ParamExecData *es_param_exec_vals; /* this is for subselects */
206 TupleTable es_tupleTable;
207 JunkFilter *es_junkFilter;
209 uint32 es_processed; /* # of tuples processed */
210 Oid es_lastoid; /* last oid processed (by INSERT) */
214 * Executor Type information needed by plannodes.h
216 *| Note: the bogus classes CommonState and CommonScanState exist only
217 *| because our inheritance system only allows single inheritance
218 *| and we have to have unique slot names. Hence two or more
219 *| classes which want to have a common slot must ALL inherit
220 *| the slot from some other class. (This is a big hack to
221 *| allow our classes to share slot names..)
224 *| the class Result and the class NestLoop nodes both want
225 *| a slot called "OuterTuple" so they both have to inherit
226 *| it from some other class. In this case they inherit
227 *| it from CommonState. "CommonState" and "CommonScanState" are
228 *| the best names I could come up with for this sort of
231 *| As a result, many classes have extra slots which they
232 *| don't use. These slots are denoted (unused) in the
233 *| comment preceeding the class definition. If you
234 *| comes up with a better idea of a way of doing things
235 *| along these lines, then feel free to make your idea
236 *| known to me.. -cim 10/15/89
240 /* ----------------------------------------------------------------
241 * Common Executor State Information
242 * ----------------------------------------------------------------
245 /* BaseNode removed -- base_id moved into CommonState - jolly */
248 * CommonState information
250 *| this is a bogus class used to hold slots so other
251 *| nodes can inherit them...
253 * OuterTupleSlot pointer to slot containing current "outer" tuple
254 * ResultTupleSlot pointer to slot in tuple table for projected tuple
255 * ExprContext node's current expression context
256 * ProjInfo info this node uses to form tuple projections
257 * NumScanAttributes size of ScanAttributes array
258 * ScanAttributes attribute numbers of interest in this tuple
262 typedef struct CommonState
264 NodeTag type; /* its first field is NodeTag */
266 TupleTableSlot *cs_OuterTupleSlot;
267 TupleTableSlot *cs_ResultTupleSlot;
268 ExprContext *cs_ExprContext;
269 ProjectionInfo *cs_ProjInfo;
270 bool cs_TupFromTlist;
274 /* ----------------------------------------------------------------
275 * Control Node State Information
276 * ----------------------------------------------------------------
280 * ResultState information
282 * done flag which tells us to quit when we
283 * have already returned a constant tuple.
285 * CommonState information
287 * OuterTupleSlot pointer to slot containing current "outer" tuple
288 * ResultTupleSlot pointer to slot in tuple table for projected tuple
289 * ExprContext node's current expression context
290 * ProjInfo info this node uses to form tuple projections
291 * NumScanAttributes size of ScanAttributes array
292 * ScanAttributes attribute numbers of interest in this tuple
295 typedef struct ResultState
297 CommonState cstate; /* its first field is NodeTag */
303 * AppendState information
305 * append nodes have this field "unionplans" which is this
306 * list of plans to execute in sequence.. these variables
307 * keep track of things..
309 * whichplan which plan is being executed
310 * nplans how many plans are in the list
311 * initialized array of ExecInitNode() results
312 * rtentries range table for the current plan
313 * result_relation_info_list array of each subplan's result relation info
314 * junkFilter_list array of each subplan's junk filter
316 * CommonState information
318 * OuterTupleSlot pointer to slot containing current "outer" tuple
319 * ResultTupleSlot pointer to slot in tuple table for projected tuple
320 * ExprContext node's current expression context
321 * ProjInfo info this node uses to form tuple projections
322 * NumScanAttributes size of ScanAttributes array
323 * ScanAttributes attribute numbers of interest in this tuple
326 typedef struct AppendState
328 CommonState cstate; /* its first field is NodeTag */
331 bool *as_initialized;
333 List *as_result_relation_info_list;
334 List *as_junkFilter_list;
337 /* ----------------------------------------------------------------
338 * Scan State Information
339 * ----------------------------------------------------------------
343 * CommonScanState information
345 * CommonScanState is a class like CommonState, but is used more
346 * by the nodes like SeqScan and Sort which want to
347 * keep track of an underlying relation.
349 * currentRelation relation being scanned
350 * currentScanDesc current scan descriptor for scan
351 * ScanTupleSlot pointer to slot in tuple table holding scan tuple
353 * CommonState information
355 * OuterTupleSlot pointer to slot containing current "outer" tuple
356 * ResultTupleSlot pointer to slot in tuple table for projected tuple
357 * ExprContext node's current expression context
358 * ProjInfo info this node uses to form tuple projections
359 * NumScanAttributes size of ScanAttributes array
360 * ScanAttributes attribute numbers of interest in this tuple
363 typedef struct CommonScanState
365 CommonState cstate; /* its first field is NodeTag */
366 Relation css_currentRelation;
367 HeapScanDesc css_currentScanDesc;
368 TupleTableSlot *css_ScanTupleSlot;
372 * IndexScanState information
374 *| index scans don't use CommonScanState because
375 *| the underlying AM abstractions for heap scans and
376 *| index scans are too different.. It would be nice
377 *| if the current abstraction was more useful but ... -cim 10/15/89
379 * IndexPtr current index in use
380 * NumIndices number of indices in this scan
381 * ScanKeys Skey structures to scan index rels
382 * NumScanKeys array of no of keys in each Skey struct
383 * RuntimeKeyInfo array of array of flags for Skeys evaled at runtime
384 * RelationDescs ptr to array of relation descriptors
385 * ScanDescs ptr to array of scan descriptors
387 * CommonState information
389 * OuterTupleSlot pointer to slot containing current "outer" tuple
390 * ResultTupleSlot pointer to slot in tuple table for projected tuple
391 * ExprContext node's current expression context
392 * ProjInfo info this node uses to form tuple projections
393 * NumScanAttributes size of ScanAttributes array
394 * ScanAttributes attribute numbers of interest in this tuple
397 typedef struct IndexScanState
399 CommonState cstate; /* its first field is NodeTag */
402 int iss_MarkIndexPtr;
403 ScanKey *iss_ScanKeys;
404 int *iss_NumScanKeys;
405 Pointer iss_RuntimeKeyInfo;
406 RelationPtr iss_RelationDescs;
407 IndexScanDescPtr iss_ScanDescs;
411 /* ----------------------------------------------------------------
412 * Join State Information
413 * ----------------------------------------------------------------
417 * JoinState information
419 * CommonState information
421 * OuterTupleSlot pointer to slot containing current "outer" tuple
422 * ResultTupleSlot pointer to slot in tuple table for projected tuple
423 * ExprContext node's current expression context
424 * ProjInfo info this node uses to form tuple projections
425 * NumScanAttributes size of ScanAttributes array
426 * ScanAttributes attribute numbers of interest in this tuple
429 typedef CommonState JoinState;
432 * NestLoopState information
434 * PortalFlag Set to enable portals to work.
436 * JoinState information
438 * CommonState information
440 * OuterTupleSlot pointer to slot containing current "outer" tuple
441 * ResultTupleSlot pointer to slot in tuple table for projected tuple
442 * ExprContext node's current expression context
443 * ProjInfo info this node uses to form tuple projections
444 * NumScanAttributes size of ScanAttributes array
445 * ScanAttributes attribute numbers of interest in this tuple
448 typedef struct NestLoopState
450 JoinState jstate; /* its first field is NodeTag */
455 * MergeJoinState information
457 * OSortopI outerKey1 sortOp innerKey1 ...
458 * ISortopO innerkey1 sortOp outerkey1 ...
459 * JoinState current "state" of join. see executor.h
460 * MarkedTupleSlot pointer to slot in tuple table for marked tuple
462 * JoinState information
464 * CommonState information
466 * OuterTupleSlot pointer to slot containing current "outer" tuple
467 * ResultTupleSlot pointer to slot in tuple table for projected tuple
468 * ExprContext node's current expression context
469 * ProjInfo info this node uses to form tuple projections
470 * NumScanAttributes size of ScanAttributes array
471 * ScanAttributes attribute numbers of interest in this tuple
474 typedef struct MergeJoinState
476 JoinState jstate; /* its first field is NodeTag */
480 TupleTableSlot *mj_MarkedTupleSlot;
484 * HashJoinState information
486 * hj_HashTable address of the hash table for the hashjoin
487 * hj_HashTableShmId shared memory id of hash table
488 * hj_CurBucket the current hash bucket that we are searching
489 * for matches of the current outer tuple
490 * hj_CurTuple the current matching inner tuple in the
491 * current hash bucket
492 * hj_CurOTuple the current matching inner tuple in the
493 * current hash overflow chain
494 * hj_InnerHashKey the inner hash key in the hashjoin condition
495 * hj_OuterBatches file descriptors for outer batches
496 * hj_InnerBatches file descriptors for inner batches
497 * hj_OuterReadPos current read position of outer batch
498 * hj_OuterReadBlk current read block of outer batch
499 * hj_OuterTupleSlot tuple slot for outer tuples
500 * hj_HashTupleSlot tuple slot for hashed tuples
504 * JoinState information
506 * CommonState information
508 * OuterTupleSlot pointer to slot containing current "outer" tuple
509 * ResultTupleSlot pointer to slot in tuple table for projected tuple
510 * ExprContext node's current expression context
511 * ProjInfo info this node uses to form tuple projections
512 * NumScanAttributes size of ScanAttributes array
513 * ScanAttributes attribute numbers of interest in this tuple
516 typedef struct HashJoinState
518 JoinState jstate; /* its first field is NodeTag */
519 HashJoinTable hj_HashTable;
520 IpcMemoryId hj_HashTableShmId;
521 HashBucket hj_CurBucket;
522 HeapTuple hj_CurTuple;
523 OverflowTuple hj_CurOTuple;
524 Var *hj_InnerHashKey;
525 File *hj_OuterBatches;
526 File *hj_InnerBatches;
527 char *hj_OuterReadPos;
529 TupleTableSlot *hj_OuterTupleSlot;
530 TupleTableSlot *hj_HashTupleSlot;
534 /* ----------------------------------------------------------------
535 * Materialization State Information
536 * ----------------------------------------------------------------
540 * MaterialState information
542 * materialize nodes are used to materialize the results
543 * of a subplan into a temporary relation.
545 * Flag indicated whether subplan has been materialized
546 * TempRelation temporary relation containing result of executing
549 * CommonScanState information
551 * currentRelation relation descriptor of sorted relation
552 * currentScanDesc current scan descriptor for scan
553 * ScanTupleSlot pointer to slot in tuple table holding scan tuple
555 * CommonState information
557 * OuterTupleSlot pointer to slot containing current "outer" tuple
558 * ResultTupleSlot pointer to slot in tuple table for projected tuple
559 * ExprContext node's current expression context
560 * ProjInfo info this node uses to form tuple projections
561 * NumScanAttributes size of ScanAttributes array
562 * ScanAttributes attribute numbers of interest in this tuple
565 typedef struct MaterialState
567 CommonScanState csstate; /* its first field is NodeTag */
569 Relation mat_TempRelation;
572 /* ---------------------
573 * AggregateState information
575 * done indicated whether aggregate has been materialized
576 * -------------------------
578 typedef struct AggState
580 CommonScanState csstate; /* its first field is NodeTag */
584 /* ---------------------
585 * GroupState information
587 * -------------------------
589 typedef struct GroupState
591 CommonScanState csstate; /* its first field is NodeTag */
592 bool grp_useFirstTuple; /* first tuple not processed yet */
594 HeapTuple grp_firstTuple;
598 * SortState information
600 *| sort nodes are really just a kind of a scan since
601 *| we implement sorts by retrieveing the entire subplan
602 *| into a temp relation, sorting the temp relation into
603 *| another sorted relation, and then preforming a simple
604 *| unqualified sequential scan on the sorted relation..
607 * Flag indicated whether relation has been sorted
608 * Keys scan key structures used to keep info on sort keys
609 * TempRelation temporary relation containing result of executing
612 * CommonScanState information
614 * currentRelation relation descriptor of sorted relation
615 * currentScanDesc current scan descriptor for scan
616 * ScanTupleSlot pointer to slot in tuple table holding scan tuple
618 * CommonState information
620 * OuterTupleSlot pointer to slot containing current "outer" tuple
621 * ResultTupleSlot pointer to slot in tuple table for projected tuple
622 * ExprContext node's current expression context
623 * ProjInfo info this node uses to form tuple projections
624 * NumScanAttributes size of ScanAttributes array
625 * ScanAttributes attribute numbers of interest in this tuple
628 typedef struct SortState
630 CommonScanState csstate; /* its first field is NodeTag */
637 * UniqueState information
639 * Unique nodes are used "on top of" sort nodes to discard
640 * duplicate tuples returned from the sort phase. Basically
641 * all it does is compare the current tuple from the subplan
642 * with the previously fetched tuple stored in OuterTuple and
643 * if the two are identical, then we just fetch another tuple
644 * from the sort and try again.
646 * CommonState information
648 * OuterTupleSlot pointer to slot containing current "outer" tuple
649 * ResultTupleSlot pointer to slot in tuple table for projected tuple
650 * ExprContext node's current expression context
651 * ProjInfo info this node uses to form tuple projections
652 * NumScanAttributes size of ScanAttributes array
653 * ScanAttributes attribute numbers of interest in this tuple
656 typedef CommonState UniqueState;
660 * HashState information
662 * hashBatches file descriptors for the batches
664 * CommonState information
666 * OuterTupleSlot pointer to slot containing current "outer" tuple
667 * ResultTupleSlot pointer to slot in tuple table for projected tuple
668 * ExprContext node's current expression context
669 * ProjInfo info this node uses to form tuple projections
670 * NumScanAttributes size of ScanAttributes array
671 * ScanAttributes attribute numbers of interest in this tuple
674 typedef struct HashState
676 CommonState cstate; /* its first field is NodeTag */
680 /* -----------------------
681 * TeeState information
682 * leftPlace : next item in the queue unseen by the left parent
683 * rightPlace : next item in the queue unseen by the right parent
684 * lastPlace : last item in the queue
685 * bufferRelname : name of the relation used as the buffer queue
686 * bufferRel : the relation used as the buffer queue
687 * mcxt : for now, tee's have their own memory context
688 * may be cleaned up later if portals are cleaned up
690 * initially, a Tee starts with [left/right]Place variables set to -1.
691 * on cleanup, queue is free'd when both leftPlace and rightPlace = -1
692 * -------------------------
694 typedef struct TeeState
696 CommonState cstate; /* its first field is NodeTag */
700 char *tee_bufferRelname;
701 Relation tee_bufferRel;
702 MemoryContext tee_mcxt;
703 HeapScanDesc tee_leftScanDesc;
704 HeapScanDesc tee_rightScanDesc;
707 #endif /* EXECNODES_H */