1 /*-------------------------------------------------------------------------
4 * definitions for executor state nodes
7 * Copyright (c) 1994, Regents of the University of California
9 * $Id: execnodes.h,v 1.6 1996/11/04 08:52:54 scrappy 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 {
38 int ii_NumKeyAttributes;
39 AttrNumber *ii_KeyAttributeNumbers;
40 FuncIndexInfoPtr ii_FuncIndexInfo;
45 * RelationInfo information
47 * whenever we update an existing relation, we have to
48 * update indices on the relation. The RelationInfo class
49 * is used to hold all the information on result relations,
50 * including indices.. -cim 10/15/89
52 * RangeTableIndex result relation's range table index
53 * RelationDesc relation descriptor for result relation
54 * NumIndices number indices existing on result relation
55 * IndexRelationDescs array of relation descriptors for indices
56 * IndexRelationInfo array of key/attr info for indices
59 typedef struct RelationInfo {
61 Index ri_RangeTableIndex;
62 Relation ri_RelationDesc;
64 RelationPtr ri_IndexRelationDescs;
65 IndexInfo **ri_IndexRelationInfo;
71 * This class holds the "current context" information
72 * needed to evaluate expressions for doing tuple qualifications
73 * and tuple projections. For example, if an expression refers
74 * to an attribute in the current inner tuple then we need to know
75 * what the current inner tuple is and so we look at the expression
79 typedef struct ExprContext {
81 TupleTableSlot *ecxt_scantuple;
82 TupleTableSlot *ecxt_innertuple;
83 TupleTableSlot *ecxt_outertuple;
84 Relation ecxt_relation;
86 ParamListInfo ecxt_param_list_info;
87 List *ecxt_range_table;
88 Datum *ecxt_values; /* precomputed values for aggreg */
89 char *ecxt_nulls; /* null flags for aggreg values */
93 * ProjectionInfo node information
95 * This is all the information needed to preform projections
96 * on a tuple. Nodes which need to do projections create one
97 * of these. In theory, when a node wants to preform a projection
98 * it should just update this information as necessary and then
99 * call ExecProject(). -cim 6/3/91
101 * targetlist target list for projection
102 * len length of target list
103 * tupValue array of pointers to projection results
104 * exprContext expression context for ExecTargetList
105 * slot slot to place projection result in
108 typedef struct ProjectionInfo {
113 ExprContext *pi_exprContext;
114 TupleTableSlot *pi_slot;
120 * this class is used to store information regarding junk attributes.
121 * A junk attribute is an attribute in a tuple that is needed only for
122 * storing intermediate information in the executor, and does not belong
123 * in the tuple proper. For example, when we do a delete or replace
124 * query, the planner adds an entry to the targetlist so that the tuples
125 * returned to ExecutePlan() contain an extra attribute: the t_ctid of
126 * the tuple to be deleted/replaced. This is needed for amdelete() and
127 * amreplace(). In doing a delete this does not make much of a
128 * difference, but in doing a replace we have to make sure we disgard
129 * all the junk in a tuple before calling amreplace(). Otherwise the
130 * inserted tuple will not have the correct schema. This solves a
131 * problem with hash-join and merge-sort replace plans. -cim 10/10/90
133 * targetList: the original target list (including junk attributes).
134 * length: the length of 'targetList'.
135 * tupType: the tuple descriptor for the "original" tuple
136 * (including the junk attributes).
137 * cleanTargetList: the "clean" target list (junk attributes removed).
138 * cleanLength: the length of 'cleanTargetList'
139 * cleanTupTyp: the tuple descriptor of the "clean" tuple (with
140 * junk attributes removed).
141 * cleanMap: A map with the correspondance between the non junk
142 * attributes of the "original" tuple and the
143 * attributes of the "clean" tuple.
146 typedef struct JunkFilter {
150 TupleDesc jf_tupType;
151 List *jf_cleanTargetList;
153 TupleDesc jf_cleanTupType;
154 AttrNumber *jf_cleanMap;
160 * direction direction of the scan
162 * range_table array of scan relation information
164 * result_relation_information for update queries
166 * into_relation_descriptor relation being retrieved "into"
168 * param_list_info information needed to transform
169 * Param nodes into Const nodes
171 * BaseId during InitPlan(), each node is
172 * given a number. this is the next
173 * number to be assigned.
175 * tupleTable this is a pointer to an array
176 * of pointers to tuples used by
177 * the executor at any given moment.
179 * junkFilter contains information used to
180 * extract junk attributes from a tuple.
181 * (see JunkFilter above)
183 * refcount local buffer refcounts used in
184 * an ExecMain cycle. this is introduced
185 * to avoid ExecStart's unpinning each
186 * other's buffers when called recursively
189 typedef struct EState {
191 ScanDirection es_direction;
192 List *es_range_table;
193 RelationInfo *es_result_relation_info;
194 Relation es_into_relation_descriptor;
195 ParamListInfo es_param_list_info;
197 TupleTable es_tupleTable;
198 JunkFilter *es_junkFilter;
203 * Executor Type information needed by plannodes.h
205 *| Note: the bogus classes CommonState and CommonScanState exist only
206 *| because our inheritance system only allows single inheritance
207 *| and we have to have unique slot names. Hence two or more
208 *| classes which want to have a common slot must ALL inherit
209 *| the slot from some other class. (This is a big hack to
210 *| allow our classes to share slot names..)
213 *| the class Result and the class NestLoop nodes both want
214 *| a slot called "OuterTuple" so they both have to inherit
215 *| it from some other class. In this case they inherit
216 *| it from CommonState. "CommonState" and "CommonScanState" are
217 *| the best names I could come up with for this sort of
220 *| As a result, many classes have extra slots which they
221 *| don't use. These slots are denoted (unused) in the
222 *| comment preceeding the class definition. If you
223 *| comes up with a better idea of a way of doing things
224 *| along these lines, then feel free to make your idea
225 *| known to me.. -cim 10/15/89
229 /* ----------------------------------------------------------------
230 * Common Executor State Information
231 * ----------------------------------------------------------------
234 /* BaseNode removed -- base_id moved into CommonState - jolly */
237 * CommonState information
239 *| this is a bogus class used to hold slots so other
240 *| nodes can inherit them...
242 * OuterTupleSlot pointer to slot containing current "outer" tuple
243 * ResultTupleSlot pointer to slot in tuple table for projected tuple
244 * ExprContext node's current expression context
245 * ProjInfo info this node uses to form tuple projections
246 * NumScanAttributes size of ScanAttributes array
247 * ScanAttributes attribute numbers of interest in this tuple
251 typedef struct CommonState {
252 NodeTag type; /* its first field is NodeTag */
254 TupleTableSlot *cs_OuterTupleSlot;
255 TupleTableSlot *cs_ResultTupleSlot;
256 ExprContext *cs_ExprContext;
257 ProjectionInfo *cs_ProjInfo;
258 bool cs_TupFromTlist;
262 /* ----------------------------------------------------------------
263 * Control Node State Information
264 * ----------------------------------------------------------------
268 * ResultState information
270 * done flag which tells us to quit when we
271 * have already returned a constant tuple.
273 * CommonState information
275 * OuterTupleSlot pointer to slot containing current "outer" tuple
276 * ResultTupleSlot pointer to slot in tuple table for projected tuple
277 * ExprContext node's current expression context
278 * ProjInfo info this node uses to form tuple projections
279 * NumScanAttributes size of ScanAttributes array
280 * ScanAttributes attribute numbers of interest in this tuple
283 typedef struct ResultState {
284 CommonState cstate; /* its first field is NodeTag */
289 * AppendState information
291 * append nodes have this field "unionplans" which is this
292 * list of plans to execute in sequence.. these variables
293 * keep track of things..
295 * whichplan which plan is being executed
296 * nplans how many plans are in the list
297 * initialized array of ExecInitNode() results
298 * rtentries range table for the current plan
299 * result_relation_info_list array of each subplan's result relation info
300 * junkFilter_list array of each subplan's junk filter
302 * CommonState information
304 * OuterTupleSlot pointer to slot containing current "outer" tuple
305 * ResultTupleSlot pointer to slot in tuple table for projected tuple
306 * ExprContext node's current expression context
307 * ProjInfo info this node uses to form tuple projections
308 * NumScanAttributes size of ScanAttributes array
309 * ScanAttributes attribute numbers of interest in this tuple
312 typedef struct AppendState {
313 CommonState cstate; /* its first field is NodeTag */
316 bool *as_initialized;
318 List *as_result_relation_info_list;
319 List *as_junkFilter_list;
322 /* ----------------------------------------------------------------
323 * Scan State Information
324 * ----------------------------------------------------------------
328 * CommonScanState information
330 * CommonScanState is a class like CommonState, but is used more
331 * by the nodes like SeqScan and Sort which want to
332 * keep track of an underlying relation.
334 * currentRelation relation being scanned
335 * currentScanDesc current scan descriptor for scan
336 * ScanTupleSlot pointer to slot in tuple table holding scan tuple
338 * CommonState information
340 * OuterTupleSlot pointer to slot containing current "outer" tuple
341 * ResultTupleSlot pointer to slot in tuple table for projected tuple
342 * ExprContext node's current expression context
343 * ProjInfo info this node uses to form tuple projections
344 * NumScanAttributes size of ScanAttributes array
345 * ScanAttributes attribute numbers of interest in this tuple
348 typedef struct CommonScanState {
349 CommonState cstate; /* its first field is NodeTag */
350 Relation css_currentRelation;
351 HeapScanDesc css_currentScanDesc;
352 TupleTableSlot *css_ScanTupleSlot;
356 * IndexScanState information
358 *| index scans don't use CommonScanState because
359 *| the underlying AM abstractions for heap scans and
360 *| index scans are too different.. It would be nice
361 *| if the current abstraction was more useful but ... -cim 10/15/89
363 * IndexPtr current index in use
364 * NumIndices number of indices in this scan
365 * ScanKeys Skey structures to scan index rels
366 * NumScanKeys array of no of keys in each Skey struct
367 * RuntimeKeyInfo array of array of flags for Skeys evaled at runtime
368 * RelationDescs ptr to array of relation descriptors
369 * ScanDescs ptr to array of scan descriptors
371 * CommonState information
373 * OuterTupleSlot pointer to slot containing current "outer" tuple
374 * ResultTupleSlot pointer to slot in tuple table for projected tuple
375 * ExprContext node's current expression context
376 * ProjInfo info this node uses to form tuple projections
377 * NumScanAttributes size of ScanAttributes array
378 * ScanAttributes attribute numbers of interest in this tuple
381 typedef struct IndexScanState {
382 CommonState cstate; /* its first field is NodeTag */
385 ScanKey *iss_ScanKeys;
386 int *iss_NumScanKeys;
387 Pointer iss_RuntimeKeyInfo;
388 RelationPtr iss_RelationDescs;
389 IndexScanDescPtr iss_ScanDescs;
393 /* ----------------------------------------------------------------
394 * Join State Information
395 * ----------------------------------------------------------------
399 * JoinState information
401 * CommonState information
403 * OuterTupleSlot pointer to slot containing current "outer" tuple
404 * ResultTupleSlot pointer to slot in tuple table for projected tuple
405 * ExprContext node's current expression context
406 * ProjInfo info this node uses to form tuple projections
407 * NumScanAttributes size of ScanAttributes array
408 * ScanAttributes attribute numbers of interest in this tuple
411 typedef CommonState JoinState;
414 * NestLoopState information
416 * PortalFlag Set to enable portals to work.
418 * JoinState information
420 * CommonState information
422 * OuterTupleSlot pointer to slot containing current "outer" tuple
423 * ResultTupleSlot pointer to slot in tuple table for projected tuple
424 * ExprContext node's current expression context
425 * ProjInfo info this node uses to form tuple projections
426 * NumScanAttributes size of ScanAttributes array
427 * ScanAttributes attribute numbers of interest in this tuple
430 typedef struct NestLoopState {
431 JoinState jstate; /* its first field is NodeTag */
436 * MergeJoinState information
438 * OSortopI outerKey1 sortOp innerKey1 ...
439 * ISortopO innerkey1 sortOp outerkey1 ...
440 * JoinState current "state" of join. see executor.h
441 * MarkedTupleSlot pointer to slot in tuple table for marked tuple
443 * JoinState information
445 * CommonState information
447 * OuterTupleSlot pointer to slot containing current "outer" tuple
448 * ResultTupleSlot pointer to slot in tuple table for projected tuple
449 * ExprContext node's current expression context
450 * ProjInfo info this node uses to form tuple projections
451 * NumScanAttributes size of ScanAttributes array
452 * ScanAttributes attribute numbers of interest in this tuple
455 typedef struct MergeJoinState {
456 JoinState jstate; /* its first field is NodeTag */
460 TupleTableSlot *mj_MarkedTupleSlot;
464 * HashJoinState information
466 * hj_HashTable address of the hash table for the hashjoin
467 * hj_HashTableShmId shared memory id of hash table
468 * hj_CurBucket the current hash bucket that we are searching
469 * for matches of the current outer tuple
470 * hj_CurTuple the current matching inner tuple in the
471 * current hash bucket
472 * hj_CurOTuple the current matching inner tuple in the
473 * current hash overflow chain
474 * hj_InnerHashKey the inner hash key in the hashjoin condition
475 * hj_OuterBatches file descriptors for outer batches
476 * hj_InnerBatches file descriptors for inner batches
477 * hj_OuterReadPos current read position of outer batch
478 * hj_OuterReadBlk current read block of outer batch
479 * hj_OuterTupleSlot tuple slot for outer tuples
480 * hj_HashTupleSlot tuple slot for hashed tuples
484 * JoinState information
486 * CommonState information
488 * OuterTupleSlot pointer to slot containing current "outer" tuple
489 * ResultTupleSlot pointer to slot in tuple table for projected tuple
490 * ExprContext node's current expression context
491 * ProjInfo info this node uses to form tuple projections
492 * NumScanAttributes size of ScanAttributes array
493 * ScanAttributes attribute numbers of interest in this tuple
496 typedef struct HashJoinState {
497 JoinState jstate; /* its first field is NodeTag */
498 HashJoinTable hj_HashTable;
499 IpcMemoryId hj_HashTableShmId;
500 HashBucket hj_CurBucket;
501 HeapTuple hj_CurTuple;
502 OverflowTuple hj_CurOTuple;
503 Var *hj_InnerHashKey;
504 File *hj_OuterBatches;
505 File *hj_InnerBatches;
506 char *hj_OuterReadPos;
508 TupleTableSlot *hj_OuterTupleSlot;
509 TupleTableSlot *hj_HashTupleSlot;
513 /* ----------------------------------------------------------------
514 * Materialization State Information
515 * ----------------------------------------------------------------
519 * MaterialState information
521 * materialize nodes are used to materialize the results
522 * of a subplan into a temporary relation.
524 * Flag indicated whether subplan has been materialized
525 * TempRelation temporary relation containing result of executing
528 * CommonScanState information
530 * currentRelation relation descriptor of sorted relation
531 * currentScanDesc current scan descriptor for scan
532 * ScanTupleSlot pointer to slot in tuple table holding scan tuple
534 * CommonState information
536 * OuterTupleSlot pointer to slot containing current "outer" tuple
537 * ResultTupleSlot pointer to slot in tuple table for projected tuple
538 * ExprContext node's current expression context
539 * ProjInfo info this node uses to form tuple projections
540 * NumScanAttributes size of ScanAttributes array
541 * ScanAttributes attribute numbers of interest in this tuple
544 typedef struct MaterialState {
545 CommonScanState csstate; /* its first field is NodeTag */
547 Relation mat_TempRelation;
550 /* ---------------------
551 * AggregateState information
553 * done indicated whether aggregate has been materialized
554 * -------------------------
556 typedef struct AggState {
557 CommonScanState csstate; /* its first field is NodeTag */
561 /* ---------------------
562 * GroupState information
564 * -------------------------
566 typedef struct GroupState {
567 CommonScanState csstate; /* its first field is NodeTag */
568 bool grp_useLastTuple; /* last tuple not processed yet */
570 TupleTableSlot *grp_lastSlot;
574 * SortState information
576 *| sort nodes are really just a kind of a scan since
577 *| we implement sorts by retrieveing the entire subplan
578 *| into a temp relation, sorting the temp relation into
579 *| another sorted relation, and then preforming a simple
580 *| unqualified sequential scan on the sorted relation..
583 * Flag indicated whether relation has been sorted
584 * Keys scan key structures used to keep info on sort keys
585 * TempRelation temporary relation containing result of executing
588 * CommonScanState information
590 * currentRelation relation descriptor of sorted relation
591 * currentScanDesc current scan descriptor for scan
592 * ScanTupleSlot pointer to slot in tuple table holding scan tuple
594 * CommonState information
596 * OuterTupleSlot pointer to slot containing current "outer" tuple
597 * ResultTupleSlot pointer to slot in tuple table for projected tuple
598 * ExprContext node's current expression context
599 * ProjInfo info this node uses to form tuple projections
600 * NumScanAttributes size of ScanAttributes array
601 * ScanAttributes attribute numbers of interest in this tuple
604 typedef struct SortState {
605 CommonScanState csstate; /* its first field is NodeTag */
608 Relation sort_TempRelation;
612 * UniqueState information
614 * Unique nodes are used "on top of" sort nodes to discard
615 * duplicate tuples returned from the sort phase. Basically
616 * all it does is compare the current tuple from the subplan
617 * with the previously fetched tuple stored in OuterTuple and
618 * if the two are identical, then we just fetch another tuple
619 * from the sort and try again.
621 * CommonState information
623 * OuterTupleSlot pointer to slot containing current "outer" tuple
624 * ResultTupleSlot pointer to slot in tuple table for projected tuple
625 * ExprContext node's current expression context
626 * ProjInfo info this node uses to form tuple projections
627 * NumScanAttributes size of ScanAttributes array
628 * ScanAttributes attribute numbers of interest in this tuple
631 typedef CommonState UniqueState;
635 * HashState information
637 * hashBatches file descriptors for the batches
639 * CommonState information
641 * OuterTupleSlot pointer to slot containing current "outer" tuple
642 * ResultTupleSlot pointer to slot in tuple table for projected tuple
643 * ExprContext node's current expression context
644 * ProjInfo info this node uses to form tuple projections
645 * NumScanAttributes size of ScanAttributes array
646 * ScanAttributes attribute numbers of interest in this tuple
649 typedef struct HashState {
650 CommonState cstate; /* its first field is NodeTag */
654 /* -----------------------
655 * TeeState information
656 * leftPlace : next item in the queue unseen by the left parent
657 * rightPlace : next item in the queue unseen by the right parent
658 * lastPlace : last item in the queue
659 * bufferRelname : name of the relation used as the buffer queue
660 * bufferRel : the relation used as the buffer queue
661 * mcxt : for now, tee's have their own memory context
662 * may be cleaned up later if portals are cleaned up
664 * initially, a Tee starts with [left/right]Place variables set to -1.
665 * on cleanup, queue is free'd when both leftPlace and rightPlace = -1
666 * -------------------------
668 typedef struct TeeState {
669 CommonState cstate; /* its first field is NodeTag */
673 char *tee_bufferRelname;
674 Relation tee_bufferRel;
675 MemoryContext tee_mcxt;
676 HeapScanDesc tee_leftScanDesc;
677 HeapScanDesc tee_rightScanDesc;
680 #endif /* EXECNODES_H */