1 /*-------------------------------------------------------------------------
4 * definitions for executor state nodes
7 * Copyright (c) 1994, Regents of the University of California
9 * $Id: execnodes.h,v 1.28 1999/05/18 21:34:26 tgl 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 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;
210 uint32 es_processed; /* # of tuples processed */
211 Oid es_lastoid; /* last oid processed (by INSERT) */
212 List *es_rowMark; /* not good place, but there is no other */
213 /* Below is to re-evaluate plan qual in READ COMMITTED mode */
214 struct Plan *es_origPlan;
215 Pointer es_evalPlanQual;
216 bool *es_evTupleNull;
217 HeapTuple *es_evTuple;
222 * Executor Type information needed by plannodes.h
224 *| Note: the bogus classes CommonState and CommonScanState exist only
225 *| because our inheritance system only allows single inheritance
226 *| and we have to have unique slot names. Hence two or more
227 *| classes which want to have a common slot must ALL inherit
228 *| the slot from some other class. (This is a big hack to
229 *| allow our classes to share slot names..)
232 *| the class Result and the class NestLoop nodes both want
233 *| a slot called "OuterTuple" so they both have to inherit
234 *| it from some other class. In this case they inherit
235 *| it from CommonState. "CommonState" and "CommonScanState" are
236 *| the best names I could come up with for this sort of
239 *| As a result, many classes have extra slots which they
240 *| don't use. These slots are denoted (unused) in the
241 *| comment preceeding the class definition. If you
242 *| comes up with a better idea of a way of doing things
243 *| along these lines, then feel free to make your idea
244 *| known to me.. -cim 10/15/89
248 /* ----------------------------------------------------------------
249 * Common Executor State Information
250 * ----------------------------------------------------------------
253 /* BaseNode removed -- base_id moved into CommonState - jolly */
256 * CommonState information
258 *| this is a bogus class used to hold slots so other
259 *| nodes can inherit them...
261 * OuterTupleSlot pointer to slot containing current "outer" tuple
262 * ResultTupleSlot pointer to slot in tuple table for projected tuple
263 * ExprContext node's current expression context
264 * ProjInfo info this node uses to form tuple projections
265 * NumScanAttributes size of ScanAttributes array
266 * ScanAttributes attribute numbers of interest in this tuple
270 typedef struct CommonState
272 NodeTag type; /* its first field is NodeTag */
274 TupleTableSlot *cs_OuterTupleSlot;
275 TupleTableSlot *cs_ResultTupleSlot;
276 ExprContext *cs_ExprContext;
277 ProjectionInfo *cs_ProjInfo;
278 bool cs_TupFromTlist;
282 /* ----------------------------------------------------------------
283 * Control Node State Information
284 * ----------------------------------------------------------------
288 * ResultState information
290 * done flag which tells us to quit when we
291 * have already returned a constant tuple.
293 * CommonState information
295 * OuterTupleSlot pointer to slot containing current "outer" tuple
296 * ResultTupleSlot pointer to slot in tuple table for projected tuple
297 * ExprContext node's current expression context
298 * ProjInfo info this node uses to form tuple projections
299 * NumScanAttributes size of ScanAttributes array
300 * ScanAttributes attribute numbers of interest in this tuple
303 typedef struct ResultState
305 CommonState cstate; /* its first field is NodeTag */
311 * AppendState information
313 * append nodes have this field "unionplans" which is this
314 * list of plans to execute in sequence.. these variables
315 * keep track of things..
317 * whichplan which plan is being executed
318 * nplans how many plans are in the list
319 * initialized array of ExecInitNode() results
320 * rtentries range table for the current plan
321 * result_relation_info_list array of each subplan's result relation info
322 * junkFilter_list array of each subplan's junk filter
324 * CommonState information
326 * OuterTupleSlot pointer to slot containing current "outer" tuple
327 * ResultTupleSlot pointer to slot in tuple table for projected tuple
328 * ExprContext node's current expression context
329 * ProjInfo info this node uses to form tuple projections
330 * NumScanAttributes size of ScanAttributes array
331 * ScanAttributes attribute numbers of interest in this tuple
334 typedef struct AppendState
336 CommonState cstate; /* its first field is NodeTag */
339 bool *as_initialized;
341 List *as_result_relation_info_list;
342 List *as_junkFilter_list;
345 /* ----------------------------------------------------------------
346 * Scan State Information
347 * ----------------------------------------------------------------
351 * CommonScanState information
353 * CommonScanState is a class like CommonState, but is used more
354 * by the nodes like SeqScan and Sort which want to
355 * keep track of an underlying relation.
357 * currentRelation relation being scanned
358 * currentScanDesc current scan descriptor for scan
359 * ScanTupleSlot pointer to slot in tuple table holding scan tuple
361 * CommonState information
363 * OuterTupleSlot pointer to slot containing current "outer" tuple
364 * ResultTupleSlot pointer to slot in tuple table for projected tuple
365 * ExprContext node's current expression context
366 * ProjInfo info this node uses to form tuple projections
367 * NumScanAttributes size of ScanAttributes array
368 * ScanAttributes attribute numbers of interest in this tuple
371 typedef struct CommonScanState
373 CommonState cstate; /* its first field is NodeTag */
374 Relation css_currentRelation;
375 HeapScanDesc css_currentScanDesc;
376 TupleTableSlot *css_ScanTupleSlot;
380 * IndexScanState information
382 *| index scans don't use CommonScanState because
383 *| the underlying AM abstractions for heap scans and
384 *| index scans are too different.. It would be nice
385 *| if the current abstraction was more useful but ... -cim 10/15/89
387 * IndexPtr current index in use
388 * NumIndices number of indices in this scan
389 * ScanKeys Skey structures to scan index rels
390 * NumScanKeys array of no of keys in each Skey struct
391 * RuntimeKeyInfo array of array of flags for Skeys evaled at runtime
392 * RelationDescs ptr to array of relation descriptors
393 * ScanDescs ptr to array of scan descriptors
395 * CommonState information
397 * OuterTupleSlot pointer to slot containing current "outer" tuple
398 * ResultTupleSlot pointer to slot in tuple table for projected tuple
399 * ExprContext node's current expression context
400 * ProjInfo info this node uses to form tuple projections
401 * NumScanAttributes size of ScanAttributes array
402 * ScanAttributes attribute numbers of interest in this tuple
405 typedef struct IndexScanState
407 CommonState cstate; /* its first field is NodeTag */
410 int iss_MarkIndexPtr;
411 ScanKey *iss_ScanKeys;
412 int *iss_NumScanKeys;
413 Pointer iss_RuntimeKeyInfo;
414 RelationPtr iss_RelationDescs;
415 IndexScanDescPtr iss_ScanDescs;
416 HeapTupleData iss_htup;
420 /* ----------------------------------------------------------------
421 * Join State Information
422 * ----------------------------------------------------------------
426 * JoinState information
428 * CommonState information
430 * OuterTupleSlot pointer to slot containing current "outer" tuple
431 * ResultTupleSlot pointer to slot in tuple table for projected tuple
432 * ExprContext node's current expression context
433 * ProjInfo info this node uses to form tuple projections
434 * NumScanAttributes size of ScanAttributes array
435 * ScanAttributes attribute numbers of interest in this tuple
438 typedef CommonState JoinState;
441 * NestLoopState information
443 * PortalFlag Set to enable portals to work.
445 * JoinState information
447 * CommonState information
449 * OuterTupleSlot pointer to slot containing current "outer" tuple
450 * ResultTupleSlot pointer to slot in tuple table for projected tuple
451 * ExprContext node's current expression context
452 * ProjInfo info this node uses to form tuple projections
453 * NumScanAttributes size of ScanAttributes array
454 * ScanAttributes attribute numbers of interest in this tuple
457 typedef struct NestLoopState
459 JoinState jstate; /* its first field is NodeTag */
464 * MergeJoinState information
466 * OuterSkipQual outerKey1 < innerKey1 ...
467 * InnerSkipQual outerKey1 > innerKey1 ...
468 * JoinState current "state" of join. see executor.h
469 * MarkedTupleSlot pointer to slot in tuple table for marked tuple
471 * JoinState information
473 * CommonState information
475 * OuterTupleSlot pointer to slot containing current "outer" tuple
476 * ResultTupleSlot pointer to slot in tuple table for projected tuple
477 * ExprContext node's current expression context
478 * ProjInfo info this node uses to form tuple projections
479 * NumScanAttributes size of ScanAttributes array
480 * ScanAttributes attribute numbers of interest in this tuple
483 typedef struct MergeJoinState
485 JoinState jstate; /* its first field is NodeTag */
486 List *mj_OuterSkipQual;
487 List *mj_InnerSkipQual;
489 TupleTableSlot *mj_MarkedTupleSlot;
493 * HashJoinState information
495 * hj_HashTable hash table for the hashjoin
496 * hj_CurBucketNo bucket# for current outer tuple
497 * hj_CurTuple last inner tuple matched to current outer
498 * tuple, or NULL if starting search
499 * (CurBucketNo and CurTuple are meaningless
500 * unless OuterTupleSlot is nonempty!)
501 * hj_InnerHashKey the inner hash key in the hashjoin condition
502 * hj_OuterTupleSlot tuple slot for outer tuples
503 * hj_HashTupleSlot tuple slot for hashed tuples
505 * JoinState information
507 * CommonState information
509 * OuterTupleSlot pointer to slot containing current "outer" tuple
510 * ResultTupleSlot pointer to slot in tuple table for projected tuple
511 * ExprContext node's current expression context
512 * ProjInfo info this node uses to form tuple projections
513 * NumScanAttributes size of ScanAttributes array
514 * ScanAttributes attribute numbers of interest in this tuple
517 typedef struct HashJoinState
519 JoinState jstate; /* its first field is NodeTag */
520 HashJoinTable hj_HashTable;
522 HashJoinTuple hj_CurTuple;
523 Var *hj_InnerHashKey;
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_useFirstTuple; /* first tuple not processed yet */
589 HeapTuple grp_firstTuple;
593 * SortState information
595 *| sort nodes are really just a kind of a scan since
596 *| we implement sorts by retrieving 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 * hashtable hash table for the hashjoin
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 */
672 HashJoinTable hashtable;
676 /* -----------------------
677 * TeeState information
678 * leftPlace : next item in the queue unseen by the left parent
679 * rightPlace : next item in the queue unseen by the right parent
680 * lastPlace : last item in the queue
681 * bufferRelname : name of the relation used as the buffer queue
682 * bufferRel : the relation used as the buffer queue
683 * mcxt : for now, tee's have their own memory context
684 * may be cleaned up later if portals are cleaned up
686 * initially, a Tee starts with [left/right]Place variables set to -1.
687 * on cleanup, queue is free'd when both leftPlace and rightPlace = -1
688 * -------------------------
690 typedef struct TeeState
692 CommonState cstate; /* its first field is NodeTag */
696 char *tee_bufferRelname;
697 Relation tee_bufferRel;
698 MemoryContext tee_mcxt;
699 HeapScanDesc tee_leftScanDesc,
704 #endif /* EXECNODES_H */