1 /*-------------------------------------------------------------------------
4 * definitions for executor state nodes
7 * Copyright (c) 1994, Regents of the University of California
9 * $Id: execnodes.h,v 1.10 1997/09/08 02:37:12 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 List *ecxt_range_table;
91 Datum *ecxt_values; /* precomputed values for aggreg */
92 char *ecxt_nulls; /* null flags for aggreg values */
96 * ProjectionInfo node information
98 * This is all the information needed to preform projections
99 * on a tuple. Nodes which need to do projections create one
100 * of these. In theory, when a node wants to preform a projection
101 * it should just update this information as necessary and then
102 * call ExecProject(). -cim 6/3/91
104 * targetlist target list for projection
105 * len length of target list
106 * tupValue array of pointers to projection results
107 * exprContext expression context for ExecTargetList
108 * slot slot to place projection result in
111 typedef struct ProjectionInfo
117 ExprContext *pi_exprContext;
118 TupleTableSlot *pi_slot;
124 * this class is used to store information regarding junk attributes.
125 * A junk attribute is an attribute in a tuple that is needed only for
126 * storing intermediate information in the executor, and does not belong
127 * in the tuple proper. For example, when we do a delete or replace
128 * query, the planner adds an entry to the targetlist so that the tuples
129 * returned to ExecutePlan() contain an extra attribute: the t_ctid of
130 * the tuple to be deleted/replaced. This is needed for amdelete() and
131 * amreplace(). In doing a delete this does not make much of a
132 * difference, but in doing a replace we have to make sure we disgard
133 * all the junk in a tuple before calling amreplace(). Otherwise the
134 * inserted tuple will not have the correct schema. This solves a
135 * problem with hash-join and merge-sort replace plans. -cim 10/10/90
137 * targetList: the original target list (including junk attributes).
138 * length: the length of 'targetList'.
139 * tupType: the tuple descriptor for the "original" tuple
140 * (including the junk attributes).
141 * cleanTargetList: the "clean" target list (junk attributes removed).
142 * cleanLength: the length of 'cleanTargetList'
143 * cleanTupTyp: the tuple descriptor of the "clean" tuple (with
144 * junk attributes removed).
145 * cleanMap: A map with the correspondance between the non junk
146 * attributes of the "original" tuple and the
147 * attributes of the "clean" tuple.
150 typedef struct JunkFilter
155 TupleDesc jf_tupType;
156 List *jf_cleanTargetList;
158 TupleDesc jf_cleanTupType;
159 AttrNumber *jf_cleanMap;
165 * direction direction of the scan
167 * range_table array of scan relation information
169 * result_relation_information for update queries
171 * into_relation_descriptor relation being retrieved "into"
173 * param_list_info information needed to transform
174 * Param nodes into Const nodes
176 * BaseId during InitPlan(), each node is
177 * given a number. this is the next
178 * number to be assigned.
180 * tupleTable this is a pointer to an array
181 * of pointers to tuples used by
182 * the executor at any given moment.
184 * junkFilter contains information used to
185 * extract junk attributes from a tuple.
186 * (see JunkFilter above)
188 * refcount local buffer refcounts used in
189 * an ExecMain cycle. this is introduced
190 * to avoid ExecStart's unpinning each
191 * other's buffers when called recursively
194 typedef struct EState
197 ScanDirection es_direction;
198 List *es_range_table;
199 RelationInfo *es_result_relation_info;
200 Relation es_into_relation_descriptor;
201 ParamListInfo es_param_list_info;
203 TupleTable es_tupleTable;
204 JunkFilter *es_junkFilter;
206 uint32 es_processed; /* # of tuples processed */
207 Oid es_lastoid; /* last oid processed (by INSERT) */
211 * Executor Type information needed by plannodes.h
213 *| Note: the bogus classes CommonState and CommonScanState exist only
214 *| because our inheritance system only allows single inheritance
215 *| and we have to have unique slot names. Hence two or more
216 *| classes which want to have a common slot must ALL inherit
217 *| the slot from some other class. (This is a big hack to
218 *| allow our classes to share slot names..)
221 *| the class Result and the class NestLoop nodes both want
222 *| a slot called "OuterTuple" so they both have to inherit
223 *| it from some other class. In this case they inherit
224 *| it from CommonState. "CommonState" and "CommonScanState" are
225 *| the best names I could come up with for this sort of
228 *| As a result, many classes have extra slots which they
229 *| don't use. These slots are denoted (unused) in the
230 *| comment preceeding the class definition. If you
231 *| comes up with a better idea of a way of doing things
232 *| along these lines, then feel free to make your idea
233 *| known to me.. -cim 10/15/89
237 /* ----------------------------------------------------------------
238 * Common Executor State Information
239 * ----------------------------------------------------------------
242 /* BaseNode removed -- base_id moved into CommonState - jolly */
245 * CommonState information
247 *| this is a bogus class used to hold slots so other
248 *| nodes can inherit them...
250 * OuterTupleSlot pointer to slot containing current "outer" tuple
251 * ResultTupleSlot pointer to slot in tuple table for projected tuple
252 * ExprContext node's current expression context
253 * ProjInfo info this node uses to form tuple projections
254 * NumScanAttributes size of ScanAttributes array
255 * ScanAttributes attribute numbers of interest in this tuple
259 typedef struct CommonState
261 NodeTag type; /* its first field is NodeTag */
263 TupleTableSlot *cs_OuterTupleSlot;
264 TupleTableSlot *cs_ResultTupleSlot;
265 ExprContext *cs_ExprContext;
266 ProjectionInfo *cs_ProjInfo;
267 bool cs_TupFromTlist;
271 /* ----------------------------------------------------------------
272 * Control Node State Information
273 * ----------------------------------------------------------------
277 * ResultState information
279 * done flag which tells us to quit when we
280 * have already returned a constant tuple.
282 * CommonState information
284 * OuterTupleSlot pointer to slot containing current "outer" tuple
285 * ResultTupleSlot pointer to slot in tuple table for projected tuple
286 * ExprContext node's current expression context
287 * ProjInfo info this node uses to form tuple projections
288 * NumScanAttributes size of ScanAttributes array
289 * ScanAttributes attribute numbers of interest in this tuple
292 typedef struct ResultState
294 CommonState cstate; /* its first field is NodeTag */
299 * AppendState information
301 * append nodes have this field "unionplans" which is this
302 * list of plans to execute in sequence.. these variables
303 * keep track of things..
305 * whichplan which plan is being executed
306 * nplans how many plans are in the list
307 * initialized array of ExecInitNode() results
308 * rtentries range table for the current plan
309 * result_relation_info_list array of each subplan's result relation info
310 * junkFilter_list array of each subplan's junk filter
312 * CommonState information
314 * OuterTupleSlot pointer to slot containing current "outer" tuple
315 * ResultTupleSlot pointer to slot in tuple table for projected tuple
316 * ExprContext node's current expression context
317 * ProjInfo info this node uses to form tuple projections
318 * NumScanAttributes size of ScanAttributes array
319 * ScanAttributes attribute numbers of interest in this tuple
322 typedef struct AppendState
324 CommonState cstate; /* its first field is NodeTag */
327 bool *as_initialized;
329 List *as_result_relation_info_list;
330 List *as_junkFilter_list;
333 /* ----------------------------------------------------------------
334 * Scan State Information
335 * ----------------------------------------------------------------
339 * CommonScanState information
341 * CommonScanState is a class like CommonState, but is used more
342 * by the nodes like SeqScan and Sort which want to
343 * keep track of an underlying relation.
345 * currentRelation relation being scanned
346 * currentScanDesc current scan descriptor for scan
347 * ScanTupleSlot pointer to slot in tuple table holding scan tuple
349 * CommonState information
351 * OuterTupleSlot pointer to slot containing current "outer" tuple
352 * ResultTupleSlot pointer to slot in tuple table for projected tuple
353 * ExprContext node's current expression context
354 * ProjInfo info this node uses to form tuple projections
355 * NumScanAttributes size of ScanAttributes array
356 * ScanAttributes attribute numbers of interest in this tuple
359 typedef struct CommonScanState
361 CommonState cstate; /* its first field is NodeTag */
362 Relation css_currentRelation;
363 HeapScanDesc css_currentScanDesc;
364 TupleTableSlot *css_ScanTupleSlot;
368 * IndexScanState information
370 *| index scans don't use CommonScanState because
371 *| the underlying AM abstractions for heap scans and
372 *| index scans are too different.. It would be nice
373 *| if the current abstraction was more useful but ... -cim 10/15/89
375 * IndexPtr current index in use
376 * NumIndices number of indices in this scan
377 * ScanKeys Skey structures to scan index rels
378 * NumScanKeys array of no of keys in each Skey struct
379 * RuntimeKeyInfo array of array of flags for Skeys evaled at runtime
380 * RelationDescs ptr to array of relation descriptors
381 * ScanDescs ptr to array of scan descriptors
383 * CommonState information
385 * OuterTupleSlot pointer to slot containing current "outer" tuple
386 * ResultTupleSlot pointer to slot in tuple table for projected tuple
387 * ExprContext node's current expression context
388 * ProjInfo info this node uses to form tuple projections
389 * NumScanAttributes size of ScanAttributes array
390 * ScanAttributes attribute numbers of interest in this tuple
393 typedef struct IndexScanState
395 CommonState cstate; /* its first field is NodeTag */
398 ScanKey *iss_ScanKeys;
399 int *iss_NumScanKeys;
400 Pointer iss_RuntimeKeyInfo;
401 RelationPtr iss_RelationDescs;
402 IndexScanDescPtr iss_ScanDescs;
406 /* ----------------------------------------------------------------
407 * Join State Information
408 * ----------------------------------------------------------------
412 * JoinState information
414 * CommonState information
416 * OuterTupleSlot pointer to slot containing current "outer" tuple
417 * ResultTupleSlot pointer to slot in tuple table for projected tuple
418 * ExprContext node's current expression context
419 * ProjInfo info this node uses to form tuple projections
420 * NumScanAttributes size of ScanAttributes array
421 * ScanAttributes attribute numbers of interest in this tuple
424 typedef CommonState JoinState;
427 * NestLoopState information
429 * PortalFlag Set to enable portals to work.
431 * JoinState information
433 * CommonState information
435 * OuterTupleSlot pointer to slot containing current "outer" tuple
436 * ResultTupleSlot pointer to slot in tuple table for projected tuple
437 * ExprContext node's current expression context
438 * ProjInfo info this node uses to form tuple projections
439 * NumScanAttributes size of ScanAttributes array
440 * ScanAttributes attribute numbers of interest in this tuple
443 typedef struct NestLoopState
445 JoinState jstate; /* its first field is NodeTag */
450 * MergeJoinState information
452 * OSortopI outerKey1 sortOp innerKey1 ...
453 * ISortopO innerkey1 sortOp outerkey1 ...
454 * JoinState current "state" of join. see executor.h
455 * MarkedTupleSlot pointer to slot in tuple table for marked tuple
457 * JoinState information
459 * CommonState information
461 * OuterTupleSlot pointer to slot containing current "outer" tuple
462 * ResultTupleSlot pointer to slot in tuple table for projected tuple
463 * ExprContext node's current expression context
464 * ProjInfo info this node uses to form tuple projections
465 * NumScanAttributes size of ScanAttributes array
466 * ScanAttributes attribute numbers of interest in this tuple
469 typedef struct MergeJoinState
471 JoinState jstate; /* its first field is NodeTag */
475 TupleTableSlot *mj_MarkedTupleSlot;
479 * HashJoinState information
481 * hj_HashTable address of the hash table for the hashjoin
482 * hj_HashTableShmId shared memory id of hash table
483 * hj_CurBucket the current hash bucket that we are searching
484 * for matches of the current outer tuple
485 * hj_CurTuple the current matching inner tuple in the
486 * current hash bucket
487 * hj_CurOTuple the current matching inner tuple in the
488 * current hash overflow chain
489 * hj_InnerHashKey the inner hash key in the hashjoin condition
490 * hj_OuterBatches file descriptors for outer batches
491 * hj_InnerBatches file descriptors for inner batches
492 * hj_OuterReadPos current read position of outer batch
493 * hj_OuterReadBlk current read block of outer batch
494 * hj_OuterTupleSlot tuple slot for outer tuples
495 * hj_HashTupleSlot tuple slot for hashed tuples
499 * JoinState information
501 * CommonState information
503 * OuterTupleSlot pointer to slot containing current "outer" tuple
504 * ResultTupleSlot pointer to slot in tuple table for projected tuple
505 * ExprContext node's current expression context
506 * ProjInfo info this node uses to form tuple projections
507 * NumScanAttributes size of ScanAttributes array
508 * ScanAttributes attribute numbers of interest in this tuple
511 typedef struct HashJoinState
513 JoinState jstate; /* its first field is NodeTag */
514 HashJoinTable hj_HashTable;
515 IpcMemoryId hj_HashTableShmId;
516 HashBucket hj_CurBucket;
517 HeapTuple hj_CurTuple;
518 OverflowTuple hj_CurOTuple;
519 Var *hj_InnerHashKey;
520 File *hj_OuterBatches;
521 File *hj_InnerBatches;
522 char *hj_OuterReadPos;
524 TupleTableSlot *hj_OuterTupleSlot;
525 TupleTableSlot *hj_HashTupleSlot;
529 /* ----------------------------------------------------------------
530 * Materialization State Information
531 * ----------------------------------------------------------------
535 * MaterialState information
537 * materialize nodes are used to materialize the results
538 * of a subplan into a temporary relation.
540 * Flag indicated whether subplan has been materialized
541 * TempRelation temporary relation containing result of executing
544 * CommonScanState information
546 * currentRelation relation descriptor of sorted relation
547 * currentScanDesc current scan descriptor for scan
548 * ScanTupleSlot pointer to slot in tuple table holding scan tuple
550 * CommonState information
552 * OuterTupleSlot pointer to slot containing current "outer" tuple
553 * ResultTupleSlot pointer to slot in tuple table for projected tuple
554 * ExprContext node's current expression context
555 * ProjInfo info this node uses to form tuple projections
556 * NumScanAttributes size of ScanAttributes array
557 * ScanAttributes attribute numbers of interest in this tuple
560 typedef struct MaterialState
562 CommonScanState csstate; /* its first field is NodeTag */
564 Relation mat_TempRelation;
567 /* ---------------------
568 * AggregateState information
570 * done indicated whether aggregate has been materialized
571 * -------------------------
573 typedef struct AggState
575 CommonScanState csstate; /* its first field is NodeTag */
579 /* ---------------------
580 * GroupState information
582 * -------------------------
584 typedef struct GroupState
586 CommonScanState csstate; /* its first field is NodeTag */
587 bool grp_useLastTuple; /* last tuple not processed yet */
589 TupleTableSlot *grp_lastSlot;
593 * SortState information
595 *| sort nodes are really just a kind of a scan since
596 *| we implement sorts by retrieveing the entire subplan
597 *| into a temp relation, sorting the temp relation into
598 *| another sorted relation, and then preforming a simple
599 *| unqualified sequential scan on the sorted relation..
602 * Flag indicated whether relation has been sorted
603 * Keys scan key structures used to keep info on sort keys
604 * TempRelation temporary relation containing result of executing
607 * CommonScanState information
609 * currentRelation relation descriptor of sorted relation
610 * currentScanDesc current scan descriptor for scan
611 * ScanTupleSlot pointer to slot in tuple table holding scan tuple
613 * CommonState information
615 * OuterTupleSlot pointer to slot containing current "outer" tuple
616 * ResultTupleSlot pointer to slot in tuple table for projected tuple
617 * ExprContext node's current expression context
618 * ProjInfo info this node uses to form tuple projections
619 * NumScanAttributes size of ScanAttributes array
620 * ScanAttributes attribute numbers of interest in this tuple
623 typedef struct SortState
625 CommonScanState csstate; /* its first field is NodeTag */
632 * UniqueState information
634 * Unique nodes are used "on top of" sort nodes to discard
635 * duplicate tuples returned from the sort phase. Basically
636 * all it does is compare the current tuple from the subplan
637 * with the previously fetched tuple stored in OuterTuple and
638 * if the two are identical, then we just fetch another tuple
639 * from the sort and try again.
641 * CommonState information
643 * OuterTupleSlot pointer to slot containing current "outer" tuple
644 * ResultTupleSlot pointer to slot in tuple table for projected tuple
645 * ExprContext node's current expression context
646 * ProjInfo info this node uses to form tuple projections
647 * NumScanAttributes size of ScanAttributes array
648 * ScanAttributes attribute numbers of interest in this tuple
651 typedef CommonState UniqueState;
655 * HashState information
657 * hashBatches file descriptors for the batches
659 * CommonState information
661 * OuterTupleSlot pointer to slot containing current "outer" tuple
662 * ResultTupleSlot pointer to slot in tuple table for projected tuple
663 * ExprContext node's current expression context
664 * ProjInfo info this node uses to form tuple projections
665 * NumScanAttributes size of ScanAttributes array
666 * ScanAttributes attribute numbers of interest in this tuple
669 typedef struct HashState
671 CommonState cstate; /* its first field is NodeTag */
675 /* -----------------------
676 * TeeState information
677 * leftPlace : next item in the queue unseen by the left parent
678 * rightPlace : next item in the queue unseen by the right parent
679 * lastPlace : last item in the queue
680 * bufferRelname : name of the relation used as the buffer queue
681 * bufferRel : the relation used as the buffer queue
682 * mcxt : for now, tee's have their own memory context
683 * may be cleaned up later if portals are cleaned up
685 * initially, a Tee starts with [left/right]Place variables set to -1.
686 * on cleanup, queue is free'd when both leftPlace and rightPlace = -1
687 * -------------------------
689 typedef struct TeeState
691 CommonState cstate; /* its first field is NodeTag */
695 char *tee_bufferRelname;
696 Relation tee_bufferRel;
697 MemoryContext tee_mcxt;
698 HeapScanDesc tee_leftScanDesc;
699 HeapScanDesc tee_rightScanDesc;
702 #endif /* EXECNODES_H */