| 1 |
/*------------------------------------------------------------------------- |
| 2 |
* |
| 3 |
* execnodes.h |
| 4 |
* definitions for executor state nodes |
| 5 |
* |
| 6 |
* Most plan node types declared in plannodes.h have a corresponding |
| 7 |
* execution-state node type declared here. An exception is that |
| 8 |
* expression nodes (subtypes of Expr) are usually represented by steps |
| 9 |
* of an ExprState, and fully handled within execExpr* - but sometimes |
| 10 |
* their state needs to be shared with other parts of the executor, as |
| 11 |
* for example with SubPlanState, which nodeSubplan.c has to modify. |
| 12 |
* |
| 13 |
* Node types declared in this file do not have any copy/equal/out/read |
| 14 |
* support. (That is currently hard-wired in gen_node_support.pl, rather |
| 15 |
* than being explicitly represented by pg_node_attr decorations here.) |
| 16 |
* There is no need for copy, equal, or read support for executor trees. |
| 17 |
* Output support could be useful for debugging; but there are a lot of |
| 18 |
* specialized fields that would require custom code, so for now it's |
| 19 |
* not provided. |
| 20 |
* |
| 21 |
* |
| 22 |
* Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group |
| 23 |
* Portions Copyright (c) 1994, Regents of the University of California |
| 24 |
* |
| 25 |
* src/include/nodes/execnodes.h |
| 26 |
* |
| 27 |
*------------------------------------------------------------------------- |
| 28 |
*/ |
| 29 |
#ifndef EXECNODES_H |
| 30 |
#define EXECNODES_H |
| 31 |
|
| 32 |
#include "access/tupconvert.h" |
| 33 |
#include "executor/instrument.h" |
| 34 |
#include "fmgr.h" |
| 35 |
#include "lib/ilist.h" |
| 36 |
#include "lib/pairingheap.h" |
| 37 |
#include "nodes/miscnodes.h" |
| 38 |
#include "nodes/params.h" |
| 39 |
#include "nodes/plannodes.h" |
| 40 |
#include "nodes/tidbitmap.h" |
| 41 |
#include "partitioning/partdefs.h" |
| 42 |
#include "storage/condition_variable.h" |
| 43 |
#include "utils/hsearch.h" |
| 44 |
#include "utils/queryenvironment.h" |
| 45 |
#include "utils/reltrigger.h" |
| 46 |
#include "utils/sharedtuplestore.h" |
| 47 |
#include "utils/snapshot.h" |
| 48 |
#include "utils/sortsupport.h" |
| 49 |
#include "utils/tuplesort.h" |
| 50 |
#include "utils/tuplestore.h" |
| 51 |
|
| 52 |
struct PlanState; /* forward references in this file */ |
| 53 |
struct ParallelHashJoinState; |
| 54 |
struct ExecRowMark; |
| 55 |
struct ExprState; |
| 56 |
struct ExprContext; |
| 57 |
struct RangeTblEntry; /* avoid including parsenodes.h here */ |
| 58 |
struct ExprEvalStep; /* avoid including execExpr.h everywhere */ |
| 59 |
struct CopyMultiInsertBuffer; |
| 60 |
struct LogicalTapeSet; |
| 61 |
|
| 62 |
|
| 63 |
/* ---------------- |
| 64 |
* ExprState node |
| 65 |
* |
| 66 |
* ExprState represents the evaluation state for a whole expression tree. |
| 67 |
* It contains instructions (in ->steps) to evaluate the expression. |
| 68 |
* ---------------- |
| 69 |
*/ |
| 70 |
typedef Datum (*ExprStateEvalFunc) (struct ExprState *expression, |
| 71 |
struct ExprContext *econtext, |
| 72 |
bool *isNull); |
| 73 |
|
| 74 |
/* Bits in ExprState->flags (see also execExpr.h for private flag bits): */ |
| 75 |
/* expression is for use with ExecQual() */ |
| 76 |
#define EEO_FLAG_IS_QUAL (1 << 0) |
| 77 |
/* expression refers to OLD table columns */ |
| 78 |
#define EEO_FLAG_HAS_OLD (1 << 1) |
| 79 |
/* expression refers to NEW table columns */ |
| 80 |
#define EEO_FLAG_HAS_NEW (1 << 2) |
| 81 |
/* OLD table row is NULL in RETURNING list */ |
| 82 |
#define EEO_FLAG_OLD_IS_NULL (1 << 3) |
| 83 |
/* NEW table row is NULL in RETURNING list */ |
| 84 |
#define EEO_FLAG_NEW_IS_NULL (1 << 4) |
| 85 |
|
| 86 |
typedef struct ExprState |
| 87 |
{ |
| 88 |
NodeTag type; |
| 89 |
|
| 90 |
#define FIELDNO_EXPRSTATE_FLAGS 1 |
| 91 |
uint8 flags; /* bitmask of EEO_FLAG_* bits, see above */ |
| 92 |
|
| 93 |
/* |
| 94 |
* Storage for result value of a scalar expression, or for individual |
| 95 |
* column results within expressions built by ExecBuildProjectionInfo(). |
| 96 |
*/ |
| 97 |
#define FIELDNO_EXPRSTATE_RESNULL 2 |
| 98 |
bool resnull; |
| 99 |
#define FIELDNO_EXPRSTATE_RESVALUE 3 |
| 100 |
Datum resvalue; |
| 101 |
|
| 102 |
/* |
| 103 |
* If projecting a tuple result, this slot holds the result; else NULL. |
| 104 |
*/ |
| 105 |
#define FIELDNO_EXPRSTATE_RESULTSLOT 4 |
| 106 |
TupleTableSlot *resultslot; |
| 107 |
|
| 108 |
/* |
| 109 |
* Instructions to compute expression's return value. |
| 110 |
*/ |
| 111 |
struct ExprEvalStep *steps; |
| 112 |
|
| 113 |
/* |
| 114 |
* Function that actually evaluates the expression. This can be set to |
| 115 |
* different values depending on the complexity of the expression. |
| 116 |
*/ |
| 117 |
ExprStateEvalFunc evalfunc; |
| 118 |
|
| 119 |
/* original expression tree, for debugging only */ |
| 120 |
Expr *expr; |
| 121 |
|
| 122 |
/* private state for an evalfunc */ |
| 123 |
void *evalfunc_private; |
| 124 |
|
| 125 |
/* |
| 126 |
* XXX: following fields only needed during "compilation" (ExecInitExpr); |
| 127 |
* could be thrown away afterwards. |
| 128 |
*/ |
| 129 |
|
| 130 |
int steps_len; /* number of steps currently */ |
| 131 |
int steps_alloc; /* allocated length of steps array */ |
| 132 |
|
| 133 |
#define FIELDNO_EXPRSTATE_PARENT 11 |
| 134 |
struct PlanState *parent; /* parent PlanState node, if any */ |
| 135 |
ParamListInfo ext_params; /* for compiling PARAM_EXTERN nodes */ |
| 136 |
|
| 137 |
Datum *innermost_caseval; |
| 138 |
bool *innermost_casenull; |
| 139 |
|
| 140 |
Datum *innermost_domainval; |
| 141 |
bool *innermost_domainnull; |
| 142 |
|
| 143 |
/* |
| 144 |
* For expression nodes that support soft errors. Should be set to NULL if |
| 145 |
* the caller wants errors to be thrown. Callers that do not want errors |
| 146 |
* thrown should set it to a valid ErrorSaveContext before calling |
| 147 |
* ExecInitExprRec(). |
| 148 |
*/ |
| 149 |
ErrorSaveContext *escontext; |
| 150 |
} ExprState; |
| 151 |
|
| 152 |
|
| 153 |
/* ---------------- |
| 154 |
* IndexInfo information |
| 155 |
* |
| 156 |
* this struct holds the information needed to construct new index |
| 157 |
* entries for a particular index. Used for both index_build and |
| 158 |
* retail creation of index entries. |
| 159 |
* |
| 160 |
* NumIndexAttrs total number of columns in this index |
| 161 |
* NumIndexKeyAttrs number of key columns in index |
| 162 |
* IndexAttrNumbers underlying-rel attribute numbers used as keys |
| 163 |
* (zeroes indicate expressions). It also contains |
| 164 |
* info about included columns. |
| 165 |
* Expressions expr trees for expression entries, or NIL if none |
| 166 |
* ExpressionsState exec state for expressions, or NIL if none |
| 167 |
* Predicate partial-index predicate, or NIL if none |
| 168 |
* PredicateState exec state for predicate, or NIL if none |
| 169 |
* ExclusionOps Per-column exclusion operators, or NULL if none |
| 170 |
* ExclusionProcs Underlying function OIDs for ExclusionOps |
| 171 |
* ExclusionStrats Opclass strategy numbers for ExclusionOps |
| 172 |
* UniqueOps These are like Exclusion*, but for unique indexes |
| 173 |
* UniqueProcs |
| 174 |
* UniqueStrats |
| 175 |
* Unique is it a unique index? |
| 176 |
* NullsNotDistinct is NULLS NOT DISTINCT? |
| 177 |
* ReadyForInserts is it valid for inserts? |
| 178 |
* CheckedUnchanged IndexUnchanged status determined yet? |
| 179 |
* IndexUnchanged aminsert hint, cached for retail inserts |
| 180 |
* Concurrent are we doing a concurrent index build? |
| 181 |
* BrokenHotChain did we detect any broken HOT chains? |
| 182 |
* WithoutOverlaps is it a WITHOUT OVERLAPS index? |
| 183 |
* Summarizing is it a summarizing index? |
| 184 |
* ParallelWorkers # of workers requested (excludes leader) |
| 185 |
* Am Oid of index AM |
| 186 |
* AmCache private cache area for index AM |
| 187 |
* Context memory context holding this IndexInfo |
| 188 |
* |
| 189 |
* ii_Concurrent, ii_BrokenHotChain, and ii_ParallelWorkers are used only |
| 190 |
* during index build; they're conventionally zeroed otherwise. |
| 191 |
* ---------------- |
| 192 |
*/ |
| 193 |
typedef struct IndexInfo |
| 194 |
{ |
| 195 |
NodeTag type; |
| 196 |
int ii_NumIndexAttrs; /* total number of columns in index */ |
| 197 |
int ii_NumIndexKeyAttrs; /* number of key columns in index */ |
| 198 |
AttrNumber ii_IndexAttrNumbers[INDEX_MAX_KEYS]; |
| 199 |
List *ii_Expressions; /* list of Expr */ |
| 200 |
List *ii_ExpressionsState; /* list of ExprState */ |
| 201 |
List *ii_Predicate; /* list of Expr */ |
| 202 |
ExprState *ii_PredicateState; |
| 203 |
Oid *ii_ExclusionOps; /* array with one entry per column */ |
| 204 |
Oid *ii_ExclusionProcs; /* array with one entry per column */ |
| 205 |
uint16 *ii_ExclusionStrats; /* array with one entry per column */ |
| 206 |
Oid *ii_UniqueOps; /* array with one entry per column */ |
| 207 |
Oid *ii_UniqueProcs; /* array with one entry per column */ |
| 208 |
uint16 *ii_UniqueStrats; /* array with one entry per column */ |
| 209 |
bool ii_Unique; |
| 210 |
bool ii_NullsNotDistinct; |
| 211 |
bool ii_ReadyForInserts; |
| 212 |
bool ii_CheckedUnchanged; |
| 213 |
bool ii_IndexUnchanged; |
| 214 |
bool ii_Concurrent; |
| 215 |
bool ii_BrokenHotChain; |
| 216 |
bool ii_Summarizing; |
| 217 |
bool ii_WithoutOverlaps; |
| 218 |
int ii_ParallelWorkers; |
| 219 |
Oid ii_Am; |
| 220 |
void *ii_AmCache; |
| 221 |
MemoryContext ii_Context; |
| 222 |
} IndexInfo; |
| 223 |
|
| 224 |
/* ---------------- |
| 225 |
* ExprContext_CB |
| 226 |
* |
| 227 |
* List of callbacks to be called at ExprContext shutdown. |
| 228 |
* ---------------- |
| 229 |
*/ |
| 230 |
typedef void (*ExprContextCallbackFunction) (Datum arg); |
| 231 |
|
| 232 |
typedef struct ExprContext_CB |
| 233 |
{ |
| 234 |
struct ExprContext_CB *next; |
| 235 |
ExprContextCallbackFunction function; |
| 236 |
Datum arg; |
| 237 |
} ExprContext_CB; |
| 238 |
|
| 239 |
/* ---------------- |
| 240 |
* ExprContext |
| 241 |
* |
| 242 |
* This class holds the "current context" information |
| 243 |
* needed to evaluate expressions for doing tuple qualifications |
| 244 |
* and tuple projections. For example, if an expression refers |
| 245 |
* to an attribute in the current inner tuple then we need to know |
| 246 |
* what the current inner tuple is and so we look at the expression |
| 247 |
* context. |
| 248 |
* |
| 249 |
* There are two memory contexts associated with an ExprContext: |
| 250 |
* * ecxt_per_query_memory is a query-lifespan context, typically the same |
| 251 |
* context the ExprContext node itself is allocated in. This context |
| 252 |
* can be used for purposes such as storing function call cache info. |
| 253 |
* * ecxt_per_tuple_memory is a short-term context for expression results. |
| 254 |
* As the name suggests, it will typically be reset once per tuple, |
| 255 |
* before we begin to evaluate expressions for that tuple. Each |
| 256 |
* ExprContext normally has its very own per-tuple memory context. |
| 257 |
* |
| 258 |
* CurrentMemoryContext should be set to ecxt_per_tuple_memory before |
| 259 |
* calling ExecEvalExpr() --- see ExecEvalExprSwitchContext(). |
| 260 |
* ---------------- |
| 261 |
*/ |
| 262 |
typedef struct ExprContext |
| 263 |
{ |
| 264 |
NodeTag type; |
| 265 |
|
| 266 |
/* Tuples that Var nodes in expression may refer to */ |
| 267 |
#define FIELDNO_EXPRCONTEXT_SCANTUPLE 1 |
| 268 |
TupleTableSlot *ecxt_scantuple; |
| 269 |
#define FIELDNO_EXPRCONTEXT_INNERTUPLE 2 |
| 270 |
TupleTableSlot *ecxt_innertuple; |
| 271 |
#define FIELDNO_EXPRCONTEXT_OUTERTUPLE 3 |
| 272 |
TupleTableSlot *ecxt_outertuple; |
| 273 |
|
| 274 |
/* Memory contexts for expression evaluation --- see notes above */ |
| 275 |
MemoryContext ecxt_per_query_memory; |
| 276 |
MemoryContext ecxt_per_tuple_memory; |
| 277 |
|
| 278 |
/* Values to substitute for Param nodes in expression */ |
| 279 |
ParamExecData *ecxt_param_exec_vals; /* for PARAM_EXEC params */ |
| 280 |
ParamListInfo ecxt_param_list_info; /* for other param types */ |
| 281 |
|
| 282 |
/* |
| 283 |
* Values to substitute for Aggref nodes in the expressions of an Agg |
| 284 |
* node, or for WindowFunc nodes within a WindowAgg node. |
| 285 |
*/ |
| 286 |
#define FIELDNO_EXPRCONTEXT_AGGVALUES 8 |
| 287 |
Datum *ecxt_aggvalues; /* precomputed values for aggs/windowfuncs */ |
| 288 |
#define FIELDNO_EXPRCONTEXT_AGGNULLS 9 |
| 289 |
bool *ecxt_aggnulls; /* null flags for aggs/windowfuncs */ |
| 290 |
|
| 291 |
/* Value to substitute for CaseTestExpr nodes in expression */ |
| 292 |
#define FIELDNO_EXPRCONTEXT_CASEDATUM 10 |
| 293 |
Datum caseValue_datum; |
| 294 |
#define FIELDNO_EXPRCONTEXT_CASENULL 11 |
| 295 |
bool caseValue_isNull; |
| 296 |
|
| 297 |
/* Value to substitute for CoerceToDomainValue nodes in expression */ |
| 298 |
#define FIELDNO_EXPRCONTEXT_DOMAINDATUM 12 |
| 299 |
Datum domainValue_datum; |
| 300 |
#define FIELDNO_EXPRCONTEXT_DOMAINNULL 13 |
| 301 |
bool domainValue_isNull; |
| 302 |
|
| 303 |
/* Tuples that OLD/NEW Var nodes in RETURNING may refer to */ |
| 304 |
#define FIELDNO_EXPRCONTEXT_OLDTUPLE 14 |
| 305 |
TupleTableSlot *ecxt_oldtuple; |
| 306 |
#define FIELDNO_EXPRCONTEXT_NEWTUPLE 15 |
| 307 |
TupleTableSlot *ecxt_newtuple; |
| 308 |
|
| 309 |
/* Link to containing EState (NULL if a standalone ExprContext) */ |
| 310 |
struct EState *ecxt_estate; |
| 311 |
|
| 312 |
/* Functions to call back when ExprContext is shut down or rescanned */ |
| 313 |
ExprContext_CB *ecxt_callbacks; |
| 314 |
} ExprContext; |
| 315 |
|
| 316 |
/* |
| 317 |
* Set-result status used when evaluating functions potentially returning a |
| 318 |
* set. |
| 319 |
*/ |
| 320 |
typedef enum |
| 321 |
{ |
| 322 |
ExprSingleResult, /* expression does not return a set */ |
| 323 |
ExprMultipleResult, /* this result is an element of a set */ |
| 324 |
ExprEndResult, /* there are no more elements in the set */ |
| 325 |
} ExprDoneCond; |
| 326 |
|
| 327 |
/* |
| 328 |
* Return modes for functions returning sets. Note values must be chosen |
| 329 |
* as separate bits so that a bitmask can be formed to indicate supported |
| 330 |
* modes. SFRM_Materialize_Random and SFRM_Materialize_Preferred are |
| 331 |
* auxiliary flags about SFRM_Materialize mode, rather than separate modes. |
| 332 |
*/ |
| 333 |
typedef enum |
| 334 |
{ |
| 335 |
SFRM_ValuePerCall = 0x01, /* one value returned per call */ |
| 336 |
SFRM_Materialize = 0x02, /* result set instantiated in Tuplestore */ |
| 337 |
SFRM_Materialize_Random = 0x04, /* Tuplestore needs randomAccess */ |
| 338 |
SFRM_Materialize_Preferred = 0x08, /* caller prefers Tuplestore */ |
| 339 |
} SetFunctionReturnMode; |
| 340 |
|
| 341 |
/* |
| 342 |
* When calling a function that might return a set (multiple rows), |
| 343 |
* a node of this type is passed as fcinfo->resultinfo to allow |
| 344 |
* return status to be passed back. A function returning set should |
| 345 |
* raise an error if no such resultinfo is provided. |
| 346 |
*/ |
| 347 |
typedef struct ReturnSetInfo |
| 348 |
{ |
| 349 |
NodeTag type; |
| 350 |
/* values set by caller: */ |
| 351 |
ExprContext *econtext; /* context function is being called in */ |
| 352 |
TupleDesc expectedDesc; /* tuple descriptor expected by caller */ |
| 353 |
int allowedModes; /* bitmask: return modes caller can handle */ |
| 354 |
/* result status from function (but pre-initialized by caller): */ |
| 355 |
SetFunctionReturnMode returnMode; /* actual return mode */ |
| 356 |
ExprDoneCond isDone; /* status for ValuePerCall mode */ |
| 357 |
/* fields filled by function in Materialize return mode: */ |
| 358 |
Tuplestorestate *setResult; /* holds the complete returned tuple set */ |
| 359 |
TupleDesc setDesc; /* actual descriptor for returned tuples */ |
| 360 |
} ReturnSetInfo; |
| 361 |
|
| 362 |
/* ---------------- |
| 363 |
* ProjectionInfo node information |
| 364 |
* |
| 365 |
* This is all the information needed to perform projections --- |
| 366 |
* that is, form new tuples by evaluation of targetlist expressions. |
| 367 |
* Nodes which need to do projections create one of these. |
| 368 |
* |
| 369 |
* The target tuple slot is kept in ProjectionInfo->pi_state.resultslot. |
| 370 |
* ExecProject() evaluates the tlist, forms a tuple, and stores it |
| 371 |
* in the given slot. Note that the result will be a "virtual" tuple |
| 372 |
* unless ExecMaterializeSlot() is then called to force it to be |
| 373 |
* converted to a physical tuple. The slot must have a tupledesc |
| 374 |
* that matches the output of the tlist! |
| 375 |
* ---------------- |
| 376 |
*/ |
| 377 |
typedef struct ProjectionInfo |
| 378 |
{ |
| 379 |
NodeTag type; |
| 380 |
/* instructions to evaluate projection */ |
| 381 |
ExprState pi_state; |
| 382 |
/* expression context in which to evaluate expression */ |
| 383 |
ExprContext *pi_exprContext; |
| 384 |
} ProjectionInfo; |
| 385 |
|
| 386 |
/* ---------------- |
| 387 |
* JunkFilter |
| 388 |
* |
| 389 |
* This class is used to store information regarding junk attributes. |
| 390 |
* A junk attribute is an attribute in a tuple that is needed only for |
| 391 |
* storing intermediate information in the executor, and does not belong |
| 392 |
* in emitted tuples. For example, when we do an UPDATE query, |
| 393 |
* the planner adds a "junk" entry to the targetlist so that the tuples |
| 394 |
* returned to ExecutePlan() contain an extra attribute: the ctid of |
| 395 |
* the tuple to be updated. This is needed to do the update, but we |
| 396 |
* don't want the ctid to be part of the stored new tuple! So, we |
| 397 |
* apply a "junk filter" to remove the junk attributes and form the |
| 398 |
* real output tuple. The junkfilter code also provides routines to |
| 399 |
* extract the values of the junk attribute(s) from the input tuple. |
| 400 |
* |
| 401 |
* targetList: the original target list (including junk attributes). |
| 402 |
* cleanTupType: the tuple descriptor for the "clean" tuple (with |
| 403 |
* junk attributes removed). |
| 404 |
* cleanMap: A map with the correspondence between the non-junk |
| 405 |
* attribute numbers of the "original" tuple and the |
| 406 |
* attribute numbers of the "clean" tuple. |
| 407 |
* resultSlot: tuple slot used to hold cleaned tuple. |
| 408 |
* ---------------- |
| 409 |
*/ |
| 410 |
typedef struct JunkFilter |
| 411 |
{ |
| 412 |
NodeTag type; |
| 413 |
List *jf_targetList; |
| 414 |
TupleDesc jf_cleanTupType; |
| 415 |
AttrNumber *jf_cleanMap; |
| 416 |
TupleTableSlot *jf_resultSlot; |
| 417 |
} JunkFilter; |
| 418 |
|
| 419 |
/* |
| 420 |
* OnConflictSetState |
| 421 |
* |
| 422 |
* Executor state of an ON CONFLICT DO UPDATE operation. |
| 423 |
*/ |
| 424 |
typedef struct OnConflictSetState |
| 425 |
{ |
| 426 |
NodeTag type; |
| 427 |
|
| 428 |
TupleTableSlot *oc_Existing; /* slot to store existing target tuple in */ |
| 429 |
TupleTableSlot *oc_ProjSlot; /* CONFLICT ... SET ... projection target */ |
| 430 |
ProjectionInfo *oc_ProjInfo; /* for ON CONFLICT DO UPDATE SET */ |
| 431 |
ExprState *oc_WhereClause; /* state for the WHERE clause */ |
| 432 |
} OnConflictSetState; |
| 433 |
|
| 434 |
/* ---------------- |
| 435 |
* MergeActionState information |
| 436 |
* |
| 437 |
* Executor state for a MERGE action. |
| 438 |
* ---------------- |
| 439 |
*/ |
| 440 |
typedef struct MergeActionState |
| 441 |
{ |
| 442 |
NodeTag type; |
| 443 |
|
| 444 |
MergeAction *mas_action; /* associated MergeAction node */ |
| 445 |
ProjectionInfo *mas_proj; /* projection of the action's targetlist for |
| 446 |
* this rel */ |
| 447 |
ExprState *mas_whenqual; /* WHEN [NOT] MATCHED AND conditions */ |
| 448 |
} MergeActionState; |
| 449 |
|
| 450 |
/* |
| 451 |
* ResultRelInfo |
| 452 |
* |
| 453 |
* Whenever we update an existing relation, we have to update indexes on the |
| 454 |
* relation, and perhaps also fire triggers. ResultRelInfo holds all the |
| 455 |
* information needed about a result relation, including indexes. |
| 456 |
* |
| 457 |
* Normally, a ResultRelInfo refers to a table that is in the query's range |
| 458 |
* table; then ri_RangeTableIndex is the RT index and ri_RelationDesc is |
| 459 |
* just a copy of the relevant es_relations[] entry. However, in some |
| 460 |
* situations we create ResultRelInfos for relations that are not in the |
| 461 |
* range table, namely for targets of tuple routing in a partitioned table, |
| 462 |
* and when firing triggers in tables other than the target tables (See |
| 463 |
* ExecGetTriggerResultRel). In these situations, ri_RangeTableIndex is 0 |
| 464 |
* and ri_RelationDesc is a separately-opened relcache pointer that needs to |
| 465 |
* be separately closed. |
| 466 |
*/ |
| 467 |
typedef struct ResultRelInfo |
| 468 |
{ |
| 469 |
NodeTag type; |
| 470 |
|
| 471 |
/* result relation's range table index, or 0 if not in range table */ |
| 472 |
Index ri_RangeTableIndex; |
| 473 |
|
| 474 |
/* relation descriptor for result relation */ |
| 475 |
Relation ri_RelationDesc; |
| 476 |
|
| 477 |
/* # of indices existing on result relation */ |
| 478 |
int ri_NumIndices; |
| 479 |
|
| 480 |
/* array of relation descriptors for indices */ |
| 481 |
RelationPtr ri_IndexRelationDescs; |
| 482 |
|
| 483 |
/* array of key/attr info for indices */ |
| 484 |
IndexInfo **ri_IndexRelationInfo; |
| 485 |
|
| 486 |
/* |
| 487 |
* For UPDATE/DELETE/MERGE result relations, the attribute number of the |
| 488 |
* row identity junk attribute in the source plan's output tuples |
| 489 |
*/ |
| 490 |
AttrNumber ri_RowIdAttNo; |
| 491 |
|
| 492 |
/* For UPDATE, attnums of generated columns to be computed */ |
| 493 |
Bitmapset *ri_extraUpdatedCols; |
| 494 |
/* true if the above has been computed */ |
| 495 |
bool ri_extraUpdatedCols_valid; |
| 496 |
|
| 497 |
/* Projection to generate new tuple in an INSERT/UPDATE */ |
| 498 |
ProjectionInfo *ri_projectNew; |
| 499 |
/* Slot to hold that tuple */ |
| 500 |
TupleTableSlot *ri_newTupleSlot; |
| 501 |
/* Slot to hold the old tuple being updated */ |
| 502 |
TupleTableSlot *ri_oldTupleSlot; |
| 503 |
/* Have the projection and the slots above been initialized? */ |
| 504 |
bool ri_projectNewInfoValid; |
| 505 |
|
| 506 |
/* updates do LockTuple() before oldtup read; see README.tuplock */ |
| 507 |
bool ri_needLockTagTuple; |
| 508 |
|
| 509 |
/* triggers to be fired, if any */ |
| 510 |
TriggerDesc *ri_TrigDesc; |
| 511 |
|
| 512 |
/* cached lookup info for trigger functions */ |
| 513 |
FmgrInfo *ri_TrigFunctions; |
| 514 |
|
| 515 |
/* array of trigger WHEN expr states */ |
| 516 |
ExprState **ri_TrigWhenExprs; |
| 517 |
|
| 518 |
/* optional runtime measurements for triggers */ |
| 519 |
Instrumentation *ri_TrigInstrument; |
| 520 |
|
| 521 |
/* On-demand created slots for triggers / returning processing */ |
| 522 |
TupleTableSlot *ri_ReturningSlot; /* for trigger output tuples */ |
| 523 |
TupleTableSlot *ri_TrigOldSlot; /* for a trigger's old tuple */ |
| 524 |
TupleTableSlot *ri_TrigNewSlot; /* for a trigger's new tuple */ |
| 525 |
TupleTableSlot *ri_AllNullSlot; /* for RETURNING OLD/NEW */ |
| 526 |
|
| 527 |
/* FDW callback functions, if foreign table */ |
| 528 |
struct FdwRoutine *ri_FdwRoutine; |
| 529 |
|
| 530 |
/* available to save private state of FDW */ |
| 531 |
void *ri_FdwState; |
| 532 |
|
| 533 |
/* true when modifying foreign table directly */ |
| 534 |
bool ri_usesFdwDirectModify; |
| 535 |
|
| 536 |
/* batch insert stuff */ |
| 537 |
int ri_NumSlots; /* number of slots in the array */ |
| 538 |
int ri_NumSlotsInitialized; /* number of initialized slots */ |
| 539 |
int ri_BatchSize; /* max slots inserted in a single batch */ |
| 540 |
TupleTableSlot **ri_Slots; /* input tuples for batch insert */ |
| 541 |
TupleTableSlot **ri_PlanSlots; |
| 542 |
|
| 543 |
/* list of WithCheckOption's to be checked */ |
| 544 |
List *ri_WithCheckOptions; |
| 545 |
|
| 546 |
/* list of WithCheckOption expr states */ |
| 547 |
List *ri_WithCheckOptionExprs; |
| 548 |
|
| 549 |
/* array of expr states for checking check constraints */ |
| 550 |
ExprState **ri_CheckConstraintExprs; |
| 551 |
|
| 552 |
/* |
| 553 |
* array of expr states for checking not-null constraints on virtual |
| 554 |
* generated columns |
| 555 |
*/ |
| 556 |
ExprState **ri_GenVirtualNotNullConstraintExprs; |
| 557 |
|
| 558 |
/* |
| 559 |
* Arrays of stored generated columns ExprStates for INSERT/UPDATE/MERGE. |
| 560 |
*/ |
| 561 |
ExprState **ri_GeneratedExprsI; |
| 562 |
ExprState **ri_GeneratedExprsU; |
| 563 |
|
| 564 |
/* number of stored generated columns we need to compute */ |
| 565 |
int ri_NumGeneratedNeededI; |
| 566 |
int ri_NumGeneratedNeededU; |
| 567 |
|
| 568 |
/* list of RETURNING expressions */ |
| 569 |
List *ri_returningList; |
| 570 |
|
| 571 |
/* for computing a RETURNING list */ |
| 572 |
ProjectionInfo *ri_projectReturning; |
| 573 |
|
| 574 |
/* list of arbiter indexes to use to check conflicts */ |
| 575 |
List *ri_onConflictArbiterIndexes; |
| 576 |
|
| 577 |
/* ON CONFLICT evaluation state */ |
| 578 |
OnConflictSetState *ri_onConflict; |
| 579 |
|
| 580 |
/* for MERGE, lists of MergeActionState (one per MergeMatchKind) */ |
| 581 |
List *ri_MergeActions[NUM_MERGE_MATCH_KINDS]; |
| 582 |
|
| 583 |
/* for MERGE, expr state for checking the join condition */ |
| 584 |
ExprState *ri_MergeJoinCondition; |
| 585 |
|
| 586 |
/* partition check expression state (NULL if not set up yet) */ |
| 587 |
ExprState *ri_PartitionCheckExpr; |
| 588 |
|
| 589 |
/* |
| 590 |
* Map to convert child result relation tuples to the format of the table |
| 591 |
* actually mentioned in the query (called "root"). Computed only if |
| 592 |
* needed. A NULL map value indicates that no conversion is needed, so we |
| 593 |
* must have a separate flag to show if the map has been computed. |
| 594 |
*/ |
| 595 |
TupleConversionMap *ri_ChildToRootMap; |
| 596 |
bool ri_ChildToRootMapValid; |
| 597 |
|
| 598 |
/* |
| 599 |
* As above, but in the other direction. |
| 600 |
*/ |
| 601 |
TupleConversionMap *ri_RootToChildMap; |
| 602 |
bool ri_RootToChildMapValid; |
| 603 |
|
| 604 |
/* |
| 605 |
* Other information needed by child result relations |
| 606 |
* |
| 607 |
* ri_RootResultRelInfo gives the target relation mentioned in the query. |
| 608 |
* Used as the root for tuple routing and/or transition capture. |
| 609 |
* |
| 610 |
* ri_PartitionTupleSlot is non-NULL if the relation is a partition to |
| 611 |
* route tuples into and ri_RootToChildMap conversion is needed. |
| 612 |
*/ |
| 613 |
struct ResultRelInfo *ri_RootResultRelInfo; |
| 614 |
TupleTableSlot *ri_PartitionTupleSlot; |
| 615 |
|
| 616 |
/* for use by copyfrom.c when performing multi-inserts */ |
| 617 |
struct CopyMultiInsertBuffer *ri_CopyMultiInsertBuffer; |
| 618 |
|
| 619 |
/* |
| 620 |
* Used when a leaf partition is involved in a cross-partition update of |
| 621 |
* one of its ancestors; see ExecCrossPartitionUpdateForeignKey(). |
| 622 |
*/ |
| 623 |
List *ri_ancestorResultRels; |
| 624 |
} ResultRelInfo; |
| 625 |
|
| 626 |
/* ---------------- |
| 627 |
* AsyncRequest |
| 628 |
* |
| 629 |
* State for an asynchronous tuple request. |
| 630 |
* ---------------- |
| 631 |
*/ |
| 632 |
typedef struct AsyncRequest |
| 633 |
{ |
| 634 |
struct PlanState *requestor; /* Node that wants a tuple */ |
| 635 |
struct PlanState *requestee; /* Node from which a tuple is wanted */ |
| 636 |
int request_index; /* Scratch space for requestor */ |
| 637 |
bool callback_pending; /* Callback is needed */ |
| 638 |
bool request_complete; /* Request complete, result valid */ |
| 639 |
TupleTableSlot *result; /* Result (NULL or an empty slot if no more |
| 640 |
* tuples) */ |
| 641 |
} AsyncRequest; |
| 642 |
|
| 643 |
/* ---------------- |
| 644 |
* EState information |
| 645 |
* |
| 646 |
* Working state for an Executor invocation |
| 647 |
* ---------------- |
| 648 |
*/ |
| 649 |
typedef struct EState |
| 650 |
{ |
| 651 |
NodeTag type; |
| 652 |
|
| 653 |
/* Basic state for all query types: */ |
| 654 |
ScanDirection es_direction; /* current scan direction */ |
| 655 |
Snapshot es_snapshot; /* time qual to use */ |
| 656 |
Snapshot es_crosscheck_snapshot; /* crosscheck time qual for RI */ |
| 657 |
List *es_range_table; /* List of RangeTblEntry */ |
| 658 |
Index es_range_table_size; /* size of the range table arrays */ |
| 659 |
Relation *es_relations; /* Array of per-range-table-entry Relation |
| 660 |
* pointers, or NULL if not yet opened */ |
| 661 |
struct ExecRowMark **es_rowmarks; /* Array of per-range-table-entry |
| 662 |
* ExecRowMarks, or NULL if none */ |
| 663 |
List *es_rteperminfos; /* List of RTEPermissionInfo */ |
| 664 |
PlannedStmt *es_plannedstmt; /* link to top of plan tree */ |
| 665 |
List *es_part_prune_infos; /* List of PartitionPruneInfo */ |
| 666 |
List *es_part_prune_states; /* List of PartitionPruneState */ |
| 667 |
List *es_part_prune_results; /* List of Bitmapset */ |
| 668 |
Bitmapset *es_unpruned_relids; /* PlannedStmt.unprunableRelids + RT |
| 669 |
* indexes of leaf partitions that survive |
| 670 |
* initial pruning; see |
| 671 |
* ExecDoInitialPruning() */ |
| 672 |
const char *es_sourceText; /* Source text from QueryDesc */ |
| 673 |
|
| 674 |
JunkFilter *es_junkFilter; /* top-level junk filter, if any */ |
| 675 |
|
| 676 |
/* If query can insert/delete tuples, the command ID to mark them with */ |
| 677 |
CommandId es_output_cid; |
| 678 |
|
| 679 |
/* Info about target table(s) for insert/update/delete queries: */ |
| 680 |
ResultRelInfo **es_result_relations; /* Array of per-range-table-entry |
| 681 |
* ResultRelInfo pointers, or NULL |
| 682 |
* if not a target table */ |
| 683 |
List *es_opened_result_relations; /* List of non-NULL entries in |
| 684 |
* es_result_relations in no |
| 685 |
* specific order */ |
| 686 |
|
| 687 |
PartitionDirectory es_partition_directory; /* for PartitionDesc lookup */ |
| 688 |
|
| 689 |
/* |
| 690 |
* The following list contains ResultRelInfos created by the tuple routing |
| 691 |
* code for partitions that aren't found in the es_result_relations array. |
| 692 |
*/ |
| 693 |
List *es_tuple_routing_result_relations; |
| 694 |
|
| 695 |
/* Stuff used for firing triggers: */ |
| 696 |
List *es_trig_target_relations; /* trigger-only ResultRelInfos */ |
| 697 |
|
| 698 |
/* Parameter info: */ |
| 699 |
ParamListInfo es_param_list_info; /* values of external params */ |
| 700 |
ParamExecData *es_param_exec_vals; /* values of internal params */ |
| 701 |
|
| 702 |
QueryEnvironment *es_queryEnv; /* query environment */ |
| 703 |
|
| 704 |
/* Other working state: */ |
| 705 |
MemoryContext es_query_cxt; /* per-query context in which EState lives */ |
| 706 |
|
| 707 |
List *es_tupleTable; /* List of TupleTableSlots */ |
| 708 |
|
| 709 |
uint64 es_processed; /* # of tuples processed during one |
| 710 |
* ExecutorRun() call. */ |
| 711 |
uint64 es_total_processed; /* total # of tuples aggregated across all |
| 712 |
* ExecutorRun() calls. */ |
| 713 |
|
| 714 |
int es_top_eflags; /* eflags passed to ExecutorStart */ |
| 715 |
int es_instrument; /* OR of InstrumentOption flags */ |
| 716 |
bool es_finished; /* true when ExecutorFinish is done */ |
| 717 |
|
| 718 |
List *es_exprcontexts; /* List of ExprContexts within EState */ |
| 719 |
|
| 720 |
List *es_subplanstates; /* List of PlanState for SubPlans */ |
| 721 |
|
| 722 |
List *es_auxmodifytables; /* List of secondary ModifyTableStates */ |
| 723 |
|
| 724 |
/* |
| 725 |
* this ExprContext is for per-output-tuple operations, such as constraint |
| 726 |
* checks and index-value computations. It will be reset for each output |
| 727 |
* tuple. Note that it will be created only if needed. |
| 728 |
*/ |
| 729 |
ExprContext *es_per_tuple_exprcontext; |
| 730 |
|
| 731 |
/* |
| 732 |
* If not NULL, this is an EPQState's EState. This is a field in EState |
| 733 |
* both to allow EvalPlanQual aware executor nodes to detect that they |
| 734 |
* need to perform EPQ related work, and to provide necessary information |
| 735 |
* to do so. |
| 736 |
*/ |
| 737 |
struct EPQState *es_epq_active; |
| 738 |
|
| 739 |
bool es_use_parallel_mode; /* can we use parallel workers? */ |
| 740 |
|
| 741 |
int es_parallel_workers_to_launch; /* number of workers to |
| 742 |
* launch. */ |
| 743 |
int es_parallel_workers_launched; /* number of workers actually |
| 744 |
* launched. */ |
| 745 |
|
| 746 |
/* The per-query shared memory area to use for parallel execution. */ |
| 747 |
struct dsa_area *es_query_dsa; |
| 748 |
|
| 749 |
/* |
| 750 |
* JIT information. es_jit_flags indicates whether JIT should be performed |
| 751 |
* and with which options. es_jit is created on-demand when JITing is |
| 752 |
* performed. |
| 753 |
* |
| 754 |
* es_jit_worker_instr is the combined, on demand allocated, |
| 755 |
* instrumentation from all workers. The leader's instrumentation is kept |
| 756 |
* separate, and is combined on demand by ExplainPrintJITSummary(). |
| 757 |
*/ |
| 758 |
int es_jit_flags; |
| 759 |
struct JitContext *es_jit; |
| 760 |
struct JitInstrumentation *es_jit_worker_instr; |
| 761 |
|
| 762 |
/* |
| 763 |
* Lists of ResultRelInfos for foreign tables on which batch-inserts are |
| 764 |
* to be executed and owning ModifyTableStates, stored in the same order. |
| 765 |
*/ |
| 766 |
List *es_insert_pending_result_relations; |
| 767 |
List *es_insert_pending_modifytables; |
| 768 |
} EState; |
| 769 |
|
| 770 |
|
| 771 |
/* |
| 772 |
* ExecRowMark - |
| 773 |
* runtime representation of FOR [KEY] UPDATE/SHARE clauses |
| 774 |
* |
| 775 |
* When doing UPDATE/DELETE/MERGE/SELECT FOR [KEY] UPDATE/SHARE, we will have |
| 776 |
* an ExecRowMark for each non-target relation in the query (except inheritance |
| 777 |
* parent RTEs, which can be ignored at runtime). Virtual relations such as |
| 778 |
* subqueries-in-FROM will have an ExecRowMark with relation == NULL. See |
| 779 |
* PlanRowMark for details about most of the fields. In addition to fields |
| 780 |
* directly derived from PlanRowMark, we store an activity flag (to denote |
| 781 |
* inactive children of inheritance trees), curCtid, which is used by the |
| 782 |
* WHERE CURRENT OF code, and ermExtra, which is available for use by the plan |
| 783 |
* node that sources the relation (e.g., for a foreign table the FDW can use |
| 784 |
* ermExtra to hold information). |
| 785 |
* |
| 786 |
* EState->es_rowmarks is an array of these structs, indexed by RT index, |
| 787 |
* with NULLs for irrelevant RT indexes. es_rowmarks itself is NULL if |
| 788 |
* there are no rowmarks. |
| 789 |
*/ |
| 790 |
typedef struct ExecRowMark |
| 791 |
{ |
| 792 |
Relation relation; /* opened and suitably locked relation */ |
| 793 |
Oid relid; /* its OID (or InvalidOid, if subquery) */ |
| 794 |
Index rti; /* its range table index */ |
| 795 |
Index prti; /* parent range table index, if child */ |
| 796 |
Index rowmarkId; /* unique identifier for resjunk columns */ |
| 797 |
RowMarkType markType; /* see enum in nodes/plannodes.h */ |
| 798 |
LockClauseStrength strength; /* LockingClause's strength, or LCS_NONE */ |
| 799 |
LockWaitPolicy waitPolicy; /* NOWAIT and SKIP LOCKED */ |
| 800 |
bool ermActive; /* is this mark relevant for current tuple? */ |
| 801 |
ItemPointerData curCtid; /* ctid of currently locked tuple, if any */ |
| 802 |
void *ermExtra; /* available for use by relation source node */ |
| 803 |
} ExecRowMark; |
| 804 |
|
| 805 |
/* |
| 806 |
* ExecAuxRowMark - |
| 807 |
* additional runtime representation of FOR [KEY] UPDATE/SHARE clauses |
| 808 |
* |
| 809 |
* Each LockRows and ModifyTable node keeps a list of the rowmarks it needs to |
| 810 |
* deal with. In addition to a pointer to the related entry in es_rowmarks, |
| 811 |
* this struct carries the column number(s) of the resjunk columns associated |
| 812 |
* with the rowmark (see comments for PlanRowMark for more detail). |
| 813 |
*/ |
| 814 |
typedef struct ExecAuxRowMark |
| 815 |
{ |
| 816 |
ExecRowMark *rowmark; /* related entry in es_rowmarks */ |
| 817 |
AttrNumber ctidAttNo; /* resno of ctid junk attribute, if any */ |
| 818 |
AttrNumber toidAttNo; /* resno of tableoid junk attribute, if any */ |
| 819 |
AttrNumber wholeAttNo; /* resno of whole-row junk attribute, if any */ |
| 820 |
} ExecAuxRowMark; |
| 821 |
|
| 822 |
|
| 823 |
/* ---------------------------------------------------------------- |
| 824 |
* Tuple Hash Tables |
| 825 |
* |
| 826 |
* All-in-memory tuple hash tables are used for a number of purposes. |
| 827 |
* |
| 828 |
* Note: tab_hash_expr is for hashing the key datatype(s) stored in the table, |
| 829 |
* and tab_eq_func is a non-cross-type ExprState for equality checks on those |
| 830 |
* types. Normally these are the only ExprStates used, but |
| 831 |
* FindTupleHashEntry() supports searching a hashtable using cross-data-type |
| 832 |
* hashing. For that, the caller must supply an ExprState to hash the LHS |
| 833 |
* datatype as well as the cross-type equality ExprState to use. in_hash_expr |
| 834 |
* and cur_eq_func are set to point to the caller's hash and equality |
| 835 |
* ExprStates while doing such a search. During LookupTupleHashEntry(), they |
| 836 |
* point to tab_hash_expr and tab_eq_func respectively. |
| 837 |
* ---------------------------------------------------------------- |
| 838 |
*/ |
| 839 |
typedef struct TupleHashEntryData *TupleHashEntry; |
| 840 |
typedef struct TupleHashTableData *TupleHashTable; |
| 841 |
|
| 842 |
typedef struct TupleHashEntryData |
| 843 |
{ |
| 844 |
MinimalTuple firstTuple; /* copy of first tuple in this group */ |
| 845 |
uint32 status; /* hash status */ |
| 846 |
uint32 hash; /* hash value (cached) */ |
| 847 |
} TupleHashEntryData; |
| 848 |
|
| 849 |
/* define parameters necessary to generate the tuple hash table interface */ |
| 850 |
#define SH_PREFIX tuplehash |
| 851 |
#define SH_ELEMENT_TYPE TupleHashEntryData |
| 852 |
#define SH_KEY_TYPE MinimalTuple |
| 853 |
#define SH_SCOPE extern |
| 854 |
#define SH_DECLARE |
| 855 |
#include "lib/simplehash.h" |
| 856 |
|
| 857 |
typedef struct TupleHashTableData |
| 858 |
{ |
| 859 |
tuplehash_hash *hashtab; /* underlying hash table */ |
| 860 |
int numCols; /* number of columns in lookup key */ |
| 861 |
AttrNumber *keyColIdx; /* attr numbers of key columns */ |
| 862 |
ExprState *tab_hash_expr; /* ExprState for hashing table datatype(s) */ |
| 863 |
ExprState *tab_eq_func; /* comparator for table datatype(s) */ |
| 864 |
Oid *tab_collations; /* collations for hash and comparison */ |
| 865 |
MemoryContext tablecxt; /* memory context containing table */ |
| 866 |
MemoryContext tempcxt; /* context for function evaluations */ |
| 867 |
Size additionalsize; /* size of additional data */ |
| 868 |
TupleTableSlot *tableslot; /* slot for referencing table entries */ |
| 869 |
/* The following fields are set transiently for each table search: */ |
| 870 |
TupleTableSlot *inputslot; /* current input tuple's slot */ |
| 871 |
ExprState *in_hash_expr; /* ExprState for hashing input datatype(s) */ |
| 872 |
ExprState *cur_eq_func; /* comparator for input vs. table */ |
| 873 |
ExprContext *exprcontext; /* expression context */ |
| 874 |
} TupleHashTableData; |
| 875 |
|
| 876 |
typedef tuplehash_iterator TupleHashIterator; |
| 877 |
|
| 878 |
/* |
| 879 |
* Use InitTupleHashIterator/TermTupleHashIterator for a read/write scan. |
| 880 |
* Use ResetTupleHashIterator if the table can be frozen (in this case no |
| 881 |
* explicit scan termination is needed). |
| 882 |
*/ |
| 883 |
#define InitTupleHashIterator(htable, iter) \ |
| 884 |
tuplehash_start_iterate(htable->hashtab, iter) |
| 885 |
#define TermTupleHashIterator(iter) \ |
| 886 |
((void) 0) |
| 887 |
#define ResetTupleHashIterator(htable, iter) \ |
| 888 |
InitTupleHashIterator(htable, iter) |
| 889 |
#define ScanTupleHashTable(htable, iter) \ |
| 890 |
tuplehash_iterate(htable->hashtab, iter) |
| 891 |
|
| 892 |
|
| 893 |
/* ---------------------------------------------------------------- |
| 894 |
* Expression State Nodes |
| 895 |
* |
| 896 |
* Formerly, there was a separate executor expression state node corresponding |
| 897 |
* to each node in a planned expression tree. That's no longer the case; for |
| 898 |
* common expression node types, all the execution info is embedded into |
| 899 |
* step(s) in a single ExprState node. But we still have a few executor state |
| 900 |
* node types for selected expression node types, mostly those in which info |
| 901 |
* has to be shared with other parts of the execution state tree. |
| 902 |
* ---------------------------------------------------------------- |
| 903 |
*/ |
| 904 |
|
| 905 |
/* ---------------- |
| 906 |
* WindowFuncExprState node |
| 907 |
* ---------------- |
| 908 |
*/ |
| 909 |
typedef struct WindowFuncExprState |
| 910 |
{ |
| 911 |
NodeTag type; |
| 912 |
WindowFunc *wfunc; /* expression plan node */ |
| 913 |
List *args; /* ExprStates for argument expressions */ |
| 914 |
ExprState *aggfilter; /* FILTER expression */ |
| 915 |
int wfuncno; /* ID number for wfunc within its plan node */ |
| 916 |
} WindowFuncExprState; |
| 917 |
|
| 918 |
|
| 919 |
/* ---------------- |
| 920 |
* SetExprState node |
| 921 |
* |
| 922 |
* State for evaluating a potentially set-returning expression (like FuncExpr |
| 923 |
* or OpExpr). In some cases, like some of the expressions in ROWS FROM(...) |
| 924 |
* the expression might not be a SRF, but nonetheless it uses the same |
| 925 |
* machinery as SRFs; it will be treated as a SRF returning a single row. |
| 926 |
* ---------------- |
| 927 |
*/ |
| 928 |
typedef struct SetExprState |
| 929 |
{ |
| 930 |
NodeTag type; |
| 931 |
Expr *expr; /* expression plan node */ |
| 932 |
List *args; /* ExprStates for argument expressions */ |
| 933 |
|
| 934 |
/* |
| 935 |
* In ROWS FROM, functions can be inlined, removing the FuncExpr normally |
| 936 |
* inside. In such a case this is the compiled expression (which cannot |
| 937 |
* return a set), which'll be evaluated using regular ExecEvalExpr(). |
| 938 |
*/ |
| 939 |
ExprState *elidedFuncState; |
| 940 |
|
| 941 |
/* |
| 942 |
* Function manager's lookup info for the target function. If func.fn_oid |
| 943 |
* is InvalidOid, we haven't initialized it yet (nor any of the following |
| 944 |
* fields, except funcReturnsSet). |
| 945 |
*/ |
| 946 |
FmgrInfo func; |
| 947 |
|
| 948 |
/* |
| 949 |
* For a set-returning function (SRF) that returns a tuplestore, we keep |
| 950 |
* the tuplestore here and dole out the result rows one at a time. The |
| 951 |
* slot holds the row currently being returned. |
| 952 |
*/ |
| 953 |
Tuplestorestate *funcResultStore; |
| 954 |
TupleTableSlot *funcResultSlot; |
| 955 |
|
| 956 |
/* |
| 957 |
* In some cases we need to compute a tuple descriptor for the function's |
| 958 |
* output. If so, it's stored here. |
| 959 |
*/ |
| 960 |
TupleDesc funcResultDesc; |
| 961 |
bool funcReturnsTuple; /* valid when funcResultDesc isn't NULL */ |
| 962 |
|
| 963 |
/* |
| 964 |
* Remember whether the function is declared to return a set. This is set |
| 965 |
* by ExecInitExpr, and is valid even before the FmgrInfo is set up. |
| 966 |
*/ |
| 967 |
bool funcReturnsSet; |
| 968 |
|
| 969 |
/* |
| 970 |
* setArgsValid is true when we are evaluating a set-returning function |
| 971 |
* that uses value-per-call mode and we are in the middle of a call |
| 972 |
* series; we want to pass the same argument values to the function again |
| 973 |
* (and again, until it returns ExprEndResult). This indicates that |
| 974 |
* fcinfo_data already contains valid argument data. |
| 975 |
*/ |
| 976 |
bool setArgsValid; |
| 977 |
|
| 978 |
/* |
| 979 |
* Flag to remember whether we have registered a shutdown callback for |
| 980 |
* this SetExprState. We do so only if funcResultStore or setArgsValid |
| 981 |
* has been set at least once (since all the callback is for is to release |
| 982 |
* the tuplestore or clear setArgsValid). |
| 983 |
*/ |
| 984 |
bool shutdown_reg; /* a shutdown callback is registered */ |
| 985 |
|
| 986 |
/* |
| 987 |
* Call parameter structure for the function. This has been initialized |
| 988 |
* (by InitFunctionCallInfoData) if func.fn_oid is valid. It also saves |
| 989 |
* argument values between calls, when setArgsValid is true. |
| 990 |
*/ |
| 991 |
FunctionCallInfo fcinfo; |
| 992 |
} SetExprState; |
| 993 |
|
| 994 |
/* ---------------- |
| 995 |
* SubPlanState node |
| 996 |
* ---------------- |
| 997 |
*/ |
| 998 |
typedef struct SubPlanState |
| 999 |
{ |
| 1000 |
NodeTag type; |
| 1001 |
SubPlan *subplan; /* expression plan node */ |
| 1002 |
struct PlanState *planstate; /* subselect plan's state tree */ |
| 1003 |
struct PlanState *parent; /* parent plan node's state tree */ |
| 1004 |
ExprState *testexpr; /* state of combining expression */ |
| 1005 |
HeapTuple curTuple; /* copy of most recent tuple from subplan */ |
| 1006 |
Datum curArray; /* most recent array from ARRAY() subplan */ |
| 1007 |
/* these are used when hashing the subselect's output: */ |
| 1008 |
TupleDesc descRight; /* subselect desc after projection */ |
| 1009 |
ProjectionInfo *projLeft; /* for projecting lefthand exprs */ |
| 1010 |
ProjectionInfo *projRight; /* for projecting subselect output */ |
| 1011 |
TupleHashTable hashtable; /* hash table for no-nulls subselect rows */ |
| 1012 |
TupleHashTable hashnulls; /* hash table for rows with null(s) */ |
| 1013 |
bool havehashrows; /* true if hashtable is not empty */ |
| 1014 |
bool havenullrows; /* true if hashnulls is not empty */ |
| 1015 |
MemoryContext hashtablecxt; /* memory context containing hash tables */ |
| 1016 |
MemoryContext hashtempcxt; /* temp memory context for hash tables */ |
| 1017 |
ExprContext *innerecontext; /* econtext for computing inner tuples */ |
| 1018 |
int numCols; /* number of columns being hashed */ |
| 1019 |
/* each of the remaining fields is an array of length numCols: */ |
| 1020 |
AttrNumber *keyColIdx; /* control data for hash tables */ |
| 1021 |
Oid *tab_eq_funcoids; /* equality func oids for table |
| 1022 |
* datatype(s) */ |
| 1023 |
Oid *tab_collations; /* collations for hash and comparison */ |
| 1024 |
FmgrInfo *tab_hash_funcs; /* hash functions for table datatype(s) */ |
| 1025 |
ExprState *lhs_hash_expr; /* hash expr for lefthand datatype(s) */ |
| 1026 |
FmgrInfo *cur_eq_funcs; /* equality functions for LHS vs. table */ |
| 1027 |
ExprState *cur_eq_comp; /* equality comparator for LHS vs. table */ |
| 1028 |
} SubPlanState; |
| 1029 |
|
| 1030 |
/* |
| 1031 |
* DomainConstraintState - one item to check during CoerceToDomain |
| 1032 |
* |
| 1033 |
* Note: we consider this to be part of an ExprState tree, so we give it |
| 1034 |
* a name following the xxxState convention. But there's no directly |
| 1035 |
* associated plan-tree node. |
| 1036 |
*/ |
| 1037 |
typedef enum DomainConstraintType |
| 1038 |
{ |
| 1039 |
DOM_CONSTRAINT_NOTNULL, |
| 1040 |
DOM_CONSTRAINT_CHECK, |
| 1041 |
} DomainConstraintType; |
| 1042 |
|
| 1043 |
typedef struct DomainConstraintState |
| 1044 |
{ |
| 1045 |
NodeTag type; |
| 1046 |
DomainConstraintType constrainttype; /* constraint type */ |
| 1047 |
char *name; /* name of constraint (for error msgs) */ |
| 1048 |
Expr *check_expr; /* for CHECK, a boolean expression */ |
| 1049 |
ExprState *check_exprstate; /* check_expr's eval state, or NULL */ |
| 1050 |
} DomainConstraintState; |
| 1051 |
|
| 1052 |
/* |
| 1053 |
* State for JsonExpr evaluation, too big to inline. |
| 1054 |
* |
| 1055 |
* This contains the information going into and coming out of the |
| 1056 |
* EEOP_JSONEXPR_PATH eval step. |
| 1057 |
*/ |
| 1058 |
typedef struct JsonExprState |
| 1059 |
{ |
| 1060 |
/* original expression node */ |
| 1061 |
JsonExpr *jsexpr; |
| 1062 |
|
| 1063 |
/* value/isnull for formatted_expr */ |
| 1064 |
NullableDatum formatted_expr; |
| 1065 |
|
| 1066 |
/* value/isnull for pathspec */ |
| 1067 |
NullableDatum pathspec; |
| 1068 |
|
| 1069 |
/* JsonPathVariable entries for passing_values */ |
| 1070 |
List *args; |
| 1071 |
|
| 1072 |
/* |
| 1073 |
* Output variables that drive the EEOP_JUMP_IF_NOT_TRUE steps that are |
| 1074 |
* added for ON ERROR and ON EMPTY expressions, if any. |
| 1075 |
* |
| 1076 |
* Reset for each evaluation of EEOP_JSONEXPR_PATH. |
| 1077 |
*/ |
| 1078 |
|
| 1079 |
/* Set to true if jsonpath evaluation cause an error. */ |
| 1080 |
NullableDatum error; |
| 1081 |
|
| 1082 |
/* Set to true if the jsonpath evaluation returned 0 items. */ |
| 1083 |
NullableDatum empty; |
| 1084 |
|
| 1085 |
/* |
| 1086 |
* Addresses of steps that implement the non-ERROR variant of ON EMPTY and |
| 1087 |
* ON ERROR behaviors, respectively. |
| 1088 |
*/ |
| 1089 |
int jump_empty; |
| 1090 |
int jump_error; |
| 1091 |
|
| 1092 |
/* |
| 1093 |
* Address of the step to coerce the result value of jsonpath evaluation |
| 1094 |
* to the RETURNING type. -1 if no coercion if JsonExpr.use_io_coercion |
| 1095 |
* is true. |
| 1096 |
*/ |
| 1097 |
int jump_eval_coercion; |
| 1098 |
|
| 1099 |
/* |
| 1100 |
* Address to jump to when skipping all the steps after performing |
| 1101 |
* ExecEvalJsonExprPath() so as to return whatever the JsonPath* function |
| 1102 |
* returned as is, that is, in the cases where there's no error and no |
| 1103 |
* coercion is necessary. |
| 1104 |
*/ |
| 1105 |
int jump_end; |
| 1106 |
|
| 1107 |
/* |
| 1108 |
* RETURNING type input function invocation info when |
| 1109 |
* JsonExpr.use_io_coercion is true. |
| 1110 |
*/ |
| 1111 |
FunctionCallInfo input_fcinfo; |
| 1112 |
|
| 1113 |
/* |
| 1114 |
* For error-safe evaluation of coercions. When the ON ERROR behavior is |
| 1115 |
* not ERROR, a pointer to this is passed to ExecInitExprRec() when |
| 1116 |
* initializing the coercion expressions or to ExecInitJsonCoercion(). |
| 1117 |
* |
| 1118 |
* Reset for each evaluation of EEOP_JSONEXPR_PATH. |
| 1119 |
*/ |
| 1120 |
ErrorSaveContext escontext; |
| 1121 |
} JsonExprState; |
| 1122 |
|
| 1123 |
|
| 1124 |
/* ---------------------------------------------------------------- |
| 1125 |
* Executor State Trees |
| 1126 |
* |
| 1127 |
* An executing query has a PlanState tree paralleling the Plan tree |
| 1128 |
* that describes the plan. |
| 1129 |
* ---------------------------------------------------------------- |
| 1130 |
*/ |
| 1131 |
|
| 1132 |
/* ---------------- |
| 1133 |
* ExecProcNodeMtd |
| 1134 |
* |
| 1135 |
* This is the method called by ExecProcNode to return the next tuple |
| 1136 |
* from an executor node. It returns NULL, or an empty TupleTableSlot, |
| 1137 |
* if no more tuples are available. |
| 1138 |
* ---------------- |
| 1139 |
*/ |
| 1140 |
typedef TupleTableSlot *(*ExecProcNodeMtd) (struct PlanState *pstate); |
| 1141 |
|
| 1142 |
/* ---------------- |
| 1143 |
* PlanState node |
| 1144 |
* |
| 1145 |
* We never actually instantiate any PlanState nodes; this is just the common |
| 1146 |
* abstract superclass for all PlanState-type nodes. |
| 1147 |
* ---------------- |
| 1148 |
*/ |
| 1149 |
typedef struct PlanState |
| 1150 |
{ |
| 1151 |
pg_node_attr(abstract) |
| 1152 |
|
| 1153 |
NodeTag type; |
| 1154 |
|
| 1155 |
Plan *plan; /* associated Plan node */ |
| 1156 |
|
| 1157 |
EState *state; /* at execution time, states of individual |
| 1158 |
* nodes point to one EState for the whole |
| 1159 |
* top-level plan */ |
| 1160 |
|
| 1161 |
ExecProcNodeMtd ExecProcNode; /* function to return next tuple */ |
| 1162 |
ExecProcNodeMtd ExecProcNodeReal; /* actual function, if above is a |
| 1163 |
* wrapper */ |
| 1164 |
|
| 1165 |
Instrumentation *instrument; /* Optional runtime stats for this node */ |
| 1166 |
WorkerInstrumentation *worker_instrument; /* per-worker instrumentation */ |
| 1167 |
|
| 1168 |
/* Per-worker JIT instrumentation */ |
| 1169 |
struct SharedJitInstrumentation *worker_jit_instrument; |
| 1170 |
|
| 1171 |
/* |
| 1172 |
* Common structural data for all Plan types. These links to subsidiary |
| 1173 |
* state trees parallel links in the associated plan tree (except for the |
| 1174 |
* subPlan list, which does not exist in the plan tree). |
| 1175 |
*/ |
| 1176 |
ExprState *qual; /* boolean qual condition */ |
| 1177 |
struct PlanState *lefttree; /* input plan tree(s) */ |
| 1178 |
struct PlanState *righttree; |
| 1179 |
|
| 1180 |
List *initPlan; /* Init SubPlanState nodes (un-correlated expr |
| 1181 |
* subselects) */ |
| 1182 |
List *subPlan; /* SubPlanState nodes in my expressions */ |
| 1183 |
|
| 1184 |
/* |
| 1185 |
* State for management of parameter-change-driven rescanning |
| 1186 |
*/ |
| 1187 |
Bitmapset *chgParam; /* set of IDs of changed Params */ |
| 1188 |
|
| 1189 |
/* |
| 1190 |
* Other run-time state needed by most if not all node types. |
| 1191 |
*/ |
| 1192 |
TupleDesc ps_ResultTupleDesc; /* node's return type */ |
| 1193 |
TupleTableSlot *ps_ResultTupleSlot; /* slot for my result tuples */ |
| 1194 |
ExprContext *ps_ExprContext; /* node's expression-evaluation context */ |
| 1195 |
ProjectionInfo *ps_ProjInfo; /* info for doing tuple projection */ |
| 1196 |
|
| 1197 |
bool async_capable; /* true if node is async-capable */ |
| 1198 |
|
| 1199 |
/* |
| 1200 |
* Scanslot's descriptor if known. This is a bit of a hack, but otherwise |
| 1201 |
* it's hard for expression compilation to optimize based on the |
| 1202 |
* descriptor, without encoding knowledge about all executor nodes. |
| 1203 |
*/ |
| 1204 |
TupleDesc scandesc; |
| 1205 |
|
| 1206 |
/* |
| 1207 |
* Define the slot types for inner, outer and scanslots for expression |
| 1208 |
* contexts with this state as a parent. If *opsset is set, then |
| 1209 |
* *opsfixed indicates whether *ops is guaranteed to be the type of slot |
| 1210 |
* used. That means that every slot in the corresponding |
| 1211 |
* ExprContext.ecxt_*tuple will point to a slot of that type, while |
| 1212 |
* evaluating the expression. If *opsfixed is false, but *ops is set, |
| 1213 |
* that indicates the most likely type of slot. |
| 1214 |
* |
| 1215 |
* The scan* fields are set by ExecInitScanTupleSlot(). If that's not |
| 1216 |
* called, nodes can initialize the fields themselves. |
| 1217 |
* |
| 1218 |
* If outer/inneropsset is false, the information is inferred on-demand |
| 1219 |
* using ExecGetResultSlotOps() on ->righttree/lefttree, using the |
| 1220 |
* corresponding node's resultops* fields. |
| 1221 |
* |
| 1222 |
* The result* fields are automatically set when ExecInitResultSlot is |
| 1223 |
* used (be it directly or when the slot is created by |
| 1224 |
* ExecAssignScanProjectionInfo() / |
| 1225 |
* ExecConditionalAssignProjectionInfo()). If no projection is necessary |
| 1226 |
* ExecConditionalAssignProjectionInfo() defaults those fields to the scan |
| 1227 |
* operations. |
| 1228 |
*/ |
| 1229 |
const TupleTableSlotOps *scanops; |
| 1230 |
const TupleTableSlotOps *outerops; |
| 1231 |
const TupleTableSlotOps *innerops; |
| 1232 |
const TupleTableSlotOps *resultops; |
| 1233 |
bool scanopsfixed; |
| 1234 |
bool outeropsfixed; |
| 1235 |
bool inneropsfixed; |
| 1236 |
bool resultopsfixed; |
| 1237 |
bool scanopsset; |
| 1238 |
bool outeropsset; |
| 1239 |
bool inneropsset; |
| 1240 |
bool resultopsset; |
| 1241 |
} PlanState; |
| 1242 |
|
| 1243 |
/* ---------------- |
| 1244 |
* these are defined to avoid confusion problems with "left" |
| 1245 |
* and "right" and "inner" and "outer". The convention is that |
| 1246 |
* the "left" plan is the "outer" plan and the "right" plan is |
| 1247 |
* the inner plan, but these make the code more readable. |
| 1248 |
* ---------------- |
| 1249 |
*/ |
| 1250 |
#define innerPlanState(node) (((PlanState *)(node))->righttree) |
| 1251 |
#define outerPlanState(node) (((PlanState *)(node))->lefttree) |
| 1252 |
|
| 1253 |
/* Macros for inline access to certain instrumentation counters */ |
| 1254 |
#define InstrCountTuples2(node, delta) \ |
| 1255 |
do { \ |
| 1256 |
if (((PlanState *)(node))->instrument) \ |
| 1257 |
((PlanState *)(node))->instrument->ntuples2 += (delta); \ |
| 1258 |
} while (0) |
| 1259 |
#define InstrCountFiltered1(node, delta) \ |
| 1260 |
do { \ |
| 1261 |
if (((PlanState *)(node))->instrument) \ |
| 1262 |
((PlanState *)(node))->instrument->nfiltered1 += (delta); \ |
| 1263 |
} while(0) |
| 1264 |
#define InstrCountFiltered2(node, delta) \ |
| 1265 |
do { \ |
| 1266 |
if (((PlanState *)(node))->instrument) \ |
| 1267 |
((PlanState *)(node))->instrument->nfiltered2 += (delta); \ |
| 1268 |
} while(0) |
| 1269 |
|
| 1270 |
/* |
| 1271 |
* EPQState is state for executing an EvalPlanQual recheck on a candidate |
| 1272 |
* tuples e.g. in ModifyTable or LockRows. |
| 1273 |
* |
| 1274 |
* To execute EPQ a separate EState is created (stored in ->recheckestate), |
| 1275 |
* which shares some resources, like the rangetable, with the main query's |
| 1276 |
* EState (stored in ->parentestate). The (sub-)tree of the plan that needs to |
| 1277 |
* be rechecked (in ->plan), is separately initialized (into |
| 1278 |
* ->recheckplanstate), but shares plan nodes with the corresponding nodes in |
| 1279 |
* the main query. The scan nodes in that separate executor tree are changed |
| 1280 |
* to return only the current tuple of interest for the respective |
| 1281 |
* table. Those tuples are either provided by the caller (using |
| 1282 |
* EvalPlanQualSlot), and/or found using the rowmark mechanism (non-locking |
| 1283 |
* rowmarks by the EPQ machinery itself, locking ones by the caller). |
| 1284 |
* |
| 1285 |
* While the plan to be checked may be changed using EvalPlanQualSetPlan(), |
| 1286 |
* all such plans need to share the same EState. |
| 1287 |
*/ |
| 1288 |
typedef struct EPQState |
| 1289 |
{ |
| 1290 |
/* These are initialized by EvalPlanQualInit() and do not change later: */ |
| 1291 |
EState *parentestate; /* main query's EState */ |
| 1292 |
int epqParam; /* ID of Param to force scan node re-eval */ |
| 1293 |
List *resultRelations; /* integer list of RT indexes, or NIL */ |
| 1294 |
|
| 1295 |
/* |
| 1296 |
* relsubs_slot[scanrelid - 1] holds the EPQ test tuple to be returned by |
| 1297 |
* the scan node for the scanrelid'th RT index, in place of performing an |
| 1298 |
* actual table scan. Callers should use EvalPlanQualSlot() to fetch |
| 1299 |
* these slots. |
| 1300 |
*/ |
| 1301 |
List *tuple_table; /* tuple table for relsubs_slot */ |
| 1302 |
TupleTableSlot **relsubs_slot; |
| 1303 |
|
| 1304 |
/* |
| 1305 |
* Initialized by EvalPlanQualInit(), may be changed later with |
| 1306 |
* EvalPlanQualSetPlan(): |
| 1307 |
*/ |
| 1308 |
|
| 1309 |
Plan *plan; /* plan tree to be executed */ |
| 1310 |
List *arowMarks; /* ExecAuxRowMarks (non-locking only) */ |
| 1311 |
|
| 1312 |
|
| 1313 |
/* |
| 1314 |
* The original output tuple to be rechecked. Set by |
| 1315 |
* EvalPlanQualSetSlot(), before EvalPlanQualNext() or EvalPlanQual() may |
| 1316 |
* be called. |
| 1317 |
*/ |
| 1318 |
TupleTableSlot *origslot; |
| 1319 |
|
| 1320 |
|
| 1321 |
/* Initialized or reset by EvalPlanQualBegin(): */ |
| 1322 |
|
| 1323 |
EState *recheckestate; /* EState for EPQ execution, see above */ |
| 1324 |
|
| 1325 |
/* |
| 1326 |
* Rowmarks that can be fetched on-demand using |
| 1327 |
* EvalPlanQualFetchRowMark(), indexed by scanrelid - 1. Only non-locking |
| 1328 |
* rowmarks. |
| 1329 |
*/ |
| 1330 |
ExecAuxRowMark **relsubs_rowmark; |
| 1331 |
|
| 1332 |
/* |
| 1333 |
* relsubs_done[scanrelid - 1] is true if there is no EPQ tuple for this |
| 1334 |
* target relation or it has already been fetched in the current scan of |
| 1335 |
* this target relation within the current EvalPlanQual test. |
| 1336 |
*/ |
| 1337 |
bool *relsubs_done; |
| 1338 |
|
| 1339 |
/* |
| 1340 |
* relsubs_blocked[scanrelid - 1] is true if there is no EPQ tuple for |
| 1341 |
* this target relation during the current EvalPlanQual test. We keep |
| 1342 |
* these flags set for all relids listed in resultRelations, but |
| 1343 |
* transiently clear the one for the relation whose tuple is actually |
| 1344 |
* passed to EvalPlanQual(). |
| 1345 |
*/ |
| 1346 |
bool *relsubs_blocked; |
| 1347 |
|
| 1348 |
PlanState *recheckplanstate; /* EPQ specific exec nodes, for ->plan */ |
| 1349 |
} EPQState; |
| 1350 |
|
| 1351 |
|
| 1352 |
/* ---------------- |
| 1353 |
* ResultState information |
| 1354 |
* ---------------- |
| 1355 |
*/ |
| 1356 |
typedef struct ResultState |
| 1357 |
{ |
| 1358 |
PlanState ps; /* its first field is NodeTag */ |
| 1359 |
ExprState *resconstantqual; |
| 1360 |
bool rs_done; /* are we done? */ |
| 1361 |
bool rs_checkqual; /* do we need to check the qual? */ |
| 1362 |
} ResultState; |
| 1363 |
|
| 1364 |
/* ---------------- |
| 1365 |
* ProjectSetState information |
| 1366 |
* |
| 1367 |
* Note: at least one of the "elems" will be a SetExprState; the rest are |
| 1368 |
* regular ExprStates. |
| 1369 |
* ---------------- |
| 1370 |
*/ |
| 1371 |
typedef struct ProjectSetState |
| 1372 |
{ |
| 1373 |
PlanState ps; /* its first field is NodeTag */ |
| 1374 |
Node **elems; /* array of expression states */ |
| 1375 |
ExprDoneCond *elemdone; /* array of per-SRF is-done states */ |
| 1376 |
int nelems; /* length of elemdone[] array */ |
| 1377 |
bool pending_srf_tuples; /* still evaluating srfs in tlist? */ |
| 1378 |
MemoryContext argcontext; /* context for SRF arguments */ |
| 1379 |
} ProjectSetState; |
| 1380 |
|
| 1381 |
|
| 1382 |
/* flags for mt_merge_subcommands */ |
| 1383 |
#define MERGE_INSERT 0x01 |
| 1384 |
#define MERGE_UPDATE 0x02 |
| 1385 |
#define MERGE_DELETE 0x04 |
| 1386 |
|
| 1387 |
/* ---------------- |
| 1388 |
* ModifyTableState information |
| 1389 |
* ---------------- |
| 1390 |
*/ |
| 1391 |
typedef struct ModifyTableState |
| 1392 |
{ |
| 1393 |
PlanState ps; /* its first field is NodeTag */ |
| 1394 |
CmdType operation; /* INSERT, UPDATE, DELETE, or MERGE */ |
| 1395 |
bool canSetTag; /* do we set the command tag/es_processed? */ |
| 1396 |
bool mt_done; /* are we done? */ |
| 1397 |
int mt_nrels; /* number of entries in resultRelInfo[] */ |
| 1398 |
ResultRelInfo *resultRelInfo; /* info about target relation(s) */ |
| 1399 |
|
| 1400 |
/* |
| 1401 |
* Target relation mentioned in the original statement, used to fire |
| 1402 |
* statement-level triggers and as the root for tuple routing. (This |
| 1403 |
* might point to one of the resultRelInfo[] entries, but it can also be a |
| 1404 |
* distinct struct.) |
| 1405 |
*/ |
| 1406 |
ResultRelInfo *rootResultRelInfo; |
| 1407 |
|
| 1408 |
EPQState mt_epqstate; /* for evaluating EvalPlanQual rechecks */ |
| 1409 |
bool fireBSTriggers; /* do we need to fire stmt triggers? */ |
| 1410 |
|
| 1411 |
/* |
| 1412 |
* These fields are used for inherited UPDATE and DELETE, to track which |
| 1413 |
* target relation a given tuple is from. If there are a lot of target |
| 1414 |
* relations, we use a hash table to translate table OIDs to |
| 1415 |
* resultRelInfo[] indexes; otherwise mt_resultOidHash is NULL. |
| 1416 |
*/ |
| 1417 |
int mt_resultOidAttno; /* resno of "tableoid" junk attr */ |
| 1418 |
Oid mt_lastResultOid; /* last-seen value of tableoid */ |
| 1419 |
int mt_lastResultIndex; /* corresponding index in resultRelInfo[] */ |
| 1420 |
HTAB *mt_resultOidHash; /* optional hash table to speed lookups */ |
| 1421 |
|
| 1422 |
/* |
| 1423 |
* Slot for storing tuples in the root partitioned table's rowtype during |
| 1424 |
* an UPDATE of a partitioned table. |
| 1425 |
*/ |
| 1426 |
TupleTableSlot *mt_root_tuple_slot; |
| 1427 |
|
| 1428 |
/* Tuple-routing support info */ |
| 1429 |
struct PartitionTupleRouting *mt_partition_tuple_routing; |
| 1430 |
|
| 1431 |
/* controls transition table population for specified operation */ |
| 1432 |
struct TransitionCaptureState *mt_transition_capture; |
| 1433 |
|
| 1434 |
/* controls transition table population for INSERT...ON CONFLICT UPDATE */ |
| 1435 |
struct TransitionCaptureState *mt_oc_transition_capture; |
| 1436 |
|
| 1437 |
/* Flags showing which subcommands are present INS/UPD/DEL/DO NOTHING */ |
| 1438 |
int mt_merge_subcommands; |
| 1439 |
|
| 1440 |
/* For MERGE, the action currently being executed */ |
| 1441 |
MergeActionState *mt_merge_action; |
| 1442 |
|
| 1443 |
/* |
| 1444 |
* For MERGE, if there is a pending NOT MATCHED [BY TARGET] action to be |
| 1445 |
* performed, this will be the last tuple read from the subplan; otherwise |
| 1446 |
* it will be NULL --- see the comments in ExecMerge(). |
| 1447 |
*/ |
| 1448 |
TupleTableSlot *mt_merge_pending_not_matched; |
| 1449 |
|
| 1450 |
/* tuple counters for MERGE */ |
| 1451 |
double mt_merge_inserted; |
| 1452 |
double mt_merge_updated; |
| 1453 |
double mt_merge_deleted; |
| 1454 |
|
| 1455 |
/* |
| 1456 |
* Lists of valid updateColnosLists, mergeActionLists, and |
| 1457 |
* mergeJoinConditions. These contain only entries for unpruned |
| 1458 |
* relations, filtered from the corresponding lists in ModifyTable. |
| 1459 |
*/ |
| 1460 |
List *mt_updateColnosLists; |
| 1461 |
List *mt_mergeActionLists; |
| 1462 |
List *mt_mergeJoinConditions; |
| 1463 |
} ModifyTableState; |
| 1464 |
|
| 1465 |
/* ---------------- |
| 1466 |
* AppendState information |
| 1467 |
* |
| 1468 |
* nplans how many plans are in the array |
| 1469 |
* whichplan which synchronous plan is being executed (0 .. n-1) |
| 1470 |
* or a special negative value. See nodeAppend.c. |
| 1471 |
* prune_state details required to allow partitions to be |
| 1472 |
* eliminated from the scan, or NULL if not possible. |
| 1473 |
* valid_subplans for runtime pruning, valid synchronous appendplans |
| 1474 |
* indexes to scan. |
| 1475 |
* ---------------- |
| 1476 |
*/ |
| 1477 |
|
| 1478 |
struct AppendState; |
| 1479 |
typedef struct AppendState AppendState; |
| 1480 |
struct ParallelAppendState; |
| 1481 |
typedef struct ParallelAppendState ParallelAppendState; |
| 1482 |
struct PartitionPruneState; |
| 1483 |
|
| 1484 |
struct AppendState |
| 1485 |
{ |
| 1486 |
PlanState ps; /* its first field is NodeTag */ |
| 1487 |
PlanState **appendplans; /* array of PlanStates for my inputs */ |
| 1488 |
int as_nplans; |
| 1489 |
int as_whichplan; |
| 1490 |
bool as_begun; /* false means need to initialize */ |
| 1491 |
Bitmapset *as_asyncplans; /* asynchronous plans indexes */ |
| 1492 |
int as_nasyncplans; /* # of asynchronous plans */ |
| 1493 |
AsyncRequest **as_asyncrequests; /* array of AsyncRequests */ |
| 1494 |
TupleTableSlot **as_asyncresults; /* unreturned results of async plans */ |
| 1495 |
int as_nasyncresults; /* # of valid entries in as_asyncresults */ |
| 1496 |
bool as_syncdone; /* true if all synchronous plans done in |
| 1497 |
* asynchronous mode, else false */ |
| 1498 |
int as_nasyncremain; /* # of remaining asynchronous plans */ |
| 1499 |
Bitmapset *as_needrequest; /* asynchronous plans needing a new request */ |
| 1500 |
struct WaitEventSet *as_eventset; /* WaitEventSet used to configure file |
| 1501 |
* descriptor wait events */ |
| 1502 |
int as_first_partial_plan; /* Index of 'appendplans' containing |
| 1503 |
* the first partial plan */ |
| 1504 |
ParallelAppendState *as_pstate; /* parallel coordination info */ |
| 1505 |
Size pstate_len; /* size of parallel coordination info */ |
| 1506 |
struct PartitionPruneState *as_prune_state; |
| 1507 |
bool as_valid_subplans_identified; /* is as_valid_subplans valid? */ |
| 1508 |
Bitmapset *as_valid_subplans; |
| 1509 |
Bitmapset *as_valid_asyncplans; /* valid asynchronous plans indexes */ |
| 1510 |
bool (*choose_next_subplan) (AppendState *); |
| 1511 |
}; |
| 1512 |
|
| 1513 |
/* ---------------- |
| 1514 |
* MergeAppendState information |
| 1515 |
* |
| 1516 |
* nplans how many plans are in the array |
| 1517 |
* nkeys number of sort key columns |
| 1518 |
* sortkeys sort keys in SortSupport representation |
| 1519 |
* slots current output tuple of each subplan |
| 1520 |
* heap heap of active tuples |
| 1521 |
* initialized true if we have fetched first tuple from each subplan |
| 1522 |
* prune_state details required to allow partitions to be |
| 1523 |
* eliminated from the scan, or NULL if not possible. |
| 1524 |
* valid_subplans for runtime pruning, valid mergeplans indexes to |
| 1525 |
* scan. |
| 1526 |
* ---------------- |
| 1527 |
*/ |
| 1528 |
typedef struct MergeAppendState |
| 1529 |
{ |
| 1530 |
PlanState ps; /* its first field is NodeTag */ |
| 1531 |
PlanState **mergeplans; /* array of PlanStates for my inputs */ |
| 1532 |
int ms_nplans; |
| 1533 |
int ms_nkeys; |
| 1534 |
SortSupport ms_sortkeys; /* array of length ms_nkeys */ |
| 1535 |
TupleTableSlot **ms_slots; /* array of length ms_nplans */ |
| 1536 |
struct binaryheap *ms_heap; /* binary heap of slot indices */ |
| 1537 |
bool ms_initialized; /* are subplans started? */ |
| 1538 |
struct PartitionPruneState *ms_prune_state; |
| 1539 |
Bitmapset *ms_valid_subplans; |
| 1540 |
} MergeAppendState; |
| 1541 |
|
| 1542 |
/* ---------------- |
| 1543 |
* RecursiveUnionState information |
| 1544 |
* |
| 1545 |
* RecursiveUnionState is used for performing a recursive union. |
| 1546 |
* |
| 1547 |
* recursing T when we're done scanning the non-recursive term |
| 1548 |
* intermediate_empty T if intermediate_table is currently empty |
| 1549 |
* working_table working table (to be scanned by recursive term) |
| 1550 |
* intermediate_table current recursive output (next generation of WT) |
| 1551 |
* ---------------- |
| 1552 |
*/ |
| 1553 |
typedef struct RecursiveUnionState |
| 1554 |
{ |
| 1555 |
PlanState ps; /* its first field is NodeTag */ |
| 1556 |
bool recursing; |
| 1557 |
bool intermediate_empty; |
| 1558 |
Tuplestorestate *working_table; |
| 1559 |
Tuplestorestate *intermediate_table; |
| 1560 |
/* Remaining fields are unused in UNION ALL case */ |
| 1561 |
Oid *eqfuncoids; /* per-grouping-field equality fns */ |
| 1562 |
FmgrInfo *hashfunctions; /* per-grouping-field hash fns */ |
| 1563 |
MemoryContext tempContext; /* short-term context for comparisons */ |
| 1564 |
TupleHashTable hashtable; /* hash table for tuples already seen */ |
| 1565 |
MemoryContext tableContext; /* memory context containing hash table */ |
| 1566 |
} RecursiveUnionState; |
| 1567 |
|
| 1568 |
/* ---------------- |
| 1569 |
* BitmapAndState information |
| 1570 |
* ---------------- |
| 1571 |
*/ |
| 1572 |
typedef struct BitmapAndState |
| 1573 |
{ |
| 1574 |
PlanState ps; /* its first field is NodeTag */ |
| 1575 |
PlanState **bitmapplans; /* array of PlanStates for my inputs */ |
| 1576 |
int nplans; /* number of input plans */ |
| 1577 |
} BitmapAndState; |
| 1578 |
|
| 1579 |
/* ---------------- |
| 1580 |
* BitmapOrState information |
| 1581 |
* ---------------- |
| 1582 |
*/ |
| 1583 |
typedef struct BitmapOrState |
| 1584 |
{ |
| 1585 |
PlanState ps; /* its first field is NodeTag */ |
| 1586 |
PlanState **bitmapplans; /* array of PlanStates for my inputs */ |
| 1587 |
int nplans; /* number of input plans */ |
| 1588 |
} BitmapOrState; |
| 1589 |
|
| 1590 |
/* ---------------------------------------------------------------- |
| 1591 |
* Scan State Information |
| 1592 |
* ---------------------------------------------------------------- |
| 1593 |
*/ |
| 1594 |
|
| 1595 |
/* ---------------- |
| 1596 |
* ScanState information |
| 1597 |
* |
| 1598 |
* ScanState extends PlanState for node types that represent |
| 1599 |
* scans of an underlying relation. It can also be used for nodes |
| 1600 |
* that scan the output of an underlying plan node --- in that case, |
| 1601 |
* only ScanTupleSlot is actually useful, and it refers to the tuple |
| 1602 |
* retrieved from the subplan. |
| 1603 |
* |
| 1604 |
* currentRelation relation being scanned (NULL if none) |
| 1605 |
* currentScanDesc current scan descriptor for scan (NULL if none) |
| 1606 |
* ScanTupleSlot pointer to slot in tuple table holding scan tuple |
| 1607 |
* ---------------- |
| 1608 |
*/ |
| 1609 |
typedef struct ScanState |
| 1610 |
{ |
| 1611 |
PlanState ps; /* its first field is NodeTag */ |
| 1612 |
Relation ss_currentRelation; |
| 1613 |
struct TableScanDescData *ss_currentScanDesc; |
| 1614 |
TupleTableSlot *ss_ScanTupleSlot; |
| 1615 |
} ScanState; |
| 1616 |
|
| 1617 |
/* ---------------- |
| 1618 |
* SeqScanState information |
| 1619 |
* ---------------- |
| 1620 |
*/ |
| 1621 |
typedef struct SeqScanState |
| 1622 |
{ |
| 1623 |
ScanState ss; /* its first field is NodeTag */ |
| 1624 |
Size pscan_len; /* size of parallel heap scan descriptor */ |
| 1625 |
} SeqScanState; |
| 1626 |
|
| 1627 |
/* ---------------- |
| 1628 |
* SampleScanState information |
| 1629 |
* ---------------- |
| 1630 |
*/ |
| 1631 |
typedef struct SampleScanState |
| 1632 |
{ |
| 1633 |
ScanState ss; |
| 1634 |
List *args; /* expr states for TABLESAMPLE params */ |
| 1635 |
ExprState *repeatable; /* expr state for REPEATABLE expr */ |
| 1636 |
/* use struct pointer to avoid including tsmapi.h here */ |
| 1637 |
struct TsmRoutine *tsmroutine; /* descriptor for tablesample method */ |
| 1638 |
void *tsm_state; /* tablesample method can keep state here */ |
| 1639 |
bool use_bulkread; /* use bulkread buffer access strategy? */ |
| 1640 |
bool use_pagemode; /* use page-at-a-time visibility checking? */ |
| 1641 |
bool begun; /* false means need to call BeginSampleScan */ |
| 1642 |
uint32 seed; /* random seed */ |
| 1643 |
int64 donetuples; /* number of tuples already returned */ |
| 1644 |
bool haveblock; /* has a block for sampling been determined */ |
| 1645 |
bool done; /* exhausted all tuples? */ |
| 1646 |
} SampleScanState; |
| 1647 |
|
| 1648 |
/* |
| 1649 |
* These structs store information about index quals that don't have simple |
| 1650 |
* constant right-hand sides. See comments for ExecIndexBuildScanKeys() |
| 1651 |
* for discussion. |
| 1652 |
*/ |
| 1653 |
typedef struct |
| 1654 |
{ |
| 1655 |
struct ScanKeyData *scan_key; /* scankey to put value into */ |
| 1656 |
ExprState *key_expr; /* expr to evaluate to get value */ |
| 1657 |
bool key_toastable; /* is expr's result a toastable datatype? */ |
| 1658 |
} IndexRuntimeKeyInfo; |
| 1659 |
|
| 1660 |
typedef struct |
| 1661 |
{ |
| 1662 |
struct ScanKeyData *scan_key; /* scankey to put value into */ |
| 1663 |
ExprState *array_expr; /* expr to evaluate to get array value */ |
| 1664 |
int next_elem; /* next array element to use */ |
| 1665 |
int num_elems; /* number of elems in current array value */ |
| 1666 |
Datum *elem_values; /* array of num_elems Datums */ |
| 1667 |
bool *elem_nulls; /* array of num_elems is-null flags */ |
| 1668 |
} IndexArrayKeyInfo; |
| 1669 |
|
| 1670 |
/* ---------------- |
| 1671 |
* IndexScanState information |
| 1672 |
* |
| 1673 |
* indexqualorig execution state for indexqualorig expressions |
| 1674 |
* indexorderbyorig execution state for indexorderbyorig expressions |
| 1675 |
* ScanKeys Skey structures for index quals |
| 1676 |
* NumScanKeys number of ScanKeys |
| 1677 |
* OrderByKeys Skey structures for index ordering operators |
| 1678 |
* NumOrderByKeys number of OrderByKeys |
| 1679 |
* RuntimeKeys info about Skeys that must be evaluated at runtime |
| 1680 |
* NumRuntimeKeys number of RuntimeKeys |
| 1681 |
* RuntimeKeysReady true if runtime Skeys have been computed |
| 1682 |
* RuntimeContext expr context for evaling runtime Skeys |
| 1683 |
* RelationDesc index relation descriptor |
| 1684 |
* ScanDesc index scan descriptor |
| 1685 |
* Instrument local index scan instrumentation |
| 1686 |
* SharedInfo parallel worker instrumentation (no leader entry) |
| 1687 |
* |
| 1688 |
* ReorderQueue tuples that need reordering due to re-check |
| 1689 |
* ReachedEnd have we fetched all tuples from index already? |
| 1690 |
* OrderByValues values of ORDER BY exprs of last fetched tuple |
| 1691 |
* OrderByNulls null flags for OrderByValues |
| 1692 |
* SortSupport for reordering ORDER BY exprs |
| 1693 |
* OrderByTypByVals is the datatype of order by expression pass-by-value? |
| 1694 |
* OrderByTypLens typlens of the datatypes of order by expressions |
| 1695 |
* PscanLen size of parallel index scan descriptor |
| 1696 |
* ---------------- |
| 1697 |
*/ |
| 1698 |
typedef struct IndexScanState |
| 1699 |
{ |
| 1700 |
ScanState ss; /* its first field is NodeTag */ |
| 1701 |
ExprState *indexqualorig; |
| 1702 |
List *indexorderbyorig; |
| 1703 |
struct ScanKeyData *iss_ScanKeys; |
| 1704 |
int iss_NumScanKeys; |
| 1705 |
struct ScanKeyData *iss_OrderByKeys; |
| 1706 |
int iss_NumOrderByKeys; |
| 1707 |
IndexRuntimeKeyInfo *iss_RuntimeKeys; |
| 1708 |
int iss_NumRuntimeKeys; |
| 1709 |
bool iss_RuntimeKeysReady; |
| 1710 |
ExprContext *iss_RuntimeContext; |
| 1711 |
Relation iss_RelationDesc; |
| 1712 |
struct IndexScanDescData *iss_ScanDesc; |
| 1713 |
IndexScanInstrumentation iss_Instrument; |
| 1714 |
SharedIndexScanInstrumentation *iss_SharedInfo; |
| 1715 |
|
| 1716 |
/* These are needed for re-checking ORDER BY expr ordering */ |
| 1717 |
pairingheap *iss_ReorderQueue; |
| 1718 |
bool iss_ReachedEnd; |
| 1719 |
Datum *iss_OrderByValues; |
| 1720 |
bool *iss_OrderByNulls; |
| 1721 |
SortSupport iss_SortSupport; |
| 1722 |
bool *iss_OrderByTypByVals; |
| 1723 |
int16 *iss_OrderByTypLens; |
| 1724 |
Size iss_PscanLen; |
| 1725 |
} IndexScanState; |
| 1726 |
|
| 1727 |
/* ---------------- |
| 1728 |
* IndexOnlyScanState information |
| 1729 |
* |
| 1730 |
* recheckqual execution state for recheckqual expressions |
| 1731 |
* ScanKeys Skey structures for index quals |
| 1732 |
* NumScanKeys number of ScanKeys |
| 1733 |
* OrderByKeys Skey structures for index ordering operators |
| 1734 |
* NumOrderByKeys number of OrderByKeys |
| 1735 |
* RuntimeKeys info about Skeys that must be evaluated at runtime |
| 1736 |
* NumRuntimeKeys number of RuntimeKeys |
| 1737 |
* RuntimeKeysReady true if runtime Skeys have been computed |
| 1738 |
* RuntimeContext expr context for evaling runtime Skeys |
| 1739 |
* RelationDesc index relation descriptor |
| 1740 |
* ScanDesc index scan descriptor |
| 1741 |
* Instrument local index scan instrumentation |
| 1742 |
* SharedInfo parallel worker instrumentation (no leader entry) |
| 1743 |
* TableSlot slot for holding tuples fetched from the table |
| 1744 |
* VMBuffer buffer in use for visibility map testing, if any |
| 1745 |
* PscanLen size of parallel index-only scan descriptor |
| 1746 |
* NameCStringAttNums attnums of name typed columns to pad to NAMEDATALEN |
| 1747 |
* NameCStringCount number of elements in the NameCStringAttNums array |
| 1748 |
* ---------------- |
| 1749 |
*/ |
| 1750 |
typedef struct IndexOnlyScanState |
| 1751 |
{ |
| 1752 |
ScanState ss; /* its first field is NodeTag */ |
| 1753 |
ExprState *recheckqual; |
| 1754 |
struct ScanKeyData *ioss_ScanKeys; |
| 1755 |
int ioss_NumScanKeys; |
| 1756 |
struct ScanKeyData *ioss_OrderByKeys; |
| 1757 |
int ioss_NumOrderByKeys; |
| 1758 |
IndexRuntimeKeyInfo *ioss_RuntimeKeys; |
| 1759 |
int ioss_NumRuntimeKeys; |
| 1760 |
bool ioss_RuntimeKeysReady; |
| 1761 |
ExprContext *ioss_RuntimeContext; |
| 1762 |
Relation ioss_RelationDesc; |
| 1763 |
struct IndexScanDescData *ioss_ScanDesc; |
| 1764 |
IndexScanInstrumentation ioss_Instrument; |
| 1765 |
SharedIndexScanInstrumentation *ioss_SharedInfo; |
| 1766 |
TupleTableSlot *ioss_TableSlot; |
| 1767 |
Buffer ioss_VMBuffer; |
| 1768 |
Size ioss_PscanLen; |
| 1769 |
AttrNumber *ioss_NameCStringAttNums; |
| 1770 |
int ioss_NameCStringCount; |
| 1771 |
} IndexOnlyScanState; |
| 1772 |
|
| 1773 |
/* ---------------- |
| 1774 |
* BitmapIndexScanState information |
| 1775 |
* |
| 1776 |
* result bitmap to return output into, or NULL |
| 1777 |
* ScanKeys Skey structures for index quals |
| 1778 |
* NumScanKeys number of ScanKeys |
| 1779 |
* RuntimeKeys info about Skeys that must be evaluated at runtime |
| 1780 |
* NumRuntimeKeys number of RuntimeKeys |
| 1781 |
* ArrayKeys info about Skeys that come from ScalarArrayOpExprs |
| 1782 |
* NumArrayKeys number of ArrayKeys |
| 1783 |
* RuntimeKeysReady true if runtime Skeys have been computed |
| 1784 |
* RuntimeContext expr context for evaling runtime Skeys |
| 1785 |
* RelationDesc index relation descriptor |
| 1786 |
* ScanDesc index scan descriptor |
| 1787 |
* Instrument local index scan instrumentation |
| 1788 |
* SharedInfo parallel worker instrumentation (no leader entry) |
| 1789 |
* ---------------- |
| 1790 |
*/ |
| 1791 |
typedef struct BitmapIndexScanState |
| 1792 |
{ |
| 1793 |
ScanState ss; /* its first field is NodeTag */ |
| 1794 |
TIDBitmap *biss_result; |
| 1795 |
struct ScanKeyData *biss_ScanKeys; |
| 1796 |
int biss_NumScanKeys; |
| 1797 |
IndexRuntimeKeyInfo *biss_RuntimeKeys; |
| 1798 |
int biss_NumRuntimeKeys; |
| 1799 |
IndexArrayKeyInfo *biss_ArrayKeys; |
| 1800 |
int biss_NumArrayKeys; |
| 1801 |
bool biss_RuntimeKeysReady; |
| 1802 |
ExprContext *biss_RuntimeContext; |
| 1803 |
Relation biss_RelationDesc; |
| 1804 |
struct IndexScanDescData *biss_ScanDesc; |
| 1805 |
IndexScanInstrumentation biss_Instrument; |
| 1806 |
SharedIndexScanInstrumentation *biss_SharedInfo; |
| 1807 |
} BitmapIndexScanState; |
| 1808 |
|
| 1809 |
/* ---------------- |
| 1810 |
* BitmapHeapScanInstrumentation information |
| 1811 |
* |
| 1812 |
* exact_pages total number of exact pages retrieved |
| 1813 |
* lossy_pages total number of lossy pages retrieved |
| 1814 |
* ---------------- |
| 1815 |
*/ |
| 1816 |
typedef struct BitmapHeapScanInstrumentation |
| 1817 |
{ |
| 1818 |
uint64 exact_pages; |
| 1819 |
uint64 lossy_pages; |
| 1820 |
} BitmapHeapScanInstrumentation; |
| 1821 |
|
| 1822 |
/* ---------------- |
| 1823 |
* SharedBitmapState information |
| 1824 |
* |
| 1825 |
* BM_INITIAL TIDBitmap creation is not yet started, so first worker |
| 1826 |
* to see this state will set the state to BM_INPROGRESS |
| 1827 |
* and that process will be responsible for creating |
| 1828 |
* TIDBitmap. |
| 1829 |
* BM_INPROGRESS TIDBitmap creation is in progress; workers need to |
| 1830 |
* sleep until it's finished. |
| 1831 |
* BM_FINISHED TIDBitmap creation is done, so now all workers can |
| 1832 |
* proceed to iterate over TIDBitmap. |
| 1833 |
* ---------------- |
| 1834 |
*/ |
| 1835 |
typedef enum |
| 1836 |
{ |
| 1837 |
BM_INITIAL, |
| 1838 |
BM_INPROGRESS, |
| 1839 |
BM_FINISHED, |
| 1840 |
} SharedBitmapState; |
| 1841 |
|
| 1842 |
/* ---------------- |
| 1843 |
* ParallelBitmapHeapState information |
| 1844 |
* tbmiterator iterator for scanning current pages |
| 1845 |
* mutex mutual exclusion for state |
| 1846 |
* state current state of the TIDBitmap |
| 1847 |
* cv conditional wait variable |
| 1848 |
* ---------------- |
| 1849 |
*/ |
| 1850 |
typedef struct ParallelBitmapHeapState |
| 1851 |
{ |
| 1852 |
dsa_pointer tbmiterator; |
| 1853 |
slock_t mutex; |
| 1854 |
SharedBitmapState state; |
| 1855 |
ConditionVariable cv; |
| 1856 |
} ParallelBitmapHeapState; |
| 1857 |
|
| 1858 |
/* ---------------- |
| 1859 |
* Instrumentation data for a parallel bitmap heap scan. |
| 1860 |
* |
| 1861 |
* A shared memory struct that each parallel worker copies its |
| 1862 |
* BitmapHeapScanInstrumentation information into at executor shutdown to |
| 1863 |
* allow the leader to display the information in EXPLAIN ANALYZE. |
| 1864 |
* ---------------- |
| 1865 |
*/ |
| 1866 |
typedef struct SharedBitmapHeapInstrumentation |
| 1867 |
{ |
| 1868 |
int num_workers; |
| 1869 |
BitmapHeapScanInstrumentation sinstrument[FLEXIBLE_ARRAY_MEMBER]; |
| 1870 |
} SharedBitmapHeapInstrumentation; |
| 1871 |
|
| 1872 |
/* ---------------- |
| 1873 |
* BitmapHeapScanState information |
| 1874 |
* |
| 1875 |
* bitmapqualorig execution state for bitmapqualorig expressions |
| 1876 |
* tbm bitmap obtained from child index scan(s) |
| 1877 |
* stats execution statistics |
| 1878 |
* initialized is node is ready to iterate |
| 1879 |
* pstate shared state for parallel bitmap scan |
| 1880 |
* sinstrument statistics for parallel workers |
| 1881 |
* recheck do current page's tuples need recheck |
| 1882 |
* ---------------- |
| 1883 |
*/ |
| 1884 |
typedef struct BitmapHeapScanState |
| 1885 |
{ |
| 1886 |
ScanState ss; /* its first field is NodeTag */ |
| 1887 |
ExprState *bitmapqualorig; |
| 1888 |
TIDBitmap *tbm; |
| 1889 |
BitmapHeapScanInstrumentation stats; |
| 1890 |
bool initialized; |
| 1891 |
ParallelBitmapHeapState *pstate; |
| 1892 |
SharedBitmapHeapInstrumentation *sinstrument; |
| 1893 |
bool recheck; |
| 1894 |
} BitmapHeapScanState; |
| 1895 |
|
| 1896 |
/* ---------------- |
| 1897 |
* TidScanState information |
| 1898 |
* |
| 1899 |
* tidexprs list of TidExpr structs (see nodeTidscan.c) |
| 1900 |
* isCurrentOf scan has a CurrentOfExpr qual |
| 1901 |
* NumTids number of tids in this scan |
| 1902 |
* TidPtr index of currently fetched tid |
| 1903 |
* TidList evaluated item pointers (array of size NumTids) |
| 1904 |
* ---------------- |
| 1905 |
*/ |
| 1906 |
typedef struct TidScanState |
| 1907 |
{ |
| 1908 |
ScanState ss; /* its first field is NodeTag */ |
| 1909 |
List *tss_tidexprs; |
| 1910 |
bool tss_isCurrentOf; |
| 1911 |
int tss_NumTids; |
| 1912 |
int tss_TidPtr; |
| 1913 |
ItemPointerData *tss_TidList; |
| 1914 |
} TidScanState; |
| 1915 |
|
| 1916 |
/* ---------------- |
| 1917 |
* TidRangeScanState information |
| 1918 |
* |
| 1919 |
* trss_tidexprs list of TidOpExpr structs (see nodeTidrangescan.c) |
| 1920 |
* trss_mintid the lowest TID in the scan range |
| 1921 |
* trss_maxtid the highest TID in the scan range |
| 1922 |
* trss_inScan is a scan currently in progress? |
| 1923 |
* ---------------- |
| 1924 |
*/ |
| 1925 |
typedef struct TidRangeScanState |
| 1926 |
{ |
| 1927 |
ScanState ss; /* its first field is NodeTag */ |
| 1928 |
List *trss_tidexprs; |
| 1929 |
ItemPointerData trss_mintid; |
| 1930 |
ItemPointerData trss_maxtid; |
| 1931 |
bool trss_inScan; |
| 1932 |
} TidRangeScanState; |
| 1933 |
|
| 1934 |
/* ---------------- |
| 1935 |
* SubqueryScanState information |
| 1936 |
* |
| 1937 |
* SubqueryScanState is used for scanning a sub-query in the range table. |
| 1938 |
* ScanTupleSlot references the current output tuple of the sub-query. |
| 1939 |
* ---------------- |
| 1940 |
*/ |
| 1941 |
typedef struct SubqueryScanState |
| 1942 |
{ |
| 1943 |
ScanState ss; /* its first field is NodeTag */ |
| 1944 |
PlanState *subplan; |
| 1945 |
} SubqueryScanState; |
| 1946 |
|
| 1947 |
/* ---------------- |
| 1948 |
* FunctionScanState information |
| 1949 |
* |
| 1950 |
* Function nodes are used to scan the results of a |
| 1951 |
* function appearing in FROM (typically a function returning set). |
| 1952 |
* |
| 1953 |
* eflags node's capability flags |
| 1954 |
* ordinality is this scan WITH ORDINALITY? |
| 1955 |
* simple true if we have 1 function and no ordinality |
| 1956 |
* ordinal current ordinal column value |
| 1957 |
* nfuncs number of functions being executed |
| 1958 |
* funcstates per-function execution states (private in |
| 1959 |
* nodeFunctionscan.c) |
| 1960 |
* argcontext memory context to evaluate function arguments in |
| 1961 |
* ---------------- |
| 1962 |
*/ |
| 1963 |
struct FunctionScanPerFuncState; |
| 1964 |
|
| 1965 |
typedef struct FunctionScanState |
| 1966 |
{ |
| 1967 |
ScanState ss; /* its first field is NodeTag */ |
| 1968 |
int eflags; |
| 1969 |
bool ordinality; |
| 1970 |
bool simple; |
| 1971 |
int64 ordinal; |
| 1972 |
int nfuncs; |
| 1973 |
struct FunctionScanPerFuncState *funcstates; /* array of length nfuncs */ |
| 1974 |
MemoryContext argcontext; |
| 1975 |
} FunctionScanState; |
| 1976 |
|
| 1977 |
/* ---------------- |
| 1978 |
* ValuesScanState information |
| 1979 |
* |
| 1980 |
* ValuesScan nodes are used to scan the results of a VALUES list |
| 1981 |
* |
| 1982 |
* rowcontext per-expression-list context |
| 1983 |
* exprlists array of expression lists being evaluated |
| 1984 |
* exprstatelists array of expression state lists, for SubPlans only |
| 1985 |
* array_len size of above arrays |
| 1986 |
* curr_idx current array index (0-based) |
| 1987 |
* |
| 1988 |
* Note: ss.ps.ps_ExprContext is used to evaluate any qual or projection |
| 1989 |
* expressions attached to the node. We create a second ExprContext, |
| 1990 |
* rowcontext, in which to build the executor expression state for each |
| 1991 |
* Values sublist. Resetting this context lets us get rid of expression |
| 1992 |
* state for each row, avoiding major memory leakage over a long values list. |
| 1993 |
* However, that doesn't work for sublists containing SubPlans, because a |
| 1994 |
* SubPlan has to be connected up to the outer plan tree to work properly. |
| 1995 |
* Therefore, for only those sublists containing SubPlans, we do expression |
| 1996 |
* state construction at executor start, and store those pointers in |
| 1997 |
* exprstatelists[]. NULL entries in that array correspond to simple |
| 1998 |
* subexpressions that are handled as described above. |
| 1999 |
* ---------------- |
| 2000 |
*/ |
| 2001 |
typedef struct ValuesScanState |
| 2002 |
{ |
| 2003 |
ScanState ss; /* its first field is NodeTag */ |
| 2004 |
ExprContext *rowcontext; |
| 2005 |
List **exprlists; |
| 2006 |
List **exprstatelists; |
| 2007 |
int array_len; |
| 2008 |
int curr_idx; |
| 2009 |
} ValuesScanState; |
| 2010 |
|
| 2011 |
/* ---------------- |
| 2012 |
* TableFuncScanState node |
| 2013 |
* |
| 2014 |
* Used in table-expression functions like XMLTABLE. |
| 2015 |
* ---------------- |
| 2016 |
*/ |
| 2017 |
typedef struct TableFuncScanState |
| 2018 |
{ |
| 2019 |
ScanState ss; /* its first field is NodeTag */ |
| 2020 |
ExprState *docexpr; /* state for document expression */ |
| 2021 |
ExprState *rowexpr; /* state for row-generating expression */ |
| 2022 |
List *colexprs; /* state for column-generating expression */ |
| 2023 |
List *coldefexprs; /* state for column default expressions */ |
| 2024 |
List *colvalexprs; /* state for column value expressions */ |
| 2025 |
List *passingvalexprs; /* state for PASSING argument expressions */ |
| 2026 |
List *ns_names; /* same as TableFunc.ns_names */ |
| 2027 |
List *ns_uris; /* list of states of namespace URI exprs */ |
| 2028 |
Bitmapset *notnulls; /* nullability flag for each output column */ |
| 2029 |
void *opaque; /* table builder private space */ |
| 2030 |
const struct TableFuncRoutine *routine; /* table builder methods */ |
| 2031 |
FmgrInfo *in_functions; /* input function for each column */ |
| 2032 |
Oid *typioparams; /* typioparam for each column */ |
| 2033 |
int64 ordinal; /* row number to be output next */ |
| 2034 |
MemoryContext perTableCxt; /* per-table context */ |
| 2035 |
Tuplestorestate *tupstore; /* output tuple store */ |
| 2036 |
} TableFuncScanState; |
| 2037 |
|
| 2038 |
/* ---------------- |
| 2039 |
* CteScanState information |
| 2040 |
* |
| 2041 |
* CteScan nodes are used to scan a CommonTableExpr query. |
| 2042 |
* |
| 2043 |
* Multiple CteScan nodes can read out from the same CTE query. We use |
| 2044 |
* a tuplestore to hold rows that have been read from the CTE query but |
| 2045 |
* not yet consumed by all readers. |
| 2046 |
* ---------------- |
| 2047 |
*/ |
| 2048 |
typedef struct CteScanState |
| 2049 |
{ |
| 2050 |
ScanState ss; /* its first field is NodeTag */ |
| 2051 |
int eflags; /* capability flags to pass to tuplestore */ |
| 2052 |
int readptr; /* index of my tuplestore read pointer */ |
| 2053 |
PlanState *cteplanstate; /* PlanState for the CTE query itself */ |
| 2054 |
/* Link to the "leader" CteScanState (possibly this same node) */ |
| 2055 |
struct CteScanState *leader; |
| 2056 |
/* The remaining fields are only valid in the "leader" CteScanState */ |
| 2057 |
Tuplestorestate *cte_table; /* rows already read from the CTE query */ |
| 2058 |
bool eof_cte; /* reached end of CTE query? */ |
| 2059 |
} CteScanState; |
| 2060 |
|
| 2061 |
/* ---------------- |
| 2062 |
* NamedTuplestoreScanState information |
| 2063 |
* |
| 2064 |
* NamedTuplestoreScan nodes are used to scan a Tuplestore created and |
| 2065 |
* named prior to execution of the query. An example is a transition |
| 2066 |
* table for an AFTER trigger. |
| 2067 |
* |
| 2068 |
* Multiple NamedTuplestoreScan nodes can read out from the same Tuplestore. |
| 2069 |
* ---------------- |
| 2070 |
*/ |
| 2071 |
typedef struct NamedTuplestoreScanState |
| 2072 |
{ |
| 2073 |
ScanState ss; /* its first field is NodeTag */ |
| 2074 |
int readptr; /* index of my tuplestore read pointer */ |
| 2075 |
TupleDesc tupdesc; /* format of the tuples in the tuplestore */ |
| 2076 |
Tuplestorestate *relation; /* the rows */ |
| 2077 |
} NamedTuplestoreScanState; |
| 2078 |
|
| 2079 |
/* ---------------- |
| 2080 |
* WorkTableScanState information |
| 2081 |
* |
| 2082 |
* WorkTableScan nodes are used to scan the work table created by |
| 2083 |
* a RecursiveUnion node. We locate the RecursiveUnion node |
| 2084 |
* during executor startup. |
| 2085 |
* ---------------- |
| 2086 |
*/ |
| 2087 |
typedef struct WorkTableScanState |
| 2088 |
{ |
| 2089 |
ScanState ss; /* its first field is NodeTag */ |
| 2090 |
RecursiveUnionState *rustate; |
| 2091 |
} WorkTableScanState; |
| 2092 |
|
| 2093 |
/* ---------------- |
| 2094 |
* ForeignScanState information |
| 2095 |
* |
| 2096 |
* ForeignScan nodes are used to scan foreign-data tables. |
| 2097 |
* ---------------- |
| 2098 |
*/ |
| 2099 |
typedef struct ForeignScanState |
| 2100 |
{ |
| 2101 |
ScanState ss; /* its first field is NodeTag */ |
| 2102 |
ExprState *fdw_recheck_quals; /* original quals not in ss.ps.qual */ |
| 2103 |
Size pscan_len; /* size of parallel coordination information */ |
| 2104 |
ResultRelInfo *resultRelInfo; /* result rel info, if UPDATE or DELETE */ |
| 2105 |
/* use struct pointer to avoid including fdwapi.h here */ |
| 2106 |
struct FdwRoutine *fdwroutine; |
| 2107 |
void *fdw_state; /* foreign-data wrapper can keep state here */ |
| 2108 |
} ForeignScanState; |
| 2109 |
|
| 2110 |
/* ---------------- |
| 2111 |
* CustomScanState information |
| 2112 |
* |
| 2113 |
* CustomScan nodes are used to execute custom code within executor. |
| 2114 |
* |
| 2115 |
* Core code must avoid assuming that the CustomScanState is only as large as |
| 2116 |
* the structure declared here; providers are allowed to make it the first |
| 2117 |
* element in a larger structure, and typically would need to do so. The |
| 2118 |
* struct is actually allocated by the CreateCustomScanState method associated |
| 2119 |
* with the plan node. Any additional fields can be initialized there, or in |
| 2120 |
* the BeginCustomScan method. |
| 2121 |
* ---------------- |
| 2122 |
*/ |
| 2123 |
struct CustomExecMethods; |
| 2124 |
|
| 2125 |
typedef struct CustomScanState |
| 2126 |
{ |
| 2127 |
ScanState ss; |
| 2128 |
uint32 flags; /* mask of CUSTOMPATH_* flags, see |
| 2129 |
* nodes/extensible.h */ |
| 2130 |
List *custom_ps; /* list of child PlanState nodes, if any */ |
| 2131 |
Size pscan_len; /* size of parallel coordination information */ |
| 2132 |
const struct CustomExecMethods *methods; |
| 2133 |
const struct TupleTableSlotOps *slotOps; |
| 2134 |
} CustomScanState; |
| 2135 |
|
| 2136 |
/* ---------------------------------------------------------------- |
| 2137 |
* Join State Information |
| 2138 |
* ---------------------------------------------------------------- |
| 2139 |
*/ |
| 2140 |
|
| 2141 |
/* ---------------- |
| 2142 |
* JoinState information |
| 2143 |
* |
| 2144 |
* Superclass for state nodes of join plans. |
| 2145 |
* ---------------- |
| 2146 |
*/ |
| 2147 |
typedef struct JoinState |
| 2148 |
{ |
| 2149 |
PlanState ps; |
| 2150 |
JoinType jointype; |
| 2151 |
bool single_match; /* True if we should skip to next outer tuple |
| 2152 |
* after finding one inner match */ |
| 2153 |
ExprState *joinqual; /* JOIN quals (in addition to ps.qual) */ |
| 2154 |
} JoinState; |
| 2155 |
|
| 2156 |
/* ---------------- |
| 2157 |
* NestLoopState information |
| 2158 |
* |
| 2159 |
* NeedNewOuter true if need new outer tuple on next call |
| 2160 |
* MatchedOuter true if found a join match for current outer tuple |
| 2161 |
* NullInnerTupleSlot prepared null tuple for left outer joins |
| 2162 |
* ---------------- |
| 2163 |
*/ |
| 2164 |
typedef struct NestLoopState |
| 2165 |
{ |
| 2166 |
JoinState js; /* its first field is NodeTag */ |
| 2167 |
bool nl_NeedNewOuter; |
| 2168 |
bool nl_MatchedOuter; |
| 2169 |
TupleTableSlot *nl_NullInnerTupleSlot; |
| 2170 |
} NestLoopState; |
| 2171 |
|
| 2172 |
/* ---------------- |
| 2173 |
* MergeJoinState information |
| 2174 |
* |
| 2175 |
* NumClauses number of mergejoinable join clauses |
| 2176 |
* Clauses info for each mergejoinable clause |
| 2177 |
* JoinState current state of ExecMergeJoin state machine |
| 2178 |
* SkipMarkRestore true if we may skip Mark and Restore operations |
| 2179 |
* ExtraMarks true to issue extra Mark operations on inner scan |
| 2180 |
* ConstFalseJoin true if we have a constant-false joinqual |
| 2181 |
* FillOuter true if should emit unjoined outer tuples anyway |
| 2182 |
* FillInner true if should emit unjoined inner tuples anyway |
| 2183 |
* MatchedOuter true if found a join match for current outer tuple |
| 2184 |
* MatchedInner true if found a join match for current inner tuple |
| 2185 |
* OuterTupleSlot slot in tuple table for cur outer tuple |
| 2186 |
* InnerTupleSlot slot in tuple table for cur inner tuple |
| 2187 |
* MarkedTupleSlot slot in tuple table for marked tuple |
| 2188 |
* NullOuterTupleSlot prepared null tuple for right outer joins |
| 2189 |
* NullInnerTupleSlot prepared null tuple for left outer joins |
| 2190 |
* OuterEContext workspace for computing outer tuple's join values |
| 2191 |
* InnerEContext workspace for computing inner tuple's join values |
| 2192 |
* ---------------- |
| 2193 |
*/ |
| 2194 |
/* private in nodeMergejoin.c: */ |
| 2195 |
typedef struct MergeJoinClauseData *MergeJoinClause; |
| 2196 |
|
| 2197 |
typedef struct MergeJoinState |
| 2198 |
{ |
| 2199 |
JoinState js; /* its first field is NodeTag */ |
| 2200 |
int mj_NumClauses; |
| 2201 |
MergeJoinClause mj_Clauses; /* array of length mj_NumClauses */ |
| 2202 |
int mj_JoinState; |
| 2203 |
bool mj_SkipMarkRestore; |
| 2204 |
bool mj_ExtraMarks; |
| 2205 |
bool mj_ConstFalseJoin; |
| 2206 |
bool mj_FillOuter; |
| 2207 |
bool mj_FillInner; |
| 2208 |
bool mj_MatchedOuter; |
| 2209 |
bool mj_MatchedInner; |
| 2210 |
TupleTableSlot *mj_OuterTupleSlot; |
| 2211 |
TupleTableSlot *mj_InnerTupleSlot; |
| 2212 |
TupleTableSlot *mj_MarkedTupleSlot; |
| 2213 |
TupleTableSlot *mj_NullOuterTupleSlot; |
| 2214 |
TupleTableSlot *mj_NullInnerTupleSlot; |
| 2215 |
ExprContext *mj_OuterEContext; |
| 2216 |
ExprContext *mj_InnerEContext; |
| 2217 |
} MergeJoinState; |
| 2218 |
|
| 2219 |
/* ---------------- |
| 2220 |
* HashJoinState information |
| 2221 |
* |
| 2222 |
* hashclauses original form of the hashjoin condition |
| 2223 |
* hj_OuterHash ExprState for hashing outer keys |
| 2224 |
* hj_HashTable hash table for the hashjoin |
| 2225 |
* (NULL if table not built yet) |
| 2226 |
* hj_CurHashValue hash value for current outer tuple |
| 2227 |
* hj_CurBucketNo regular bucket# for current outer tuple |
| 2228 |
* hj_CurSkewBucketNo skew bucket# for current outer tuple |
| 2229 |
* hj_CurTuple last inner tuple matched to current outer |
| 2230 |
* tuple, or NULL if starting search |
| 2231 |
* (hj_CurXXX variables are undefined if |
| 2232 |
* OuterTupleSlot is empty!) |
| 2233 |
* hj_OuterTupleSlot tuple slot for outer tuples |
| 2234 |
* hj_HashTupleSlot tuple slot for inner (hashed) tuples |
| 2235 |
* hj_NullOuterTupleSlot prepared null tuple for right/right-anti/full |
| 2236 |
* outer joins |
| 2237 |
* hj_NullInnerTupleSlot prepared null tuple for left/full outer joins |
| 2238 |
* hj_FirstOuterTupleSlot first tuple retrieved from outer plan |
| 2239 |
* hj_JoinState current state of ExecHashJoin state machine |
| 2240 |
* hj_MatchedOuter true if found a join match for current outer |
| 2241 |
* hj_OuterNotEmpty true if outer relation known not empty |
| 2242 |
* ---------------- |
| 2243 |
*/ |
| 2244 |
|
| 2245 |
/* these structs are defined in executor/hashjoin.h: */ |
| 2246 |
typedef struct HashJoinTupleData *HashJoinTuple; |
| 2247 |
typedef struct HashJoinTableData *HashJoinTable; |
| 2248 |
|
| 2249 |
typedef struct HashJoinState |
| 2250 |
{ |
| 2251 |
JoinState js; /* its first field is NodeTag */ |
| 2252 |
ExprState *hashclauses; |
| 2253 |
ExprState *hj_OuterHash; |
| 2254 |
HashJoinTable hj_HashTable; |
| 2255 |
uint32 hj_CurHashValue; |
| 2256 |
int hj_CurBucketNo; |
| 2257 |
int hj_CurSkewBucketNo; |
| 2258 |
HashJoinTuple hj_CurTuple; |
| 2259 |
TupleTableSlot *hj_OuterTupleSlot; |
| 2260 |
TupleTableSlot *hj_HashTupleSlot; |
| 2261 |
TupleTableSlot *hj_NullOuterTupleSlot; |
| 2262 |
TupleTableSlot *hj_NullInnerTupleSlot; |
| 2263 |
TupleTableSlot *hj_FirstOuterTupleSlot; |
| 2264 |
int hj_JoinState; |
| 2265 |
bool hj_MatchedOuter; |
| 2266 |
bool hj_OuterNotEmpty; |
| 2267 |
} HashJoinState; |
| 2268 |
|
| 2269 |
|
| 2270 |
/* ---------------------------------------------------------------- |
| 2271 |
* Materialization State Information |
| 2272 |
* ---------------------------------------------------------------- |
| 2273 |
*/ |
| 2274 |
|
| 2275 |
/* ---------------- |
| 2276 |
* MaterialState information |
| 2277 |
* |
| 2278 |
* materialize nodes are used to materialize the results |
| 2279 |
* of a subplan into a temporary file. |
| 2280 |
* |
| 2281 |
* ss.ss_ScanTupleSlot refers to output of underlying plan. |
| 2282 |
* ---------------- |
| 2283 |
*/ |
| 2284 |
typedef struct MaterialState |
| 2285 |
{ |
| 2286 |
ScanState ss; /* its first field is NodeTag */ |
| 2287 |
int eflags; /* capability flags to pass to tuplestore */ |
| 2288 |
bool eof_underlying; /* reached end of underlying plan? */ |
| 2289 |
Tuplestorestate *tuplestorestate; |
| 2290 |
} MaterialState; |
| 2291 |
|
| 2292 |
struct MemoizeEntry; |
| 2293 |
struct MemoizeTuple; |
| 2294 |
struct MemoizeKey; |
| 2295 |
|
| 2296 |
typedef struct MemoizeInstrumentation |
| 2297 |
{ |
| 2298 |
uint64 cache_hits; /* number of rescans where we've found the |
| 2299 |
* scan parameter values to be cached */ |
| 2300 |
uint64 cache_misses; /* number of rescans where we've not found the |
| 2301 |
* scan parameter values to be cached. */ |
| 2302 |
uint64 cache_evictions; /* number of cache entries removed due to |
| 2303 |
* the need to free memory */ |
| 2304 |
uint64 cache_overflows; /* number of times we've had to bypass the |
| 2305 |
* cache when filling it due to not being |
| 2306 |
* able to free enough space to store the |
| 2307 |
* current scan's tuples. */ |
| 2308 |
uint64 mem_peak; /* peak memory usage in bytes */ |
| 2309 |
} MemoizeInstrumentation; |
| 2310 |
|
| 2311 |
/* ---------------- |
| 2312 |
* Shared memory container for per-worker memoize information |
| 2313 |
* ---------------- |
| 2314 |
*/ |
| 2315 |
typedef struct SharedMemoizeInfo |
| 2316 |
{ |
| 2317 |
int num_workers; |
| 2318 |
MemoizeInstrumentation sinstrument[FLEXIBLE_ARRAY_MEMBER]; |
| 2319 |
} SharedMemoizeInfo; |
| 2320 |
|
| 2321 |
/* ---------------- |
| 2322 |
* MemoizeState information |
| 2323 |
* |
| 2324 |
* memoize nodes are used to cache recent and commonly seen results from |
| 2325 |
* a parameterized scan. |
| 2326 |
* ---------------- |
| 2327 |
*/ |
| 2328 |
typedef struct MemoizeState |
| 2329 |
{ |
| 2330 |
ScanState ss; /* its first field is NodeTag */ |
| 2331 |
int mstatus; /* value of ExecMemoize state machine */ |
| 2332 |
int nkeys; /* number of cache keys */ |
| 2333 |
struct memoize_hash *hashtable; /* hash table for cache entries */ |
| 2334 |
TupleDesc hashkeydesc; /* tuple descriptor for cache keys */ |
| 2335 |
TupleTableSlot *tableslot; /* min tuple slot for existing cache entries */ |
| 2336 |
TupleTableSlot *probeslot; /* virtual slot used for hash lookups */ |
| 2337 |
ExprState *cache_eq_expr; /* Compare exec params to hash key */ |
| 2338 |
ExprState **param_exprs; /* exprs containing the parameters to this |
| 2339 |
* node */ |
| 2340 |
FmgrInfo *hashfunctions; /* lookup data for hash funcs nkeys in size */ |
| 2341 |
Oid *collations; /* collation for comparisons nkeys in size */ |
| 2342 |
uint64 mem_used; /* bytes of memory used by cache */ |
| 2343 |
uint64 mem_limit; /* memory limit in bytes for the cache */ |
| 2344 |
MemoryContext tableContext; /* memory context to store cache data */ |
| 2345 |
dlist_head lru_list; /* least recently used entry list */ |
| 2346 |
struct MemoizeTuple *last_tuple; /* Used to point to the last tuple |
| 2347 |
* returned during a cache hit and the |
| 2348 |
* tuple we last stored when |
| 2349 |
* populating the cache. */ |
| 2350 |
struct MemoizeEntry *entry; /* the entry that 'last_tuple' belongs to or |
| 2351 |
* NULL if 'last_tuple' is NULL. */ |
| 2352 |
bool singlerow; /* true if the cache entry is to be marked as |
| 2353 |
* complete after caching the first tuple. */ |
| 2354 |
bool binary_mode; /* true when cache key should be compared bit |
| 2355 |
* by bit, false when using hash equality ops */ |
| 2356 |
MemoizeInstrumentation stats; /* execution statistics */ |
| 2357 |
SharedMemoizeInfo *shared_info; /* statistics for parallel workers */ |
| 2358 |
Bitmapset *keyparamids; /* Param->paramids of expressions belonging to |
| 2359 |
* param_exprs */ |
| 2360 |
} MemoizeState; |
| 2361 |
|
| 2362 |
/* ---------------- |
| 2363 |
* When performing sorting by multiple keys, it's possible that the input |
| 2364 |
* dataset is already sorted on a prefix of those keys. We call these |
| 2365 |
* "presorted keys". |
| 2366 |
* PresortedKeyData represents information about one such key. |
| 2367 |
* ---------------- |
| 2368 |
*/ |
| 2369 |
typedef struct PresortedKeyData |
| 2370 |
{ |
| 2371 |
FmgrInfo flinfo; /* comparison function info */ |
| 2372 |
FunctionCallInfo fcinfo; /* comparison function call info */ |
| 2373 |
OffsetNumber attno; /* attribute number in tuple */ |
| 2374 |
} PresortedKeyData; |
| 2375 |
|
| 2376 |
/* ---------------- |
| 2377 |
* Shared memory container for per-worker sort information |
| 2378 |
* ---------------- |
| 2379 |
*/ |
| 2380 |
typedef struct SharedSortInfo |
| 2381 |
{ |
| 2382 |
int num_workers; |
| 2383 |
TuplesortInstrumentation sinstrument[FLEXIBLE_ARRAY_MEMBER]; |
| 2384 |
} SharedSortInfo; |
| 2385 |
|
| 2386 |
/* ---------------- |
| 2387 |
* SortState information |
| 2388 |
* ---------------- |
| 2389 |
*/ |
| 2390 |
typedef struct SortState |
| 2391 |
{ |
| 2392 |
ScanState ss; /* its first field is NodeTag */ |
| 2393 |
bool randomAccess; /* need random access to sort output? */ |
| 2394 |
bool bounded; /* is the result set bounded? */ |
| 2395 |
int64 bound; /* if bounded, how many tuples are needed */ |
| 2396 |
bool sort_Done; /* sort completed yet? */ |
| 2397 |
bool bounded_Done; /* value of bounded we did the sort with */ |
| 2398 |
int64 bound_Done; /* value of bound we did the sort with */ |
| 2399 |
void *tuplesortstate; /* private state of tuplesort.c */ |
| 2400 |
bool am_worker; /* are we a worker? */ |
| 2401 |
bool datumSort; /* Datum sort instead of tuple sort? */ |
| 2402 |
SharedSortInfo *shared_info; /* one entry per worker */ |
| 2403 |
} SortState; |
| 2404 |
|
| 2405 |
/* ---------------- |
| 2406 |
* Instrumentation information for IncrementalSort |
| 2407 |
* ---------------- |
| 2408 |
*/ |
| 2409 |
typedef struct IncrementalSortGroupInfo |
| 2410 |
{ |
| 2411 |
int64 groupCount; |
| 2412 |
int64 maxDiskSpaceUsed; |
| 2413 |
int64 totalDiskSpaceUsed; |
| 2414 |
int64 maxMemorySpaceUsed; |
| 2415 |
int64 totalMemorySpaceUsed; |
| 2416 |
bits32 sortMethods; /* bitmask of TuplesortMethod */ |
| 2417 |
} IncrementalSortGroupInfo; |
| 2418 |
|
| 2419 |
typedef struct IncrementalSortInfo |
| 2420 |
{ |
| 2421 |
IncrementalSortGroupInfo fullsortGroupInfo; |
| 2422 |
IncrementalSortGroupInfo prefixsortGroupInfo; |
| 2423 |
} IncrementalSortInfo; |
| 2424 |
|
| 2425 |
/* ---------------- |
| 2426 |
* Shared memory container for per-worker incremental sort information |
| 2427 |
* ---------------- |
| 2428 |
*/ |
| 2429 |
typedef struct SharedIncrementalSortInfo |
| 2430 |
{ |
| 2431 |
int num_workers; |
| 2432 |
IncrementalSortInfo sinfo[FLEXIBLE_ARRAY_MEMBER]; |
| 2433 |
} SharedIncrementalSortInfo; |
| 2434 |
|
| 2435 |
/* ---------------- |
| 2436 |
* IncrementalSortState information |
| 2437 |
* ---------------- |
| 2438 |
*/ |
| 2439 |
typedef enum |
| 2440 |
{ |
| 2441 |
INCSORT_LOADFULLSORT, |
| 2442 |
INCSORT_LOADPREFIXSORT, |
| 2443 |
INCSORT_READFULLSORT, |
| 2444 |
INCSORT_READPREFIXSORT, |
| 2445 |
} IncrementalSortExecutionStatus; |
| 2446 |
|
| 2447 |
typedef struct IncrementalSortState |
| 2448 |
{ |
| 2449 |
ScanState ss; /* its first field is NodeTag */ |
| 2450 |
bool bounded; /* is the result set bounded? */ |
| 2451 |
int64 bound; /* if bounded, how many tuples are needed */ |
| 2452 |
bool outerNodeDone; /* finished fetching tuples from outer node */ |
| 2453 |
int64 bound_Done; /* value of bound we did the sort with */ |
| 2454 |
IncrementalSortExecutionStatus execution_status; |
| 2455 |
int64 n_fullsort_remaining; |
| 2456 |
Tuplesortstate *fullsort_state; /* private state of tuplesort.c */ |
| 2457 |
Tuplesortstate *prefixsort_state; /* private state of tuplesort.c */ |
| 2458 |
/* the keys by which the input path is already sorted */ |
| 2459 |
PresortedKeyData *presorted_keys; |
| 2460 |
|
| 2461 |
IncrementalSortInfo incsort_info; |
| 2462 |
|
| 2463 |
/* slot for pivot tuple defining values of presorted keys within group */ |
| 2464 |
TupleTableSlot *group_pivot; |
| 2465 |
TupleTableSlot *transfer_tuple; |
| 2466 |
bool am_worker; /* are we a worker? */ |
| 2467 |
SharedIncrementalSortInfo *shared_info; /* one entry per worker */ |
| 2468 |
} IncrementalSortState; |
| 2469 |
|
| 2470 |
/* --------------------- |
| 2471 |
* GroupState information |
| 2472 |
* --------------------- |
| 2473 |
*/ |
| 2474 |
typedef struct GroupState |
| 2475 |
{ |
| 2476 |
ScanState ss; /* its first field is NodeTag */ |
| 2477 |
ExprState *eqfunction; /* equality function */ |
| 2478 |
bool grp_done; /* indicates completion of Group scan */ |
| 2479 |
} GroupState; |
| 2480 |
|
| 2481 |
/* --------------------- |
| 2482 |
* per-worker aggregate information |
| 2483 |
* --------------------- |
| 2484 |
*/ |
| 2485 |
typedef struct AggregateInstrumentation |
| 2486 |
{ |
| 2487 |
Size hash_mem_peak; /* peak hash table memory usage */ |
| 2488 |
uint64 hash_disk_used; /* kB of disk space used */ |
| 2489 |
int hash_batches_used; /* batches used during entire execution */ |
| 2490 |
} AggregateInstrumentation; |
| 2491 |
|
| 2492 |
/* ---------------- |
| 2493 |
* Shared memory container for per-worker aggregate information |
| 2494 |
* ---------------- |
| 2495 |
*/ |
| 2496 |
typedef struct SharedAggInfo |
| 2497 |
{ |
| 2498 |
int num_workers; |
| 2499 |
AggregateInstrumentation sinstrument[FLEXIBLE_ARRAY_MEMBER]; |
| 2500 |
} SharedAggInfo; |
| 2501 |
|
| 2502 |
/* --------------------- |
| 2503 |
* AggState information |
| 2504 |
* |
| 2505 |
* ss.ss_ScanTupleSlot refers to output of underlying plan. |
| 2506 |
* |
| 2507 |
* Note: ss.ps.ps_ExprContext contains ecxt_aggvalues and |
| 2508 |
* ecxt_aggnulls arrays, which hold the computed agg values for the current |
| 2509 |
* input group during evaluation of an Agg node's output tuple(s). We |
| 2510 |
* create a second ExprContext, tmpcontext, in which to evaluate input |
| 2511 |
* expressions and run the aggregate transition functions. |
| 2512 |
* --------------------- |
| 2513 |
*/ |
| 2514 |
/* these structs are private in nodeAgg.c: */ |
| 2515 |
typedef struct AggStatePerAggData *AggStatePerAgg; |
| 2516 |
typedef struct AggStatePerTransData *AggStatePerTrans; |
| 2517 |
typedef struct AggStatePerGroupData *AggStatePerGroup; |
| 2518 |
typedef struct AggStatePerPhaseData *AggStatePerPhase; |
| 2519 |
typedef struct AggStatePerHashData *AggStatePerHash; |
| 2520 |
|
| 2521 |
typedef struct AggState |
| 2522 |
{ |
| 2523 |
ScanState ss; /* its first field is NodeTag */ |
| 2524 |
List *aggs; /* all Aggref nodes in targetlist & quals */ |
| 2525 |
int numaggs; /* length of list (could be zero!) */ |
| 2526 |
int numtrans; /* number of pertrans items */ |
| 2527 |
AggStrategy aggstrategy; /* strategy mode */ |
| 2528 |
AggSplit aggsplit; /* agg-splitting mode, see nodes.h */ |
| 2529 |
AggStatePerPhase phase; /* pointer to current phase data */ |
| 2530 |
int numphases; /* number of phases (including phase 0) */ |
| 2531 |
int current_phase; /* current phase number */ |
| 2532 |
AggStatePerAgg peragg; /* per-Aggref information */ |
| 2533 |
AggStatePerTrans pertrans; /* per-Trans state information */ |
| 2534 |
ExprContext *hashcontext; /* econtexts for long-lived data (hashtable) */ |
| 2535 |
ExprContext **aggcontexts; /* econtexts for long-lived data (per GS) */ |
| 2536 |
ExprContext *tmpcontext; /* econtext for input expressions */ |
| 2537 |
#define FIELDNO_AGGSTATE_CURAGGCONTEXT 14 |
| 2538 |
ExprContext *curaggcontext; /* currently active aggcontext */ |
| 2539 |
AggStatePerAgg curperagg; /* currently active aggregate, if any */ |
| 2540 |
#define FIELDNO_AGGSTATE_CURPERTRANS 16 |
| 2541 |
AggStatePerTrans curpertrans; /* currently active trans state, if any */ |
| 2542 |
bool input_done; /* indicates end of input */ |
| 2543 |
bool agg_done; /* indicates completion of Agg scan */ |
| 2544 |
int projected_set; /* The last projected grouping set */ |
| 2545 |
#define FIELDNO_AGGSTATE_CURRENT_SET 20 |
| 2546 |
int current_set; /* The current grouping set being evaluated */ |
| 2547 |
Bitmapset *grouped_cols; /* grouped cols in current projection */ |
| 2548 |
List *all_grouped_cols; /* list of all grouped cols in DESC order */ |
| 2549 |
Bitmapset *colnos_needed; /* all columns needed from the outer plan */ |
| 2550 |
int max_colno_needed; /* highest colno needed from outer plan */ |
| 2551 |
bool all_cols_needed; /* are all cols from outer plan needed? */ |
| 2552 |
/* These fields are for grouping set phase data */ |
| 2553 |
int maxsets; /* The max number of sets in any phase */ |
| 2554 |
AggStatePerPhase phases; /* array of all phases */ |
| 2555 |
Tuplesortstate *sort_in; /* sorted input to phases > 1 */ |
| 2556 |
Tuplesortstate *sort_out; /* input is copied here for next phase */ |
| 2557 |
TupleTableSlot *sort_slot; /* slot for sort results */ |
| 2558 |
/* these fields are used in AGG_PLAIN and AGG_SORTED modes: */ |
| 2559 |
AggStatePerGroup *pergroups; /* grouping set indexed array of per-group |
| 2560 |
* pointers */ |
| 2561 |
HeapTuple grp_firstTuple; /* copy of first tuple of current group */ |
| 2562 |
/* these fields are used in AGG_HASHED and AGG_MIXED modes: */ |
| 2563 |
bool table_filled; /* hash table filled yet? */ |
| 2564 |
int num_hashes; |
| 2565 |
MemoryContext hash_metacxt; /* memory for hash table bucket array */ |
| 2566 |
MemoryContext hash_tablecxt; /* memory for hash table entries */ |
| 2567 |
struct LogicalTapeSet *hash_tapeset; /* tape set for hash spill tapes */ |
| 2568 |
struct HashAggSpill *hash_spills; /* HashAggSpill for each grouping set, |
| 2569 |
* exists only during first pass */ |
| 2570 |
TupleTableSlot *hash_spill_rslot; /* for reading spill files */ |
| 2571 |
TupleTableSlot *hash_spill_wslot; /* for writing spill files */ |
| 2572 |
List *hash_batches; /* hash batches remaining to be processed */ |
| 2573 |
bool hash_ever_spilled; /* ever spilled during this execution? */ |
| 2574 |
bool hash_spill_mode; /* we hit a limit during the current batch |
| 2575 |
* and we must not create new groups */ |
| 2576 |
Size hash_mem_limit; /* limit before spilling hash table */ |
| 2577 |
uint64 hash_ngroups_limit; /* limit before spilling hash table */ |
| 2578 |
int hash_planned_partitions; /* number of partitions planned |
| 2579 |
* for first pass */ |
| 2580 |
double hashentrysize; /* estimate revised during execution */ |
| 2581 |
Size hash_mem_peak; /* peak hash table memory usage */ |
| 2582 |
uint64 hash_ngroups_current; /* number of groups currently in |
| 2583 |
* memory in all hash tables */ |
| 2584 |
uint64 hash_disk_used; /* kB of disk space used */ |
| 2585 |
int hash_batches_used; /* batches used during entire execution */ |
| 2586 |
|
| 2587 |
AggStatePerHash perhash; /* array of per-hashtable data */ |
| 2588 |
AggStatePerGroup *hash_pergroup; /* grouping set indexed array of |
| 2589 |
* per-group pointers */ |
| 2590 |
|
| 2591 |
/* support for evaluation of agg input expressions: */ |
| 2592 |
#define FIELDNO_AGGSTATE_ALL_PERGROUPS 54 |
| 2593 |
AggStatePerGroup *all_pergroups; /* array of first ->pergroups, than |
| 2594 |
* ->hash_pergroup */ |
| 2595 |
SharedAggInfo *shared_info; /* one entry per worker */ |
| 2596 |
} AggState; |
| 2597 |
|
| 2598 |
/* ---------------- |
| 2599 |
* WindowAggState information |
| 2600 |
* ---------------- |
| 2601 |
*/ |
| 2602 |
/* these structs are private in nodeWindowAgg.c: */ |
| 2603 |
typedef struct WindowStatePerFuncData *WindowStatePerFunc; |
| 2604 |
typedef struct WindowStatePerAggData *WindowStatePerAgg; |
| 2605 |
|
| 2606 |
/* |
| 2607 |
* WindowAggStatus -- Used to track the status of WindowAggState |
| 2608 |
*/ |
| 2609 |
typedef enum WindowAggStatus |
| 2610 |
{ |
| 2611 |
WINDOWAGG_DONE, /* No more processing to do */ |
| 2612 |
WINDOWAGG_RUN, /* Normal processing of window funcs */ |
| 2613 |
WINDOWAGG_PASSTHROUGH, /* Don't eval window funcs */ |
| 2614 |
WINDOWAGG_PASSTHROUGH_STRICT, /* Pass-through plus don't store new |
| 2615 |
* tuples during spool */ |
| 2616 |
} WindowAggStatus; |
| 2617 |
|
| 2618 |
typedef struct WindowAggState |
| 2619 |
{ |
| 2620 |
ScanState ss; /* its first field is NodeTag */ |
| 2621 |
|
| 2622 |
/* these fields are filled in by ExecInitExpr: */ |
| 2623 |
List *funcs; /* all WindowFunc nodes in targetlist */ |
| 2624 |
int numfuncs; /* total number of window functions */ |
| 2625 |
int numaggs; /* number that are plain aggregates */ |
| 2626 |
|
| 2627 |
WindowStatePerFunc perfunc; /* per-window-function information */ |
| 2628 |
WindowStatePerAgg peragg; /* per-plain-aggregate information */ |
| 2629 |
ExprState *partEqfunction; /* equality funcs for partition columns */ |
| 2630 |
ExprState *ordEqfunction; /* equality funcs for ordering columns */ |
| 2631 |
Tuplestorestate *buffer; /* stores rows of current partition */ |
| 2632 |
int current_ptr; /* read pointer # for current row */ |
| 2633 |
int framehead_ptr; /* read pointer # for frame head, if used */ |
| 2634 |
int frametail_ptr; /* read pointer # for frame tail, if used */ |
| 2635 |
int grouptail_ptr; /* read pointer # for group tail, if used */ |
| 2636 |
int64 spooled_rows; /* total # of rows in buffer */ |
| 2637 |
int64 currentpos; /* position of current row in partition */ |
| 2638 |
int64 frameheadpos; /* current frame head position */ |
| 2639 |
int64 frametailpos; /* current frame tail position (frame end+1) */ |
| 2640 |
/* use struct pointer to avoid including windowapi.h here */ |
| 2641 |
struct WindowObjectData *agg_winobj; /* winobj for aggregate fetches */ |
| 2642 |
int64 aggregatedbase; /* start row for current aggregates */ |
| 2643 |
int64 aggregatedupto; /* rows before this one are aggregated */ |
| 2644 |
WindowAggStatus status; /* run status of WindowAggState */ |
| 2645 |
|
| 2646 |
int frameOptions; /* frame_clause options, see WindowDef */ |
| 2647 |
ExprState *startOffset; /* expression for starting bound offset */ |
| 2648 |
ExprState *endOffset; /* expression for ending bound offset */ |
| 2649 |
Datum startOffsetValue; /* result of startOffset evaluation */ |
| 2650 |
Datum endOffsetValue; /* result of endOffset evaluation */ |
| 2651 |
|
| 2652 |
/* these fields are used with RANGE offset PRECEDING/FOLLOWING: */ |
| 2653 |
FmgrInfo startInRangeFunc; /* in_range function for startOffset */ |
| 2654 |
FmgrInfo endInRangeFunc; /* in_range function for endOffset */ |
| 2655 |
Oid inRangeColl; /* collation for in_range tests */ |
| 2656 |
bool inRangeAsc; /* use ASC sort order for in_range tests? */ |
| 2657 |
bool inRangeNullsFirst; /* nulls sort first for in_range tests? */ |
| 2658 |
|
| 2659 |
/* fields relating to runconditions */ |
| 2660 |
bool use_pass_through; /* When false, stop execution when |
| 2661 |
* runcondition is no longer true. Else |
| 2662 |
* just stop evaluating window funcs. */ |
| 2663 |
bool top_window; /* true if this is the top-most WindowAgg or |
| 2664 |
* the only WindowAgg in this query level */ |
| 2665 |
ExprState *runcondition; /* Condition which must remain true otherwise |
| 2666 |
* execution of the WindowAgg will finish or |
| 2667 |
* go into pass-through mode. NULL when there |
| 2668 |
* is no such condition. */ |
| 2669 |
|
| 2670 |
/* these fields are used in GROUPS mode: */ |
| 2671 |
int64 currentgroup; /* peer group # of current row in partition */ |
| 2672 |
int64 frameheadgroup; /* peer group # of frame head row */ |
| 2673 |
int64 frametailgroup; /* peer group # of frame tail row */ |
| 2674 |
int64 groupheadpos; /* current row's peer group head position */ |
| 2675 |
int64 grouptailpos; /* " " " " tail position (group end+1) */ |
| 2676 |
|
| 2677 |
MemoryContext partcontext; /* context for partition-lifespan data */ |
| 2678 |
MemoryContext aggcontext; /* shared context for aggregate working data */ |
| 2679 |
MemoryContext curaggcontext; /* current aggregate's working data */ |
| 2680 |
ExprContext *tmpcontext; /* short-term evaluation context */ |
| 2681 |
|
| 2682 |
bool all_first; /* true if the scan is starting */ |
| 2683 |
bool partition_spooled; /* true if all tuples in current partition |
| 2684 |
* have been spooled into tuplestore */ |
| 2685 |
bool next_partition; /* true if begin_partition needs to be called */ |
| 2686 |
bool more_partitions; /* true if there's more partitions after |
| 2687 |
* this one */ |
| 2688 |
bool framehead_valid; /* true if frameheadpos is known up to |
| 2689 |
* date for current row */ |
| 2690 |
bool frametail_valid; /* true if frametailpos is known up to |
| 2691 |
* date for current row */ |
| 2692 |
bool grouptail_valid; /* true if grouptailpos is known up to |
| 2693 |
* date for current row */ |
| 2694 |
|
| 2695 |
TupleTableSlot *first_part_slot; /* first tuple of current or next |
| 2696 |
* partition */ |
| 2697 |
TupleTableSlot *framehead_slot; /* first tuple of current frame */ |
| 2698 |
TupleTableSlot *frametail_slot; /* first tuple after current frame */ |
| 2699 |
|
| 2700 |
/* temporary slots for tuples fetched back from tuplestore */ |
| 2701 |
TupleTableSlot *agg_row_slot; |
| 2702 |
TupleTableSlot *temp_slot_1; |
| 2703 |
TupleTableSlot *temp_slot_2; |
| 2704 |
} WindowAggState; |
| 2705 |
|
| 2706 |
/* ---------------- |
| 2707 |
* UniqueState information |
| 2708 |
* |
| 2709 |
* Unique nodes are used "on top of" sort nodes to discard |
| 2710 |
* duplicate tuples returned from the sort phase. Basically |
| 2711 |
* all it does is compare the current tuple from the subplan |
| 2712 |
* with the previously fetched tuple (stored in its result slot). |
| 2713 |
* If the two are identical in all interesting fields, then |
| 2714 |
* we just fetch another tuple from the sort and try again. |
| 2715 |
* ---------------- |
| 2716 |
*/ |
| 2717 |
typedef struct UniqueState |
| 2718 |
{ |
| 2719 |
PlanState ps; /* its first field is NodeTag */ |
| 2720 |
ExprState *eqfunction; /* tuple equality qual */ |
| 2721 |
} UniqueState; |
| 2722 |
|
| 2723 |
/* ---------------- |
| 2724 |
* GatherState information |
| 2725 |
* |
| 2726 |
* Gather nodes launch 1 or more parallel workers, run a subplan |
| 2727 |
* in those workers, and collect the results. |
| 2728 |
* ---------------- |
| 2729 |
*/ |
| 2730 |
typedef struct GatherState |
| 2731 |
{ |
| 2732 |
PlanState ps; /* its first field is NodeTag */ |
| 2733 |
bool initialized; /* workers launched? */ |
| 2734 |
bool need_to_scan_locally; /* need to read from local plan? */ |
| 2735 |
int64 tuples_needed; /* tuple bound, see ExecSetTupleBound */ |
| 2736 |
/* these fields are set up once: */ |
| 2737 |
TupleTableSlot *funnel_slot; |
| 2738 |
struct ParallelExecutorInfo *pei; |
| 2739 |
/* all remaining fields are reinitialized during a rescan: */ |
| 2740 |
int nworkers_launched; /* original number of workers */ |
| 2741 |
int nreaders; /* number of still-active workers */ |
| 2742 |
int nextreader; /* next one to try to read from */ |
| 2743 |
struct TupleQueueReader **reader; /* array with nreaders active entries */ |
| 2744 |
} GatherState; |
| 2745 |
|
| 2746 |
/* ---------------- |
| 2747 |
* GatherMergeState information |
| 2748 |
* |
| 2749 |
* Gather merge nodes launch 1 or more parallel workers, run a |
| 2750 |
* subplan which produces sorted output in each worker, and then |
| 2751 |
* merge the results into a single sorted stream. |
| 2752 |
* ---------------- |
| 2753 |
*/ |
| 2754 |
struct GMReaderTupleBuffer; /* private in nodeGatherMerge.c */ |
| 2755 |
|
| 2756 |
typedef struct GatherMergeState |
| 2757 |
{ |
| 2758 |
PlanState ps; /* its first field is NodeTag */ |
| 2759 |
bool initialized; /* workers launched? */ |
| 2760 |
bool gm_initialized; /* gather_merge_init() done? */ |
| 2761 |
bool need_to_scan_locally; /* need to read from local plan? */ |
| 2762 |
int64 tuples_needed; /* tuple bound, see ExecSetTupleBound */ |
| 2763 |
/* these fields are set up once: */ |
| 2764 |
TupleDesc tupDesc; /* descriptor for subplan result tuples */ |
| 2765 |
int gm_nkeys; /* number of sort columns */ |
| 2766 |
SortSupport gm_sortkeys; /* array of length gm_nkeys */ |
| 2767 |
struct ParallelExecutorInfo *pei; |
| 2768 |
/* all remaining fields are reinitialized during a rescan */ |
| 2769 |
/* (but the arrays are not reallocated, just cleared) */ |
| 2770 |
int nworkers_launched; /* original number of workers */ |
| 2771 |
int nreaders; /* number of active workers */ |
| 2772 |
TupleTableSlot **gm_slots; /* array with nreaders+1 entries */ |
| 2773 |
struct TupleQueueReader **reader; /* array with nreaders active entries */ |
| 2774 |
struct GMReaderTupleBuffer *gm_tuple_buffers; /* nreaders tuple buffers */ |
| 2775 |
struct binaryheap *gm_heap; /* binary heap of slot indices */ |
| 2776 |
} GatherMergeState; |
| 2777 |
|
| 2778 |
/* ---------------- |
| 2779 |
* Values displayed by EXPLAIN ANALYZE |
| 2780 |
* ---------------- |
| 2781 |
*/ |
| 2782 |
typedef struct HashInstrumentation |
| 2783 |
{ |
| 2784 |
int nbuckets; /* number of buckets at end of execution */ |
| 2785 |
int nbuckets_original; /* planned number of buckets */ |
| 2786 |
int nbatch; /* number of batches at end of execution */ |
| 2787 |
int nbatch_original; /* planned number of batches */ |
| 2788 |
Size space_peak; /* peak memory usage in bytes */ |
| 2789 |
} HashInstrumentation; |
| 2790 |
|
| 2791 |
/* ---------------- |
| 2792 |
* Shared memory container for per-worker hash information |
| 2793 |
* ---------------- |
| 2794 |
*/ |
| 2795 |
typedef struct SharedHashInfo |
| 2796 |
{ |
| 2797 |
int num_workers; |
| 2798 |
HashInstrumentation hinstrument[FLEXIBLE_ARRAY_MEMBER]; |
| 2799 |
} SharedHashInfo; |
| 2800 |
|
| 2801 |
/* ---------------- |
| 2802 |
* HashState information |
| 2803 |
* ---------------- |
| 2804 |
*/ |
| 2805 |
typedef struct HashState |
| 2806 |
{ |
| 2807 |
PlanState ps; /* its first field is NodeTag */ |
| 2808 |
HashJoinTable hashtable; /* hash table for the hashjoin */ |
| 2809 |
ExprState *hash_expr; /* ExprState to get hash value */ |
| 2810 |
|
| 2811 |
FmgrInfo *skew_hashfunction; /* lookup data for skew hash function */ |
| 2812 |
Oid skew_collation; /* collation to call skew_hashfunction with */ |
| 2813 |
|
| 2814 |
/* |
| 2815 |
* In a parallelized hash join, the leader retains a pointer to the |
| 2816 |
* shared-memory stats area in its shared_info field, and then copies the |
| 2817 |
* shared-memory info back to local storage before DSM shutdown. The |
| 2818 |
* shared_info field remains NULL in workers, or in non-parallel joins. |
| 2819 |
*/ |
| 2820 |
SharedHashInfo *shared_info; |
| 2821 |
|
| 2822 |
/* |
| 2823 |
* If we are collecting hash stats, this points to an initially-zeroed |
| 2824 |
* collection area, which could be either local storage or in shared |
| 2825 |
* memory; either way it's for just one process. |
| 2826 |
*/ |
| 2827 |
HashInstrumentation *hinstrument; |
| 2828 |
|
| 2829 |
/* Parallel hash state. */ |
| 2830 |
struct ParallelHashJoinState *parallel_state; |
| 2831 |
} HashState; |
| 2832 |
|
| 2833 |
/* ---------------- |
| 2834 |
* SetOpState information |
| 2835 |
* |
| 2836 |
* SetOp nodes support either sorted or hashed de-duplication. |
| 2837 |
* The sorted mode is a bit like MergeJoin, the hashed mode like Agg. |
| 2838 |
* ---------------- |
| 2839 |
*/ |
| 2840 |
typedef struct SetOpStatePerInput |
| 2841 |
{ |
| 2842 |
TupleTableSlot *firstTupleSlot; /* first tuple of current group */ |
| 2843 |
int64 numTuples; /* number of tuples in current group */ |
| 2844 |
TupleTableSlot *nextTupleSlot; /* next input tuple, if already read */ |
| 2845 |
bool needGroup; /* do we need to load a new group? */ |
| 2846 |
} SetOpStatePerInput; |
| 2847 |
|
| 2848 |
typedef struct SetOpState |
| 2849 |
{ |
| 2850 |
PlanState ps; /* its first field is NodeTag */ |
| 2851 |
bool setop_done; /* indicates completion of output scan */ |
| 2852 |
int64 numOutput; /* number of dups left to output */ |
| 2853 |
int numCols; /* number of grouping columns */ |
| 2854 |
|
| 2855 |
/* these fields are used in SETOP_SORTED mode: */ |
| 2856 |
SortSupport sortKeys; /* per-grouping-field sort data */ |
| 2857 |
SetOpStatePerInput leftInput; /* current outer-relation input state */ |
| 2858 |
SetOpStatePerInput rightInput; /* current inner-relation input state */ |
| 2859 |
bool need_init; /* have we read the first tuples yet? */ |
| 2860 |
|
| 2861 |
/* these fields are used in SETOP_HASHED mode: */ |
| 2862 |
Oid *eqfuncoids; /* per-grouping-field equality fns */ |
| 2863 |
FmgrInfo *hashfunctions; /* per-grouping-field hash fns */ |
| 2864 |
TupleHashTable hashtable; /* hash table with one entry per group */ |
| 2865 |
MemoryContext tableContext; /* memory context containing hash table */ |
| 2866 |
bool table_filled; /* hash table filled yet? */ |
| 2867 |
TupleHashIterator hashiter; /* for iterating through hash table */ |
| 2868 |
} SetOpState; |
| 2869 |
|
| 2870 |
/* ---------------- |
| 2871 |
* LockRowsState information |
| 2872 |
* |
| 2873 |
* LockRows nodes are used to enforce FOR [KEY] UPDATE/SHARE locking. |
| 2874 |
* ---------------- |
| 2875 |
*/ |
| 2876 |
typedef struct LockRowsState |
| 2877 |
{ |
| 2878 |
PlanState ps; /* its first field is NodeTag */ |
| 2879 |
List *lr_arowMarks; /* List of ExecAuxRowMarks */ |
| 2880 |
EPQState lr_epqstate; /* for evaluating EvalPlanQual rechecks */ |
| 2881 |
} LockRowsState; |
| 2882 |
|
| 2883 |
/* ---------------- |
| 2884 |
* LimitState information |
| 2885 |
* |
| 2886 |
* Limit nodes are used to enforce LIMIT/OFFSET clauses. |
| 2887 |
* They just select the desired subrange of their subplan's output. |
| 2888 |
* |
| 2889 |
* offset is the number of initial tuples to skip (0 does nothing). |
| 2890 |
* count is the number of tuples to return after skipping the offset tuples. |
| 2891 |
* If no limit count was specified, count is undefined and noCount is true. |
| 2892 |
* When lstate == LIMIT_INITIAL, offset/count/noCount haven't been set yet. |
| 2893 |
* ---------------- |
| 2894 |
*/ |
| 2895 |
typedef enum |
| 2896 |
{ |
| 2897 |
LIMIT_INITIAL, /* initial state for LIMIT node */ |
| 2898 |
LIMIT_RESCAN, /* rescan after recomputing parameters */ |
| 2899 |
LIMIT_EMPTY, /* there are no returnable rows */ |
| 2900 |
LIMIT_INWINDOW, /* have returned a row in the window */ |
| 2901 |
LIMIT_WINDOWEND_TIES, /* have returned a tied row */ |
| 2902 |
LIMIT_SUBPLANEOF, /* at EOF of subplan (within window) */ |
| 2903 |
LIMIT_WINDOWEND, /* stepped off end of window */ |
| 2904 |
LIMIT_WINDOWSTART, /* stepped off beginning of window */ |
| 2905 |
} LimitStateCond; |
| 2906 |
|
| 2907 |
typedef struct LimitState |
| 2908 |
{ |
| 2909 |
PlanState ps; /* its first field is NodeTag */ |
| 2910 |
ExprState *limitOffset; /* OFFSET parameter, or NULL if none */ |
| 2911 |
ExprState *limitCount; /* COUNT parameter, or NULL if none */ |
| 2912 |
LimitOption limitOption; /* limit specification type */ |
| 2913 |
int64 offset; /* current OFFSET value */ |
| 2914 |
int64 count; /* current COUNT, if any */ |
| 2915 |
bool noCount; /* if true, ignore count */ |
| 2916 |
LimitStateCond lstate; /* state machine status, as above */ |
| 2917 |
int64 position; /* 1-based index of last tuple returned */ |
| 2918 |
TupleTableSlot *subSlot; /* tuple last obtained from subplan */ |
| 2919 |
ExprState *eqfunction; /* tuple equality qual in case of WITH TIES |
| 2920 |
* option */ |
| 2921 |
TupleTableSlot *last_slot; /* slot for evaluation of ties */ |
| 2922 |
} LimitState; |
| 2923 |
|
| 2924 |
#endif /* EXECNODES_H */ |