| 1 | /*------------------------------------------------------------------------- |
| 2 | * |
| 3 | * execnodes.h |
| 4 | * definitions for executor state nodes |
| 5 | * |
| 6 | * |
| 7 | * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group |
| 8 | * Portions Copyright (c) 1994, Regents of the University of California |
| 9 | * |
| 10 | * src/include/nodes/execnodes.h |
| 11 | * |
| 12 | *------------------------------------------------------------------------- |
| 13 | */ |
| 14 | #ifndef EXECNODES_H |
| 15 | #define EXECNODES_H |
| 16 | |
| 17 | #include "access/tupconvert.h" |
| 18 | #include "executor/instrument.h" |
| 19 | #include "lib/pairingheap.h" |
| 20 | #include "nodes/params.h" |
| 21 | #include "nodes/plannodes.h" |
| 22 | #include "partitioning/partdefs.h" |
| 23 | #include "utils/hsearch.h" |
| 24 | #include "utils/queryenvironment.h" |
| 25 | #include "utils/reltrigger.h" |
| 26 | #include "utils/sharedtuplestore.h" |
| 27 | #include "utils/snapshot.h" |
| 28 | #include "utils/sortsupport.h" |
| 29 | #include "utils/tuplestore.h" |
| 30 | #include "utils/tuplesort.h" |
| 31 | #include "nodes/tidbitmap.h" |
| 32 | #include "storage/condition_variable.h" |
| 33 | |
| 34 | |
| 35 | struct PlanState; /* forward references in this file */ |
| 36 | struct PartitionRoutingInfo; |
| 37 | struct ParallelHashJoinState; |
| 38 | struct ExecRowMark; |
| 39 | struct ExprState; |
| 40 | struct ExprContext; |
| 41 | struct RangeTblEntry; /* avoid including parsenodes.h here */ |
| 42 | struct ExprEvalStep; /* avoid including execExpr.h everywhere */ |
| 43 | struct CopyMultiInsertBuffer; |
| 44 | |
| 45 | |
| 46 | /* ---------------- |
| 47 | * ExprState node |
| 48 | * |
| 49 | * ExprState is the top-level node for expression evaluation. |
| 50 | * It contains instructions (in ->steps) to evaluate the expression. |
| 51 | * ---------------- |
| 52 | */ |
| 53 | typedef Datum (*ExprStateEvalFunc) (struct ExprState *expression, |
| 54 | struct ExprContext *econtext, |
| 55 | bool *isNull); |
| 56 | |
| 57 | /* Bits in ExprState->flags (see also execExpr.h for private flag bits): */ |
| 58 | /* expression is for use with ExecQual() */ |
| 59 | #define EEO_FLAG_IS_QUAL (1 << 0) |
| 60 | |
| 61 | typedef struct ExprState |
| 62 | { |
| 63 | Node tag; |
| 64 | |
| 65 | uint8 flags; /* bitmask of EEO_FLAG_* bits, see above */ |
| 66 | |
| 67 | /* |
| 68 | * Storage for result value of a scalar expression, or for individual |
| 69 | * column results within expressions built by ExecBuildProjectionInfo(). |
| 70 | */ |
| 71 | #define FIELDNO_EXPRSTATE_RESNULL 2 |
| 72 | bool resnull; |
| 73 | #define FIELDNO_EXPRSTATE_RESVALUE 3 |
| 74 | Datum resvalue; |
| 75 | |
| 76 | /* |
| 77 | * If projecting a tuple result, this slot holds the result; else NULL. |
| 78 | */ |
| 79 | #define FIELDNO_EXPRSTATE_RESULTSLOT 4 |
| 80 | TupleTableSlot *resultslot; |
| 81 | |
| 82 | /* |
| 83 | * Instructions to compute expression's return value. |
| 84 | */ |
| 85 | struct ExprEvalStep *steps; |
| 86 | |
| 87 | /* |
| 88 | * Function that actually evaluates the expression. This can be set to |
| 89 | * different values depending on the complexity of the expression. |
| 90 | */ |
| 91 | ExprStateEvalFunc evalfunc; |
| 92 | |
| 93 | /* original expression tree, for debugging only */ |
| 94 | Expr *expr; |
| 95 | |
| 96 | /* private state for an evalfunc */ |
| 97 | void *evalfunc_private; |
| 98 | |
| 99 | /* |
| 100 | * XXX: following fields only needed during "compilation" (ExecInitExpr); |
| 101 | * could be thrown away afterwards. |
| 102 | */ |
| 103 | |
| 104 | int steps_len; /* number of steps currently */ |
| 105 | int steps_alloc; /* allocated length of steps array */ |
| 106 | |
| 107 | struct PlanState *parent; /* parent PlanState node, if any */ |
| 108 | ParamListInfo ext_params; /* for compiling PARAM_EXTERN nodes */ |
| 109 | |
| 110 | Datum *innermost_caseval; |
| 111 | bool *innermost_casenull; |
| 112 | |
| 113 | Datum *innermost_domainval; |
| 114 | bool *innermost_domainnull; |
| 115 | } ExprState; |
| 116 | |
| 117 | |
| 118 | /* ---------------- |
| 119 | * IndexInfo information |
| 120 | * |
| 121 | * this struct holds the information needed to construct new index |
| 122 | * entries for a particular index. Used for both index_build and |
| 123 | * retail creation of index entries. |
| 124 | * |
| 125 | * NumIndexAttrs total number of columns in this index |
| 126 | * NumIndexKeyAttrs number of key columns in index |
| 127 | * IndexAttrNumbers underlying-rel attribute numbers used as keys |
| 128 | * (zeroes indicate expressions). It also contains |
| 129 | * info about included columns. |
| 130 | * Expressions expr trees for expression entries, or NIL if none |
| 131 | * ExpressionsState exec state for expressions, or NIL if none |
| 132 | * Predicate partial-index predicate, or NIL if none |
| 133 | * PredicateState exec state for predicate, or NIL if none |
| 134 | * ExclusionOps Per-column exclusion operators, or NULL if none |
| 135 | * ExclusionProcs Underlying function OIDs for ExclusionOps |
| 136 | * ExclusionStrats Opclass strategy numbers for ExclusionOps |
| 137 | * UniqueOps These are like Exclusion*, but for unique indexes |
| 138 | * UniqueProcs |
| 139 | * UniqueStrats |
| 140 | * Unique is it a unique index? |
| 141 | * ReadyForInserts is it valid for inserts? |
| 142 | * Concurrent are we doing a concurrent index build? |
| 143 | * BrokenHotChain did we detect any broken HOT chains? |
| 144 | * ParallelWorkers # of workers requested (excludes leader) |
| 145 | * Am Oid of index AM |
| 146 | * AmCache private cache area for index AM |
| 147 | * Context memory context holding this IndexInfo |
| 148 | * |
| 149 | * ii_Concurrent, ii_BrokenHotChain, and ii_ParallelWorkers are used only |
| 150 | * during index build; they're conventionally zeroed otherwise. |
| 151 | * ---------------- |
| 152 | */ |
| 153 | typedef struct IndexInfo |
| 154 | { |
| 155 | NodeTag type; |
| 156 | int ii_NumIndexAttrs; /* total number of columns in index */ |
| 157 | int ii_NumIndexKeyAttrs; /* number of key columns in index */ |
| 158 | AttrNumber ii_IndexAttrNumbers[INDEX_MAX_KEYS]; |
| 159 | List *ii_Expressions; /* list of Expr */ |
| 160 | List *ii_ExpressionsState; /* list of ExprState */ |
| 161 | List *ii_Predicate; /* list of Expr */ |
| 162 | ExprState *ii_PredicateState; |
| 163 | Oid *ii_ExclusionOps; /* array with one entry per column */ |
| 164 | Oid *ii_ExclusionProcs; /* array with one entry per column */ |
| 165 | uint16 *ii_ExclusionStrats; /* array with one entry per column */ |
| 166 | Oid *ii_UniqueOps; /* array with one entry per column */ |
| 167 | Oid *ii_UniqueProcs; /* array with one entry per column */ |
| 168 | uint16 *ii_UniqueStrats; /* array with one entry per column */ |
| 169 | bool ii_Unique; |
| 170 | bool ii_ReadyForInserts; |
| 171 | bool ii_Concurrent; |
| 172 | bool ii_BrokenHotChain; |
| 173 | int ii_ParallelWorkers; |
| 174 | Oid ii_Am; |
| 175 | void *ii_AmCache; |
| 176 | MemoryContext ii_Context; |
| 177 | } IndexInfo; |
| 178 | |
| 179 | /* ---------------- |
| 180 | * ExprContext_CB |
| 181 | * |
| 182 | * List of callbacks to be called at ExprContext shutdown. |
| 183 | * ---------------- |
| 184 | */ |
| 185 | typedef void (*ExprContextCallbackFunction) (Datum arg); |
| 186 | |
| 187 | typedef struct ExprContext_CB |
| 188 | { |
| 189 | struct ExprContext_CB *next; |
| 190 | ExprContextCallbackFunction function; |
| 191 | Datum arg; |
| 192 | } ExprContext_CB; |
| 193 | |
| 194 | /* ---------------- |
| 195 | * ExprContext |
| 196 | * |
| 197 | * This class holds the "current context" information |
| 198 | * needed to evaluate expressions for doing tuple qualifications |
| 199 | * and tuple projections. For example, if an expression refers |
| 200 | * to an attribute in the current inner tuple then we need to know |
| 201 | * what the current inner tuple is and so we look at the expression |
| 202 | * context. |
| 203 | * |
| 204 | * There are two memory contexts associated with an ExprContext: |
| 205 | * * ecxt_per_query_memory is a query-lifespan context, typically the same |
| 206 | * context the ExprContext node itself is allocated in. This context |
| 207 | * can be used for purposes such as storing function call cache info. |
| 208 | * * ecxt_per_tuple_memory is a short-term context for expression results. |
| 209 | * As the name suggests, it will typically be reset once per tuple, |
| 210 | * before we begin to evaluate expressions for that tuple. Each |
| 211 | * ExprContext normally has its very own per-tuple memory context. |
| 212 | * |
| 213 | * CurrentMemoryContext should be set to ecxt_per_tuple_memory before |
| 214 | * calling ExecEvalExpr() --- see ExecEvalExprSwitchContext(). |
| 215 | * ---------------- |
| 216 | */ |
| 217 | typedef struct ExprContext |
| 218 | { |
| 219 | NodeTag type; |
| 220 | |
| 221 | /* Tuples that Var nodes in expression may refer to */ |
| 222 | #define FIELDNO_EXPRCONTEXT_SCANTUPLE 1 |
| 223 | TupleTableSlot *ecxt_scantuple; |
| 224 | #define FIELDNO_EXPRCONTEXT_INNERTUPLE 2 |
| 225 | TupleTableSlot *ecxt_innertuple; |
| 226 | #define FIELDNO_EXPRCONTEXT_OUTERTUPLE 3 |
| 227 | TupleTableSlot *ecxt_outertuple; |
| 228 | |
| 229 | /* Memory contexts for expression evaluation --- see notes above */ |
| 230 | MemoryContext ecxt_per_query_memory; |
| 231 | MemoryContext ecxt_per_tuple_memory; |
| 232 | |
| 233 | /* Values to substitute for Param nodes in expression */ |
| 234 | ParamExecData *ecxt_param_exec_vals; /* for PARAM_EXEC params */ |
| 235 | ParamListInfo ecxt_param_list_info; /* for other param types */ |
| 236 | |
| 237 | /* |
| 238 | * Values to substitute for Aggref nodes in the expressions of an Agg |
| 239 | * node, or for WindowFunc nodes within a WindowAgg node. |
| 240 | */ |
| 241 | #define FIELDNO_EXPRCONTEXT_AGGVALUES 8 |
| 242 | Datum *ecxt_aggvalues; /* precomputed values for aggs/windowfuncs */ |
| 243 | #define FIELDNO_EXPRCONTEXT_AGGNULLS 9 |
| 244 | bool *ecxt_aggnulls; /* null flags for aggs/windowfuncs */ |
| 245 | |
| 246 | /* Value to substitute for CaseTestExpr nodes in expression */ |
| 247 | #define FIELDNO_EXPRCONTEXT_CASEDATUM 10 |
| 248 | Datum caseValue_datum; |
| 249 | #define FIELDNO_EXPRCONTEXT_CASENULL 11 |
| 250 | bool caseValue_isNull; |
| 251 | |
| 252 | /* Value to substitute for CoerceToDomainValue nodes in expression */ |
| 253 | #define FIELDNO_EXPRCONTEXT_DOMAINDATUM 12 |
| 254 | Datum domainValue_datum; |
| 255 | #define FIELDNO_EXPRCONTEXT_DOMAINNULL 13 |
| 256 | bool domainValue_isNull; |
| 257 | |
| 258 | /* Link to containing EState (NULL if a standalone ExprContext) */ |
| 259 | struct EState *ecxt_estate; |
| 260 | |
| 261 | /* Functions to call back when ExprContext is shut down or rescanned */ |
| 262 | ExprContext_CB *ecxt_callbacks; |
| 263 | } ExprContext; |
| 264 | |
| 265 | /* |
| 266 | * Set-result status used when evaluating functions potentially returning a |
| 267 | * set. |
| 268 | */ |
| 269 | typedef enum |
| 270 | { |
| 271 | ExprSingleResult, /* expression does not return a set */ |
| 272 | ExprMultipleResult, /* this result is an element of a set */ |
| 273 | ExprEndResult /* there are no more elements in the set */ |
| 274 | } ExprDoneCond; |
| 275 | |
| 276 | /* |
| 277 | * Return modes for functions returning sets. Note values must be chosen |
| 278 | * as separate bits so that a bitmask can be formed to indicate supported |
| 279 | * modes. SFRM_Materialize_Random and SFRM_Materialize_Preferred are |
| 280 | * auxiliary flags about SFRM_Materialize mode, rather than separate modes. |
| 281 | */ |
| 282 | typedef enum |
| 283 | { |
| 284 | SFRM_ValuePerCall = 0x01, /* one value returned per call */ |
| 285 | SFRM_Materialize = 0x02, /* result set instantiated in Tuplestore */ |
| 286 | SFRM_Materialize_Random = 0x04, /* Tuplestore needs randomAccess */ |
| 287 | SFRM_Materialize_Preferred = 0x08 /* caller prefers Tuplestore */ |
| 288 | } SetFunctionReturnMode; |
| 289 | |
| 290 | /* |
| 291 | * When calling a function that might return a set (multiple rows), |
| 292 | * a node of this type is passed as fcinfo->resultinfo to allow |
| 293 | * return status to be passed back. A function returning set should |
| 294 | * raise an error if no such resultinfo is provided. |
| 295 | */ |
| 296 | typedef struct ReturnSetInfo |
| 297 | { |
| 298 | NodeTag type; |
| 299 | /* values set by caller: */ |
| 300 | ExprContext *econtext; /* context function is being called in */ |
| 301 | TupleDesc expectedDesc; /* tuple descriptor expected by caller */ |
| 302 | int allowedModes; /* bitmask: return modes caller can handle */ |
| 303 | /* result status from function (but pre-initialized by caller): */ |
| 304 | SetFunctionReturnMode returnMode; /* actual return mode */ |
| 305 | ExprDoneCond isDone; /* status for ValuePerCall mode */ |
| 306 | /* fields filled by function in Materialize return mode: */ |
| 307 | Tuplestorestate *setResult; /* holds the complete returned tuple set */ |
| 308 | TupleDesc setDesc; /* actual descriptor for returned tuples */ |
| 309 | } ReturnSetInfo; |
| 310 | |
| 311 | /* ---------------- |
| 312 | * ProjectionInfo node information |
| 313 | * |
| 314 | * This is all the information needed to perform projections --- |
| 315 | * that is, form new tuples by evaluation of targetlist expressions. |
| 316 | * Nodes which need to do projections create one of these. |
| 317 | * |
| 318 | * The target tuple slot is kept in ProjectionInfo->pi_state.resultslot. |
| 319 | * ExecProject() evaluates the tlist, forms a tuple, and stores it |
| 320 | * in the given slot. Note that the result will be a "virtual" tuple |
| 321 | * unless ExecMaterializeSlot() is then called to force it to be |
| 322 | * converted to a physical tuple. The slot must have a tupledesc |
| 323 | * that matches the output of the tlist! |
| 324 | * ---------------- |
| 325 | */ |
| 326 | typedef struct ProjectionInfo |
| 327 | { |
| 328 | NodeTag type; |
| 329 | /* instructions to evaluate projection */ |
| 330 | ExprState pi_state; |
| 331 | /* expression context in which to evaluate expression */ |
| 332 | ExprContext *pi_exprContext; |
| 333 | } ProjectionInfo; |
| 334 | |
| 335 | /* ---------------- |
| 336 | * JunkFilter |
| 337 | * |
| 338 | * This class is used to store information regarding junk attributes. |
| 339 | * A junk attribute is an attribute in a tuple that is needed only for |
| 340 | * storing intermediate information in the executor, and does not belong |
| 341 | * in emitted tuples. For example, when we do an UPDATE query, |
| 342 | * the planner adds a "junk" entry to the targetlist so that the tuples |
| 343 | * returned to ExecutePlan() contain an extra attribute: the ctid of |
| 344 | * the tuple to be updated. This is needed to do the update, but we |
| 345 | * don't want the ctid to be part of the stored new tuple! So, we |
| 346 | * apply a "junk filter" to remove the junk attributes and form the |
| 347 | * real output tuple. The junkfilter code also provides routines to |
| 348 | * extract the values of the junk attribute(s) from the input tuple. |
| 349 | * |
| 350 | * targetList: the original target list (including junk attributes). |
| 351 | * cleanTupType: the tuple descriptor for the "clean" tuple (with |
| 352 | * junk attributes removed). |
| 353 | * cleanMap: A map with the correspondence between the non-junk |
| 354 | * attribute numbers of the "original" tuple and the |
| 355 | * attribute numbers of the "clean" tuple. |
| 356 | * resultSlot: tuple slot used to hold cleaned tuple. |
| 357 | * junkAttNo: not used by junkfilter code. Can be used by caller |
| 358 | * to remember the attno of a specific junk attribute |
| 359 | * (nodeModifyTable.c keeps the "ctid" or "wholerow" |
| 360 | * attno here). |
| 361 | * ---------------- |
| 362 | */ |
| 363 | typedef struct JunkFilter |
| 364 | { |
| 365 | NodeTag type; |
| 366 | List *jf_targetList; |
| 367 | TupleDesc jf_cleanTupType; |
| 368 | AttrNumber *jf_cleanMap; |
| 369 | TupleTableSlot *jf_resultSlot; |
| 370 | AttrNumber jf_junkAttNo; |
| 371 | } JunkFilter; |
| 372 | |
| 373 | /* |
| 374 | * OnConflictSetState |
| 375 | * |
| 376 | * Executor state of an ON CONFLICT DO UPDATE operation. |
| 377 | */ |
| 378 | typedef struct OnConflictSetState |
| 379 | { |
| 380 | NodeTag type; |
| 381 | |
| 382 | TupleTableSlot *oc_Existing; /* slot to store existing target tuple in */ |
| 383 | TupleTableSlot *oc_ProjSlot; /* CONFLICT ... SET ... projection target */ |
| 384 | ProjectionInfo *oc_ProjInfo; /* for ON CONFLICT DO UPDATE SET */ |
| 385 | ExprState *oc_WhereClause; /* state for the WHERE clause */ |
| 386 | } OnConflictSetState; |
| 387 | |
| 388 | /* |
| 389 | * ResultRelInfo |
| 390 | * |
| 391 | * Whenever we update an existing relation, we have to update indexes on the |
| 392 | * relation, and perhaps also fire triggers. ResultRelInfo holds all the |
| 393 | * information needed about a result relation, including indexes. |
| 394 | * |
| 395 | * Normally, a ResultRelInfo refers to a table that is in the query's |
| 396 | * range table; then ri_RangeTableIndex is the RT index and ri_RelationDesc |
| 397 | * is just a copy of the relevant es_relations[] entry. But sometimes, |
| 398 | * in ResultRelInfos used only for triggers, ri_RangeTableIndex is zero |
| 399 | * and ri_RelationDesc is a separately-opened relcache pointer that needs |
| 400 | * to be separately closed. See ExecGetTriggerResultRel. |
| 401 | */ |
| 402 | typedef struct ResultRelInfo |
| 403 | { |
| 404 | NodeTag type; |
| 405 | |
| 406 | /* result relation's range table index, or 0 if not in range table */ |
| 407 | Index ri_RangeTableIndex; |
| 408 | |
| 409 | /* relation descriptor for result relation */ |
| 410 | Relation ri_RelationDesc; |
| 411 | |
| 412 | /* # of indices existing on result relation */ |
| 413 | int ri_NumIndices; |
| 414 | |
| 415 | /* array of relation descriptors for indices */ |
| 416 | RelationPtr ri_IndexRelationDescs; |
| 417 | |
| 418 | /* array of key/attr info for indices */ |
| 419 | IndexInfo **ri_IndexRelationInfo; |
| 420 | |
| 421 | /* triggers to be fired, if any */ |
| 422 | TriggerDesc *ri_TrigDesc; |
| 423 | |
| 424 | /* cached lookup info for trigger functions */ |
| 425 | FmgrInfo *ri_TrigFunctions; |
| 426 | |
| 427 | /* array of trigger WHEN expr states */ |
| 428 | ExprState **ri_TrigWhenExprs; |
| 429 | |
| 430 | /* optional runtime measurements for triggers */ |
| 431 | Instrumentation *ri_TrigInstrument; |
| 432 | |
| 433 | /* On-demand created slots for triggers / returning processing */ |
| 434 | TupleTableSlot *ri_ReturningSlot; /* for trigger output tuples */ |
| 435 | TupleTableSlot *ri_TrigOldSlot; /* for a trigger's old tuple */ |
| 436 | TupleTableSlot *ri_TrigNewSlot; /* for a trigger's new tuple */ |
| 437 | |
| 438 | /* FDW callback functions, if foreign table */ |
| 439 | struct FdwRoutine *ri_FdwRoutine; |
| 440 | |
| 441 | /* available to save private state of FDW */ |
| 442 | void *ri_FdwState; |
| 443 | |
| 444 | /* true when modifying foreign table directly */ |
| 445 | bool ri_usesFdwDirectModify; |
| 446 | |
| 447 | /* list of WithCheckOption's to be checked */ |
| 448 | List *ri_WithCheckOptions; |
| 449 | |
| 450 | /* list of WithCheckOption expr states */ |
| 451 | List *ri_WithCheckOptionExprs; |
| 452 | |
| 453 | /* array of constraint-checking expr states */ |
| 454 | ExprState **ri_ConstraintExprs; |
| 455 | |
| 456 | /* array of stored generated columns expr states */ |
| 457 | ExprState **ri_GeneratedExprs; |
| 458 | |
| 459 | /* for removing junk attributes from tuples */ |
| 460 | JunkFilter *ri_junkFilter; |
| 461 | |
| 462 | /* list of RETURNING expressions */ |
| 463 | List *ri_returningList; |
| 464 | |
| 465 | /* for computing a RETURNING list */ |
| 466 | ProjectionInfo *ri_projectReturning; |
| 467 | |
| 468 | /* list of arbiter indexes to use to check conflicts */ |
| 469 | List *ri_onConflictArbiterIndexes; |
| 470 | |
| 471 | /* ON CONFLICT evaluation state */ |
| 472 | OnConflictSetState *ri_onConflict; |
| 473 | |
| 474 | /* partition check expression */ |
| 475 | List *ri_PartitionCheck; |
| 476 | |
| 477 | /* partition check expression state */ |
| 478 | ExprState *ri_PartitionCheckExpr; |
| 479 | |
| 480 | /* relation descriptor for root partitioned table */ |
| 481 | Relation ri_PartitionRoot; |
| 482 | |
| 483 | /* Additional information specific to partition tuple routing */ |
| 484 | struct PartitionRoutingInfo *ri_PartitionInfo; |
| 485 | |
| 486 | /* For use by copy.c when performing multi-inserts */ |
| 487 | struct CopyMultiInsertBuffer *ri_CopyMultiInsertBuffer; |
| 488 | } ResultRelInfo; |
| 489 | |
| 490 | /* ---------------- |
| 491 | * EState information |
| 492 | * |
| 493 | * Master working state for an Executor invocation |
| 494 | * ---------------- |
| 495 | */ |
| 496 | typedef struct EState |
| 497 | { |
| 498 | NodeTag type; |
| 499 | |
| 500 | /* Basic state for all query types: */ |
| 501 | ScanDirection es_direction; /* current scan direction */ |
| 502 | Snapshot es_snapshot; /* time qual to use */ |
| 503 | Snapshot es_crosscheck_snapshot; /* crosscheck time qual for RI */ |
| 504 | List *es_range_table; /* List of RangeTblEntry */ |
| 505 | struct RangeTblEntry **es_range_table_array; /* equivalent array */ |
| 506 | Index es_range_table_size; /* size of the range table arrays */ |
| 507 | Relation *es_relations; /* Array of per-range-table-entry Relation |
| 508 | * pointers, or NULL if not yet opened */ |
| 509 | struct ExecRowMark **es_rowmarks; /* Array of per-range-table-entry |
| 510 | * ExecRowMarks, or NULL if none */ |
| 511 | PlannedStmt *es_plannedstmt; /* link to top of plan tree */ |
| 512 | const char *es_sourceText; /* Source text from QueryDesc */ |
| 513 | |
| 514 | JunkFilter *es_junkFilter; /* top-level junk filter, if any */ |
| 515 | |
| 516 | /* If query can insert/delete tuples, the command ID to mark them with */ |
| 517 | CommandId es_output_cid; |
| 518 | |
| 519 | /* Info about target table(s) for insert/update/delete queries: */ |
| 520 | ResultRelInfo *es_result_relations; /* array of ResultRelInfos */ |
| 521 | int es_num_result_relations; /* length of array */ |
| 522 | ResultRelInfo *es_result_relation_info; /* currently active array elt */ |
| 523 | |
| 524 | /* |
| 525 | * Info about the partition root table(s) for insert/update/delete queries |
| 526 | * targeting partitioned tables. Only leaf partitions are mentioned in |
| 527 | * es_result_relations, but we need access to the roots for firing |
| 528 | * triggers and for runtime tuple routing. |
| 529 | */ |
| 530 | ResultRelInfo *es_root_result_relations; /* array of ResultRelInfos */ |
| 531 | int es_num_root_result_relations; /* length of the array */ |
| 532 | PartitionDirectory es_partition_directory; /* for PartitionDesc lookup */ |
| 533 | |
| 534 | /* |
| 535 | * The following list contains ResultRelInfos created by the tuple routing |
| 536 | * code for partitions that don't already have one. |
| 537 | */ |
| 538 | List *es_tuple_routing_result_relations; |
| 539 | |
| 540 | /* Stuff used for firing triggers: */ |
| 541 | List *es_trig_target_relations; /* trigger-only ResultRelInfos */ |
| 542 | |
| 543 | /* Parameter info: */ |
| 544 | ParamListInfo es_param_list_info; /* values of external params */ |
| 545 | ParamExecData *es_param_exec_vals; /* values of internal params */ |
| 546 | |
| 547 | QueryEnvironment *es_queryEnv; /* query environment */ |
| 548 | |
| 549 | /* Other working state: */ |
| 550 | MemoryContext es_query_cxt; /* per-query context in which EState lives */ |
| 551 | |
| 552 | List *es_tupleTable; /* List of TupleTableSlots */ |
| 553 | |
| 554 | uint64 es_processed; /* # of tuples processed */ |
| 555 | |
| 556 | int es_top_eflags; /* eflags passed to ExecutorStart */ |
| 557 | int es_instrument; /* OR of InstrumentOption flags */ |
| 558 | bool es_finished; /* true when ExecutorFinish is done */ |
| 559 | |
| 560 | List *es_exprcontexts; /* List of ExprContexts within EState */ |
| 561 | |
| 562 | List *es_subplanstates; /* List of PlanState for SubPlans */ |
| 563 | |
| 564 | List *es_auxmodifytables; /* List of secondary ModifyTableStates */ |
| 565 | |
| 566 | /* |
| 567 | * this ExprContext is for per-output-tuple operations, such as constraint |
| 568 | * checks and index-value computations. It will be reset for each output |
| 569 | * tuple. Note that it will be created only if needed. |
| 570 | */ |
| 571 | ExprContext *es_per_tuple_exprcontext; |
| 572 | |
| 573 | /* |
| 574 | * If not NULL, this is an EPQState's EState. This is a field in EState |
| 575 | * both to allow EvalPlanQual aware executor nodes to detect that they |
| 576 | * need to perform EPQ related work, and to provide necessary information |
| 577 | * to do so. |
| 578 | */ |
| 579 | struct EPQState *es_epq_active; |
| 580 | |
| 581 | bool es_use_parallel_mode; /* can we use parallel workers? */ |
| 582 | |
| 583 | /* The per-query shared memory area to use for parallel execution. */ |
| 584 | struct dsa_area *es_query_dsa; |
| 585 | |
| 586 | /* |
| 587 | * JIT information. es_jit_flags indicates whether JIT should be performed |
| 588 | * and with which options. es_jit is created on-demand when JITing is |
| 589 | * performed. |
| 590 | * |
| 591 | * es_jit_combined_instr is the combined, on demand allocated, |
| 592 | * instrumentation from all workers. The leader's instrumentation is kept |
| 593 | * separate, and is combined on demand by ExplainPrintJITSummary(). |
| 594 | */ |
| 595 | int es_jit_flags; |
| 596 | struct JitContext *es_jit; |
| 597 | struct JitInstrumentation *es_jit_worker_instr; |
| 598 | } EState; |
| 599 | |
| 600 | |
| 601 | /* |
| 602 | * ExecRowMark - |
| 603 | * runtime representation of FOR [KEY] UPDATE/SHARE clauses |
| 604 | * |
| 605 | * When doing UPDATE, DELETE, or SELECT FOR [KEY] UPDATE/SHARE, we will have an |
| 606 | * ExecRowMark for each non-target relation in the query (except inheritance |
| 607 | * parent RTEs, which can be ignored at runtime). Virtual relations such as |
| 608 | * subqueries-in-FROM will have an ExecRowMark with relation == NULL. See |
| 609 | * PlanRowMark for details about most of the fields. In addition to fields |
| 610 | * directly derived from PlanRowMark, we store an activity flag (to denote |
| 611 | * inactive children of inheritance trees), curCtid, which is used by the |
| 612 | * WHERE CURRENT OF code, and ermExtra, which is available for use by the plan |
| 613 | * node that sources the relation (e.g., for a foreign table the FDW can use |
| 614 | * ermExtra to hold information). |
| 615 | * |
| 616 | * EState->es_rowmarks is an array of these structs, indexed by RT index, |
| 617 | * with NULLs for irrelevant RT indexes. es_rowmarks itself is NULL if |
| 618 | * there are no rowmarks. |
| 619 | */ |
| 620 | typedef struct ExecRowMark |
| 621 | { |
| 622 | Relation relation; /* opened and suitably locked relation */ |
| 623 | Oid relid; /* its OID (or InvalidOid, if subquery) */ |
| 624 | Index rti; /* its range table index */ |
| 625 | Index prti; /* parent range table index, if child */ |
| 626 | Index rowmarkId; /* unique identifier for resjunk columns */ |
| 627 | RowMarkType markType; /* see enum in nodes/plannodes.h */ |
| 628 | LockClauseStrength strength; /* LockingClause's strength, or LCS_NONE */ |
| 629 | LockWaitPolicy waitPolicy; /* NOWAIT and SKIP LOCKED */ |
| 630 | bool ermActive; /* is this mark relevant for current tuple? */ |
| 631 | ItemPointerData curCtid; /* ctid of currently locked tuple, if any */ |
| 632 | void *; /* available for use by relation source node */ |
| 633 | } ExecRowMark; |
| 634 | |
| 635 | /* |
| 636 | * ExecAuxRowMark - |
| 637 | * additional runtime representation of FOR [KEY] UPDATE/SHARE clauses |
| 638 | * |
| 639 | * Each LockRows and ModifyTable node keeps a list of the rowmarks it needs to |
| 640 | * deal with. In addition to a pointer to the related entry in es_rowmarks, |
| 641 | * this struct carries the column number(s) of the resjunk columns associated |
| 642 | * with the rowmark (see comments for PlanRowMark for more detail). In the |
| 643 | * case of ModifyTable, there has to be a separate ExecAuxRowMark list for |
| 644 | * each child plan, because the resjunk columns could be at different physical |
| 645 | * column positions in different subplans. |
| 646 | */ |
| 647 | typedef struct ExecAuxRowMark |
| 648 | { |
| 649 | ExecRowMark *rowmark; /* related entry in es_rowmarks */ |
| 650 | AttrNumber ctidAttNo; /* resno of ctid junk attribute, if any */ |
| 651 | AttrNumber toidAttNo; /* resno of tableoid junk attribute, if any */ |
| 652 | AttrNumber wholeAttNo; /* resno of whole-row junk attribute, if any */ |
| 653 | } ExecAuxRowMark; |
| 654 | |
| 655 | |
| 656 | /* ---------------------------------------------------------------- |
| 657 | * Tuple Hash Tables |
| 658 | * |
| 659 | * All-in-memory tuple hash tables are used for a number of purposes. |
| 660 | * |
| 661 | * Note: tab_hash_funcs are for the key datatype(s) stored in the table, |
| 662 | * and tab_eq_funcs are non-cross-type equality operators for those types. |
| 663 | * Normally these are the only functions used, but FindTupleHashEntry() |
| 664 | * supports searching a hashtable using cross-data-type hashing. For that, |
| 665 | * the caller must supply hash functions for the LHS datatype as well as |
| 666 | * the cross-type equality operators to use. in_hash_funcs and cur_eq_func |
| 667 | * are set to point to the caller's function arrays while doing such a search. |
| 668 | * During LookupTupleHashEntry(), they point to tab_hash_funcs and |
| 669 | * tab_eq_func respectively. |
| 670 | * ---------------------------------------------------------------- |
| 671 | */ |
| 672 | typedef struct TupleHashEntryData *TupleHashEntry; |
| 673 | typedef struct TupleHashTableData *TupleHashTable; |
| 674 | |
| 675 | typedef struct TupleHashEntryData |
| 676 | { |
| 677 | MinimalTuple firstTuple; /* copy of first tuple in this group */ |
| 678 | void *additional; /* user data */ |
| 679 | uint32 status; /* hash status */ |
| 680 | uint32 hash; /* hash value (cached) */ |
| 681 | } TupleHashEntryData; |
| 682 | |
| 683 | /* define parameters necessary to generate the tuple hash table interface */ |
| 684 | #define SH_PREFIX tuplehash |
| 685 | #define SH_ELEMENT_TYPE TupleHashEntryData |
| 686 | #define SH_KEY_TYPE MinimalTuple |
| 687 | #define SH_SCOPE extern |
| 688 | #define SH_DECLARE |
| 689 | #include "lib/simplehash.h" |
| 690 | |
| 691 | typedef struct TupleHashTableData |
| 692 | { |
| 693 | tuplehash_hash *hashtab; /* underlying hash table */ |
| 694 | int numCols; /* number of columns in lookup key */ |
| 695 | AttrNumber *keyColIdx; /* attr numbers of key columns */ |
| 696 | FmgrInfo *tab_hash_funcs; /* hash functions for table datatype(s) */ |
| 697 | ExprState *tab_eq_func; /* comparator for table datatype(s) */ |
| 698 | Oid *tab_collations; /* collations for hash and comparison */ |
| 699 | MemoryContext tablecxt; /* memory context containing table */ |
| 700 | MemoryContext tempcxt; /* context for function evaluations */ |
| 701 | Size entrysize; /* actual size to make each hash entry */ |
| 702 | TupleTableSlot *tableslot; /* slot for referencing table entries */ |
| 703 | /* The following fields are set transiently for each table search: */ |
| 704 | TupleTableSlot *inputslot; /* current input tuple's slot */ |
| 705 | FmgrInfo *in_hash_funcs; /* hash functions for input datatype(s) */ |
| 706 | ExprState *cur_eq_func; /* comparator for input vs. table */ |
| 707 | uint32 hash_iv; /* hash-function IV */ |
| 708 | ExprContext *exprcontext; /* expression context */ |
| 709 | } TupleHashTableData; |
| 710 | |
| 711 | typedef tuplehash_iterator TupleHashIterator; |
| 712 | |
| 713 | /* |
| 714 | * Use InitTupleHashIterator/TermTupleHashIterator for a read/write scan. |
| 715 | * Use ResetTupleHashIterator if the table can be frozen (in this case no |
| 716 | * explicit scan termination is needed). |
| 717 | */ |
| 718 | #define InitTupleHashIterator(htable, iter) \ |
| 719 | tuplehash_start_iterate(htable->hashtab, iter) |
| 720 | #define TermTupleHashIterator(iter) \ |
| 721 | ((void) 0) |
| 722 | #define ResetTupleHashIterator(htable, iter) \ |
| 723 | InitTupleHashIterator(htable, iter) |
| 724 | #define ScanTupleHashTable(htable, iter) \ |
| 725 | tuplehash_iterate(htable->hashtab, iter) |
| 726 | |
| 727 | |
| 728 | /* ---------------------------------------------------------------- |
| 729 | * Expression State Nodes |
| 730 | * |
| 731 | * Formerly, there was a separate executor expression state node corresponding |
| 732 | * to each node in a planned expression tree. That's no longer the case; for |
| 733 | * common expression node types, all the execution info is embedded into |
| 734 | * step(s) in a single ExprState node. But we still have a few executor state |
| 735 | * node types for selected expression node types, mostly those in which info |
| 736 | * has to be shared with other parts of the execution state tree. |
| 737 | * ---------------------------------------------------------------- |
| 738 | */ |
| 739 | |
| 740 | /* ---------------- |
| 741 | * AggrefExprState node |
| 742 | * ---------------- |
| 743 | */ |
| 744 | typedef struct AggrefExprState |
| 745 | { |
| 746 | NodeTag type; |
| 747 | Aggref *aggref; /* expression plan node */ |
| 748 | int aggno; /* ID number for agg within its plan node */ |
| 749 | } AggrefExprState; |
| 750 | |
| 751 | /* ---------------- |
| 752 | * WindowFuncExprState node |
| 753 | * ---------------- |
| 754 | */ |
| 755 | typedef struct WindowFuncExprState |
| 756 | { |
| 757 | NodeTag type; |
| 758 | WindowFunc *wfunc; /* expression plan node */ |
| 759 | List *args; /* ExprStates for argument expressions */ |
| 760 | ExprState *aggfilter; /* FILTER expression */ |
| 761 | int wfuncno; /* ID number for wfunc within its plan node */ |
| 762 | } WindowFuncExprState; |
| 763 | |
| 764 | |
| 765 | /* ---------------- |
| 766 | * SetExprState node |
| 767 | * |
| 768 | * State for evaluating a potentially set-returning expression (like FuncExpr |
| 769 | * or OpExpr). In some cases, like some of the expressions in ROWS FROM(...) |
| 770 | * the expression might not be a SRF, but nonetheless it uses the same |
| 771 | * machinery as SRFs; it will be treated as a SRF returning a single row. |
| 772 | * ---------------- |
| 773 | */ |
| 774 | typedef struct SetExprState |
| 775 | { |
| 776 | NodeTag type; |
| 777 | Expr *expr; /* expression plan node */ |
| 778 | List *args; /* ExprStates for argument expressions */ |
| 779 | |
| 780 | /* |
| 781 | * In ROWS FROM, functions can be inlined, removing the FuncExpr normally |
| 782 | * inside. In such a case this is the compiled expression (which cannot |
| 783 | * return a set), which'll be evaluated using regular ExecEvalExpr(). |
| 784 | */ |
| 785 | ExprState *elidedFuncState; |
| 786 | |
| 787 | /* |
| 788 | * Function manager's lookup info for the target function. If func.fn_oid |
| 789 | * is InvalidOid, we haven't initialized it yet (nor any of the following |
| 790 | * fields, except funcReturnsSet). |
| 791 | */ |
| 792 | FmgrInfo func; |
| 793 | |
| 794 | /* |
| 795 | * For a set-returning function (SRF) that returns a tuplestore, we keep |
| 796 | * the tuplestore here and dole out the result rows one at a time. The |
| 797 | * slot holds the row currently being returned. |
| 798 | */ |
| 799 | Tuplestorestate *funcResultStore; |
| 800 | TupleTableSlot *funcResultSlot; |
| 801 | |
| 802 | /* |
| 803 | * In some cases we need to compute a tuple descriptor for the function's |
| 804 | * output. If so, it's stored here. |
| 805 | */ |
| 806 | TupleDesc funcResultDesc; |
| 807 | bool funcReturnsTuple; /* valid when funcResultDesc isn't NULL */ |
| 808 | |
| 809 | /* |
| 810 | * Remember whether the function is declared to return a set. This is set |
| 811 | * by ExecInitExpr, and is valid even before the FmgrInfo is set up. |
| 812 | */ |
| 813 | bool funcReturnsSet; |
| 814 | |
| 815 | /* |
| 816 | * setArgsValid is true when we are evaluating a set-returning function |
| 817 | * that uses value-per-call mode and we are in the middle of a call |
| 818 | * series; we want to pass the same argument values to the function again |
| 819 | * (and again, until it returns ExprEndResult). This indicates that |
| 820 | * fcinfo_data already contains valid argument data. |
| 821 | */ |
| 822 | bool setArgsValid; |
| 823 | |
| 824 | /* |
| 825 | * Flag to remember whether we have registered a shutdown callback for |
| 826 | * this SetExprState. We do so only if funcResultStore or setArgsValid |
| 827 | * has been set at least once (since all the callback is for is to release |
| 828 | * the tuplestore or clear setArgsValid). |
| 829 | */ |
| 830 | bool shutdown_reg; /* a shutdown callback is registered */ |
| 831 | |
| 832 | /* |
| 833 | * Call parameter structure for the function. This has been initialized |
| 834 | * (by InitFunctionCallInfoData) if func.fn_oid is valid. It also saves |
| 835 | * argument values between calls, when setArgsValid is true. |
| 836 | */ |
| 837 | FunctionCallInfo fcinfo; |
| 838 | } SetExprState; |
| 839 | |
| 840 | /* ---------------- |
| 841 | * SubPlanState node |
| 842 | * ---------------- |
| 843 | */ |
| 844 | typedef struct SubPlanState |
| 845 | { |
| 846 | NodeTag type; |
| 847 | SubPlan *subplan; /* expression plan node */ |
| 848 | struct PlanState *planstate; /* subselect plan's state tree */ |
| 849 | struct PlanState *parent; /* parent plan node's state tree */ |
| 850 | ExprState *testexpr; /* state of combining expression */ |
| 851 | List *args; /* states of argument expression(s) */ |
| 852 | HeapTuple curTuple; /* copy of most recent tuple from subplan */ |
| 853 | Datum curArray; /* most recent array from ARRAY() subplan */ |
| 854 | /* these are used when hashing the subselect's output: */ |
| 855 | TupleDesc descRight; /* subselect desc after projection */ |
| 856 | ProjectionInfo *projLeft; /* for projecting lefthand exprs */ |
| 857 | ProjectionInfo *projRight; /* for projecting subselect output */ |
| 858 | TupleHashTable hashtable; /* hash table for no-nulls subselect rows */ |
| 859 | TupleHashTable hashnulls; /* hash table for rows with null(s) */ |
| 860 | bool havehashrows; /* true if hashtable is not empty */ |
| 861 | bool havenullrows; /* true if hashnulls is not empty */ |
| 862 | MemoryContext hashtablecxt; /* memory context containing hash tables */ |
| 863 | MemoryContext hashtempcxt; /* temp memory context for hash tables */ |
| 864 | ExprContext *innerecontext; /* econtext for computing inner tuples */ |
| 865 | AttrNumber *keyColIdx; /* control data for hash tables */ |
| 866 | Oid *tab_eq_funcoids; /* equality func oids for table |
| 867 | * datatype(s) */ |
| 868 | Oid *tab_collations; /* collations for hash and comparison */ |
| 869 | FmgrInfo *tab_hash_funcs; /* hash functions for table datatype(s) */ |
| 870 | FmgrInfo *tab_eq_funcs; /* equality functions for table datatype(s) */ |
| 871 | FmgrInfo *lhs_hash_funcs; /* hash functions for lefthand datatype(s) */ |
| 872 | FmgrInfo *cur_eq_funcs; /* equality functions for LHS vs. table */ |
| 873 | ExprState *cur_eq_comp; /* equality comparator for LHS vs. table */ |
| 874 | } SubPlanState; |
| 875 | |
| 876 | /* ---------------- |
| 877 | * AlternativeSubPlanState node |
| 878 | * ---------------- |
| 879 | */ |
| 880 | typedef struct AlternativeSubPlanState |
| 881 | { |
| 882 | NodeTag type; |
| 883 | AlternativeSubPlan *subplan; /* expression plan node */ |
| 884 | List *subplans; /* SubPlanStates of alternative subplans */ |
| 885 | int active; /* list index of the one we're using */ |
| 886 | } AlternativeSubPlanState; |
| 887 | |
| 888 | /* |
| 889 | * DomainConstraintState - one item to check during CoerceToDomain |
| 890 | * |
| 891 | * Note: we consider this to be part of an ExprState tree, so we give it |
| 892 | * a name following the xxxState convention. But there's no directly |
| 893 | * associated plan-tree node. |
| 894 | */ |
| 895 | typedef enum DomainConstraintType |
| 896 | { |
| 897 | DOM_CONSTRAINT_NOTNULL, |
| 898 | DOM_CONSTRAINT_CHECK |
| 899 | } DomainConstraintType; |
| 900 | |
| 901 | typedef struct DomainConstraintState |
| 902 | { |
| 903 | NodeTag type; |
| 904 | DomainConstraintType constrainttype; /* constraint type */ |
| 905 | char *name; /* name of constraint (for error msgs) */ |
| 906 | Expr *check_expr; /* for CHECK, a boolean expression */ |
| 907 | ExprState *check_exprstate; /* check_expr's eval state, or NULL */ |
| 908 | } DomainConstraintState; |
| 909 | |
| 910 | |
| 911 | /* ---------------------------------------------------------------- |
| 912 | * Executor State Trees |
| 913 | * |
| 914 | * An executing query has a PlanState tree paralleling the Plan tree |
| 915 | * that describes the plan. |
| 916 | * ---------------------------------------------------------------- |
| 917 | */ |
| 918 | |
| 919 | /* ---------------- |
| 920 | * ExecProcNodeMtd |
| 921 | * |
| 922 | * This is the method called by ExecProcNode to return the next tuple |
| 923 | * from an executor node. It returns NULL, or an empty TupleTableSlot, |
| 924 | * if no more tuples are available. |
| 925 | * ---------------- |
| 926 | */ |
| 927 | typedef TupleTableSlot *(*ExecProcNodeMtd) (struct PlanState *pstate); |
| 928 | |
| 929 | /* ---------------- |
| 930 | * PlanState node |
| 931 | * |
| 932 | * We never actually instantiate any PlanState nodes; this is just the common |
| 933 | * abstract superclass for all PlanState-type nodes. |
| 934 | * ---------------- |
| 935 | */ |
| 936 | typedef struct PlanState |
| 937 | { |
| 938 | NodeTag type; |
| 939 | |
| 940 | Plan *plan; /* associated Plan node */ |
| 941 | |
| 942 | EState *state; /* at execution time, states of individual |
| 943 | * nodes point to one EState for the whole |
| 944 | * top-level plan */ |
| 945 | |
| 946 | ExecProcNodeMtd ExecProcNode; /* function to return next tuple */ |
| 947 | ExecProcNodeMtd ExecProcNodeReal; /* actual function, if above is a |
| 948 | * wrapper */ |
| 949 | |
| 950 | Instrumentation *instrument; /* Optional runtime stats for this node */ |
| 951 | WorkerInstrumentation *worker_instrument; /* per-worker instrumentation */ |
| 952 | |
| 953 | /* Per-worker JIT instrumentation */ |
| 954 | struct SharedJitInstrumentation *worker_jit_instrument; |
| 955 | |
| 956 | /* |
| 957 | * Common structural data for all Plan types. These links to subsidiary |
| 958 | * state trees parallel links in the associated plan tree (except for the |
| 959 | * subPlan list, which does not exist in the plan tree). |
| 960 | */ |
| 961 | ExprState *qual; /* boolean qual condition */ |
| 962 | struct PlanState *lefttree; /* input plan tree(s) */ |
| 963 | struct PlanState *righttree; |
| 964 | |
| 965 | List *initPlan; /* Init SubPlanState nodes (un-correlated expr |
| 966 | * subselects) */ |
| 967 | List *subPlan; /* SubPlanState nodes in my expressions */ |
| 968 | |
| 969 | /* |
| 970 | * State for management of parameter-change-driven rescanning |
| 971 | */ |
| 972 | Bitmapset *chgParam; /* set of IDs of changed Params */ |
| 973 | |
| 974 | /* |
| 975 | * Other run-time state needed by most if not all node types. |
| 976 | */ |
| 977 | TupleDesc ps_ResultTupleDesc; /* node's return type */ |
| 978 | TupleTableSlot *ps_ResultTupleSlot; /* slot for my result tuples */ |
| 979 | ExprContext *ps_ExprContext; /* node's expression-evaluation context */ |
| 980 | ProjectionInfo *ps_ProjInfo; /* info for doing tuple projection */ |
| 981 | |
| 982 | /* |
| 983 | * Scanslot's descriptor if known. This is a bit of a hack, but otherwise |
| 984 | * it's hard for expression compilation to optimize based on the |
| 985 | * descriptor, without encoding knowledge about all executor nodes. |
| 986 | */ |
| 987 | TupleDesc scandesc; |
| 988 | |
| 989 | /* |
| 990 | * Define the slot types for inner, outer and scanslots for expression |
| 991 | * contexts with this state as a parent. If *opsset is set, then |
| 992 | * *opsfixed indicates whether *ops is guaranteed to be the type of slot |
| 993 | * used. That means that every slot in the corresponding |
| 994 | * ExprContext.ecxt_*tuple will point to a slot of that type, while |
| 995 | * evaluating the expression. If *opsfixed is false, but *ops is set, |
| 996 | * that indicates the most likely type of slot. |
| 997 | * |
| 998 | * The scan* fields are set by ExecInitScanTupleSlot(). If that's not |
| 999 | * called, nodes can initialize the fields themselves. |
| 1000 | * |
| 1001 | * If outer/inneropsset is false, the information is inferred on-demand |
| 1002 | * using ExecGetResultSlotOps() on ->righttree/lefttree, using the |
| 1003 | * corresponding node's resultops* fields. |
| 1004 | * |
| 1005 | * The result* fields are automatically set when ExecInitResultSlot is |
| 1006 | * used (be it directly or when the slot is created by |
| 1007 | * ExecAssignScanProjectionInfo() / |
| 1008 | * ExecConditionalAssignProjectionInfo()). If no projection is necessary |
| 1009 | * ExecConditionalAssignProjectionInfo() defaults those fields to the scan |
| 1010 | * operations. |
| 1011 | */ |
| 1012 | const TupleTableSlotOps *scanops; |
| 1013 | const TupleTableSlotOps *outerops; |
| 1014 | const TupleTableSlotOps *innerops; |
| 1015 | const TupleTableSlotOps *resultops; |
| 1016 | bool scanopsfixed; |
| 1017 | bool outeropsfixed; |
| 1018 | bool inneropsfixed; |
| 1019 | bool resultopsfixed; |
| 1020 | bool scanopsset; |
| 1021 | bool outeropsset; |
| 1022 | bool inneropsset; |
| 1023 | bool resultopsset; |
| 1024 | } PlanState; |
| 1025 | |
| 1026 | /* ---------------- |
| 1027 | * these are defined to avoid confusion problems with "left" |
| 1028 | * and "right" and "inner" and "outer". The convention is that |
| 1029 | * the "left" plan is the "outer" plan and the "right" plan is |
| 1030 | * the inner plan, but these make the code more readable. |
| 1031 | * ---------------- |
| 1032 | */ |
| 1033 | #define innerPlanState(node) (((PlanState *)(node))->righttree) |
| 1034 | #define outerPlanState(node) (((PlanState *)(node))->lefttree) |
| 1035 | |
| 1036 | /* Macros for inline access to certain instrumentation counters */ |
| 1037 | #define InstrCountTuples2(node, delta) \ |
| 1038 | do { \ |
| 1039 | if (((PlanState *)(node))->instrument) \ |
| 1040 | ((PlanState *)(node))->instrument->ntuples2 += (delta); \ |
| 1041 | } while (0) |
| 1042 | #define InstrCountFiltered1(node, delta) \ |
| 1043 | do { \ |
| 1044 | if (((PlanState *)(node))->instrument) \ |
| 1045 | ((PlanState *)(node))->instrument->nfiltered1 += (delta); \ |
| 1046 | } while(0) |
| 1047 | #define InstrCountFiltered2(node, delta) \ |
| 1048 | do { \ |
| 1049 | if (((PlanState *)(node))->instrument) \ |
| 1050 | ((PlanState *)(node))->instrument->nfiltered2 += (delta); \ |
| 1051 | } while(0) |
| 1052 | |
| 1053 | /* |
| 1054 | * EPQState is state for executing an EvalPlanQual recheck on a candidate |
| 1055 | * tuples e.g. in ModifyTable or LockRows. |
| 1056 | * |
| 1057 | * To execute EPQ a separate EState is created (stored in ->recheckestate), |
| 1058 | * which shares some resources, like the rangetable, with the main query's |
| 1059 | * EState (stored in ->parentestate). The (sub-)tree of the plan that needs to |
| 1060 | * be rechecked (in ->plan), is separately initialized (into |
| 1061 | * ->recheckplanstate), but shares plan nodes with the corresponding nodes in |
| 1062 | * the main query. The scan nodes in that separate executor tree are changed |
| 1063 | * to return only the current tuple of interest for the respective |
| 1064 | * table. Those tuples are either provided by the caller (using |
| 1065 | * EvalPlanQualSlot), and/or found using the rowmark mechanism (non-locking |
| 1066 | * rowmarks by the EPQ machinery itself, locking ones by the caller). |
| 1067 | * |
| 1068 | * While the plan to be checked may be changed using EvalPlanQualSetPlan() - |
| 1069 | * e.g. so all source plans for a ModifyTable node can be processed - all such |
| 1070 | * plans need to share the same EState. |
| 1071 | */ |
| 1072 | typedef struct EPQState |
| 1073 | { |
| 1074 | /* Initialized at EvalPlanQualInit() time: */ |
| 1075 | |
| 1076 | EState *parentestate; /* main query's EState */ |
| 1077 | int epqParam; /* ID of Param to force scan node re-eval */ |
| 1078 | |
| 1079 | /* |
| 1080 | * Tuples to be substituted by scan nodes. They need to set up, before |
| 1081 | * calling EvalPlanQual()/EvalPlanQualNext(), into the slot returned by |
| 1082 | * EvalPlanQualSlot(scanrelid). The array is indexed by scanrelid - 1. |
| 1083 | */ |
| 1084 | List *tuple_table; /* tuple table for relsubs_slot */ |
| 1085 | TupleTableSlot **relsubs_slot; |
| 1086 | |
| 1087 | /* |
| 1088 | * Initialized by EvalPlanQualInit(), may be changed later with |
| 1089 | * EvalPlanQualSetPlan(): |
| 1090 | */ |
| 1091 | |
| 1092 | Plan *plan; /* plan tree to be executed */ |
| 1093 | List *arowMarks; /* ExecAuxRowMarks (non-locking only) */ |
| 1094 | |
| 1095 | |
| 1096 | /* |
| 1097 | * The original output tuple to be rechecked. Set by |
| 1098 | * EvalPlanQualSetSlot(), before EvalPlanQualNext() or EvalPlanQual() may |
| 1099 | * be called. |
| 1100 | */ |
| 1101 | TupleTableSlot *origslot; |
| 1102 | |
| 1103 | |
| 1104 | /* Initialized or reset by EvalPlanQualBegin(): */ |
| 1105 | |
| 1106 | EState *recheckestate; /* EState for EPQ execution, see above */ |
| 1107 | |
| 1108 | /* |
| 1109 | * Rowmarks that can be fetched on-demand using |
| 1110 | * EvalPlanQualFetchRowMark(), indexed by scanrelid - 1. Only non-locking |
| 1111 | * rowmarks. |
| 1112 | */ |
| 1113 | ExecAuxRowMark **relsubs_rowmark; |
| 1114 | |
| 1115 | /* |
| 1116 | * True if a relation's EPQ tuple has been fetched for relation, indexed |
| 1117 | * by scanrelid - 1. |
| 1118 | */ |
| 1119 | bool *relsubs_done; |
| 1120 | |
| 1121 | PlanState *recheckplanstate; /* EPQ specific exec nodes, for ->plan */ |
| 1122 | } EPQState; |
| 1123 | |
| 1124 | |
| 1125 | /* ---------------- |
| 1126 | * ResultState information |
| 1127 | * ---------------- |
| 1128 | */ |
| 1129 | typedef struct ResultState |
| 1130 | { |
| 1131 | PlanState ps; /* its first field is NodeTag */ |
| 1132 | ExprState *resconstantqual; |
| 1133 | bool rs_done; /* are we done? */ |
| 1134 | bool rs_checkqual; /* do we need to check the qual? */ |
| 1135 | } ResultState; |
| 1136 | |
| 1137 | /* ---------------- |
| 1138 | * ProjectSetState information |
| 1139 | * |
| 1140 | * Note: at least one of the "elems" will be a SetExprState; the rest are |
| 1141 | * regular ExprStates. |
| 1142 | * ---------------- |
| 1143 | */ |
| 1144 | typedef struct ProjectSetState |
| 1145 | { |
| 1146 | PlanState ps; /* its first field is NodeTag */ |
| 1147 | Node **elems; /* array of expression states */ |
| 1148 | ExprDoneCond *elemdone; /* array of per-SRF is-done states */ |
| 1149 | int nelems; /* length of elemdone[] array */ |
| 1150 | bool pending_srf_tuples; /* still evaluating srfs in tlist? */ |
| 1151 | MemoryContext argcontext; /* context for SRF arguments */ |
| 1152 | } ProjectSetState; |
| 1153 | |
| 1154 | /* ---------------- |
| 1155 | * ModifyTableState information |
| 1156 | * ---------------- |
| 1157 | */ |
| 1158 | typedef struct ModifyTableState |
| 1159 | { |
| 1160 | PlanState ps; /* its first field is NodeTag */ |
| 1161 | CmdType operation; /* INSERT, UPDATE, or DELETE */ |
| 1162 | bool canSetTag; /* do we set the command tag/es_processed? */ |
| 1163 | bool mt_done; /* are we done? */ |
| 1164 | PlanState **mt_plans; /* subplans (one per target rel) */ |
| 1165 | int mt_nplans; /* number of plans in the array */ |
| 1166 | int mt_whichplan; /* which one is being executed (0..n-1) */ |
| 1167 | TupleTableSlot **mt_scans; /* input tuple corresponding to underlying |
| 1168 | * plans */ |
| 1169 | ResultRelInfo *resultRelInfo; /* per-subplan target relations */ |
| 1170 | ResultRelInfo *rootResultRelInfo; /* root target relation (partitioned |
| 1171 | * table root) */ |
| 1172 | List **mt_arowmarks; /* per-subplan ExecAuxRowMark lists */ |
| 1173 | EPQState mt_epqstate; /* for evaluating EvalPlanQual rechecks */ |
| 1174 | bool fireBSTriggers; /* do we need to fire stmt triggers? */ |
| 1175 | List *mt_excludedtlist; /* the excluded pseudo relation's tlist */ |
| 1176 | |
| 1177 | /* |
| 1178 | * Slot for storing tuples in the root partitioned table's rowtype during |
| 1179 | * an UPDATE of a partitioned table. |
| 1180 | */ |
| 1181 | TupleTableSlot *mt_root_tuple_slot; |
| 1182 | |
| 1183 | /* Tuple-routing support info */ |
| 1184 | struct PartitionTupleRouting *mt_partition_tuple_routing; |
| 1185 | |
| 1186 | /* controls transition table population for specified operation */ |
| 1187 | struct TransitionCaptureState *mt_transition_capture; |
| 1188 | |
| 1189 | /* controls transition table population for INSERT...ON CONFLICT UPDATE */ |
| 1190 | struct TransitionCaptureState *mt_oc_transition_capture; |
| 1191 | |
| 1192 | /* Per plan map for tuple conversion from child to root */ |
| 1193 | TupleConversionMap **mt_per_subplan_tupconv_maps; |
| 1194 | } ModifyTableState; |
| 1195 | |
| 1196 | /* ---------------- |
| 1197 | * AppendState information |
| 1198 | * |
| 1199 | * nplans how many plans are in the array |
| 1200 | * whichplan which plan is being executed (0 .. n-1), or a |
| 1201 | * special negative value. See nodeAppend.c. |
| 1202 | * prune_state details required to allow partitions to be |
| 1203 | * eliminated from the scan, or NULL if not possible. |
| 1204 | * valid_subplans for runtime pruning, valid appendplans indexes to |
| 1205 | * scan. |
| 1206 | * ---------------- |
| 1207 | */ |
| 1208 | |
| 1209 | struct AppendState; |
| 1210 | typedef struct AppendState AppendState; |
| 1211 | struct ParallelAppendState; |
| 1212 | typedef struct ParallelAppendState ParallelAppendState; |
| 1213 | struct PartitionPruneState; |
| 1214 | |
| 1215 | struct AppendState |
| 1216 | { |
| 1217 | PlanState ps; /* its first field is NodeTag */ |
| 1218 | PlanState **appendplans; /* array of PlanStates for my inputs */ |
| 1219 | int as_nplans; |
| 1220 | int as_whichplan; |
| 1221 | int as_first_partial_plan; /* Index of 'appendplans' containing |
| 1222 | * the first partial plan */ |
| 1223 | ParallelAppendState *as_pstate; /* parallel coordination info */ |
| 1224 | Size pstate_len; /* size of parallel coordination info */ |
| 1225 | struct PartitionPruneState *as_prune_state; |
| 1226 | Bitmapset *as_valid_subplans; |
| 1227 | bool (*choose_next_subplan) (AppendState *); |
| 1228 | }; |
| 1229 | |
| 1230 | /* ---------------- |
| 1231 | * MergeAppendState information |
| 1232 | * |
| 1233 | * nplans how many plans are in the array |
| 1234 | * nkeys number of sort key columns |
| 1235 | * sortkeys sort keys in SortSupport representation |
| 1236 | * slots current output tuple of each subplan |
| 1237 | * heap heap of active tuples |
| 1238 | * initialized true if we have fetched first tuple from each subplan |
| 1239 | * noopscan true if partition pruning proved that none of the |
| 1240 | * mergeplans can contain a record to satisfy this query. |
| 1241 | * prune_state details required to allow partitions to be |
| 1242 | * eliminated from the scan, or NULL if not possible. |
| 1243 | * valid_subplans for runtime pruning, valid mergeplans indexes to |
| 1244 | * scan. |
| 1245 | * ---------------- |
| 1246 | */ |
| 1247 | typedef struct MergeAppendState |
| 1248 | { |
| 1249 | PlanState ps; /* its first field is NodeTag */ |
| 1250 | PlanState **mergeplans; /* array of PlanStates for my inputs */ |
| 1251 | int ms_nplans; |
| 1252 | int ms_nkeys; |
| 1253 | SortSupport ms_sortkeys; /* array of length ms_nkeys */ |
| 1254 | TupleTableSlot **ms_slots; /* array of length ms_nplans */ |
| 1255 | struct binaryheap *ms_heap; /* binary heap of slot indices */ |
| 1256 | bool ms_initialized; /* are subplans started? */ |
| 1257 | bool ms_noopscan; |
| 1258 | struct PartitionPruneState *ms_prune_state; |
| 1259 | Bitmapset *ms_valid_subplans; |
| 1260 | } MergeAppendState; |
| 1261 | |
| 1262 | /* ---------------- |
| 1263 | * RecursiveUnionState information |
| 1264 | * |
| 1265 | * RecursiveUnionState is used for performing a recursive union. |
| 1266 | * |
| 1267 | * recursing T when we're done scanning the non-recursive term |
| 1268 | * intermediate_empty T if intermediate_table is currently empty |
| 1269 | * working_table working table (to be scanned by recursive term) |
| 1270 | * intermediate_table current recursive output (next generation of WT) |
| 1271 | * ---------------- |
| 1272 | */ |
| 1273 | typedef struct RecursiveUnionState |
| 1274 | { |
| 1275 | PlanState ps; /* its first field is NodeTag */ |
| 1276 | bool recursing; |
| 1277 | bool intermediate_empty; |
| 1278 | Tuplestorestate *working_table; |
| 1279 | Tuplestorestate *intermediate_table; |
| 1280 | /* Remaining fields are unused in UNION ALL case */ |
| 1281 | Oid *eqfuncoids; /* per-grouping-field equality fns */ |
| 1282 | FmgrInfo *hashfunctions; /* per-grouping-field hash fns */ |
| 1283 | MemoryContext tempContext; /* short-term context for comparisons */ |
| 1284 | TupleHashTable hashtable; /* hash table for tuples already seen */ |
| 1285 | MemoryContext tableContext; /* memory context containing hash table */ |
| 1286 | } RecursiveUnionState; |
| 1287 | |
| 1288 | /* ---------------- |
| 1289 | * BitmapAndState information |
| 1290 | * ---------------- |
| 1291 | */ |
| 1292 | typedef struct BitmapAndState |
| 1293 | { |
| 1294 | PlanState ps; /* its first field is NodeTag */ |
| 1295 | PlanState **bitmapplans; /* array of PlanStates for my inputs */ |
| 1296 | int nplans; /* number of input plans */ |
| 1297 | } BitmapAndState; |
| 1298 | |
| 1299 | /* ---------------- |
| 1300 | * BitmapOrState information |
| 1301 | * ---------------- |
| 1302 | */ |
| 1303 | typedef struct BitmapOrState |
| 1304 | { |
| 1305 | PlanState ps; /* its first field is NodeTag */ |
| 1306 | PlanState **bitmapplans; /* array of PlanStates for my inputs */ |
| 1307 | int nplans; /* number of input plans */ |
| 1308 | } BitmapOrState; |
| 1309 | |
| 1310 | /* ---------------------------------------------------------------- |
| 1311 | * Scan State Information |
| 1312 | * ---------------------------------------------------------------- |
| 1313 | */ |
| 1314 | |
| 1315 | /* ---------------- |
| 1316 | * ScanState information |
| 1317 | * |
| 1318 | * ScanState extends PlanState for node types that represent |
| 1319 | * scans of an underlying relation. It can also be used for nodes |
| 1320 | * that scan the output of an underlying plan node --- in that case, |
| 1321 | * only ScanTupleSlot is actually useful, and it refers to the tuple |
| 1322 | * retrieved from the subplan. |
| 1323 | * |
| 1324 | * currentRelation relation being scanned (NULL if none) |
| 1325 | * currentScanDesc current scan descriptor for scan (NULL if none) |
| 1326 | * ScanTupleSlot pointer to slot in tuple table holding scan tuple |
| 1327 | * ---------------- |
| 1328 | */ |
| 1329 | typedef struct ScanState |
| 1330 | { |
| 1331 | PlanState ps; /* its first field is NodeTag */ |
| 1332 | Relation ss_currentRelation; |
| 1333 | struct TableScanDescData *ss_currentScanDesc; |
| 1334 | TupleTableSlot *ss_ScanTupleSlot; |
| 1335 | } ScanState; |
| 1336 | |
| 1337 | /* ---------------- |
| 1338 | * SeqScanState information |
| 1339 | * ---------------- |
| 1340 | */ |
| 1341 | typedef struct SeqScanState |
| 1342 | { |
| 1343 | ScanState ss; /* its first field is NodeTag */ |
| 1344 | Size pscan_len; /* size of parallel heap scan descriptor */ |
| 1345 | } SeqScanState; |
| 1346 | |
| 1347 | /* ---------------- |
| 1348 | * SampleScanState information |
| 1349 | * ---------------- |
| 1350 | */ |
| 1351 | typedef struct SampleScanState |
| 1352 | { |
| 1353 | ScanState ss; |
| 1354 | List *args; /* expr states for TABLESAMPLE params */ |
| 1355 | ExprState *repeatable; /* expr state for REPEATABLE expr */ |
| 1356 | /* use struct pointer to avoid including tsmapi.h here */ |
| 1357 | struct TsmRoutine *tsmroutine; /* descriptor for tablesample method */ |
| 1358 | void *tsm_state; /* tablesample method can keep state here */ |
| 1359 | bool use_bulkread; /* use bulkread buffer access strategy? */ |
| 1360 | bool use_pagemode; /* use page-at-a-time visibility checking? */ |
| 1361 | bool begun; /* false means need to call BeginSampleScan */ |
| 1362 | uint32 seed; /* random seed */ |
| 1363 | int64 donetuples; /* number of tuples already returned */ |
| 1364 | bool haveblock; /* has a block for sampling been determined */ |
| 1365 | bool done; /* exhausted all tuples? */ |
| 1366 | } SampleScanState; |
| 1367 | |
| 1368 | /* |
| 1369 | * These structs store information about index quals that don't have simple |
| 1370 | * constant right-hand sides. See comments for ExecIndexBuildScanKeys() |
| 1371 | * for discussion. |
| 1372 | */ |
| 1373 | typedef struct |
| 1374 | { |
| 1375 | struct ScanKeyData *scan_key; /* scankey to put value into */ |
| 1376 | ExprState *key_expr; /* expr to evaluate to get value */ |
| 1377 | bool key_toastable; /* is expr's result a toastable datatype? */ |
| 1378 | } IndexRuntimeKeyInfo; |
| 1379 | |
| 1380 | typedef struct |
| 1381 | { |
| 1382 | struct ScanKeyData *scan_key; /* scankey to put value into */ |
| 1383 | ExprState *array_expr; /* expr to evaluate to get array value */ |
| 1384 | int next_elem; /* next array element to use */ |
| 1385 | int num_elems; /* number of elems in current array value */ |
| 1386 | Datum *elem_values; /* array of num_elems Datums */ |
| 1387 | bool *elem_nulls; /* array of num_elems is-null flags */ |
| 1388 | } IndexArrayKeyInfo; |
| 1389 | |
| 1390 | /* ---------------- |
| 1391 | * IndexScanState information |
| 1392 | * |
| 1393 | * indexqualorig execution state for indexqualorig expressions |
| 1394 | * indexorderbyorig execution state for indexorderbyorig expressions |
| 1395 | * ScanKeys Skey structures for index quals |
| 1396 | * NumScanKeys number of ScanKeys |
| 1397 | * OrderByKeys Skey structures for index ordering operators |
| 1398 | * NumOrderByKeys number of OrderByKeys |
| 1399 | * RuntimeKeys info about Skeys that must be evaluated at runtime |
| 1400 | * NumRuntimeKeys number of RuntimeKeys |
| 1401 | * RuntimeKeysReady true if runtime Skeys have been computed |
| 1402 | * RuntimeContext expr context for evaling runtime Skeys |
| 1403 | * RelationDesc index relation descriptor |
| 1404 | * ScanDesc index scan descriptor |
| 1405 | * |
| 1406 | * ReorderQueue tuples that need reordering due to re-check |
| 1407 | * ReachedEnd have we fetched all tuples from index already? |
| 1408 | * OrderByValues values of ORDER BY exprs of last fetched tuple |
| 1409 | * OrderByNulls null flags for OrderByValues |
| 1410 | * SortSupport for reordering ORDER BY exprs |
| 1411 | * OrderByTypByVals is the datatype of order by expression pass-by-value? |
| 1412 | * OrderByTypLens typlens of the datatypes of order by expressions |
| 1413 | * PscanLen size of parallel index scan descriptor |
| 1414 | * ---------------- |
| 1415 | */ |
| 1416 | typedef struct IndexScanState |
| 1417 | { |
| 1418 | ScanState ss; /* its first field is NodeTag */ |
| 1419 | ExprState *indexqualorig; |
| 1420 | List *indexorderbyorig; |
| 1421 | struct ScanKeyData *iss_ScanKeys; |
| 1422 | int iss_NumScanKeys; |
| 1423 | struct ScanKeyData *iss_OrderByKeys; |
| 1424 | int iss_NumOrderByKeys; |
| 1425 | IndexRuntimeKeyInfo *iss_RuntimeKeys; |
| 1426 | int iss_NumRuntimeKeys; |
| 1427 | bool iss_RuntimeKeysReady; |
| 1428 | ExprContext *iss_RuntimeContext; |
| 1429 | Relation iss_RelationDesc; |
| 1430 | struct IndexScanDescData *iss_ScanDesc; |
| 1431 | |
| 1432 | /* These are needed for re-checking ORDER BY expr ordering */ |
| 1433 | pairingheap *iss_ReorderQueue; |
| 1434 | bool iss_ReachedEnd; |
| 1435 | Datum *iss_OrderByValues; |
| 1436 | bool *iss_OrderByNulls; |
| 1437 | SortSupport iss_SortSupport; |
| 1438 | bool *iss_OrderByTypByVals; |
| 1439 | int16 *iss_OrderByTypLens; |
| 1440 | Size iss_PscanLen; |
| 1441 | } IndexScanState; |
| 1442 | |
| 1443 | /* ---------------- |
| 1444 | * IndexOnlyScanState information |
| 1445 | * |
| 1446 | * indexqual execution state for indexqual expressions |
| 1447 | * ScanKeys Skey structures for index quals |
| 1448 | * NumScanKeys number of ScanKeys |
| 1449 | * OrderByKeys Skey structures for index ordering operators |
| 1450 | * NumOrderByKeys number of OrderByKeys |
| 1451 | * RuntimeKeys info about Skeys that must be evaluated at runtime |
| 1452 | * NumRuntimeKeys number of RuntimeKeys |
| 1453 | * RuntimeKeysReady true if runtime Skeys have been computed |
| 1454 | * RuntimeContext expr context for evaling runtime Skeys |
| 1455 | * RelationDesc index relation descriptor |
| 1456 | * ScanDesc index scan descriptor |
| 1457 | * TableSlot slot for holding tuples fetched from the table |
| 1458 | * VMBuffer buffer in use for visibility map testing, if any |
| 1459 | * PscanLen size of parallel index-only scan descriptor |
| 1460 | * ---------------- |
| 1461 | */ |
| 1462 | typedef struct IndexOnlyScanState |
| 1463 | { |
| 1464 | ScanState ss; /* its first field is NodeTag */ |
| 1465 | ExprState *indexqual; |
| 1466 | struct ScanKeyData *ioss_ScanKeys; |
| 1467 | int ioss_NumScanKeys; |
| 1468 | struct ScanKeyData *ioss_OrderByKeys; |
| 1469 | int ioss_NumOrderByKeys; |
| 1470 | IndexRuntimeKeyInfo *ioss_RuntimeKeys; |
| 1471 | int ioss_NumRuntimeKeys; |
| 1472 | bool ioss_RuntimeKeysReady; |
| 1473 | ExprContext *ioss_RuntimeContext; |
| 1474 | Relation ioss_RelationDesc; |
| 1475 | struct IndexScanDescData *ioss_ScanDesc; |
| 1476 | TupleTableSlot *ioss_TableSlot; |
| 1477 | Buffer ioss_VMBuffer; |
| 1478 | Size ioss_PscanLen; |
| 1479 | } IndexOnlyScanState; |
| 1480 | |
| 1481 | /* ---------------- |
| 1482 | * BitmapIndexScanState information |
| 1483 | * |
| 1484 | * result bitmap to return output into, or NULL |
| 1485 | * ScanKeys Skey structures for index quals |
| 1486 | * NumScanKeys number of ScanKeys |
| 1487 | * RuntimeKeys info about Skeys that must be evaluated at runtime |
| 1488 | * NumRuntimeKeys number of RuntimeKeys |
| 1489 | * ArrayKeys info about Skeys that come from ScalarArrayOpExprs |
| 1490 | * NumArrayKeys number of ArrayKeys |
| 1491 | * RuntimeKeysReady true if runtime Skeys have been computed |
| 1492 | * RuntimeContext expr context for evaling runtime Skeys |
| 1493 | * RelationDesc index relation descriptor |
| 1494 | * ScanDesc index scan descriptor |
| 1495 | * ---------------- |
| 1496 | */ |
| 1497 | typedef struct BitmapIndexScanState |
| 1498 | { |
| 1499 | ScanState ss; /* its first field is NodeTag */ |
| 1500 | TIDBitmap *biss_result; |
| 1501 | struct ScanKeyData *biss_ScanKeys; |
| 1502 | int biss_NumScanKeys; |
| 1503 | IndexRuntimeKeyInfo *biss_RuntimeKeys; |
| 1504 | int biss_NumRuntimeKeys; |
| 1505 | IndexArrayKeyInfo *biss_ArrayKeys; |
| 1506 | int biss_NumArrayKeys; |
| 1507 | bool biss_RuntimeKeysReady; |
| 1508 | ExprContext *biss_RuntimeContext; |
| 1509 | Relation biss_RelationDesc; |
| 1510 | struct IndexScanDescData *biss_ScanDesc; |
| 1511 | } BitmapIndexScanState; |
| 1512 | |
| 1513 | /* ---------------- |
| 1514 | * SharedBitmapState information |
| 1515 | * |
| 1516 | * BM_INITIAL TIDBitmap creation is not yet started, so first worker |
| 1517 | * to see this state will set the state to BM_INPROGRESS |
| 1518 | * and that process will be responsible for creating |
| 1519 | * TIDBitmap. |
| 1520 | * BM_INPROGRESS TIDBitmap creation is in progress; workers need to |
| 1521 | * sleep until it's finished. |
| 1522 | * BM_FINISHED TIDBitmap creation is done, so now all workers can |
| 1523 | * proceed to iterate over TIDBitmap. |
| 1524 | * ---------------- |
| 1525 | */ |
| 1526 | typedef enum |
| 1527 | { |
| 1528 | BM_INITIAL, |
| 1529 | BM_INPROGRESS, |
| 1530 | BM_FINISHED |
| 1531 | } SharedBitmapState; |
| 1532 | |
| 1533 | /* ---------------- |
| 1534 | * ParallelBitmapHeapState information |
| 1535 | * tbmiterator iterator for scanning current pages |
| 1536 | * prefetch_iterator iterator for prefetching ahead of current page |
| 1537 | * mutex mutual exclusion for the prefetching variable |
| 1538 | * and state |
| 1539 | * prefetch_pages # pages prefetch iterator is ahead of current |
| 1540 | * prefetch_target current target prefetch distance |
| 1541 | * state current state of the TIDBitmap |
| 1542 | * cv conditional wait variable |
| 1543 | * phs_snapshot_data snapshot data shared to workers |
| 1544 | * ---------------- |
| 1545 | */ |
| 1546 | typedef struct ParallelBitmapHeapState |
| 1547 | { |
| 1548 | dsa_pointer tbmiterator; |
| 1549 | dsa_pointer prefetch_iterator; |
| 1550 | slock_t mutex; |
| 1551 | int prefetch_pages; |
| 1552 | int prefetch_target; |
| 1553 | SharedBitmapState state; |
| 1554 | ConditionVariable cv; |
| 1555 | char phs_snapshot_data[FLEXIBLE_ARRAY_MEMBER]; |
| 1556 | } ParallelBitmapHeapState; |
| 1557 | |
| 1558 | /* ---------------- |
| 1559 | * BitmapHeapScanState information |
| 1560 | * |
| 1561 | * bitmapqualorig execution state for bitmapqualorig expressions |
| 1562 | * tbm bitmap obtained from child index scan(s) |
| 1563 | * tbmiterator iterator for scanning current pages |
| 1564 | * tbmres current-page data |
| 1565 | * can_skip_fetch can we potentially skip tuple fetches in this scan? |
| 1566 | * return_empty_tuples number of empty tuples to return |
| 1567 | * vmbuffer buffer for visibility-map lookups |
| 1568 | * pvmbuffer ditto, for prefetched pages |
| 1569 | * exact_pages total number of exact pages retrieved |
| 1570 | * lossy_pages total number of lossy pages retrieved |
| 1571 | * prefetch_iterator iterator for prefetching ahead of current page |
| 1572 | * prefetch_pages # pages prefetch iterator is ahead of current |
| 1573 | * prefetch_target current target prefetch distance |
| 1574 | * prefetch_maximum maximum value for prefetch_target |
| 1575 | * pscan_len size of the shared memory for parallel bitmap |
| 1576 | * initialized is node is ready to iterate |
| 1577 | * shared_tbmiterator shared iterator |
| 1578 | * shared_prefetch_iterator shared iterator for prefetching |
| 1579 | * pstate shared state for parallel bitmap scan |
| 1580 | * ---------------- |
| 1581 | */ |
| 1582 | typedef struct BitmapHeapScanState |
| 1583 | { |
| 1584 | ScanState ss; /* its first field is NodeTag */ |
| 1585 | ExprState *bitmapqualorig; |
| 1586 | TIDBitmap *tbm; |
| 1587 | TBMIterator *tbmiterator; |
| 1588 | TBMIterateResult *tbmres; |
| 1589 | bool can_skip_fetch; |
| 1590 | int return_empty_tuples; |
| 1591 | Buffer vmbuffer; |
| 1592 | Buffer pvmbuffer; |
| 1593 | long exact_pages; |
| 1594 | long lossy_pages; |
| 1595 | TBMIterator *prefetch_iterator; |
| 1596 | int prefetch_pages; |
| 1597 | int prefetch_target; |
| 1598 | int prefetch_maximum; |
| 1599 | Size pscan_len; |
| 1600 | bool initialized; |
| 1601 | TBMSharedIterator *shared_tbmiterator; |
| 1602 | TBMSharedIterator *shared_prefetch_iterator; |
| 1603 | ParallelBitmapHeapState *pstate; |
| 1604 | } BitmapHeapScanState; |
| 1605 | |
| 1606 | /* ---------------- |
| 1607 | * TidScanState information |
| 1608 | * |
| 1609 | * tidexprs list of TidExpr structs (see nodeTidscan.c) |
| 1610 | * isCurrentOf scan has a CurrentOfExpr qual |
| 1611 | * NumTids number of tids in this scan |
| 1612 | * TidPtr index of currently fetched tid |
| 1613 | * TidList evaluated item pointers (array of size NumTids) |
| 1614 | * htup currently-fetched tuple, if any |
| 1615 | * ---------------- |
| 1616 | */ |
| 1617 | typedef struct TidScanState |
| 1618 | { |
| 1619 | ScanState ss; /* its first field is NodeTag */ |
| 1620 | List *tss_tidexprs; |
| 1621 | bool tss_isCurrentOf; |
| 1622 | int tss_NumTids; |
| 1623 | int tss_TidPtr; |
| 1624 | ItemPointerData *tss_TidList; |
| 1625 | HeapTupleData tss_htup; |
| 1626 | } TidScanState; |
| 1627 | |
| 1628 | /* ---------------- |
| 1629 | * SubqueryScanState information |
| 1630 | * |
| 1631 | * SubqueryScanState is used for scanning a sub-query in the range table. |
| 1632 | * ScanTupleSlot references the current output tuple of the sub-query. |
| 1633 | * ---------------- |
| 1634 | */ |
| 1635 | typedef struct SubqueryScanState |
| 1636 | { |
| 1637 | ScanState ss; /* its first field is NodeTag */ |
| 1638 | PlanState *subplan; |
| 1639 | } SubqueryScanState; |
| 1640 | |
| 1641 | /* ---------------- |
| 1642 | * FunctionScanState information |
| 1643 | * |
| 1644 | * Function nodes are used to scan the results of a |
| 1645 | * function appearing in FROM (typically a function returning set). |
| 1646 | * |
| 1647 | * eflags node's capability flags |
| 1648 | * ordinality is this scan WITH ORDINALITY? |
| 1649 | * simple true if we have 1 function and no ordinality |
| 1650 | * ordinal current ordinal column value |
| 1651 | * nfuncs number of functions being executed |
| 1652 | * funcstates per-function execution states (private in |
| 1653 | * nodeFunctionscan.c) |
| 1654 | * argcontext memory context to evaluate function arguments in |
| 1655 | * ---------------- |
| 1656 | */ |
| 1657 | struct FunctionScanPerFuncState; |
| 1658 | |
| 1659 | typedef struct FunctionScanState |
| 1660 | { |
| 1661 | ScanState ss; /* its first field is NodeTag */ |
| 1662 | int eflags; |
| 1663 | bool ordinality; |
| 1664 | bool simple; |
| 1665 | int64 ordinal; |
| 1666 | int nfuncs; |
| 1667 | struct FunctionScanPerFuncState *funcstates; /* array of length nfuncs */ |
| 1668 | MemoryContext argcontext; |
| 1669 | } FunctionScanState; |
| 1670 | |
| 1671 | /* ---------------- |
| 1672 | * ValuesScanState information |
| 1673 | * |
| 1674 | * ValuesScan nodes are used to scan the results of a VALUES list |
| 1675 | * |
| 1676 | * rowcontext per-expression-list context |
| 1677 | * exprlists array of expression lists being evaluated |
| 1678 | * array_len size of array |
| 1679 | * curr_idx current array index (0-based) |
| 1680 | * |
| 1681 | * Note: ss.ps.ps_ExprContext is used to evaluate any qual or projection |
| 1682 | * expressions attached to the node. We create a second ExprContext, |
| 1683 | * rowcontext, in which to build the executor expression state for each |
| 1684 | * Values sublist. Resetting this context lets us get rid of expression |
| 1685 | * state for each row, avoiding major memory leakage over a long values list. |
| 1686 | * ---------------- |
| 1687 | */ |
| 1688 | typedef struct ValuesScanState |
| 1689 | { |
| 1690 | ScanState ss; /* its first field is NodeTag */ |
| 1691 | ExprContext *rowcontext; |
| 1692 | List **exprlists; |
| 1693 | int array_len; |
| 1694 | int curr_idx; |
| 1695 | } ValuesScanState; |
| 1696 | |
| 1697 | /* ---------------- |
| 1698 | * TableFuncScanState node |
| 1699 | * |
| 1700 | * Used in table-expression functions like XMLTABLE. |
| 1701 | * ---------------- |
| 1702 | */ |
| 1703 | typedef struct TableFuncScanState |
| 1704 | { |
| 1705 | ScanState ss; /* its first field is NodeTag */ |
| 1706 | ExprState *docexpr; /* state for document expression */ |
| 1707 | ExprState *rowexpr; /* state for row-generating expression */ |
| 1708 | List *colexprs; /* state for column-generating expression */ |
| 1709 | List *coldefexprs; /* state for column default expressions */ |
| 1710 | List *ns_names; /* same as TableFunc.ns_names */ |
| 1711 | List *ns_uris; /* list of states of namespace URI exprs */ |
| 1712 | Bitmapset *notnulls; /* nullability flag for each output column */ |
| 1713 | void *opaque; /* table builder private space */ |
| 1714 | const struct TableFuncRoutine *routine; /* table builder methods */ |
| 1715 | FmgrInfo *in_functions; /* input function for each column */ |
| 1716 | Oid *typioparams; /* typioparam for each column */ |
| 1717 | int64 ordinal; /* row number to be output next */ |
| 1718 | MemoryContext perTableCxt; /* per-table context */ |
| 1719 | Tuplestorestate *tupstore; /* output tuple store */ |
| 1720 | } TableFuncScanState; |
| 1721 | |
| 1722 | /* ---------------- |
| 1723 | * CteScanState information |
| 1724 | * |
| 1725 | * CteScan nodes are used to scan a CommonTableExpr query. |
| 1726 | * |
| 1727 | * Multiple CteScan nodes can read out from the same CTE query. We use |
| 1728 | * a tuplestore to hold rows that have been read from the CTE query but |
| 1729 | * not yet consumed by all readers. |
| 1730 | * ---------------- |
| 1731 | */ |
| 1732 | typedef struct CteScanState |
| 1733 | { |
| 1734 | ScanState ss; /* its first field is NodeTag */ |
| 1735 | int eflags; /* capability flags to pass to tuplestore */ |
| 1736 | int readptr; /* index of my tuplestore read pointer */ |
| 1737 | PlanState *cteplanstate; /* PlanState for the CTE query itself */ |
| 1738 | /* Link to the "leader" CteScanState (possibly this same node) */ |
| 1739 | struct CteScanState *leader; |
| 1740 | /* The remaining fields are only valid in the "leader" CteScanState */ |
| 1741 | Tuplestorestate *cte_table; /* rows already read from the CTE query */ |
| 1742 | bool eof_cte; /* reached end of CTE query? */ |
| 1743 | } CteScanState; |
| 1744 | |
| 1745 | /* ---------------- |
| 1746 | * NamedTuplestoreScanState information |
| 1747 | * |
| 1748 | * NamedTuplestoreScan nodes are used to scan a Tuplestore created and |
| 1749 | * named prior to execution of the query. An example is a transition |
| 1750 | * table for an AFTER trigger. |
| 1751 | * |
| 1752 | * Multiple NamedTuplestoreScan nodes can read out from the same Tuplestore. |
| 1753 | * ---------------- |
| 1754 | */ |
| 1755 | typedef struct NamedTuplestoreScanState |
| 1756 | { |
| 1757 | ScanState ss; /* its first field is NodeTag */ |
| 1758 | int readptr; /* index of my tuplestore read pointer */ |
| 1759 | TupleDesc tupdesc; /* format of the tuples in the tuplestore */ |
| 1760 | Tuplestorestate *relation; /* the rows */ |
| 1761 | } NamedTuplestoreScanState; |
| 1762 | |
| 1763 | /* ---------------- |
| 1764 | * WorkTableScanState information |
| 1765 | * |
| 1766 | * WorkTableScan nodes are used to scan the work table created by |
| 1767 | * a RecursiveUnion node. We locate the RecursiveUnion node |
| 1768 | * during executor startup. |
| 1769 | * ---------------- |
| 1770 | */ |
| 1771 | typedef struct WorkTableScanState |
| 1772 | { |
| 1773 | ScanState ss; /* its first field is NodeTag */ |
| 1774 | RecursiveUnionState *rustate; |
| 1775 | } WorkTableScanState; |
| 1776 | |
| 1777 | /* ---------------- |
| 1778 | * ForeignScanState information |
| 1779 | * |
| 1780 | * ForeignScan nodes are used to scan foreign-data tables. |
| 1781 | * ---------------- |
| 1782 | */ |
| 1783 | typedef struct ForeignScanState |
| 1784 | { |
| 1785 | ScanState ss; /* its first field is NodeTag */ |
| 1786 | ExprState *fdw_recheck_quals; /* original quals not in ss.ps.qual */ |
| 1787 | Size pscan_len; /* size of parallel coordination information */ |
| 1788 | /* use struct pointer to avoid including fdwapi.h here */ |
| 1789 | struct FdwRoutine *fdwroutine; |
| 1790 | void *fdw_state; /* foreign-data wrapper can keep state here */ |
| 1791 | } ForeignScanState; |
| 1792 | |
| 1793 | /* ---------------- |
| 1794 | * CustomScanState information |
| 1795 | * |
| 1796 | * CustomScan nodes are used to execute custom code within executor. |
| 1797 | * |
| 1798 | * Core code must avoid assuming that the CustomScanState is only as large as |
| 1799 | * the structure declared here; providers are allowed to make it the first |
| 1800 | * element in a larger structure, and typically would need to do so. The |
| 1801 | * struct is actually allocated by the CreateCustomScanState method associated |
| 1802 | * with the plan node. Any additional fields can be initialized there, or in |
| 1803 | * the BeginCustomScan method. |
| 1804 | * ---------------- |
| 1805 | */ |
| 1806 | struct CustomExecMethods; |
| 1807 | |
| 1808 | typedef struct CustomScanState |
| 1809 | { |
| 1810 | ScanState ss; |
| 1811 | uint32 flags; /* mask of CUSTOMPATH_* flags, see |
| 1812 | * nodes/extensible.h */ |
| 1813 | List *custom_ps; /* list of child PlanState nodes, if any */ |
| 1814 | Size pscan_len; /* size of parallel coordination information */ |
| 1815 | const struct CustomExecMethods *methods; |
| 1816 | } CustomScanState; |
| 1817 | |
| 1818 | /* ---------------------------------------------------------------- |
| 1819 | * Join State Information |
| 1820 | * ---------------------------------------------------------------- |
| 1821 | */ |
| 1822 | |
| 1823 | /* ---------------- |
| 1824 | * JoinState information |
| 1825 | * |
| 1826 | * Superclass for state nodes of join plans. |
| 1827 | * ---------------- |
| 1828 | */ |
| 1829 | typedef struct JoinState |
| 1830 | { |
| 1831 | PlanState ps; |
| 1832 | JoinType jointype; |
| 1833 | bool single_match; /* True if we should skip to next outer tuple |
| 1834 | * after finding one inner match */ |
| 1835 | ExprState *joinqual; /* JOIN quals (in addition to ps.qual) */ |
| 1836 | } JoinState; |
| 1837 | |
| 1838 | /* ---------------- |
| 1839 | * NestLoopState information |
| 1840 | * |
| 1841 | * NeedNewOuter true if need new outer tuple on next call |
| 1842 | * MatchedOuter true if found a join match for current outer tuple |
| 1843 | * NullInnerTupleSlot prepared null tuple for left outer joins |
| 1844 | * ---------------- |
| 1845 | */ |
| 1846 | typedef struct NestLoopState |
| 1847 | { |
| 1848 | JoinState js; /* its first field is NodeTag */ |
| 1849 | bool nl_NeedNewOuter; |
| 1850 | bool nl_MatchedOuter; |
| 1851 | TupleTableSlot *nl_NullInnerTupleSlot; |
| 1852 | } NestLoopState; |
| 1853 | |
| 1854 | /* ---------------- |
| 1855 | * MergeJoinState information |
| 1856 | * |
| 1857 | * NumClauses number of mergejoinable join clauses |
| 1858 | * Clauses info for each mergejoinable clause |
| 1859 | * JoinState current state of ExecMergeJoin state machine |
| 1860 | * SkipMarkRestore true if we may skip Mark and Restore operations |
| 1861 | * ExtraMarks true to issue extra Mark operations on inner scan |
| 1862 | * ConstFalseJoin true if we have a constant-false joinqual |
| 1863 | * FillOuter true if should emit unjoined outer tuples anyway |
| 1864 | * FillInner true if should emit unjoined inner tuples anyway |
| 1865 | * MatchedOuter true if found a join match for current outer tuple |
| 1866 | * MatchedInner true if found a join match for current inner tuple |
| 1867 | * OuterTupleSlot slot in tuple table for cur outer tuple |
| 1868 | * InnerTupleSlot slot in tuple table for cur inner tuple |
| 1869 | * MarkedTupleSlot slot in tuple table for marked tuple |
| 1870 | * NullOuterTupleSlot prepared null tuple for right outer joins |
| 1871 | * NullInnerTupleSlot prepared null tuple for left outer joins |
| 1872 | * OuterEContext workspace for computing outer tuple's join values |
| 1873 | * InnerEContext workspace for computing inner tuple's join values |
| 1874 | * ---------------- |
| 1875 | */ |
| 1876 | /* private in nodeMergejoin.c: */ |
| 1877 | typedef struct MergeJoinClauseData *MergeJoinClause; |
| 1878 | |
| 1879 | typedef struct MergeJoinState |
| 1880 | { |
| 1881 | JoinState js; /* its first field is NodeTag */ |
| 1882 | int mj_NumClauses; |
| 1883 | MergeJoinClause mj_Clauses; /* array of length mj_NumClauses */ |
| 1884 | int mj_JoinState; |
| 1885 | bool mj_SkipMarkRestore; |
| 1886 | bool ; |
| 1887 | bool mj_ConstFalseJoin; |
| 1888 | bool mj_FillOuter; |
| 1889 | bool mj_FillInner; |
| 1890 | bool mj_MatchedOuter; |
| 1891 | bool mj_MatchedInner; |
| 1892 | TupleTableSlot *mj_OuterTupleSlot; |
| 1893 | TupleTableSlot *mj_InnerTupleSlot; |
| 1894 | TupleTableSlot *mj_MarkedTupleSlot; |
| 1895 | TupleTableSlot *mj_NullOuterTupleSlot; |
| 1896 | TupleTableSlot *mj_NullInnerTupleSlot; |
| 1897 | ExprContext *mj_OuterEContext; |
| 1898 | ExprContext *mj_InnerEContext; |
| 1899 | } MergeJoinState; |
| 1900 | |
| 1901 | /* ---------------- |
| 1902 | * HashJoinState information |
| 1903 | * |
| 1904 | * hashclauses original form of the hashjoin condition |
| 1905 | * hj_OuterHashKeys the outer hash keys in the hashjoin condition |
| 1906 | * hj_HashOperators the join operators in the hashjoin condition |
| 1907 | * hj_HashTable hash table for the hashjoin |
| 1908 | * (NULL if table not built yet) |
| 1909 | * hj_CurHashValue hash value for current outer tuple |
| 1910 | * hj_CurBucketNo regular bucket# for current outer tuple |
| 1911 | * hj_CurSkewBucketNo skew bucket# for current outer tuple |
| 1912 | * hj_CurTuple last inner tuple matched to current outer |
| 1913 | * tuple, or NULL if starting search |
| 1914 | * (hj_CurXXX variables are undefined if |
| 1915 | * OuterTupleSlot is empty!) |
| 1916 | * hj_OuterTupleSlot tuple slot for outer tuples |
| 1917 | * hj_HashTupleSlot tuple slot for inner (hashed) tuples |
| 1918 | * hj_NullOuterTupleSlot prepared null tuple for right/full outer joins |
| 1919 | * hj_NullInnerTupleSlot prepared null tuple for left/full outer joins |
| 1920 | * hj_FirstOuterTupleSlot first tuple retrieved from outer plan |
| 1921 | * hj_JoinState current state of ExecHashJoin state machine |
| 1922 | * hj_MatchedOuter true if found a join match for current outer |
| 1923 | * hj_OuterNotEmpty true if outer relation known not empty |
| 1924 | * ---------------- |
| 1925 | */ |
| 1926 | |
| 1927 | /* these structs are defined in executor/hashjoin.h: */ |
| 1928 | typedef struct HashJoinTupleData *HashJoinTuple; |
| 1929 | typedef struct HashJoinTableData *HashJoinTable; |
| 1930 | |
| 1931 | typedef struct HashJoinState |
| 1932 | { |
| 1933 | JoinState js; /* its first field is NodeTag */ |
| 1934 | ExprState *hashclauses; |
| 1935 | List *hj_OuterHashKeys; /* list of ExprState nodes */ |
| 1936 | List *hj_HashOperators; /* list of operator OIDs */ |
| 1937 | List *hj_Collations; |
| 1938 | HashJoinTable hj_HashTable; |
| 1939 | uint32 hj_CurHashValue; |
| 1940 | int hj_CurBucketNo; |
| 1941 | int hj_CurSkewBucketNo; |
| 1942 | HashJoinTuple hj_CurTuple; |
| 1943 | TupleTableSlot *hj_OuterTupleSlot; |
| 1944 | TupleTableSlot *hj_HashTupleSlot; |
| 1945 | TupleTableSlot *hj_NullOuterTupleSlot; |
| 1946 | TupleTableSlot *hj_NullInnerTupleSlot; |
| 1947 | TupleTableSlot *hj_FirstOuterTupleSlot; |
| 1948 | int hj_JoinState; |
| 1949 | bool hj_MatchedOuter; |
| 1950 | bool hj_OuterNotEmpty; |
| 1951 | } HashJoinState; |
| 1952 | |
| 1953 | |
| 1954 | /* ---------------------------------------------------------------- |
| 1955 | * Materialization State Information |
| 1956 | * ---------------------------------------------------------------- |
| 1957 | */ |
| 1958 | |
| 1959 | /* ---------------- |
| 1960 | * MaterialState information |
| 1961 | * |
| 1962 | * materialize nodes are used to materialize the results |
| 1963 | * of a subplan into a temporary file. |
| 1964 | * |
| 1965 | * ss.ss_ScanTupleSlot refers to output of underlying plan. |
| 1966 | * ---------------- |
| 1967 | */ |
| 1968 | typedef struct MaterialState |
| 1969 | { |
| 1970 | ScanState ss; /* its first field is NodeTag */ |
| 1971 | int eflags; /* capability flags to pass to tuplestore */ |
| 1972 | bool eof_underlying; /* reached end of underlying plan? */ |
| 1973 | Tuplestorestate *tuplestorestate; |
| 1974 | } MaterialState; |
| 1975 | |
| 1976 | /* ---------------- |
| 1977 | * Shared memory container for per-worker sort information |
| 1978 | * ---------------- |
| 1979 | */ |
| 1980 | typedef struct SharedSortInfo |
| 1981 | { |
| 1982 | int num_workers; |
| 1983 | TuplesortInstrumentation sinstrument[FLEXIBLE_ARRAY_MEMBER]; |
| 1984 | } SharedSortInfo; |
| 1985 | |
| 1986 | /* ---------------- |
| 1987 | * SortState information |
| 1988 | * ---------------- |
| 1989 | */ |
| 1990 | typedef struct SortState |
| 1991 | { |
| 1992 | ScanState ss; /* its first field is NodeTag */ |
| 1993 | bool randomAccess; /* need random access to sort output? */ |
| 1994 | bool bounded; /* is the result set bounded? */ |
| 1995 | int64 bound; /* if bounded, how many tuples are needed */ |
| 1996 | bool sort_Done; /* sort completed yet? */ |
| 1997 | bool bounded_Done; /* value of bounded we did the sort with */ |
| 1998 | int64 bound_Done; /* value of bound we did the sort with */ |
| 1999 | void *tuplesortstate; /* private state of tuplesort.c */ |
| 2000 | bool am_worker; /* are we a worker? */ |
| 2001 | SharedSortInfo *shared_info; /* one entry per worker */ |
| 2002 | } SortState; |
| 2003 | |
| 2004 | /* --------------------- |
| 2005 | * GroupState information |
| 2006 | * --------------------- |
| 2007 | */ |
| 2008 | typedef struct GroupState |
| 2009 | { |
| 2010 | ScanState ss; /* its first field is NodeTag */ |
| 2011 | ExprState *eqfunction; /* equality function */ |
| 2012 | bool grp_done; /* indicates completion of Group scan */ |
| 2013 | } GroupState; |
| 2014 | |
| 2015 | /* --------------------- |
| 2016 | * AggState information |
| 2017 | * |
| 2018 | * ss.ss_ScanTupleSlot refers to output of underlying plan. |
| 2019 | * |
| 2020 | * Note: ss.ps.ps_ExprContext contains ecxt_aggvalues and |
| 2021 | * ecxt_aggnulls arrays, which hold the computed agg values for the current |
| 2022 | * input group during evaluation of an Agg node's output tuple(s). We |
| 2023 | * create a second ExprContext, tmpcontext, in which to evaluate input |
| 2024 | * expressions and run the aggregate transition functions. |
| 2025 | * --------------------- |
| 2026 | */ |
| 2027 | /* these structs are private in nodeAgg.c: */ |
| 2028 | typedef struct AggStatePerAggData *AggStatePerAgg; |
| 2029 | typedef struct AggStatePerTransData *AggStatePerTrans; |
| 2030 | typedef struct AggStatePerGroupData *AggStatePerGroup; |
| 2031 | typedef struct AggStatePerPhaseData *AggStatePerPhase; |
| 2032 | typedef struct AggStatePerHashData *AggStatePerHash; |
| 2033 | |
| 2034 | typedef struct AggState |
| 2035 | { |
| 2036 | ScanState ss; /* its first field is NodeTag */ |
| 2037 | List *aggs; /* all Aggref nodes in targetlist & quals */ |
| 2038 | int numaggs; /* length of list (could be zero!) */ |
| 2039 | int numtrans; /* number of pertrans items */ |
| 2040 | AggStrategy aggstrategy; /* strategy mode */ |
| 2041 | AggSplit aggsplit; /* agg-splitting mode, see nodes.h */ |
| 2042 | AggStatePerPhase phase; /* pointer to current phase data */ |
| 2043 | int numphases; /* number of phases (including phase 0) */ |
| 2044 | int current_phase; /* current phase number */ |
| 2045 | AggStatePerAgg peragg; /* per-Aggref information */ |
| 2046 | AggStatePerTrans pertrans; /* per-Trans state information */ |
| 2047 | ExprContext *hashcontext; /* econtexts for long-lived data (hashtable) */ |
| 2048 | ExprContext **aggcontexts; /* econtexts for long-lived data (per GS) */ |
| 2049 | ExprContext *tmpcontext; /* econtext for input expressions */ |
| 2050 | #define FIELDNO_AGGSTATE_CURAGGCONTEXT 14 |
| 2051 | ExprContext *curaggcontext; /* currently active aggcontext */ |
| 2052 | AggStatePerAgg curperagg; /* currently active aggregate, if any */ |
| 2053 | #define FIELDNO_AGGSTATE_CURPERTRANS 16 |
| 2054 | AggStatePerTrans curpertrans; /* currently active trans state, if any */ |
| 2055 | bool input_done; /* indicates end of input */ |
| 2056 | bool agg_done; /* indicates completion of Agg scan */ |
| 2057 | int projected_set; /* The last projected grouping set */ |
| 2058 | #define FIELDNO_AGGSTATE_CURRENT_SET 20 |
| 2059 | int current_set; /* The current grouping set being evaluated */ |
| 2060 | Bitmapset *grouped_cols; /* grouped cols in current projection */ |
| 2061 | List *all_grouped_cols; /* list of all grouped cols in DESC order */ |
| 2062 | /* These fields are for grouping set phase data */ |
| 2063 | int maxsets; /* The max number of sets in any phase */ |
| 2064 | AggStatePerPhase phases; /* array of all phases */ |
| 2065 | Tuplesortstate *sort_in; /* sorted input to phases > 1 */ |
| 2066 | Tuplesortstate *sort_out; /* input is copied here for next phase */ |
| 2067 | TupleTableSlot *sort_slot; /* slot for sort results */ |
| 2068 | /* these fields are used in AGG_PLAIN and AGG_SORTED modes: */ |
| 2069 | AggStatePerGroup *pergroups; /* grouping set indexed array of per-group |
| 2070 | * pointers */ |
| 2071 | HeapTuple grp_firstTuple; /* copy of first tuple of current group */ |
| 2072 | /* these fields are used in AGG_HASHED and AGG_MIXED modes: */ |
| 2073 | bool table_filled; /* hash table filled yet? */ |
| 2074 | int num_hashes; |
| 2075 | AggStatePerHash perhash; /* array of per-hashtable data */ |
| 2076 | AggStatePerGroup *hash_pergroup; /* grouping set indexed array of |
| 2077 | * per-group pointers */ |
| 2078 | |
| 2079 | /* support for evaluation of agg input expressions: */ |
| 2080 | #define FIELDNO_AGGSTATE_ALL_PERGROUPS 34 |
| 2081 | AggStatePerGroup *all_pergroups; /* array of first ->pergroups, than |
| 2082 | * ->hash_pergroup */ |
| 2083 | ProjectionInfo *combinedproj; /* projection machinery */ |
| 2084 | } AggState; |
| 2085 | |
| 2086 | /* ---------------- |
| 2087 | * WindowAggState information |
| 2088 | * ---------------- |
| 2089 | */ |
| 2090 | /* these structs are private in nodeWindowAgg.c: */ |
| 2091 | typedef struct WindowStatePerFuncData *WindowStatePerFunc; |
| 2092 | typedef struct WindowStatePerAggData *WindowStatePerAgg; |
| 2093 | |
| 2094 | typedef struct WindowAggState |
| 2095 | { |
| 2096 | ScanState ss; /* its first field is NodeTag */ |
| 2097 | |
| 2098 | /* these fields are filled in by ExecInitExpr: */ |
| 2099 | List *funcs; /* all WindowFunc nodes in targetlist */ |
| 2100 | int numfuncs; /* total number of window functions */ |
| 2101 | int numaggs; /* number that are plain aggregates */ |
| 2102 | |
| 2103 | WindowStatePerFunc perfunc; /* per-window-function information */ |
| 2104 | WindowStatePerAgg peragg; /* per-plain-aggregate information */ |
| 2105 | ExprState *partEqfunction; /* equality funcs for partition columns */ |
| 2106 | ExprState *ordEqfunction; /* equality funcs for ordering columns */ |
| 2107 | Tuplestorestate *buffer; /* stores rows of current partition */ |
| 2108 | int current_ptr; /* read pointer # for current row */ |
| 2109 | int framehead_ptr; /* read pointer # for frame head, if used */ |
| 2110 | int frametail_ptr; /* read pointer # for frame tail, if used */ |
| 2111 | int grouptail_ptr; /* read pointer # for group tail, if used */ |
| 2112 | int64 spooled_rows; /* total # of rows in buffer */ |
| 2113 | int64 currentpos; /* position of current row in partition */ |
| 2114 | int64 frameheadpos; /* current frame head position */ |
| 2115 | int64 frametailpos; /* current frame tail position (frame end+1) */ |
| 2116 | /* use struct pointer to avoid including windowapi.h here */ |
| 2117 | struct WindowObjectData *agg_winobj; /* winobj for aggregate fetches */ |
| 2118 | int64 aggregatedbase; /* start row for current aggregates */ |
| 2119 | int64 aggregatedupto; /* rows before this one are aggregated */ |
| 2120 | |
| 2121 | int frameOptions; /* frame_clause options, see WindowDef */ |
| 2122 | ExprState *startOffset; /* expression for starting bound offset */ |
| 2123 | ExprState *endOffset; /* expression for ending bound offset */ |
| 2124 | Datum startOffsetValue; /* result of startOffset evaluation */ |
| 2125 | Datum endOffsetValue; /* result of endOffset evaluation */ |
| 2126 | |
| 2127 | /* these fields are used with RANGE offset PRECEDING/FOLLOWING: */ |
| 2128 | FmgrInfo startInRangeFunc; /* in_range function for startOffset */ |
| 2129 | FmgrInfo endInRangeFunc; /* in_range function for endOffset */ |
| 2130 | Oid inRangeColl; /* collation for in_range tests */ |
| 2131 | bool inRangeAsc; /* use ASC sort order for in_range tests? */ |
| 2132 | bool inRangeNullsFirst; /* nulls sort first for in_range tests? */ |
| 2133 | |
| 2134 | /* these fields are used in GROUPS mode: */ |
| 2135 | int64 currentgroup; /* peer group # of current row in partition */ |
| 2136 | int64 frameheadgroup; /* peer group # of frame head row */ |
| 2137 | int64 frametailgroup; /* peer group # of frame tail row */ |
| 2138 | int64 groupheadpos; /* current row's peer group head position */ |
| 2139 | int64 grouptailpos; /* " " " " tail position (group end+1) */ |
| 2140 | |
| 2141 | MemoryContext partcontext; /* context for partition-lifespan data */ |
| 2142 | MemoryContext aggcontext; /* shared context for aggregate working data */ |
| 2143 | MemoryContext curaggcontext; /* current aggregate's working data */ |
| 2144 | ExprContext *tmpcontext; /* short-term evaluation context */ |
| 2145 | |
| 2146 | bool all_first; /* true if the scan is starting */ |
| 2147 | bool all_done; /* true if the scan is finished */ |
| 2148 | bool partition_spooled; /* true if all tuples in current partition |
| 2149 | * have been spooled into tuplestore */ |
| 2150 | bool more_partitions; /* true if there's more partitions after |
| 2151 | * this one */ |
| 2152 | bool framehead_valid; /* true if frameheadpos is known up to |
| 2153 | * date for current row */ |
| 2154 | bool frametail_valid; /* true if frametailpos is known up to |
| 2155 | * date for current row */ |
| 2156 | bool grouptail_valid; /* true if grouptailpos is known up to |
| 2157 | * date for current row */ |
| 2158 | |
| 2159 | TupleTableSlot *first_part_slot; /* first tuple of current or next |
| 2160 | * partition */ |
| 2161 | TupleTableSlot *framehead_slot; /* first tuple of current frame */ |
| 2162 | TupleTableSlot *frametail_slot; /* first tuple after current frame */ |
| 2163 | |
| 2164 | /* temporary slots for tuples fetched back from tuplestore */ |
| 2165 | TupleTableSlot *agg_row_slot; |
| 2166 | TupleTableSlot *temp_slot_1; |
| 2167 | TupleTableSlot *temp_slot_2; |
| 2168 | } WindowAggState; |
| 2169 | |
| 2170 | /* ---------------- |
| 2171 | * UniqueState information |
| 2172 | * |
| 2173 | * Unique nodes are used "on top of" sort nodes to discard |
| 2174 | * duplicate tuples returned from the sort phase. Basically |
| 2175 | * all it does is compare the current tuple from the subplan |
| 2176 | * with the previously fetched tuple (stored in its result slot). |
| 2177 | * If the two are identical in all interesting fields, then |
| 2178 | * we just fetch another tuple from the sort and try again. |
| 2179 | * ---------------- |
| 2180 | */ |
| 2181 | typedef struct UniqueState |
| 2182 | { |
| 2183 | PlanState ps; /* its first field is NodeTag */ |
| 2184 | ExprState *eqfunction; /* tuple equality qual */ |
| 2185 | } UniqueState; |
| 2186 | |
| 2187 | /* ---------------- |
| 2188 | * GatherState information |
| 2189 | * |
| 2190 | * Gather nodes launch 1 or more parallel workers, run a subplan |
| 2191 | * in those workers, and collect the results. |
| 2192 | * ---------------- |
| 2193 | */ |
| 2194 | typedef struct GatherState |
| 2195 | { |
| 2196 | PlanState ps; /* its first field is NodeTag */ |
| 2197 | bool initialized; /* workers launched? */ |
| 2198 | bool need_to_scan_locally; /* need to read from local plan? */ |
| 2199 | int64 tuples_needed; /* tuple bound, see ExecSetTupleBound */ |
| 2200 | /* these fields are set up once: */ |
| 2201 | TupleTableSlot *funnel_slot; |
| 2202 | struct ParallelExecutorInfo *pei; |
| 2203 | /* all remaining fields are reinitialized during a rescan: */ |
| 2204 | int nworkers_launched; /* original number of workers */ |
| 2205 | int nreaders; /* number of still-active workers */ |
| 2206 | int nextreader; /* next one to try to read from */ |
| 2207 | struct TupleQueueReader **reader; /* array with nreaders active entries */ |
| 2208 | } GatherState; |
| 2209 | |
| 2210 | /* ---------------- |
| 2211 | * GatherMergeState information |
| 2212 | * |
| 2213 | * Gather merge nodes launch 1 or more parallel workers, run a |
| 2214 | * subplan which produces sorted output in each worker, and then |
| 2215 | * merge the results into a single sorted stream. |
| 2216 | * ---------------- |
| 2217 | */ |
| 2218 | struct GMReaderTupleBuffer; /* private in nodeGatherMerge.c */ |
| 2219 | |
| 2220 | typedef struct GatherMergeState |
| 2221 | { |
| 2222 | PlanState ps; /* its first field is NodeTag */ |
| 2223 | bool initialized; /* workers launched? */ |
| 2224 | bool gm_initialized; /* gather_merge_init() done? */ |
| 2225 | bool need_to_scan_locally; /* need to read from local plan? */ |
| 2226 | int64 tuples_needed; /* tuple bound, see ExecSetTupleBound */ |
| 2227 | /* these fields are set up once: */ |
| 2228 | TupleDesc tupDesc; /* descriptor for subplan result tuples */ |
| 2229 | int gm_nkeys; /* number of sort columns */ |
| 2230 | SortSupport gm_sortkeys; /* array of length gm_nkeys */ |
| 2231 | struct ParallelExecutorInfo *pei; |
| 2232 | /* all remaining fields are reinitialized during a rescan */ |
| 2233 | /* (but the arrays are not reallocated, just cleared) */ |
| 2234 | int nworkers_launched; /* original number of workers */ |
| 2235 | int nreaders; /* number of active workers */ |
| 2236 | TupleTableSlot **gm_slots; /* array with nreaders+1 entries */ |
| 2237 | struct TupleQueueReader **reader; /* array with nreaders active entries */ |
| 2238 | struct GMReaderTupleBuffer *gm_tuple_buffers; /* nreaders tuple buffers */ |
| 2239 | struct binaryheap *gm_heap; /* binary heap of slot indices */ |
| 2240 | } GatherMergeState; |
| 2241 | |
| 2242 | /* ---------------- |
| 2243 | * Values displayed by EXPLAIN ANALYZE |
| 2244 | * ---------------- |
| 2245 | */ |
| 2246 | typedef struct HashInstrumentation |
| 2247 | { |
| 2248 | int nbuckets; /* number of buckets at end of execution */ |
| 2249 | int nbuckets_original; /* planned number of buckets */ |
| 2250 | int nbatch; /* number of batches at end of execution */ |
| 2251 | int nbatch_original; /* planned number of batches */ |
| 2252 | size_t space_peak; /* speak memory usage in bytes */ |
| 2253 | } HashInstrumentation; |
| 2254 | |
| 2255 | /* ---------------- |
| 2256 | * Shared memory container for per-worker hash information |
| 2257 | * ---------------- |
| 2258 | */ |
| 2259 | typedef struct SharedHashInfo |
| 2260 | { |
| 2261 | int num_workers; |
| 2262 | HashInstrumentation hinstrument[FLEXIBLE_ARRAY_MEMBER]; |
| 2263 | } SharedHashInfo; |
| 2264 | |
| 2265 | /* ---------------- |
| 2266 | * HashState information |
| 2267 | * ---------------- |
| 2268 | */ |
| 2269 | typedef struct HashState |
| 2270 | { |
| 2271 | PlanState ps; /* its first field is NodeTag */ |
| 2272 | HashJoinTable hashtable; /* hash table for the hashjoin */ |
| 2273 | List *hashkeys; /* list of ExprState nodes */ |
| 2274 | |
| 2275 | SharedHashInfo *shared_info; /* one entry per worker */ |
| 2276 | HashInstrumentation *hinstrument; /* this worker's entry */ |
| 2277 | |
| 2278 | /* Parallel hash state. */ |
| 2279 | struct ParallelHashJoinState *parallel_state; |
| 2280 | } HashState; |
| 2281 | |
| 2282 | /* ---------------- |
| 2283 | * SetOpState information |
| 2284 | * |
| 2285 | * Even in "sorted" mode, SetOp nodes are more complex than a simple |
| 2286 | * Unique, since we have to count how many duplicates to return. But |
| 2287 | * we also support hashing, so this is really more like a cut-down |
| 2288 | * form of Agg. |
| 2289 | * ---------------- |
| 2290 | */ |
| 2291 | /* this struct is private in nodeSetOp.c: */ |
| 2292 | typedef struct SetOpStatePerGroupData *SetOpStatePerGroup; |
| 2293 | |
| 2294 | typedef struct SetOpState |
| 2295 | { |
| 2296 | PlanState ps; /* its first field is NodeTag */ |
| 2297 | ExprState *eqfunction; /* equality comparator */ |
| 2298 | Oid *eqfuncoids; /* per-grouping-field equality fns */ |
| 2299 | FmgrInfo *hashfunctions; /* per-grouping-field hash fns */ |
| 2300 | bool setop_done; /* indicates completion of output scan */ |
| 2301 | long numOutput; /* number of dups left to output */ |
| 2302 | /* these fields are used in SETOP_SORTED mode: */ |
| 2303 | SetOpStatePerGroup pergroup; /* per-group working state */ |
| 2304 | HeapTuple grp_firstTuple; /* copy of first tuple of current group */ |
| 2305 | /* these fields are used in SETOP_HASHED mode: */ |
| 2306 | TupleHashTable hashtable; /* hash table with one entry per group */ |
| 2307 | MemoryContext tableContext; /* memory context containing hash table */ |
| 2308 | bool table_filled; /* hash table filled yet? */ |
| 2309 | TupleHashIterator hashiter; /* for iterating through hash table */ |
| 2310 | } SetOpState; |
| 2311 | |
| 2312 | /* ---------------- |
| 2313 | * LockRowsState information |
| 2314 | * |
| 2315 | * LockRows nodes are used to enforce FOR [KEY] UPDATE/SHARE locking. |
| 2316 | * ---------------- |
| 2317 | */ |
| 2318 | typedef struct LockRowsState |
| 2319 | { |
| 2320 | PlanState ps; /* its first field is NodeTag */ |
| 2321 | List *lr_arowMarks; /* List of ExecAuxRowMarks */ |
| 2322 | EPQState lr_epqstate; /* for evaluating EvalPlanQual rechecks */ |
| 2323 | } LockRowsState; |
| 2324 | |
| 2325 | /* ---------------- |
| 2326 | * LimitState information |
| 2327 | * |
| 2328 | * Limit nodes are used to enforce LIMIT/OFFSET clauses. |
| 2329 | * They just select the desired subrange of their subplan's output. |
| 2330 | * |
| 2331 | * offset is the number of initial tuples to skip (0 does nothing). |
| 2332 | * count is the number of tuples to return after skipping the offset tuples. |
| 2333 | * If no limit count was specified, count is undefined and noCount is true. |
| 2334 | * When lstate == LIMIT_INITIAL, offset/count/noCount haven't been set yet. |
| 2335 | * ---------------- |
| 2336 | */ |
| 2337 | typedef enum |
| 2338 | { |
| 2339 | LIMIT_INITIAL, /* initial state for LIMIT node */ |
| 2340 | LIMIT_RESCAN, /* rescan after recomputing parameters */ |
| 2341 | LIMIT_EMPTY, /* there are no returnable rows */ |
| 2342 | LIMIT_INWINDOW, /* have returned a row in the window */ |
| 2343 | LIMIT_SUBPLANEOF, /* at EOF of subplan (within window) */ |
| 2344 | LIMIT_WINDOWEND, /* stepped off end of window */ |
| 2345 | LIMIT_WINDOWSTART /* stepped off beginning of window */ |
| 2346 | } LimitStateCond; |
| 2347 | |
| 2348 | typedef struct LimitState |
| 2349 | { |
| 2350 | PlanState ps; /* its first field is NodeTag */ |
| 2351 | ExprState *limitOffset; /* OFFSET parameter, or NULL if none */ |
| 2352 | ExprState *limitCount; /* COUNT parameter, or NULL if none */ |
| 2353 | int64 offset; /* current OFFSET value */ |
| 2354 | int64 count; /* current COUNT, if any */ |
| 2355 | bool noCount; /* if true, ignore count */ |
| 2356 | LimitStateCond lstate; /* state machine status, as above */ |
| 2357 | int64 position; /* 1-based index of last tuple returned */ |
| 2358 | TupleTableSlot *subSlot; /* tuple last obtained from subplan */ |
| 2359 | } LimitState; |
| 2360 | |
| 2361 | #endif /* EXECNODES_H */ |
| 2362 | |