📄 execnodes.h
字号:
/*------------------------------------------------------------------------- * * execnodes.h * definitions for executor state nodes * * * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * $PostgreSQL: pgsql/src/include/nodes/execnodes.h,v 1.139.2.3 2005/11/28 23:46:25 tgl Exp $ * *------------------------------------------------------------------------- */#ifndef EXECNODES_H#define EXECNODES_H#include "access/relscan.h"#include "executor/tuptable.h"#include "fmgr.h"#include "nodes/bitmapset.h"#include "nodes/params.h"#include "nodes/plannodes.h"#include "nodes/tidbitmap.h"#include "utils/hsearch.h"#include "utils/tuplestore.h"/* ---------------- * IndexInfo information * * this struct holds the information needed to construct new index * entries for a particular index. Used for both index_build and * retail creation of index entries. * * NumIndexAttrs number of columns in this index * KeyAttrNumbers underlying-rel attribute numbers used as keys * (zeroes indicate expressions) * Expressions expr trees for expression entries, or NIL if none * ExpressionsState exec state for expressions, or NIL if none * Predicate partial-index predicate, or NIL if none * PredicateState exec state for predicate, or NIL if none * Unique is it a unique index? * ---------------- */typedef struct IndexInfo{ NodeTag type; int ii_NumIndexAttrs; AttrNumber ii_KeyAttrNumbers[INDEX_MAX_KEYS]; List *ii_Expressions; /* list of Expr */ List *ii_ExpressionsState; /* list of ExprState */ List *ii_Predicate; /* list of Expr */ List *ii_PredicateState; /* list of ExprState */ bool ii_Unique;} IndexInfo;/* ---------------- * ExprContext_CB * * List of callbacks to be called at ExprContext shutdown. * ---------------- */typedef void (*ExprContextCallbackFunction) (Datum arg);typedef struct ExprContext_CB{ struct ExprContext_CB *next; ExprContextCallbackFunction function; Datum arg;} ExprContext_CB;/* ---------------- * ExprContext * * This class holds the "current context" information * needed to evaluate expressions for doing tuple qualifications * and tuple projections. For example, if an expression refers * to an attribute in the current inner tuple then we need to know * what the current inner tuple is and so we look at the expression * context. * * There are two memory contexts associated with an ExprContext: * * ecxt_per_query_memory is a query-lifespan context, typically the same * context the ExprContext node itself is allocated in. This context * can be used for purposes such as storing function call cache info. * * ecxt_per_tuple_memory is a short-term context for expression results. * As the name suggests, it will typically be reset once per tuple, * before we begin to evaluate expressions for that tuple. Each * ExprContext normally has its very own per-tuple memory context. * * CurrentMemoryContext should be set to ecxt_per_tuple_memory before * calling ExecEvalExpr() --- see ExecEvalExprSwitchContext(). * ---------------- */typedef struct ExprContext{ NodeTag type; /* Tuples that Var nodes in expression may refer to */ TupleTableSlot *ecxt_scantuple; TupleTableSlot *ecxt_innertuple; TupleTableSlot *ecxt_outertuple; /* Memory contexts for expression evaluation --- see notes above */ MemoryContext ecxt_per_query_memory; MemoryContext ecxt_per_tuple_memory; /* Values to substitute for Param nodes in expression */ ParamExecData *ecxt_param_exec_vals; /* for PARAM_EXEC params */ ParamListInfo ecxt_param_list_info; /* for other param types */ /* Values to substitute for Aggref nodes in expression */ Datum *ecxt_aggvalues; /* precomputed values for Aggref nodes */ bool *ecxt_aggnulls; /* null flags for Aggref nodes */ /* Value to substitute for CaseTestExpr nodes in expression */ Datum caseValue_datum; bool caseValue_isNull; /* Value to substitute for CoerceToDomainValue nodes in expression */ Datum domainValue_datum; bool domainValue_isNull; /* Link to containing EState */ struct EState *ecxt_estate; /* Functions to call back when ExprContext is shut down */ ExprContext_CB *ecxt_callbacks;} ExprContext;/* * Set-result status returned by ExecEvalExpr() */typedef enum{ ExprSingleResult, /* expression does not return a set */ ExprMultipleResult, /* this result is an element of a set */ ExprEndResult /* there are no more elements in the set */} ExprDoneCond;/* * Return modes for functions returning sets. Note values must be chosen * as separate bits so that a bitmask can be formed to indicate supported * modes. */typedef enum{ SFRM_ValuePerCall = 0x01, /* one value returned per call */ SFRM_Materialize = 0x02 /* result set instantiated in Tuplestore */} SetFunctionReturnMode;/* * When calling a function that might return a set (multiple rows), * a node of this type is passed as fcinfo->resultinfo to allow * return status to be passed back. A function returning set should * raise an error if no such resultinfo is provided. */typedef struct ReturnSetInfo{ NodeTag type; /* values set by caller: */ ExprContext *econtext; /* context function is being called in */ TupleDesc expectedDesc; /* tuple descriptor expected by caller */ int allowedModes; /* bitmask: return modes caller can handle */ /* result status from function (but pre-initialized by caller): */ SetFunctionReturnMode returnMode; /* actual return mode */ ExprDoneCond isDone; /* status for ValuePerCall mode */ /* fields filled by function in Materialize return mode: */ Tuplestorestate *setResult; /* holds the complete returned tuple set */ TupleDesc setDesc; /* actual descriptor for returned tuples */} ReturnSetInfo;/* ---------------- * ProjectionInfo node information * * This is all the information needed to perform projections --- * that is, form new tuples by evaluation of targetlist expressions. * Nodes which need to do projections create one of these. * * ExecProject() evaluates the tlist, forms a tuple, and stores it * in the given slot. Note that the result will be a "virtual" tuple * unless ExecMaterializeSlot() is then called to force it to be * converted to a physical tuple. The slot must have a tupledesc * that matches the output of the tlist! * * The planner very often produces tlists that consist entirely of * simple Var references (lower levels of a plan tree almost always * look like that). So we have an optimization to handle that case * with minimum overhead. * * targetlist target list for projection * exprContext expression context in which to evaluate targetlist * slot slot to place projection result in * itemIsDone workspace for ExecProject * isVarList TRUE if simple-Var-list optimization applies * varSlotOffsets array indicating which slot each simple Var is from * varNumbers array indicating attr numbers of simple Vars * lastInnerVar highest attnum from inner tuple slot (0 if none) * lastOuterVar highest attnum from outer tuple slot (0 if none) * lastScanVar highest attnum from scan tuple slot (0 if none) * ---------------- */typedef struct ProjectionInfo{ NodeTag type; List *pi_targetlist; ExprContext *pi_exprContext; TupleTableSlot *pi_slot; ExprDoneCond *pi_itemIsDone; bool pi_isVarList; int *pi_varSlotOffsets; int *pi_varNumbers; int pi_lastInnerVar; int pi_lastOuterVar; int pi_lastScanVar;} ProjectionInfo;/* ---------------- * JunkFilter * * This class is used to store information regarding junk attributes. * A junk attribute is an attribute in a tuple that is needed only for * storing intermediate information in the executor, and does not belong * in emitted tuples. For example, when we do an UPDATE query, * the planner adds a "junk" entry to the targetlist so that the tuples * returned to ExecutePlan() contain an extra attribute: the ctid of * the tuple to be updated. This is needed to do the update, but we * don't want the ctid to be part of the stored new tuple! So, we * apply a "junk filter" to remove the junk attributes and form the * real output tuple. * * targetList: the original target list (including junk attributes). * cleanTupType: the tuple descriptor for the "clean" tuple (with * junk attributes removed). * cleanMap: A map with the correspondence between the non-junk * attribute numbers of the "original" tuple and the * attribute numbers of the "clean" tuple. * resultSlot: tuple slot used to hold cleaned tuple. * ---------------- */typedef struct JunkFilter{ NodeTag type; List *jf_targetList; TupleDesc jf_cleanTupType; AttrNumber *jf_cleanMap; TupleTableSlot *jf_resultSlot;} JunkFilter;/* ---------------- * ResultRelInfo information * * Whenever we update an existing relation, we have to * update indices on the relation, and perhaps also fire triggers. * The ResultRelInfo class is used to hold all the information needed * about a result relation, including indices.. -cim 10/15/89 * * RangeTableIndex result relation's range table index * RelationDesc relation descriptor for result relation * NumIndices # of indices existing on result relation * IndexRelationDescs array of relation descriptors for indices * IndexRelationInfo array of key/attr info for indices * TrigDesc triggers to be fired, if any * TrigFunctions cached lookup info for trigger functions * TrigInstrument optional runtime measurements for triggers * ConstraintExprs array of constraint-checking expr states * junkFilter for removing junk attributes from tuples * ---------------- */typedef struct ResultRelInfo{ NodeTag type; Index ri_RangeTableIndex; Relation ri_RelationDesc; int ri_NumIndices; RelationPtr ri_IndexRelationDescs; IndexInfo **ri_IndexRelationInfo; TriggerDesc *ri_TrigDesc; FmgrInfo *ri_TrigFunctions; struct Instrumentation *ri_TrigInstrument; List **ri_ConstraintExprs; JunkFilter *ri_junkFilter;} ResultRelInfo;/* ---------------- * EState information * * Master working state for an Executor invocation * ---------------- */typedef struct EState{ NodeTag type; /* Basic state for all query types: */ ScanDirection es_direction; /* current scan direction */ Snapshot es_snapshot; /* time qual to use */ Snapshot es_crosscheck_snapshot; /* crosscheck time qual for RI */ List *es_range_table; /* List of RangeTableEntrys */ /* Info about target table for insert/update/delete queries: */ ResultRelInfo *es_result_relations; /* array of ResultRelInfos */ int es_num_result_relations; /* length of array */ ResultRelInfo *es_result_relation_info; /* currently active array elt */ JunkFilter *es_junkFilter; /* currently active junk filter */ Relation es_into_relation_descriptor; /* for SELECT INTO */ bool es_into_relation_use_wal; /* Parameter info: */ ParamListInfo es_param_list_info; /* values of external params */ ParamExecData *es_param_exec_vals; /* values of internal params */ /* Other working state: */ MemoryContext es_query_cxt; /* per-query context in which EState lives */ TupleTable es_tupleTable; /* Array of TupleTableSlots */ uint32 es_processed; /* # of tuples processed */ Oid es_lastoid; /* last oid processed (by INSERT) */ List *es_rowMarks; /* not good place, but there is no other */ bool es_forUpdate; /* true = FOR UPDATE, false = FOR SHARE */ bool es_rowNoWait; /* FOR UPDATE/SHARE NOWAIT option */ bool es_instrument; /* true requests runtime instrumentation */ bool es_select_into; /* true if doing SELECT INTO */ bool es_into_oids; /* true to generate OIDs in SELECT INTO */ List *es_exprcontexts; /* List of ExprContexts within EState */ /* * this ExprContext is for per-output-tuple operations, such as constraint * checks and index-value computations. It will be reset for each output * tuple. Note that it will be created only if needed. */ ExprContext *es_per_tuple_exprcontext; /* Below is to re-evaluate plan qual in READ COMMITTED mode */ Plan *es_topPlan; /* link to top of plan tree */ struct evalPlanQual *es_evalPlanQual; /* chain of PlanQual states */ bool *es_evTupleNull; /* local array of EPQ status */ HeapTuple *es_evTuple; /* shared array of EPQ substitute tuples */ bool es_useEvalPlan; /* evaluating EPQ tuples? */ /* * this field added at end of struct to avoid post-release ABI breakage in * 8.1 series. It'll be in a more logical place in 8.2. */ TupleTableSlot *es_trig_tuple_slot; /* for trigger output tuples */} EState;/* ---------------------------------------------------------------- * Tuple Hash Tables * * All-in-memory tuple hash tables are used for a number of purposes. * ---------------------------------------------------------------- */typedef struct TupleHashEntryData *TupleHashEntry;typedef struct TupleHashTableData *TupleHashTable;typedef struct TupleHashEntryData{ /* firstTuple must be the first field in this struct! */ HeapTuple firstTuple; /* copy of first tuple in this group */ /* there may be additional data beyond the end of this struct */} TupleHashEntryData; /* VARIABLE LENGTH STRUCT */typedef struct TupleHashTableData{ HTAB *hashtab; /* underlying dynahash table */ int numCols; /* number of columns in lookup key */ AttrNumber *keyColIdx; /* attr numbers of key columns */ FmgrInfo *eqfunctions; /* lookup data for comparison functions */ FmgrInfo *hashfunctions; /* lookup data for hash functions */ MemoryContext tablecxt; /* memory context containing table */ MemoryContext tempcxt; /* context for function evaluations */ Size entrysize; /* actual size to make each hash entry */ TupleTableSlot *tableslot; /* slot for referencing table entries */ TupleTableSlot *inputslot; /* current input tuple's slot */} TupleHashTableData;typedef HASH_SEQ_STATUS TupleHashIterator;#define ResetTupleHashIterator(htable, iter) \ hash_seq_init(iter, (htable)->hashtab)#define ScanTupleHashTable(iter) \ ((TupleHashEntry) hash_seq_search(iter))/* ---------------------------------------------------------------- * Expression State Trees * * Each executable expression tree has a parallel ExprState tree. * * Unlike PlanState, there is not an exact one-for-one correspondence between * ExprState node types and Expr node types. Many Expr node types have no * need for node-type-specific run-time state, and so they can use plain * ExprState or GenericExprState as their associated ExprState node type. * ---------------------------------------------------------------- *//* ---------------- * ExprState node * * ExprState is the common superclass for all ExprState-type nodes. * * It can also be instantiated directly for leaf Expr nodes that need no * local run-time state (such as Var, Const, or Param). * * To save on dispatch overhead, each ExprState node contains a function * pointer to the routine to execute to evaluate the node. * ---------------- */typedef struct ExprState ExprState;typedef Datum (*ExprStateEvalFunc) (ExprState *expression, ExprContext *econtext, bool *isNull, ExprDoneCond *isDone);struct ExprState{ NodeTag type; Expr *expr; /* associated Expr node */ ExprStateEvalFunc evalfunc; /* routine to run to execute node */};/* ---------------- * GenericExprState node * * This is used for Expr node types that need no local run-time state,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -