00001 /*------------------------------------------------------------------------- 00002 * 00003 * execnodes.h 00004 * definitions for executor state nodes 00005 * 00006 * 00007 * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group 00008 * Portions Copyright (c) 1994, Regents of the University of California 00009 * 00010 * src/include/nodes/execnodes.h 00011 * 00012 *------------------------------------------------------------------------- 00013 */ 00014 #ifndef EXECNODES_H 00015 #define EXECNODES_H 00016 00017 #include "access/genam.h" 00018 #include "access/heapam.h" 00019 #include "executor/instrument.h" 00020 #include "nodes/params.h" 00021 #include "nodes/plannodes.h" 00022 #include "utils/reltrigger.h" 00023 #include "utils/sortsupport.h" 00024 #include "utils/tuplestore.h" 00025 00026 00027 /* ---------------- 00028 * IndexInfo information 00029 * 00030 * this struct holds the information needed to construct new index 00031 * entries for a particular index. Used for both index_build and 00032 * retail creation of index entries. 00033 * 00034 * NumIndexAttrs number of columns in this index 00035 * KeyAttrNumbers underlying-rel attribute numbers used as keys 00036 * (zeroes indicate expressions) 00037 * Expressions expr trees for expression entries, or NIL if none 00038 * ExpressionsState exec state for expressions, or NIL if none 00039 * Predicate partial-index predicate, or NIL if none 00040 * PredicateState exec state for predicate, or NIL if none 00041 * ExclusionOps Per-column exclusion operators, or NULL if none 00042 * ExclusionProcs Underlying function OIDs for ExclusionOps 00043 * ExclusionStrats Opclass strategy numbers for ExclusionOps 00044 * Unique is it a unique index? 00045 * ReadyForInserts is it valid for inserts? 00046 * Concurrent are we doing a concurrent index build? 00047 * BrokenHotChain did we detect any broken HOT chains? 00048 * 00049 * ii_Concurrent and ii_BrokenHotChain are used only during index build; 00050 * they're conventionally set to false otherwise. 00051 * ---------------- 00052 */ 00053 typedef struct IndexInfo 00054 { 00055 NodeTag type; 00056 int ii_NumIndexAttrs; 00057 AttrNumber ii_KeyAttrNumbers[INDEX_MAX_KEYS]; 00058 List *ii_Expressions; /* list of Expr */ 00059 List *ii_ExpressionsState; /* list of ExprState */ 00060 List *ii_Predicate; /* list of Expr */ 00061 List *ii_PredicateState; /* list of ExprState */ 00062 Oid *ii_ExclusionOps; /* array with one entry per column */ 00063 Oid *ii_ExclusionProcs; /* array with one entry per column */ 00064 uint16 *ii_ExclusionStrats; /* array with one entry per column */ 00065 bool ii_Unique; 00066 bool ii_ReadyForInserts; 00067 bool ii_Concurrent; 00068 bool ii_BrokenHotChain; 00069 } IndexInfo; 00070 00071 /* ---------------- 00072 * ExprContext_CB 00073 * 00074 * List of callbacks to be called at ExprContext shutdown. 00075 * ---------------- 00076 */ 00077 typedef void (*ExprContextCallbackFunction) (Datum arg); 00078 00079 typedef struct ExprContext_CB 00080 { 00081 struct ExprContext_CB *next; 00082 ExprContextCallbackFunction function; 00083 Datum arg; 00084 } ExprContext_CB; 00085 00086 /* ---------------- 00087 * ExprContext 00088 * 00089 * This class holds the "current context" information 00090 * needed to evaluate expressions for doing tuple qualifications 00091 * and tuple projections. For example, if an expression refers 00092 * to an attribute in the current inner tuple then we need to know 00093 * what the current inner tuple is and so we look at the expression 00094 * context. 00095 * 00096 * There are two memory contexts associated with an ExprContext: 00097 * * ecxt_per_query_memory is a query-lifespan context, typically the same 00098 * context the ExprContext node itself is allocated in. This context 00099 * can be used for purposes such as storing function call cache info. 00100 * * ecxt_per_tuple_memory is a short-term context for expression results. 00101 * As the name suggests, it will typically be reset once per tuple, 00102 * before we begin to evaluate expressions for that tuple. Each 00103 * ExprContext normally has its very own per-tuple memory context. 00104 * 00105 * CurrentMemoryContext should be set to ecxt_per_tuple_memory before 00106 * calling ExecEvalExpr() --- see ExecEvalExprSwitchContext(). 00107 * ---------------- 00108 */ 00109 typedef struct ExprContext 00110 { 00111 NodeTag type; 00112 00113 /* Tuples that Var nodes in expression may refer to */ 00114 TupleTableSlot *ecxt_scantuple; 00115 TupleTableSlot *ecxt_innertuple; 00116 TupleTableSlot *ecxt_outertuple; 00117 00118 /* Memory contexts for expression evaluation --- see notes above */ 00119 MemoryContext ecxt_per_query_memory; 00120 MemoryContext ecxt_per_tuple_memory; 00121 00122 /* Values to substitute for Param nodes in expression */ 00123 ParamExecData *ecxt_param_exec_vals; /* for PARAM_EXEC params */ 00124 ParamListInfo ecxt_param_list_info; /* for other param types */ 00125 00126 /* 00127 * Values to substitute for Aggref nodes in the expressions of an Agg 00128 * node, or for WindowFunc nodes within a WindowAgg node. 00129 */ 00130 Datum *ecxt_aggvalues; /* precomputed values for aggs/windowfuncs */ 00131 bool *ecxt_aggnulls; /* null flags for aggs/windowfuncs */ 00132 00133 /* Value to substitute for CaseTestExpr nodes in expression */ 00134 Datum caseValue_datum; 00135 bool caseValue_isNull; 00136 00137 /* Value to substitute for CoerceToDomainValue nodes in expression */ 00138 Datum domainValue_datum; 00139 bool domainValue_isNull; 00140 00141 /* Link to containing EState (NULL if a standalone ExprContext) */ 00142 struct EState *ecxt_estate; 00143 00144 /* Functions to call back when ExprContext is shut down */ 00145 ExprContext_CB *ecxt_callbacks; 00146 } ExprContext; 00147 00148 /* 00149 * Set-result status returned by ExecEvalExpr() 00150 */ 00151 typedef enum 00152 { 00153 ExprSingleResult, /* expression does not return a set */ 00154 ExprMultipleResult, /* this result is an element of a set */ 00155 ExprEndResult /* there are no more elements in the set */ 00156 } ExprDoneCond; 00157 00158 /* 00159 * Return modes for functions returning sets. Note values must be chosen 00160 * as separate bits so that a bitmask can be formed to indicate supported 00161 * modes. SFRM_Materialize_Random and SFRM_Materialize_Preferred are 00162 * auxiliary flags about SFRM_Materialize mode, rather than separate modes. 00163 */ 00164 typedef enum 00165 { 00166 SFRM_ValuePerCall = 0x01, /* one value returned per call */ 00167 SFRM_Materialize = 0x02, /* result set instantiated in Tuplestore */ 00168 SFRM_Materialize_Random = 0x04, /* Tuplestore needs randomAccess */ 00169 SFRM_Materialize_Preferred = 0x08 /* caller prefers Tuplestore */ 00170 } SetFunctionReturnMode; 00171 00172 /* 00173 * When calling a function that might return a set (multiple rows), 00174 * a node of this type is passed as fcinfo->resultinfo to allow 00175 * return status to be passed back. A function returning set should 00176 * raise an error if no such resultinfo is provided. 00177 */ 00178 typedef struct ReturnSetInfo 00179 { 00180 NodeTag type; 00181 /* values set by caller: */ 00182 ExprContext *econtext; /* context function is being called in */ 00183 TupleDesc expectedDesc; /* tuple descriptor expected by caller */ 00184 int allowedModes; /* bitmask: return modes caller can handle */ 00185 /* result status from function (but pre-initialized by caller): */ 00186 SetFunctionReturnMode returnMode; /* actual return mode */ 00187 ExprDoneCond isDone; /* status for ValuePerCall mode */ 00188 /* fields filled by function in Materialize return mode: */ 00189 Tuplestorestate *setResult; /* holds the complete returned tuple set */ 00190 TupleDesc setDesc; /* actual descriptor for returned tuples */ 00191 } ReturnSetInfo; 00192 00193 /* ---------------- 00194 * ProjectionInfo node information 00195 * 00196 * This is all the information needed to perform projections --- 00197 * that is, form new tuples by evaluation of targetlist expressions. 00198 * Nodes which need to do projections create one of these. 00199 * 00200 * ExecProject() evaluates the tlist, forms a tuple, and stores it 00201 * in the given slot. Note that the result will be a "virtual" tuple 00202 * unless ExecMaterializeSlot() is then called to force it to be 00203 * converted to a physical tuple. The slot must have a tupledesc 00204 * that matches the output of the tlist! 00205 * 00206 * The planner very often produces tlists that consist entirely of 00207 * simple Var references (lower levels of a plan tree almost always 00208 * look like that). And top-level tlists are often mostly Vars too. 00209 * We therefore optimize execution of simple-Var tlist entries. 00210 * The pi_targetlist list actually contains only the tlist entries that 00211 * aren't simple Vars, while those that are Vars are processed using the 00212 * varSlotOffsets/varNumbers/varOutputCols arrays. 00213 * 00214 * The lastXXXVar fields are used to optimize fetching of fields from 00215 * input tuples: they let us do a slot_getsomeattrs() call to ensure 00216 * that all needed attributes are extracted in one pass. 00217 * 00218 * targetlist target list for projection (non-Var expressions only) 00219 * exprContext expression context in which to evaluate targetlist 00220 * slot slot to place projection result in 00221 * itemIsDone workspace array for ExecProject 00222 * directMap true if varOutputCols[] is an identity map 00223 * numSimpleVars number of simple Vars found in original tlist 00224 * varSlotOffsets array indicating which slot each simple Var is from 00225 * varNumbers array containing input attr numbers of simple Vars 00226 * varOutputCols array containing output attr numbers of simple Vars 00227 * lastInnerVar highest attnum from inner tuple slot (0 if none) 00228 * lastOuterVar highest attnum from outer tuple slot (0 if none) 00229 * lastScanVar highest attnum from scan tuple slot (0 if none) 00230 * ---------------- 00231 */ 00232 typedef struct ProjectionInfo 00233 { 00234 NodeTag type; 00235 List *pi_targetlist; 00236 ExprContext *pi_exprContext; 00237 TupleTableSlot *pi_slot; 00238 ExprDoneCond *pi_itemIsDone; 00239 bool pi_directMap; 00240 int pi_numSimpleVars; 00241 int *pi_varSlotOffsets; 00242 int *pi_varNumbers; 00243 int *pi_varOutputCols; 00244 int pi_lastInnerVar; 00245 int pi_lastOuterVar; 00246 int pi_lastScanVar; 00247 } ProjectionInfo; 00248 00249 /* ---------------- 00250 * JunkFilter 00251 * 00252 * This class is used to store information regarding junk attributes. 00253 * A junk attribute is an attribute in a tuple that is needed only for 00254 * storing intermediate information in the executor, and does not belong 00255 * in emitted tuples. For example, when we do an UPDATE query, 00256 * the planner adds a "junk" entry to the targetlist so that the tuples 00257 * returned to ExecutePlan() contain an extra attribute: the ctid of 00258 * the tuple to be updated. This is needed to do the update, but we 00259 * don't want the ctid to be part of the stored new tuple! So, we 00260 * apply a "junk filter" to remove the junk attributes and form the 00261 * real output tuple. The junkfilter code also provides routines to 00262 * extract the values of the junk attribute(s) from the input tuple. 00263 * 00264 * targetList: the original target list (including junk attributes). 00265 * cleanTupType: the tuple descriptor for the "clean" tuple (with 00266 * junk attributes removed). 00267 * cleanMap: A map with the correspondence between the non-junk 00268 * attribute numbers of the "original" tuple and the 00269 * attribute numbers of the "clean" tuple. 00270 * resultSlot: tuple slot used to hold cleaned tuple. 00271 * junkAttNo: not used by junkfilter code. Can be used by caller 00272 * to remember the attno of a specific junk attribute 00273 * (nodeModifyTable.c keeps the "ctid" or "wholerow" 00274 * attno here). 00275 * ---------------- 00276 */ 00277 typedef struct JunkFilter 00278 { 00279 NodeTag type; 00280 List *jf_targetList; 00281 TupleDesc jf_cleanTupType; 00282 AttrNumber *jf_cleanMap; 00283 TupleTableSlot *jf_resultSlot; 00284 AttrNumber jf_junkAttNo; 00285 } JunkFilter; 00286 00287 /* ---------------- 00288 * ResultRelInfo information 00289 * 00290 * Whenever we update an existing relation, we have to 00291 * update indices on the relation, and perhaps also fire triggers. 00292 * The ResultRelInfo class is used to hold all the information needed 00293 * about a result relation, including indices.. -cim 10/15/89 00294 * 00295 * RangeTableIndex result relation's range table index 00296 * RelationDesc relation descriptor for result relation 00297 * NumIndices # of indices existing on result relation 00298 * IndexRelationDescs array of relation descriptors for indices 00299 * IndexRelationInfo array of key/attr info for indices 00300 * TrigDesc triggers to be fired, if any 00301 * TrigFunctions cached lookup info for trigger functions 00302 * TrigWhenExprs array of trigger WHEN expr states 00303 * TrigInstrument optional runtime measurements for triggers 00304 * FdwRoutine FDW callback functions, if foreign table 00305 * FdwState available to save private state of FDW 00306 * ConstraintExprs array of constraint-checking expr states 00307 * junkFilter for removing junk attributes from tuples 00308 * projectReturning for computing a RETURNING list 00309 * ---------------- 00310 */ 00311 typedef struct ResultRelInfo 00312 { 00313 NodeTag type; 00314 Index ri_RangeTableIndex; 00315 Relation ri_RelationDesc; 00316 int ri_NumIndices; 00317 RelationPtr ri_IndexRelationDescs; 00318 IndexInfo **ri_IndexRelationInfo; 00319 TriggerDesc *ri_TrigDesc; 00320 FmgrInfo *ri_TrigFunctions; 00321 List **ri_TrigWhenExprs; 00322 Instrumentation *ri_TrigInstrument; 00323 struct FdwRoutine *ri_FdwRoutine; 00324 void *ri_FdwState; 00325 List **ri_ConstraintExprs; 00326 JunkFilter *ri_junkFilter; 00327 ProjectionInfo *ri_projectReturning; 00328 } ResultRelInfo; 00329 00330 /* ---------------- 00331 * EState information 00332 * 00333 * Master working state for an Executor invocation 00334 * ---------------- 00335 */ 00336 typedef struct EState 00337 { 00338 NodeTag type; 00339 00340 /* Basic state for all query types: */ 00341 ScanDirection es_direction; /* current scan direction */ 00342 Snapshot es_snapshot; /* time qual to use */ 00343 Snapshot es_crosscheck_snapshot; /* crosscheck time qual for RI */ 00344 List *es_range_table; /* List of RangeTblEntry */ 00345 PlannedStmt *es_plannedstmt; /* link to top of plan tree */ 00346 00347 JunkFilter *es_junkFilter; /* top-level junk filter, if any */ 00348 00349 /* If query can insert/delete tuples, the command ID to mark them with */ 00350 CommandId es_output_cid; 00351 00352 /* Info about target table(s) for insert/update/delete queries: */ 00353 ResultRelInfo *es_result_relations; /* array of ResultRelInfos */ 00354 int es_num_result_relations; /* length of array */ 00355 ResultRelInfo *es_result_relation_info; /* currently active array elt */ 00356 00357 /* Stuff used for firing triggers: */ 00358 List *es_trig_target_relations; /* trigger-only ResultRelInfos */ 00359 TupleTableSlot *es_trig_tuple_slot; /* for trigger output tuples */ 00360 TupleTableSlot *es_trig_oldtup_slot; /* for TriggerEnabled */ 00361 TupleTableSlot *es_trig_newtup_slot; /* for TriggerEnabled */ 00362 00363 /* Parameter info: */ 00364 ParamListInfo es_param_list_info; /* values of external params */ 00365 ParamExecData *es_param_exec_vals; /* values of internal params */ 00366 00367 /* Other working state: */ 00368 MemoryContext es_query_cxt; /* per-query context in which EState lives */ 00369 00370 List *es_tupleTable; /* List of TupleTableSlots */ 00371 00372 List *es_rowMarks; /* List of ExecRowMarks */ 00373 00374 uint32 es_processed; /* # of tuples processed */ 00375 Oid es_lastoid; /* last oid processed (by INSERT) */ 00376 00377 int es_top_eflags; /* eflags passed to ExecutorStart */ 00378 int es_instrument; /* OR of InstrumentOption flags */ 00379 bool es_finished; /* true when ExecutorFinish is done */ 00380 00381 List *es_exprcontexts; /* List of ExprContexts within EState */ 00382 00383 List *es_subplanstates; /* List of PlanState for SubPlans */ 00384 00385 List *es_auxmodifytables; /* List of secondary ModifyTableStates */ 00386 00387 /* 00388 * this ExprContext is for per-output-tuple operations, such as constraint 00389 * checks and index-value computations. It will be reset for each output 00390 * tuple. Note that it will be created only if needed. 00391 */ 00392 ExprContext *es_per_tuple_exprcontext; 00393 00394 /* 00395 * These fields are for re-evaluating plan quals when an updated tuple is 00396 * substituted in READ COMMITTED mode. es_epqTuple[] contains tuples that 00397 * scan plan nodes should return instead of whatever they'd normally 00398 * return, or NULL if nothing to return; es_epqTupleSet[] is true if a 00399 * particular array entry is valid; and es_epqScanDone[] is state to 00400 * remember if the tuple has been returned already. Arrays are of size 00401 * list_length(es_range_table) and are indexed by scan node scanrelid - 1. 00402 */ 00403 HeapTuple *es_epqTuple; /* array of EPQ substitute tuples */ 00404 bool *es_epqTupleSet; /* true if EPQ tuple is provided */ 00405 bool *es_epqScanDone; /* true if EPQ tuple has been fetched */ 00406 } EState; 00407 00408 00409 /* 00410 * ExecRowMark - 00411 * runtime representation of FOR [KEY] UPDATE/SHARE clauses 00412 * 00413 * When doing UPDATE, DELETE, or SELECT FOR [KEY] UPDATE/SHARE, we should have an 00414 * ExecRowMark for each non-target relation in the query (except inheritance 00415 * parent RTEs, which can be ignored at runtime). See PlanRowMark for details 00416 * about most of the fields. In addition to fields directly derived from 00417 * PlanRowMark, we store curCtid, which is used by the WHERE CURRENT OF code. 00418 * 00419 * EState->es_rowMarks is a list of these structs. 00420 */ 00421 typedef struct ExecRowMark 00422 { 00423 Relation relation; /* opened and suitably locked relation */ 00424 Index rti; /* its range table index */ 00425 Index prti; /* parent range table index, if child */ 00426 Index rowmarkId; /* unique identifier for resjunk columns */ 00427 RowMarkType markType; /* see enum in nodes/plannodes.h */ 00428 bool noWait; /* NOWAIT option */ 00429 ItemPointerData curCtid; /* ctid of currently locked tuple, if any */ 00430 } ExecRowMark; 00431 00432 /* 00433 * ExecAuxRowMark - 00434 * additional runtime representation of FOR [KEY] UPDATE/SHARE clauses 00435 * 00436 * Each LockRows and ModifyTable node keeps a list of the rowmarks it needs to 00437 * deal with. In addition to a pointer to the related entry in es_rowMarks, 00438 * this struct carries the column number(s) of the resjunk columns associated 00439 * with the rowmark (see comments for PlanRowMark for more detail). In the 00440 * case of ModifyTable, there has to be a separate ExecAuxRowMark list for 00441 * each child plan, because the resjunk columns could be at different physical 00442 * column positions in different subplans. 00443 */ 00444 typedef struct ExecAuxRowMark 00445 { 00446 ExecRowMark *rowmark; /* related entry in es_rowMarks */ 00447 AttrNumber ctidAttNo; /* resno of ctid junk attribute, if any */ 00448 AttrNumber toidAttNo; /* resno of tableoid junk attribute, if any */ 00449 AttrNumber wholeAttNo; /* resno of whole-row junk attribute, if any */ 00450 } ExecAuxRowMark; 00451 00452 00453 /* ---------------------------------------------------------------- 00454 * Tuple Hash Tables 00455 * 00456 * All-in-memory tuple hash tables are used for a number of purposes. 00457 * 00458 * Note: tab_hash_funcs are for the key datatype(s) stored in the table, 00459 * and tab_eq_funcs are non-cross-type equality operators for those types. 00460 * Normally these are the only functions used, but FindTupleHashEntry() 00461 * supports searching a hashtable using cross-data-type hashing. For that, 00462 * the caller must supply hash functions for the LHS datatype as well as 00463 * the cross-type equality operators to use. in_hash_funcs and cur_eq_funcs 00464 * are set to point to the caller's function arrays while doing such a search. 00465 * During LookupTupleHashEntry(), they point to tab_hash_funcs and 00466 * tab_eq_funcs respectively. 00467 * ---------------------------------------------------------------- 00468 */ 00469 typedef struct TupleHashEntryData *TupleHashEntry; 00470 typedef struct TupleHashTableData *TupleHashTable; 00471 00472 typedef struct TupleHashEntryData 00473 { 00474 /* firstTuple must be the first field in this struct! */ 00475 MinimalTuple firstTuple; /* copy of first tuple in this group */ 00476 /* there may be additional data beyond the end of this struct */ 00477 } TupleHashEntryData; /* VARIABLE LENGTH STRUCT */ 00478 00479 typedef struct TupleHashTableData 00480 { 00481 HTAB *hashtab; /* underlying dynahash table */ 00482 int numCols; /* number of columns in lookup key */ 00483 AttrNumber *keyColIdx; /* attr numbers of key columns */ 00484 FmgrInfo *tab_hash_funcs; /* hash functions for table datatype(s) */ 00485 FmgrInfo *tab_eq_funcs; /* equality functions for table datatype(s) */ 00486 MemoryContext tablecxt; /* memory context containing table */ 00487 MemoryContext tempcxt; /* context for function evaluations */ 00488 Size entrysize; /* actual size to make each hash entry */ 00489 TupleTableSlot *tableslot; /* slot for referencing table entries */ 00490 /* The following fields are set transiently for each table search: */ 00491 TupleTableSlot *inputslot; /* current input tuple's slot */ 00492 FmgrInfo *in_hash_funcs; /* hash functions for input datatype(s) */ 00493 FmgrInfo *cur_eq_funcs; /* equality functions for input vs. table */ 00494 } TupleHashTableData; 00495 00496 typedef HASH_SEQ_STATUS TupleHashIterator; 00497 00498 /* 00499 * Use InitTupleHashIterator/TermTupleHashIterator for a read/write scan. 00500 * Use ResetTupleHashIterator if the table can be frozen (in this case no 00501 * explicit scan termination is needed). 00502 */ 00503 #define InitTupleHashIterator(htable, iter) \ 00504 hash_seq_init(iter, (htable)->hashtab) 00505 #define TermTupleHashIterator(iter) \ 00506 hash_seq_term(iter) 00507 #define ResetTupleHashIterator(htable, iter) \ 00508 do { \ 00509 hash_freeze((htable)->hashtab); \ 00510 hash_seq_init(iter, (htable)->hashtab); \ 00511 } while (0) 00512 #define ScanTupleHashTable(iter) \ 00513 ((TupleHashEntry) hash_seq_search(iter)) 00514 00515 00516 /* ---------------------------------------------------------------- 00517 * Expression State Trees 00518 * 00519 * Each executable expression tree has a parallel ExprState tree. 00520 * 00521 * Unlike PlanState, there is not an exact one-for-one correspondence between 00522 * ExprState node types and Expr node types. Many Expr node types have no 00523 * need for node-type-specific run-time state, and so they can use plain 00524 * ExprState or GenericExprState as their associated ExprState node type. 00525 * ---------------------------------------------------------------- 00526 */ 00527 00528 /* ---------------- 00529 * ExprState node 00530 * 00531 * ExprState is the common superclass for all ExprState-type nodes. 00532 * 00533 * It can also be instantiated directly for leaf Expr nodes that need no 00534 * local run-time state (such as Var, Const, or Param). 00535 * 00536 * To save on dispatch overhead, each ExprState node contains a function 00537 * pointer to the routine to execute to evaluate the node. 00538 * ---------------- 00539 */ 00540 00541 typedef struct ExprState ExprState; 00542 00543 typedef Datum (*ExprStateEvalFunc) (ExprState *expression, 00544 ExprContext *econtext, 00545 bool *isNull, 00546 ExprDoneCond *isDone); 00547 00548 struct ExprState 00549 { 00550 NodeTag type; 00551 Expr *expr; /* associated Expr node */ 00552 ExprStateEvalFunc evalfunc; /* routine to run to execute node */ 00553 }; 00554 00555 /* ---------------- 00556 * GenericExprState node 00557 * 00558 * This is used for Expr node types that need no local run-time state, 00559 * but have one child Expr node. 00560 * ---------------- 00561 */ 00562 typedef struct GenericExprState 00563 { 00564 ExprState xprstate; 00565 ExprState *arg; /* state of my child node */ 00566 } GenericExprState; 00567 00568 /* ---------------- 00569 * WholeRowVarExprState node 00570 * ---------------- 00571 */ 00572 typedef struct WholeRowVarExprState 00573 { 00574 ExprState xprstate; 00575 struct PlanState *parent; /* parent PlanState, or NULL if none */ 00576 JunkFilter *wrv_junkFilter; /* JunkFilter to remove resjunk cols */ 00577 } WholeRowVarExprState; 00578 00579 /* ---------------- 00580 * AggrefExprState node 00581 * ---------------- 00582 */ 00583 typedef struct AggrefExprState 00584 { 00585 ExprState xprstate; 00586 List *args; /* states of argument expressions */ 00587 int aggno; /* ID number for agg within its plan node */ 00588 } AggrefExprState; 00589 00590 /* ---------------- 00591 * WindowFuncExprState node 00592 * ---------------- 00593 */ 00594 typedef struct WindowFuncExprState 00595 { 00596 ExprState xprstate; 00597 List *args; /* states of argument expressions */ 00598 int wfuncno; /* ID number for wfunc within its plan node */ 00599 } WindowFuncExprState; 00600 00601 /* ---------------- 00602 * ArrayRefExprState node 00603 * 00604 * Note: array types can be fixed-length (typlen > 0), but only when the 00605 * element type is itself fixed-length. Otherwise they are varlena structures 00606 * and have typlen = -1. In any case, an array type is never pass-by-value. 00607 * ---------------- 00608 */ 00609 typedef struct ArrayRefExprState 00610 { 00611 ExprState xprstate; 00612 List *refupperindexpr; /* states for child nodes */ 00613 List *reflowerindexpr; 00614 ExprState *refexpr; 00615 ExprState *refassgnexpr; 00616 int16 refattrlength; /* typlen of array type */ 00617 int16 refelemlength; /* typlen of the array element type */ 00618 bool refelembyval; /* is the element type pass-by-value? */ 00619 char refelemalign; /* typalign of the element type */ 00620 } ArrayRefExprState; 00621 00622 /* ---------------- 00623 * FuncExprState node 00624 * 00625 * Although named for FuncExpr, this is also used for OpExpr, DistinctExpr, 00626 * and NullIf nodes; be careful to check what xprstate.expr is actually 00627 * pointing at! 00628 * ---------------- 00629 */ 00630 typedef struct FuncExprState 00631 { 00632 ExprState xprstate; 00633 List *args; /* states of argument expressions */ 00634 00635 /* 00636 * Function manager's lookup info for the target function. If func.fn_oid 00637 * is InvalidOid, we haven't initialized it yet (nor any of the following 00638 * fields). 00639 */ 00640 FmgrInfo func; 00641 00642 /* 00643 * For a set-returning function (SRF) that returns a tuplestore, we keep 00644 * the tuplestore here and dole out the result rows one at a time. The 00645 * slot holds the row currently being returned. 00646 */ 00647 Tuplestorestate *funcResultStore; 00648 TupleTableSlot *funcResultSlot; 00649 00650 /* 00651 * In some cases we need to compute a tuple descriptor for the function's 00652 * output. If so, it's stored here. 00653 */ 00654 TupleDesc funcResultDesc; 00655 bool funcReturnsTuple; /* valid when funcResultDesc isn't 00656 * NULL */ 00657 00658 /* 00659 * setArgsValid is true when we are evaluating a set-returning function 00660 * that uses value-per-call mode and we are in the middle of a call 00661 * series; we want to pass the same argument values to the function again 00662 * (and again, until it returns ExprEndResult). This indicates that 00663 * fcinfo_data already contains valid argument data. 00664 */ 00665 bool setArgsValid; 00666 00667 /* 00668 * Flag to remember whether we found a set-valued argument to the 00669 * function. This causes the function result to be a set as well. Valid 00670 * only when setArgsValid is true or funcResultStore isn't NULL. 00671 */ 00672 bool setHasSetArg; /* some argument returns a set */ 00673 00674 /* 00675 * Flag to remember whether we have registered a shutdown callback for 00676 * this FuncExprState. We do so only if funcResultStore or setArgsValid 00677 * has been set at least once (since all the callback is for is to release 00678 * the tuplestore or clear setArgsValid). 00679 */ 00680 bool shutdown_reg; /* a shutdown callback is registered */ 00681 00682 /* 00683 * Call parameter structure for the function. This has been initialized 00684 * (by InitFunctionCallInfoData) if func.fn_oid is valid. It also saves 00685 * argument values between calls, when setArgsValid is true. 00686 */ 00687 FunctionCallInfoData fcinfo_data; 00688 } FuncExprState; 00689 00690 /* ---------------- 00691 * ScalarArrayOpExprState node 00692 * 00693 * This is a FuncExprState plus some additional data. 00694 * ---------------- 00695 */ 00696 typedef struct ScalarArrayOpExprState 00697 { 00698 FuncExprState fxprstate; 00699 /* Cached info about array element type */ 00700 Oid element_type; 00701 int16 typlen; 00702 bool typbyval; 00703 char typalign; 00704 } ScalarArrayOpExprState; 00705 00706 /* ---------------- 00707 * BoolExprState node 00708 * ---------------- 00709 */ 00710 typedef struct BoolExprState 00711 { 00712 ExprState xprstate; 00713 List *args; /* states of argument expression(s) */ 00714 } BoolExprState; 00715 00716 /* ---------------- 00717 * SubPlanState node 00718 * ---------------- 00719 */ 00720 typedef struct SubPlanState 00721 { 00722 ExprState xprstate; 00723 struct PlanState *planstate; /* subselect plan's state tree */ 00724 ExprState *testexpr; /* state of combining expression */ 00725 List *args; /* states of argument expression(s) */ 00726 HeapTuple curTuple; /* copy of most recent tuple from subplan */ 00727 Datum curArray; /* most recent array from ARRAY() subplan */ 00728 /* these are used when hashing the subselect's output: */ 00729 ProjectionInfo *projLeft; /* for projecting lefthand exprs */ 00730 ProjectionInfo *projRight; /* for projecting subselect output */ 00731 TupleHashTable hashtable; /* hash table for no-nulls subselect rows */ 00732 TupleHashTable hashnulls; /* hash table for rows with null(s) */ 00733 bool havehashrows; /* TRUE if hashtable is not empty */ 00734 bool havenullrows; /* TRUE if hashnulls is not empty */ 00735 MemoryContext hashtablecxt; /* memory context containing hash tables */ 00736 MemoryContext hashtempcxt; /* temp memory context for hash tables */ 00737 ExprContext *innerecontext; /* econtext for computing inner tuples */ 00738 AttrNumber *keyColIdx; /* control data for hash tables */ 00739 FmgrInfo *tab_hash_funcs; /* hash functions for table datatype(s) */ 00740 FmgrInfo *tab_eq_funcs; /* equality functions for table datatype(s) */ 00741 FmgrInfo *lhs_hash_funcs; /* hash functions for lefthand datatype(s) */ 00742 FmgrInfo *cur_eq_funcs; /* equality functions for LHS vs. table */ 00743 } SubPlanState; 00744 00745 /* ---------------- 00746 * AlternativeSubPlanState node 00747 * ---------------- 00748 */ 00749 typedef struct AlternativeSubPlanState 00750 { 00751 ExprState xprstate; 00752 List *subplans; /* states of alternative subplans */ 00753 int active; /* list index of the one we're using */ 00754 } AlternativeSubPlanState; 00755 00756 /* ---------------- 00757 * FieldSelectState node 00758 * ---------------- 00759 */ 00760 typedef struct FieldSelectState 00761 { 00762 ExprState xprstate; 00763 ExprState *arg; /* input expression */ 00764 TupleDesc argdesc; /* tupdesc for most recent input */ 00765 } FieldSelectState; 00766 00767 /* ---------------- 00768 * FieldStoreState node 00769 * ---------------- 00770 */ 00771 typedef struct FieldStoreState 00772 { 00773 ExprState xprstate; 00774 ExprState *arg; /* input tuple value */ 00775 List *newvals; /* new value(s) for field(s) */ 00776 TupleDesc argdesc; /* tupdesc for most recent input */ 00777 } FieldStoreState; 00778 00779 /* ---------------- 00780 * CoerceViaIOState node 00781 * ---------------- 00782 */ 00783 typedef struct CoerceViaIOState 00784 { 00785 ExprState xprstate; 00786 ExprState *arg; /* input expression */ 00787 FmgrInfo outfunc; /* lookup info for source output function */ 00788 FmgrInfo infunc; /* lookup info for result input function */ 00789 Oid intypioparam; /* argument needed for input function */ 00790 } CoerceViaIOState; 00791 00792 /* ---------------- 00793 * ArrayCoerceExprState node 00794 * ---------------- 00795 */ 00796 typedef struct ArrayCoerceExprState 00797 { 00798 ExprState xprstate; 00799 ExprState *arg; /* input array value */ 00800 Oid resultelemtype; /* element type of result array */ 00801 FmgrInfo elemfunc; /* lookup info for element coercion function */ 00802 /* use struct pointer to avoid including array.h here */ 00803 struct ArrayMapState *amstate; /* workspace for array_map */ 00804 } ArrayCoerceExprState; 00805 00806 /* ---------------- 00807 * ConvertRowtypeExprState node 00808 * ---------------- 00809 */ 00810 typedef struct ConvertRowtypeExprState 00811 { 00812 ExprState xprstate; 00813 ExprState *arg; /* input tuple value */ 00814 TupleDesc indesc; /* tupdesc for source rowtype */ 00815 TupleDesc outdesc; /* tupdesc for result rowtype */ 00816 /* use "struct" so we needn't include tupconvert.h here */ 00817 struct TupleConversionMap *map; 00818 bool initialized; 00819 } ConvertRowtypeExprState; 00820 00821 /* ---------------- 00822 * CaseExprState node 00823 * ---------------- 00824 */ 00825 typedef struct CaseExprState 00826 { 00827 ExprState xprstate; 00828 ExprState *arg; /* implicit equality comparison argument */ 00829 List *args; /* the arguments (list of WHEN clauses) */ 00830 ExprState *defresult; /* the default result (ELSE clause) */ 00831 } CaseExprState; 00832 00833 /* ---------------- 00834 * CaseWhenState node 00835 * ---------------- 00836 */ 00837 typedef struct CaseWhenState 00838 { 00839 ExprState xprstate; 00840 ExprState *expr; /* condition expression */ 00841 ExprState *result; /* substitution result */ 00842 } CaseWhenState; 00843 00844 /* ---------------- 00845 * ArrayExprState node 00846 * 00847 * Note: ARRAY[] expressions always produce varlena arrays, never fixed-length 00848 * arrays. 00849 * ---------------- 00850 */ 00851 typedef struct ArrayExprState 00852 { 00853 ExprState xprstate; 00854 List *elements; /* states for child nodes */ 00855 int16 elemlength; /* typlen of the array element type */ 00856 bool elembyval; /* is the element type pass-by-value? */ 00857 char elemalign; /* typalign of the element type */ 00858 } ArrayExprState; 00859 00860 /* ---------------- 00861 * RowExprState node 00862 * ---------------- 00863 */ 00864 typedef struct RowExprState 00865 { 00866 ExprState xprstate; 00867 List *args; /* the arguments */ 00868 TupleDesc tupdesc; /* descriptor for result tuples */ 00869 } RowExprState; 00870 00871 /* ---------------- 00872 * RowCompareExprState node 00873 * ---------------- 00874 */ 00875 typedef struct RowCompareExprState 00876 { 00877 ExprState xprstate; 00878 List *largs; /* the left-hand input arguments */ 00879 List *rargs; /* the right-hand input arguments */ 00880 FmgrInfo *funcs; /* array of comparison function info */ 00881 Oid *collations; /* array of collations to use */ 00882 } RowCompareExprState; 00883 00884 /* ---------------- 00885 * CoalesceExprState node 00886 * ---------------- 00887 */ 00888 typedef struct CoalesceExprState 00889 { 00890 ExprState xprstate; 00891 List *args; /* the arguments */ 00892 } CoalesceExprState; 00893 00894 /* ---------------- 00895 * MinMaxExprState node 00896 * ---------------- 00897 */ 00898 typedef struct MinMaxExprState 00899 { 00900 ExprState xprstate; 00901 List *args; /* the arguments */ 00902 FmgrInfo cfunc; /* lookup info for comparison func */ 00903 } MinMaxExprState; 00904 00905 /* ---------------- 00906 * XmlExprState node 00907 * ---------------- 00908 */ 00909 typedef struct XmlExprState 00910 { 00911 ExprState xprstate; 00912 List *named_args; /* ExprStates for named arguments */ 00913 List *args; /* ExprStates for other arguments */ 00914 } XmlExprState; 00915 00916 /* ---------------- 00917 * NullTestState node 00918 * ---------------- 00919 */ 00920 typedef struct NullTestState 00921 { 00922 ExprState xprstate; 00923 ExprState *arg; /* input expression */ 00924 /* used only if input is of composite type: */ 00925 TupleDesc argdesc; /* tupdesc for most recent input */ 00926 } NullTestState; 00927 00928 /* ---------------- 00929 * CoerceToDomainState node 00930 * ---------------- 00931 */ 00932 typedef struct CoerceToDomainState 00933 { 00934 ExprState xprstate; 00935 ExprState *arg; /* input expression */ 00936 /* Cached list of constraints that need to be checked */ 00937 List *constraints; /* list of DomainConstraintState nodes */ 00938 } CoerceToDomainState; 00939 00940 /* 00941 * DomainConstraintState - one item to check during CoerceToDomain 00942 * 00943 * Note: this is just a Node, and not an ExprState, because it has no 00944 * corresponding Expr to link to. Nonetheless it is part of an ExprState 00945 * tree, so we give it a name following the xxxState convention. 00946 */ 00947 typedef enum DomainConstraintType 00948 { 00949 DOM_CONSTRAINT_NOTNULL, 00950 DOM_CONSTRAINT_CHECK 00951 } DomainConstraintType; 00952 00953 typedef struct DomainConstraintState 00954 { 00955 NodeTag type; 00956 DomainConstraintType constrainttype; /* constraint type */ 00957 char *name; /* name of constraint (for error msgs) */ 00958 ExprState *check_expr; /* for CHECK, a boolean expression */ 00959 } DomainConstraintState; 00960 00961 00962 /* ---------------------------------------------------------------- 00963 * Executor State Trees 00964 * 00965 * An executing query has a PlanState tree paralleling the Plan tree 00966 * that describes the plan. 00967 * ---------------------------------------------------------------- 00968 */ 00969 00970 /* ---------------- 00971 * PlanState node 00972 * 00973 * We never actually instantiate any PlanState nodes; this is just the common 00974 * abstract superclass for all PlanState-type nodes. 00975 * ---------------- 00976 */ 00977 typedef struct PlanState 00978 { 00979 NodeTag type; 00980 00981 Plan *plan; /* associated Plan node */ 00982 00983 EState *state; /* at execution time, states of individual 00984 * nodes point to one EState for the whole 00985 * top-level plan */ 00986 00987 Instrumentation *instrument; /* Optional runtime stats for this node */ 00988 00989 /* 00990 * Common structural data for all Plan types. These links to subsidiary 00991 * state trees parallel links in the associated plan tree (except for the 00992 * subPlan list, which does not exist in the plan tree). 00993 */ 00994 List *targetlist; /* target list to be computed at this node */ 00995 List *qual; /* implicitly-ANDed qual conditions */ 00996 struct PlanState *lefttree; /* input plan tree(s) */ 00997 struct PlanState *righttree; 00998 List *initPlan; /* Init SubPlanState nodes (un-correlated expr 00999 * subselects) */ 01000 List *subPlan; /* SubPlanState nodes in my expressions */ 01001 01002 /* 01003 * State for management of parameter-change-driven rescanning 01004 */ 01005 Bitmapset *chgParam; /* set of IDs of changed Params */ 01006 01007 /* 01008 * Other run-time state needed by most if not all node types. 01009 */ 01010 TupleTableSlot *ps_ResultTupleSlot; /* slot for my result tuples */ 01011 ExprContext *ps_ExprContext; /* node's expression-evaluation context */ 01012 ProjectionInfo *ps_ProjInfo; /* info for doing tuple projection */ 01013 bool ps_TupFromTlist;/* state flag for processing set-valued 01014 * functions in targetlist */ 01015 } PlanState; 01016 01017 /* ---------------- 01018 * these are defined to avoid confusion problems with "left" 01019 * and "right" and "inner" and "outer". The convention is that 01020 * the "left" plan is the "outer" plan and the "right" plan is 01021 * the inner plan, but these make the code more readable. 01022 * ---------------- 01023 */ 01024 #define innerPlanState(node) (((PlanState *)(node))->righttree) 01025 #define outerPlanState(node) (((PlanState *)(node))->lefttree) 01026 01027 /* Macros for inline access to certain instrumentation counters */ 01028 #define InstrCountFiltered1(node, delta) \ 01029 do { \ 01030 if (((PlanState *)(node))->instrument) \ 01031 ((PlanState *)(node))->instrument->nfiltered1 += (delta); \ 01032 } while(0) 01033 #define InstrCountFiltered2(node, delta) \ 01034 do { \ 01035 if (((PlanState *)(node))->instrument) \ 01036 ((PlanState *)(node))->instrument->nfiltered2 += (delta); \ 01037 } while(0) 01038 01039 /* 01040 * EPQState is state for executing an EvalPlanQual recheck on a candidate 01041 * tuple in ModifyTable or LockRows. The estate and planstate fields are 01042 * NULL if inactive. 01043 */ 01044 typedef struct EPQState 01045 { 01046 EState *estate; /* subsidiary EState */ 01047 PlanState *planstate; /* plan state tree ready to be executed */ 01048 TupleTableSlot *origslot; /* original output tuple to be rechecked */ 01049 Plan *plan; /* plan tree to be executed */ 01050 List *arowMarks; /* ExecAuxRowMarks (non-locking only) */ 01051 int epqParam; /* ID of Param to force scan node re-eval */ 01052 } EPQState; 01053 01054 01055 /* ---------------- 01056 * ResultState information 01057 * ---------------- 01058 */ 01059 typedef struct ResultState 01060 { 01061 PlanState ps; /* its first field is NodeTag */ 01062 ExprState *resconstantqual; 01063 bool rs_done; /* are we done? */ 01064 bool rs_checkqual; /* do we need to check the qual? */ 01065 } ResultState; 01066 01067 /* ---------------- 01068 * ModifyTableState information 01069 * ---------------- 01070 */ 01071 typedef struct ModifyTableState 01072 { 01073 PlanState ps; /* its first field is NodeTag */ 01074 CmdType operation; /* INSERT, UPDATE, or DELETE */ 01075 bool canSetTag; /* do we set the command tag/es_processed? */ 01076 bool mt_done; /* are we done? */ 01077 PlanState **mt_plans; /* subplans (one per target rel) */ 01078 int mt_nplans; /* number of plans in the array */ 01079 int mt_whichplan; /* which one is being executed (0..n-1) */ 01080 ResultRelInfo *resultRelInfo; /* per-subplan target relations */ 01081 List **mt_arowmarks; /* per-subplan ExecAuxRowMark lists */ 01082 EPQState mt_epqstate; /* for evaluating EvalPlanQual rechecks */ 01083 bool fireBSTriggers; /* do we need to fire stmt triggers? */ 01084 } ModifyTableState; 01085 01086 /* ---------------- 01087 * AppendState information 01088 * 01089 * nplans how many plans are in the array 01090 * whichplan which plan is being executed (0 .. n-1) 01091 * ---------------- 01092 */ 01093 typedef struct AppendState 01094 { 01095 PlanState ps; /* its first field is NodeTag */ 01096 PlanState **appendplans; /* array of PlanStates for my inputs */ 01097 int as_nplans; 01098 int as_whichplan; 01099 } AppendState; 01100 01101 /* ---------------- 01102 * MergeAppendState information 01103 * 01104 * nplans how many plans are in the array 01105 * nkeys number of sort key columns 01106 * sortkeys sort keys in SortSupport representation 01107 * slots current output tuple of each subplan 01108 * heap heap of active tuples 01109 * initialized true if we have fetched first tuple from each subplan 01110 * ---------------- 01111 */ 01112 typedef struct MergeAppendState 01113 { 01114 PlanState ps; /* its first field is NodeTag */ 01115 PlanState **mergeplans; /* array of PlanStates for my inputs */ 01116 int ms_nplans; 01117 int ms_nkeys; 01118 SortSupport ms_sortkeys; /* array of length ms_nkeys */ 01119 TupleTableSlot **ms_slots; /* array of length ms_nplans */ 01120 struct binaryheap *ms_heap; /* binary heap of slot indices */ 01121 bool ms_initialized; /* are subplans started? */ 01122 } MergeAppendState; 01123 01124 /* ---------------- 01125 * RecursiveUnionState information 01126 * 01127 * RecursiveUnionState is used for performing a recursive union. 01128 * 01129 * recursing T when we're done scanning the non-recursive term 01130 * intermediate_empty T if intermediate_table is currently empty 01131 * working_table working table (to be scanned by recursive term) 01132 * intermediate_table current recursive output (next generation of WT) 01133 * ---------------- 01134 */ 01135 typedef struct RecursiveUnionState 01136 { 01137 PlanState ps; /* its first field is NodeTag */ 01138 bool recursing; 01139 bool intermediate_empty; 01140 Tuplestorestate *working_table; 01141 Tuplestorestate *intermediate_table; 01142 /* Remaining fields are unused in UNION ALL case */ 01143 FmgrInfo *eqfunctions; /* per-grouping-field equality fns */ 01144 FmgrInfo *hashfunctions; /* per-grouping-field hash fns */ 01145 MemoryContext tempContext; /* short-term context for comparisons */ 01146 TupleHashTable hashtable; /* hash table for tuples already seen */ 01147 MemoryContext tableContext; /* memory context containing hash table */ 01148 } RecursiveUnionState; 01149 01150 /* ---------------- 01151 * BitmapAndState information 01152 * ---------------- 01153 */ 01154 typedef struct BitmapAndState 01155 { 01156 PlanState ps; /* its first field is NodeTag */ 01157 PlanState **bitmapplans; /* array of PlanStates for my inputs */ 01158 int nplans; /* number of input plans */ 01159 } BitmapAndState; 01160 01161 /* ---------------- 01162 * BitmapOrState information 01163 * ---------------- 01164 */ 01165 typedef struct BitmapOrState 01166 { 01167 PlanState ps; /* its first field is NodeTag */ 01168 PlanState **bitmapplans; /* array of PlanStates for my inputs */ 01169 int nplans; /* number of input plans */ 01170 } BitmapOrState; 01171 01172 /* ---------------------------------------------------------------- 01173 * Scan State Information 01174 * ---------------------------------------------------------------- 01175 */ 01176 01177 /* ---------------- 01178 * ScanState information 01179 * 01180 * ScanState extends PlanState for node types that represent 01181 * scans of an underlying relation. It can also be used for nodes 01182 * that scan the output of an underlying plan node --- in that case, 01183 * only ScanTupleSlot is actually useful, and it refers to the tuple 01184 * retrieved from the subplan. 01185 * 01186 * currentRelation relation being scanned (NULL if none) 01187 * currentScanDesc current scan descriptor for scan (NULL if none) 01188 * ScanTupleSlot pointer to slot in tuple table holding scan tuple 01189 * ---------------- 01190 */ 01191 typedef struct ScanState 01192 { 01193 PlanState ps; /* its first field is NodeTag */ 01194 Relation ss_currentRelation; 01195 HeapScanDesc ss_currentScanDesc; 01196 TupleTableSlot *ss_ScanTupleSlot; 01197 } ScanState; 01198 01199 /* 01200 * SeqScan uses a bare ScanState as its state node, since it needs 01201 * no additional fields. 01202 */ 01203 typedef ScanState SeqScanState; 01204 01205 /* 01206 * These structs store information about index quals that don't have simple 01207 * constant right-hand sides. See comments for ExecIndexBuildScanKeys() 01208 * for discussion. 01209 */ 01210 typedef struct 01211 { 01212 ScanKey scan_key; /* scankey to put value into */ 01213 ExprState *key_expr; /* expr to evaluate to get value */ 01214 bool key_toastable; /* is expr's result a toastable datatype? */ 01215 } IndexRuntimeKeyInfo; 01216 01217 typedef struct 01218 { 01219 ScanKey scan_key; /* scankey to put value into */ 01220 ExprState *array_expr; /* expr to evaluate to get array value */ 01221 int next_elem; /* next array element to use */ 01222 int num_elems; /* number of elems in current array value */ 01223 Datum *elem_values; /* array of num_elems Datums */ 01224 bool *elem_nulls; /* array of num_elems is-null flags */ 01225 } IndexArrayKeyInfo; 01226 01227 /* ---------------- 01228 * IndexScanState information 01229 * 01230 * indexqualorig execution state for indexqualorig expressions 01231 * ScanKeys Skey structures for index quals 01232 * NumScanKeys number of ScanKeys 01233 * OrderByKeys Skey structures for index ordering operators 01234 * NumOrderByKeys number of OrderByKeys 01235 * RuntimeKeys info about Skeys that must be evaluated at runtime 01236 * NumRuntimeKeys number of RuntimeKeys 01237 * RuntimeKeysReady true if runtime Skeys have been computed 01238 * RuntimeContext expr context for evaling runtime Skeys 01239 * RelationDesc index relation descriptor 01240 * ScanDesc index scan descriptor 01241 * ---------------- 01242 */ 01243 typedef struct IndexScanState 01244 { 01245 ScanState ss; /* its first field is NodeTag */ 01246 List *indexqualorig; 01247 ScanKey iss_ScanKeys; 01248 int iss_NumScanKeys; 01249 ScanKey iss_OrderByKeys; 01250 int iss_NumOrderByKeys; 01251 IndexRuntimeKeyInfo *iss_RuntimeKeys; 01252 int iss_NumRuntimeKeys; 01253 bool iss_RuntimeKeysReady; 01254 ExprContext *iss_RuntimeContext; 01255 Relation iss_RelationDesc; 01256 IndexScanDesc iss_ScanDesc; 01257 } IndexScanState; 01258 01259 /* ---------------- 01260 * IndexOnlyScanState information 01261 * 01262 * indexqual execution state for indexqual expressions 01263 * ScanKeys Skey structures for index quals 01264 * NumScanKeys number of ScanKeys 01265 * OrderByKeys Skey structures for index ordering operators 01266 * NumOrderByKeys number of OrderByKeys 01267 * RuntimeKeys info about Skeys that must be evaluated at runtime 01268 * NumRuntimeKeys number of RuntimeKeys 01269 * RuntimeKeysReady true if runtime Skeys have been computed 01270 * RuntimeContext expr context for evaling runtime Skeys 01271 * RelationDesc index relation descriptor 01272 * ScanDesc index scan descriptor 01273 * VMBuffer buffer in use for visibility map testing, if any 01274 * HeapFetches number of tuples we were forced to fetch from heap 01275 * ---------------- 01276 */ 01277 typedef struct IndexOnlyScanState 01278 { 01279 ScanState ss; /* its first field is NodeTag */ 01280 List *indexqual; 01281 ScanKey ioss_ScanKeys; 01282 int ioss_NumScanKeys; 01283 ScanKey ioss_OrderByKeys; 01284 int ioss_NumOrderByKeys; 01285 IndexRuntimeKeyInfo *ioss_RuntimeKeys; 01286 int ioss_NumRuntimeKeys; 01287 bool ioss_RuntimeKeysReady; 01288 ExprContext *ioss_RuntimeContext; 01289 Relation ioss_RelationDesc; 01290 IndexScanDesc ioss_ScanDesc; 01291 Buffer ioss_VMBuffer; 01292 long ioss_HeapFetches; 01293 } IndexOnlyScanState; 01294 01295 /* ---------------- 01296 * BitmapIndexScanState information 01297 * 01298 * result bitmap to return output into, or NULL 01299 * ScanKeys Skey structures for index quals 01300 * NumScanKeys number of ScanKeys 01301 * RuntimeKeys info about Skeys that must be evaluated at runtime 01302 * NumRuntimeKeys number of RuntimeKeys 01303 * ArrayKeys info about Skeys that come from ScalarArrayOpExprs 01304 * NumArrayKeys number of ArrayKeys 01305 * RuntimeKeysReady true if runtime Skeys have been computed 01306 * RuntimeContext expr context for evaling runtime Skeys 01307 * RelationDesc index relation descriptor 01308 * ScanDesc index scan descriptor 01309 * ---------------- 01310 */ 01311 typedef struct BitmapIndexScanState 01312 { 01313 ScanState ss; /* its first field is NodeTag */ 01314 TIDBitmap *biss_result; 01315 ScanKey biss_ScanKeys; 01316 int biss_NumScanKeys; 01317 IndexRuntimeKeyInfo *biss_RuntimeKeys; 01318 int biss_NumRuntimeKeys; 01319 IndexArrayKeyInfo *biss_ArrayKeys; 01320 int biss_NumArrayKeys; 01321 bool biss_RuntimeKeysReady; 01322 ExprContext *biss_RuntimeContext; 01323 Relation biss_RelationDesc; 01324 IndexScanDesc biss_ScanDesc; 01325 } BitmapIndexScanState; 01326 01327 /* ---------------- 01328 * BitmapHeapScanState information 01329 * 01330 * bitmapqualorig execution state for bitmapqualorig expressions 01331 * tbm bitmap obtained from child index scan(s) 01332 * tbmiterator iterator for scanning current pages 01333 * tbmres current-page data 01334 * prefetch_iterator iterator for prefetching ahead of current page 01335 * prefetch_pages # pages prefetch iterator is ahead of current 01336 * prefetch_target target prefetch distance 01337 * ---------------- 01338 */ 01339 typedef struct BitmapHeapScanState 01340 { 01341 ScanState ss; /* its first field is NodeTag */ 01342 List *bitmapqualorig; 01343 TIDBitmap *tbm; 01344 TBMIterator *tbmiterator; 01345 TBMIterateResult *tbmres; 01346 TBMIterator *prefetch_iterator; 01347 int prefetch_pages; 01348 int prefetch_target; 01349 } BitmapHeapScanState; 01350 01351 /* ---------------- 01352 * TidScanState information 01353 * 01354 * isCurrentOf scan has a CurrentOfExpr qual 01355 * NumTids number of tids in this scan 01356 * TidPtr index of currently fetched tid 01357 * TidList evaluated item pointers (array of size NumTids) 01358 * ---------------- 01359 */ 01360 typedef struct TidScanState 01361 { 01362 ScanState ss; /* its first field is NodeTag */ 01363 List *tss_tidquals; /* list of ExprState nodes */ 01364 bool tss_isCurrentOf; 01365 int tss_NumTids; 01366 int tss_TidPtr; 01367 int tss_MarkTidPtr; 01368 ItemPointerData *tss_TidList; 01369 HeapTupleData tss_htup; 01370 } TidScanState; 01371 01372 /* ---------------- 01373 * SubqueryScanState information 01374 * 01375 * SubqueryScanState is used for scanning a sub-query in the range table. 01376 * ScanTupleSlot references the current output tuple of the sub-query. 01377 * ---------------- 01378 */ 01379 typedef struct SubqueryScanState 01380 { 01381 ScanState ss; /* its first field is NodeTag */ 01382 PlanState *subplan; 01383 } SubqueryScanState; 01384 01385 /* ---------------- 01386 * FunctionScanState information 01387 * 01388 * Function nodes are used to scan the results of a 01389 * function appearing in FROM (typically a function returning set). 01390 * 01391 * eflags node's capability flags 01392 * tupdesc expected return tuple description 01393 * tuplestorestate private state of tuplestore.c 01394 * funcexpr state for function expression being evaluated 01395 * ---------------- 01396 */ 01397 typedef struct FunctionScanState 01398 { 01399 ScanState ss; /* its first field is NodeTag */ 01400 int eflags; 01401 TupleDesc tupdesc; 01402 Tuplestorestate *tuplestorestate; 01403 ExprState *funcexpr; 01404 } FunctionScanState; 01405 01406 /* ---------------- 01407 * ValuesScanState information 01408 * 01409 * ValuesScan nodes are used to scan the results of a VALUES list 01410 * 01411 * rowcontext per-expression-list context 01412 * exprlists array of expression lists being evaluated 01413 * array_len size of array 01414 * curr_idx current array index (0-based) 01415 * marked_idx marked position (for mark/restore) 01416 * 01417 * Note: ss.ps.ps_ExprContext is used to evaluate any qual or projection 01418 * expressions attached to the node. We create a second ExprContext, 01419 * rowcontext, in which to build the executor expression state for each 01420 * Values sublist. Resetting this context lets us get rid of expression 01421 * state for each row, avoiding major memory leakage over a long values list. 01422 * ---------------- 01423 */ 01424 typedef struct ValuesScanState 01425 { 01426 ScanState ss; /* its first field is NodeTag */ 01427 ExprContext *rowcontext; 01428 List **exprlists; 01429 int array_len; 01430 int curr_idx; 01431 int marked_idx; 01432 } ValuesScanState; 01433 01434 /* ---------------- 01435 * CteScanState information 01436 * 01437 * CteScan nodes are used to scan a CommonTableExpr query. 01438 * 01439 * Multiple CteScan nodes can read out from the same CTE query. We use 01440 * a tuplestore to hold rows that have been read from the CTE query but 01441 * not yet consumed by all readers. 01442 * ---------------- 01443 */ 01444 typedef struct CteScanState 01445 { 01446 ScanState ss; /* its first field is NodeTag */ 01447 int eflags; /* capability flags to pass to tuplestore */ 01448 int readptr; /* index of my tuplestore read pointer */ 01449 PlanState *cteplanstate; /* PlanState for the CTE query itself */ 01450 /* Link to the "leader" CteScanState (possibly this same node) */ 01451 struct CteScanState *leader; 01452 /* The remaining fields are only valid in the "leader" CteScanState */ 01453 Tuplestorestate *cte_table; /* rows already read from the CTE query */ 01454 bool eof_cte; /* reached end of CTE query? */ 01455 } CteScanState; 01456 01457 /* ---------------- 01458 * WorkTableScanState information 01459 * 01460 * WorkTableScan nodes are used to scan the work table created by 01461 * a RecursiveUnion node. We locate the RecursiveUnion node 01462 * during executor startup. 01463 * ---------------- 01464 */ 01465 typedef struct WorkTableScanState 01466 { 01467 ScanState ss; /* its first field is NodeTag */ 01468 RecursiveUnionState *rustate; 01469 } WorkTableScanState; 01470 01471 /* ---------------- 01472 * ForeignScanState information 01473 * 01474 * ForeignScan nodes are used to scan foreign-data tables. 01475 * ---------------- 01476 */ 01477 typedef struct ForeignScanState 01478 { 01479 ScanState ss; /* its first field is NodeTag */ 01480 /* use struct pointer to avoid including fdwapi.h here */ 01481 struct FdwRoutine *fdwroutine; 01482 void *fdw_state; /* foreign-data wrapper can keep state here */ 01483 } ForeignScanState; 01484 01485 /* ---------------------------------------------------------------- 01486 * Join State Information 01487 * ---------------------------------------------------------------- 01488 */ 01489 01490 /* ---------------- 01491 * JoinState information 01492 * 01493 * Superclass for state nodes of join plans. 01494 * ---------------- 01495 */ 01496 typedef struct JoinState 01497 { 01498 PlanState ps; 01499 JoinType jointype; 01500 List *joinqual; /* JOIN quals (in addition to ps.qual) */ 01501 } JoinState; 01502 01503 /* ---------------- 01504 * NestLoopState information 01505 * 01506 * NeedNewOuter true if need new outer tuple on next call 01507 * MatchedOuter true if found a join match for current outer tuple 01508 * NullInnerTupleSlot prepared null tuple for left outer joins 01509 * ---------------- 01510 */ 01511 typedef struct NestLoopState 01512 { 01513 JoinState js; /* its first field is NodeTag */ 01514 bool nl_NeedNewOuter; 01515 bool nl_MatchedOuter; 01516 TupleTableSlot *nl_NullInnerTupleSlot; 01517 } NestLoopState; 01518 01519 /* ---------------- 01520 * MergeJoinState information 01521 * 01522 * NumClauses number of mergejoinable join clauses 01523 * Clauses info for each mergejoinable clause 01524 * JoinState current state of ExecMergeJoin state machine 01525 * ExtraMarks true to issue extra Mark operations on inner scan 01526 * ConstFalseJoin true if we have a constant-false joinqual 01527 * FillOuter true if should emit unjoined outer tuples anyway 01528 * FillInner true if should emit unjoined inner tuples anyway 01529 * MatchedOuter true if found a join match for current outer tuple 01530 * MatchedInner true if found a join match for current inner tuple 01531 * OuterTupleSlot slot in tuple table for cur outer tuple 01532 * InnerTupleSlot slot in tuple table for cur inner tuple 01533 * MarkedTupleSlot slot in tuple table for marked tuple 01534 * NullOuterTupleSlot prepared null tuple for right outer joins 01535 * NullInnerTupleSlot prepared null tuple for left outer joins 01536 * OuterEContext workspace for computing outer tuple's join values 01537 * InnerEContext workspace for computing inner tuple's join values 01538 * ---------------- 01539 */ 01540 /* private in nodeMergejoin.c: */ 01541 typedef struct MergeJoinClauseData *MergeJoinClause; 01542 01543 typedef struct MergeJoinState 01544 { 01545 JoinState js; /* its first field is NodeTag */ 01546 int mj_NumClauses; 01547 MergeJoinClause mj_Clauses; /* array of length mj_NumClauses */ 01548 int mj_JoinState; 01549 bool mj_ExtraMarks; 01550 bool mj_ConstFalseJoin; 01551 bool mj_FillOuter; 01552 bool mj_FillInner; 01553 bool mj_MatchedOuter; 01554 bool mj_MatchedInner; 01555 TupleTableSlot *mj_OuterTupleSlot; 01556 TupleTableSlot *mj_InnerTupleSlot; 01557 TupleTableSlot *mj_MarkedTupleSlot; 01558 TupleTableSlot *mj_NullOuterTupleSlot; 01559 TupleTableSlot *mj_NullInnerTupleSlot; 01560 ExprContext *mj_OuterEContext; 01561 ExprContext *mj_InnerEContext; 01562 } MergeJoinState; 01563 01564 /* ---------------- 01565 * HashJoinState information 01566 * 01567 * hashclauses original form of the hashjoin condition 01568 * hj_OuterHashKeys the outer hash keys in the hashjoin condition 01569 * hj_InnerHashKeys the inner hash keys in the hashjoin condition 01570 * hj_HashOperators the join operators in the hashjoin condition 01571 * hj_HashTable hash table for the hashjoin 01572 * (NULL if table not built yet) 01573 * hj_CurHashValue hash value for current outer tuple 01574 * hj_CurBucketNo regular bucket# for current outer tuple 01575 * hj_CurSkewBucketNo skew bucket# for current outer tuple 01576 * hj_CurTuple last inner tuple matched to current outer 01577 * tuple, or NULL if starting search 01578 * (hj_CurXXX variables are undefined if 01579 * OuterTupleSlot is empty!) 01580 * hj_OuterTupleSlot tuple slot for outer tuples 01581 * hj_HashTupleSlot tuple slot for inner (hashed) tuples 01582 * hj_NullOuterTupleSlot prepared null tuple for right/full outer joins 01583 * hj_NullInnerTupleSlot prepared null tuple for left/full outer joins 01584 * hj_FirstOuterTupleSlot first tuple retrieved from outer plan 01585 * hj_JoinState current state of ExecHashJoin state machine 01586 * hj_MatchedOuter true if found a join match for current outer 01587 * hj_OuterNotEmpty true if outer relation known not empty 01588 * ---------------- 01589 */ 01590 01591 /* these structs are defined in executor/hashjoin.h: */ 01592 typedef struct HashJoinTupleData *HashJoinTuple; 01593 typedef struct HashJoinTableData *HashJoinTable; 01594 01595 typedef struct HashJoinState 01596 { 01597 JoinState js; /* its first field is NodeTag */ 01598 List *hashclauses; /* list of ExprState nodes */ 01599 List *hj_OuterHashKeys; /* list of ExprState nodes */ 01600 List *hj_InnerHashKeys; /* list of ExprState nodes */ 01601 List *hj_HashOperators; /* list of operator OIDs */ 01602 HashJoinTable hj_HashTable; 01603 uint32 hj_CurHashValue; 01604 int hj_CurBucketNo; 01605 int hj_CurSkewBucketNo; 01606 HashJoinTuple hj_CurTuple; 01607 TupleTableSlot *hj_OuterTupleSlot; 01608 TupleTableSlot *hj_HashTupleSlot; 01609 TupleTableSlot *hj_NullOuterTupleSlot; 01610 TupleTableSlot *hj_NullInnerTupleSlot; 01611 TupleTableSlot *hj_FirstOuterTupleSlot; 01612 int hj_JoinState; 01613 bool hj_MatchedOuter; 01614 bool hj_OuterNotEmpty; 01615 } HashJoinState; 01616 01617 01618 /* ---------------------------------------------------------------- 01619 * Materialization State Information 01620 * ---------------------------------------------------------------- 01621 */ 01622 01623 /* ---------------- 01624 * MaterialState information 01625 * 01626 * materialize nodes are used to materialize the results 01627 * of a subplan into a temporary file. 01628 * 01629 * ss.ss_ScanTupleSlot refers to output of underlying plan. 01630 * ---------------- 01631 */ 01632 typedef struct MaterialState 01633 { 01634 ScanState ss; /* its first field is NodeTag */ 01635 int eflags; /* capability flags to pass to tuplestore */ 01636 bool eof_underlying; /* reached end of underlying plan? */ 01637 Tuplestorestate *tuplestorestate; 01638 } MaterialState; 01639 01640 /* ---------------- 01641 * SortState information 01642 * ---------------- 01643 */ 01644 typedef struct SortState 01645 { 01646 ScanState ss; /* its first field is NodeTag */ 01647 bool randomAccess; /* need random access to sort output? */ 01648 bool bounded; /* is the result set bounded? */ 01649 int64 bound; /* if bounded, how many tuples are needed */ 01650 bool sort_Done; /* sort completed yet? */ 01651 bool bounded_Done; /* value of bounded we did the sort with */ 01652 int64 bound_Done; /* value of bound we did the sort with */ 01653 void *tuplesortstate; /* private state of tuplesort.c */ 01654 } SortState; 01655 01656 /* --------------------- 01657 * GroupState information 01658 * ------------------------- 01659 */ 01660 typedef struct GroupState 01661 { 01662 ScanState ss; /* its first field is NodeTag */ 01663 FmgrInfo *eqfunctions; /* per-field lookup data for equality fns */ 01664 bool grp_done; /* indicates completion of Group scan */ 01665 } GroupState; 01666 01667 /* --------------------- 01668 * AggState information 01669 * 01670 * ss.ss_ScanTupleSlot refers to output of underlying plan. 01671 * 01672 * Note: ss.ps.ps_ExprContext contains ecxt_aggvalues and 01673 * ecxt_aggnulls arrays, which hold the computed agg values for the current 01674 * input group during evaluation of an Agg node's output tuple(s). We 01675 * create a second ExprContext, tmpcontext, in which to evaluate input 01676 * expressions and run the aggregate transition functions. 01677 * ------------------------- 01678 */ 01679 /* these structs are private in nodeAgg.c: */ 01680 typedef struct AggStatePerAggData *AggStatePerAgg; 01681 typedef struct AggStatePerGroupData *AggStatePerGroup; 01682 01683 typedef struct AggState 01684 { 01685 ScanState ss; /* its first field is NodeTag */ 01686 List *aggs; /* all Aggref nodes in targetlist & quals */ 01687 int numaggs; /* length of list (could be zero!) */ 01688 FmgrInfo *eqfunctions; /* per-grouping-field equality fns */ 01689 FmgrInfo *hashfunctions; /* per-grouping-field hash fns */ 01690 AggStatePerAgg peragg; /* per-Aggref information */ 01691 MemoryContext aggcontext; /* memory context for long-lived data */ 01692 ExprContext *tmpcontext; /* econtext for input expressions */ 01693 bool agg_done; /* indicates completion of Agg scan */ 01694 /* these fields are used in AGG_PLAIN and AGG_SORTED modes: */ 01695 AggStatePerGroup pergroup; /* per-Aggref-per-group working state */ 01696 HeapTuple grp_firstTuple; /* copy of first tuple of current group */ 01697 /* these fields are used in AGG_HASHED mode: */ 01698 TupleHashTable hashtable; /* hash table with one entry per group */ 01699 TupleTableSlot *hashslot; /* slot for loading hash table */ 01700 List *hash_needed; /* list of columns needed in hash table */ 01701 bool table_filled; /* hash table filled yet? */ 01702 TupleHashIterator hashiter; /* for iterating through hash table */ 01703 } AggState; 01704 01705 /* ---------------- 01706 * WindowAggState information 01707 * ---------------- 01708 */ 01709 /* these structs are private in nodeWindowAgg.c: */ 01710 typedef struct WindowStatePerFuncData *WindowStatePerFunc; 01711 typedef struct WindowStatePerAggData *WindowStatePerAgg; 01712 01713 typedef struct WindowAggState 01714 { 01715 ScanState ss; /* its first field is NodeTag */ 01716 01717 /* these fields are filled in by ExecInitExpr: */ 01718 List *funcs; /* all WindowFunc nodes in targetlist */ 01719 int numfuncs; /* total number of window functions */ 01720 int numaggs; /* number that are plain aggregates */ 01721 01722 WindowStatePerFunc perfunc; /* per-window-function information */ 01723 WindowStatePerAgg peragg; /* per-plain-aggregate information */ 01724 FmgrInfo *partEqfunctions; /* equality funcs for partition columns */ 01725 FmgrInfo *ordEqfunctions; /* equality funcs for ordering columns */ 01726 Tuplestorestate *buffer; /* stores rows of current partition */ 01727 int current_ptr; /* read pointer # for current */ 01728 int64 spooled_rows; /* total # of rows in buffer */ 01729 int64 currentpos; /* position of current row in partition */ 01730 int64 frameheadpos; /* current frame head position */ 01731 int64 frametailpos; /* current frame tail position */ 01732 /* use struct pointer to avoid including windowapi.h here */ 01733 struct WindowObjectData *agg_winobj; /* winobj for aggregate 01734 * fetches */ 01735 int64 aggregatedbase; /* start row for current aggregates */ 01736 int64 aggregatedupto; /* rows before this one are aggregated */ 01737 01738 int frameOptions; /* frame_clause options, see WindowDef */ 01739 ExprState *startOffset; /* expression for starting bound offset */ 01740 ExprState *endOffset; /* expression for ending bound offset */ 01741 Datum startOffsetValue; /* result of startOffset evaluation */ 01742 Datum endOffsetValue; /* result of endOffset evaluation */ 01743 01744 MemoryContext partcontext; /* context for partition-lifespan data */ 01745 MemoryContext aggcontext; /* context for each aggregate data */ 01746 ExprContext *tmpcontext; /* short-term evaluation context */ 01747 01748 bool all_first; /* true if the scan is starting */ 01749 bool all_done; /* true if the scan is finished */ 01750 bool partition_spooled; /* true if all tuples in current 01751 * partition have been spooled into 01752 * tuplestore */ 01753 bool more_partitions;/* true if there's more partitions after this 01754 * one */ 01755 bool framehead_valid;/* true if frameheadpos is known up to date 01756 * for current row */ 01757 bool frametail_valid;/* true if frametailpos is known up to date 01758 * for current row */ 01759 01760 TupleTableSlot *first_part_slot; /* first tuple of current or next 01761 * partition */ 01762 01763 /* temporary slots for tuples fetched back from tuplestore */ 01764 TupleTableSlot *agg_row_slot; 01765 TupleTableSlot *temp_slot_1; 01766 TupleTableSlot *temp_slot_2; 01767 } WindowAggState; 01768 01769 /* ---------------- 01770 * UniqueState information 01771 * 01772 * Unique nodes are used "on top of" sort nodes to discard 01773 * duplicate tuples returned from the sort phase. Basically 01774 * all it does is compare the current tuple from the subplan 01775 * with the previously fetched tuple (stored in its result slot). 01776 * If the two are identical in all interesting fields, then 01777 * we just fetch another tuple from the sort and try again. 01778 * ---------------- 01779 */ 01780 typedef struct UniqueState 01781 { 01782 PlanState ps; /* its first field is NodeTag */ 01783 FmgrInfo *eqfunctions; /* per-field lookup data for equality fns */ 01784 MemoryContext tempContext; /* short-term context for comparisons */ 01785 } UniqueState; 01786 01787 /* ---------------- 01788 * HashState information 01789 * ---------------- 01790 */ 01791 typedef struct HashState 01792 { 01793 PlanState ps; /* its first field is NodeTag */ 01794 HashJoinTable hashtable; /* hash table for the hashjoin */ 01795 List *hashkeys; /* list of ExprState nodes */ 01796 /* hashkeys is same as parent's hj_InnerHashKeys */ 01797 } HashState; 01798 01799 /* ---------------- 01800 * SetOpState information 01801 * 01802 * Even in "sorted" mode, SetOp nodes are more complex than a simple 01803 * Unique, since we have to count how many duplicates to return. But 01804 * we also support hashing, so this is really more like a cut-down 01805 * form of Agg. 01806 * ---------------- 01807 */ 01808 /* this struct is private in nodeSetOp.c: */ 01809 typedef struct SetOpStatePerGroupData *SetOpStatePerGroup; 01810 01811 typedef struct SetOpState 01812 { 01813 PlanState ps; /* its first field is NodeTag */ 01814 FmgrInfo *eqfunctions; /* per-grouping-field equality fns */ 01815 FmgrInfo *hashfunctions; /* per-grouping-field hash fns */ 01816 bool setop_done; /* indicates completion of output scan */ 01817 long numOutput; /* number of dups left to output */ 01818 MemoryContext tempContext; /* short-term context for comparisons */ 01819 /* these fields are used in SETOP_SORTED mode: */ 01820 SetOpStatePerGroup pergroup; /* per-group working state */ 01821 HeapTuple grp_firstTuple; /* copy of first tuple of current group */ 01822 /* these fields are used in SETOP_HASHED mode: */ 01823 TupleHashTable hashtable; /* hash table with one entry per group */ 01824 MemoryContext tableContext; /* memory context containing hash table */ 01825 bool table_filled; /* hash table filled yet? */ 01826 TupleHashIterator hashiter; /* for iterating through hash table */ 01827 } SetOpState; 01828 01829 /* ---------------- 01830 * LockRowsState information 01831 * 01832 * LockRows nodes are used to enforce FOR [KEY] UPDATE/SHARE locking. 01833 * ---------------- 01834 */ 01835 typedef struct LockRowsState 01836 { 01837 PlanState ps; /* its first field is NodeTag */ 01838 List *lr_arowMarks; /* List of ExecAuxRowMarks */ 01839 EPQState lr_epqstate; /* for evaluating EvalPlanQual rechecks */ 01840 } LockRowsState; 01841 01842 /* ---------------- 01843 * LimitState information 01844 * 01845 * Limit nodes are used to enforce LIMIT/OFFSET clauses. 01846 * They just select the desired subrange of their subplan's output. 01847 * 01848 * offset is the number of initial tuples to skip (0 does nothing). 01849 * count is the number of tuples to return after skipping the offset tuples. 01850 * If no limit count was specified, count is undefined and noCount is true. 01851 * When lstate == LIMIT_INITIAL, offset/count/noCount haven't been set yet. 01852 * ---------------- 01853 */ 01854 typedef enum 01855 { 01856 LIMIT_INITIAL, /* initial state for LIMIT node */ 01857 LIMIT_RESCAN, /* rescan after recomputing parameters */ 01858 LIMIT_EMPTY, /* there are no returnable rows */ 01859 LIMIT_INWINDOW, /* have returned a row in the window */ 01860 LIMIT_SUBPLANEOF, /* at EOF of subplan (within window) */ 01861 LIMIT_WINDOWEND, /* stepped off end of window */ 01862 LIMIT_WINDOWSTART /* stepped off beginning of window */ 01863 } LimitStateCond; 01864 01865 typedef struct LimitState 01866 { 01867 PlanState ps; /* its first field is NodeTag */ 01868 ExprState *limitOffset; /* OFFSET parameter, or NULL if none */ 01869 ExprState *limitCount; /* COUNT parameter, or NULL if none */ 01870 int64 offset; /* current OFFSET value */ 01871 int64 count; /* current COUNT, if any */ 01872 bool noCount; /* if true, ignore count */ 01873 LimitStateCond lstate; /* state machine status, as above */ 01874 int64 position; /* 1-based index of last tuple returned */ 01875 TupleTableSlot *subSlot; /* tuple last obtained from subplan */ 01876 } LimitState; 01877 01878 #endif /* EXECNODES_H */