execnodes.h 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058
  1. /*-------------------------------------------------------------------------
  2. *
  3. * execnodes.h
  4. * definitions for executor state nodes
  5. *
  6. *
  7. * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
  8. * Portions Copyright (c) 1994, Regents of the University of California
  9. *
  10. * src/include/nodes/execnodes.h
  11. *
  12. *-------------------------------------------------------------------------
  13. */
  14. #ifndef EXECNODES_H
  15. #define EXECNODES_H
  16. #include "access/genam.h"
  17. #include "access/heapam.h"
  18. #include "executor/instrument.h"
  19. #include "lib/pairingheap.h"
  20. #include "nodes/params.h"
  21. #include "nodes/plannodes.h"
  22. #include "utils/reltrigger.h"
  23. #include "utils/sortsupport.h"
  24. #include "utils/tuplestore.h"
  25. #include "utils/tuplesort.h"
  26. /* ----------------
  27. * IndexInfo information
  28. *
  29. * this struct holds the information needed to construct new index
  30. * entries for a particular index. Used for both index_build and
  31. * retail creation of index entries.
  32. *
  33. * NumIndexAttrs number of columns in this index
  34. * KeyAttrNumbers underlying-rel attribute numbers used as keys
  35. * (zeroes indicate expressions)
  36. * Expressions expr trees for expression entries, or NIL if none
  37. * ExpressionsState exec state for expressions, or NIL if none
  38. * Predicate partial-index predicate, or NIL if none
  39. * PredicateState exec state for predicate, or NIL if none
  40. * ExclusionOps Per-column exclusion operators, or NULL if none
  41. * ExclusionProcs Underlying function OIDs for ExclusionOps
  42. * ExclusionStrats Opclass strategy numbers for ExclusionOps
  43. * UniqueOps Theses are like Exclusion*, but for unique indexes
  44. * UniqueProcs
  45. * UniqueStrats
  46. * Unique is it a unique index?
  47. * ReadyForInserts is it valid for inserts?
  48. * Concurrent are we doing a concurrent index build?
  49. * BrokenHotChain did we detect any broken HOT chains?
  50. *
  51. * ii_Concurrent and ii_BrokenHotChain are used only during index build;
  52. * they're conventionally set to false otherwise.
  53. * ----------------
  54. */
  55. typedef struct IndexInfo
  56. {
  57. NodeTag type;
  58. int ii_NumIndexAttrs;
  59. AttrNumber ii_KeyAttrNumbers[INDEX_MAX_KEYS];
  60. List *ii_Expressions; /* list of Expr */
  61. List *ii_ExpressionsState; /* list of ExprState */
  62. List *ii_Predicate; /* list of Expr */
  63. List *ii_PredicateState; /* list of ExprState */
  64. Oid *ii_ExclusionOps; /* array with one entry per column */
  65. Oid *ii_ExclusionProcs; /* array with one entry per column */
  66. uint16 *ii_ExclusionStrats; /* array with one entry per column */
  67. Oid *ii_UniqueOps; /* array with one entry per column */
  68. Oid *ii_UniqueProcs; /* array with one entry per column */
  69. uint16 *ii_UniqueStrats; /* array with one entry per column */
  70. bool ii_Unique;
  71. bool ii_ReadyForInserts;
  72. bool ii_Concurrent;
  73. bool ii_BrokenHotChain;
  74. } IndexInfo;
  75. /* ----------------
  76. * ExprContext_CB
  77. *
  78. * List of callbacks to be called at ExprContext shutdown.
  79. * ----------------
  80. */
  81. typedef void (*ExprContextCallbackFunction) (Datum arg);
  82. typedef struct ExprContext_CB
  83. {
  84. struct ExprContext_CB *next;
  85. ExprContextCallbackFunction function;
  86. Datum arg;
  87. } ExprContext_CB;
  88. /* ----------------
  89. * ExprContext
  90. *
  91. * This class holds the "current context" information
  92. * needed to evaluate expressions for doing tuple qualifications
  93. * and tuple projections. For example, if an expression refers
  94. * to an attribute in the current inner tuple then we need to know
  95. * what the current inner tuple is and so we look at the expression
  96. * context.
  97. *
  98. * There are two memory contexts associated with an ExprContext:
  99. * * ecxt_per_query_memory is a query-lifespan context, typically the same
  100. * context the ExprContext node itself is allocated in. This context
  101. * can be used for purposes such as storing function call cache info.
  102. * * ecxt_per_tuple_memory is a short-term context for expression results.
  103. * As the name suggests, it will typically be reset once per tuple,
  104. * before we begin to evaluate expressions for that tuple. Each
  105. * ExprContext normally has its very own per-tuple memory context.
  106. *
  107. * CurrentMemoryContext should be set to ecxt_per_tuple_memory before
  108. * calling ExecEvalExpr() --- see ExecEvalExprSwitchContext().
  109. * ----------------
  110. */
  111. typedef struct ExprContext
  112. {
  113. NodeTag type;
  114. /* Tuples that Var nodes in expression may refer to */
  115. TupleTableSlot *ecxt_scantuple;
  116. TupleTableSlot *ecxt_innertuple;
  117. TupleTableSlot *ecxt_outertuple;
  118. /* Memory contexts for expression evaluation --- see notes above */
  119. MemoryContext ecxt_per_query_memory;
  120. MemoryContext ecxt_per_tuple_memory;
  121. /* Values to substitute for Param nodes in expression */
  122. ParamExecData *ecxt_param_exec_vals; /* for PARAM_EXEC params */
  123. ParamListInfo ecxt_param_list_info; /* for other param types */
  124. /*
  125. * Values to substitute for Aggref nodes in the expressions of an Agg
  126. * node, or for WindowFunc nodes within a WindowAgg node.
  127. */
  128. Datum *ecxt_aggvalues; /* precomputed values for aggs/windowfuncs */
  129. bool *ecxt_aggnulls; /* null flags for aggs/windowfuncs */
  130. /* Value to substitute for CaseTestExpr nodes in expression */
  131. Datum caseValue_datum;
  132. bool caseValue_isNull;
  133. /* Value to substitute for CoerceToDomainValue nodes in expression */
  134. Datum domainValue_datum;
  135. bool domainValue_isNull;
  136. /* Link to containing EState (NULL if a standalone ExprContext) */
  137. struct EState *ecxt_estate;
  138. /* Functions to call back when ExprContext is shut down or rescanned */
  139. ExprContext_CB *ecxt_callbacks;
  140. } ExprContext;
  141. /*
  142. * Set-result status returned by ExecEvalExpr()
  143. */
  144. typedef enum
  145. {
  146. ExprSingleResult, /* expression does not return a set */
  147. ExprMultipleResult, /* this result is an element of a set */
  148. ExprEndResult /* there are no more elements in the set */
  149. } ExprDoneCond;
  150. /*
  151. * Return modes for functions returning sets. Note values must be chosen
  152. * as separate bits so that a bitmask can be formed to indicate supported
  153. * modes. SFRM_Materialize_Random and SFRM_Materialize_Preferred are
  154. * auxiliary flags about SFRM_Materialize mode, rather than separate modes.
  155. */
  156. typedef enum
  157. {
  158. SFRM_ValuePerCall = 0x01, /* one value returned per call */
  159. SFRM_Materialize = 0x02, /* result set instantiated in Tuplestore */
  160. SFRM_Materialize_Random = 0x04, /* Tuplestore needs randomAccess */
  161. SFRM_Materialize_Preferred = 0x08 /* caller prefers Tuplestore */
  162. } SetFunctionReturnMode;
  163. /*
  164. * When calling a function that might return a set (multiple rows),
  165. * a node of this type is passed as fcinfo->resultinfo to allow
  166. * return status to be passed back. A function returning set should
  167. * raise an error if no such resultinfo is provided.
  168. */
  169. typedef struct ReturnSetInfo
  170. {
  171. NodeTag type;
  172. /* values set by caller: */
  173. ExprContext *econtext; /* context function is being called in */
  174. TupleDesc expectedDesc; /* tuple descriptor expected by caller */
  175. int allowedModes; /* bitmask: return modes caller can handle */
  176. /* result status from function (but pre-initialized by caller): */
  177. SetFunctionReturnMode returnMode; /* actual return mode */
  178. ExprDoneCond isDone; /* status for ValuePerCall mode */
  179. /* fields filled by function in Materialize return mode: */
  180. Tuplestorestate *setResult; /* holds the complete returned tuple set */
  181. TupleDesc setDesc; /* actual descriptor for returned tuples */
  182. } ReturnSetInfo;
  183. /* ----------------
  184. * ProjectionInfo node information
  185. *
  186. * This is all the information needed to perform projections ---
  187. * that is, form new tuples by evaluation of targetlist expressions.
  188. * Nodes which need to do projections create one of these.
  189. *
  190. * ExecProject() evaluates the tlist, forms a tuple, and stores it
  191. * in the given slot. Note that the result will be a "virtual" tuple
  192. * unless ExecMaterializeSlot() is then called to force it to be
  193. * converted to a physical tuple. The slot must have a tupledesc
  194. * that matches the output of the tlist!
  195. *
  196. * The planner very often produces tlists that consist entirely of
  197. * simple Var references (lower levels of a plan tree almost always
  198. * look like that). And top-level tlists are often mostly Vars too.
  199. * We therefore optimize execution of simple-Var tlist entries.
  200. * The pi_targetlist list actually contains only the tlist entries that
  201. * aren't simple Vars, while those that are Vars are processed using the
  202. * varSlotOffsets/varNumbers/varOutputCols arrays.
  203. *
  204. * The lastXXXVar fields are used to optimize fetching of fields from
  205. * input tuples: they let us do a slot_getsomeattrs() call to ensure
  206. * that all needed attributes are extracted in one pass.
  207. *
  208. * targetlist target list for projection (non-Var expressions only)
  209. * exprContext expression context in which to evaluate targetlist
  210. * slot slot to place projection result in
  211. * itemIsDone workspace array for ExecProject
  212. * directMap true if varOutputCols[] is an identity map
  213. * numSimpleVars number of simple Vars found in original tlist
  214. * varSlotOffsets array indicating which slot each simple Var is from
  215. * varNumbers array containing input attr numbers of simple Vars
  216. * varOutputCols array containing output attr numbers of simple Vars
  217. * lastInnerVar highest attnum from inner tuple slot (0 if none)
  218. * lastOuterVar highest attnum from outer tuple slot (0 if none)
  219. * lastScanVar highest attnum from scan tuple slot (0 if none)
  220. * ----------------
  221. */
  222. typedef struct ProjectionInfo
  223. {
  224. NodeTag type;
  225. List *pi_targetlist;
  226. ExprContext *pi_exprContext;
  227. TupleTableSlot *pi_slot;
  228. ExprDoneCond *pi_itemIsDone;
  229. bool pi_directMap;
  230. int pi_numSimpleVars;
  231. int *pi_varSlotOffsets;
  232. int *pi_varNumbers;
  233. int *pi_varOutputCols;
  234. int pi_lastInnerVar;
  235. int pi_lastOuterVar;
  236. int pi_lastScanVar;
  237. } ProjectionInfo;
  238. /* ----------------
  239. * JunkFilter
  240. *
  241. * This class is used to store information regarding junk attributes.
  242. * A junk attribute is an attribute in a tuple that is needed only for
  243. * storing intermediate information in the executor, and does not belong
  244. * in emitted tuples. For example, when we do an UPDATE query,
  245. * the planner adds a "junk" entry to the targetlist so that the tuples
  246. * returned to ExecutePlan() contain an extra attribute: the ctid of
  247. * the tuple to be updated. This is needed to do the update, but we
  248. * don't want the ctid to be part of the stored new tuple! So, we
  249. * apply a "junk filter" to remove the junk attributes and form the
  250. * real output tuple. The junkfilter code also provides routines to
  251. * extract the values of the junk attribute(s) from the input tuple.
  252. *
  253. * targetList: the original target list (including junk attributes).
  254. * cleanTupType: the tuple descriptor for the "clean" tuple (with
  255. * junk attributes removed).
  256. * cleanMap: A map with the correspondence between the non-junk
  257. * attribute numbers of the "original" tuple and the
  258. * attribute numbers of the "clean" tuple.
  259. * resultSlot: tuple slot used to hold cleaned tuple.
  260. * junkAttNo: not used by junkfilter code. Can be used by caller
  261. * to remember the attno of a specific junk attribute
  262. * (nodeModifyTable.c keeps the "ctid" or "wholerow"
  263. * attno here).
  264. * ----------------
  265. */
  266. typedef struct JunkFilter
  267. {
  268. NodeTag type;
  269. List *jf_targetList;
  270. TupleDesc jf_cleanTupType;
  271. AttrNumber *jf_cleanMap;
  272. TupleTableSlot *jf_resultSlot;
  273. AttrNumber jf_junkAttNo;
  274. } JunkFilter;
  275. /* ----------------
  276. * ResultRelInfo information
  277. *
  278. * Whenever we update an existing relation, we have to
  279. * update indices on the relation, and perhaps also fire triggers.
  280. * The ResultRelInfo class is used to hold all the information needed
  281. * about a result relation, including indices.. -cim 10/15/89
  282. *
  283. * RangeTableIndex result relation's range table index
  284. * RelationDesc relation descriptor for result relation
  285. * NumIndices # of indices existing on result relation
  286. * IndexRelationDescs array of relation descriptors for indices
  287. * IndexRelationInfo array of key/attr info for indices
  288. * TrigDesc triggers to be fired, if any
  289. * TrigFunctions cached lookup info for trigger functions
  290. * TrigWhenExprs array of trigger WHEN expr states
  291. * TrigInstrument optional runtime measurements for triggers
  292. * FdwRoutine FDW callback functions, if foreign table
  293. * FdwState available to save private state of FDW
  294. * usesFdwDirectModify true when modifying foreign table directly
  295. * WithCheckOptions list of WithCheckOption's to be checked
  296. * WithCheckOptionExprs list of WithCheckOption expr states
  297. * ConstraintExprs array of constraint-checking expr states
  298. * junkFilter for removing junk attributes from tuples
  299. * projectReturning for computing a RETURNING list
  300. * onConflictSetProj for computing ON CONFLICT DO UPDATE SET
  301. * onConflictSetWhere list of ON CONFLICT DO UPDATE exprs (qual)
  302. * ----------------
  303. */
  304. typedef struct ResultRelInfo
  305. {
  306. NodeTag type;
  307. Index ri_RangeTableIndex;
  308. Relation ri_RelationDesc;
  309. int ri_NumIndices;
  310. RelationPtr ri_IndexRelationDescs;
  311. IndexInfo **ri_IndexRelationInfo;
  312. TriggerDesc *ri_TrigDesc;
  313. FmgrInfo *ri_TrigFunctions;
  314. List **ri_TrigWhenExprs;
  315. Instrumentation *ri_TrigInstrument;
  316. struct FdwRoutine *ri_FdwRoutine;
  317. void *ri_FdwState;
  318. bool ri_usesFdwDirectModify;
  319. List *ri_WithCheckOptions;
  320. List *ri_WithCheckOptionExprs;
  321. List **ri_ConstraintExprs;
  322. JunkFilter *ri_junkFilter;
  323. ProjectionInfo *ri_projectReturning;
  324. ProjectionInfo *ri_onConflictSetProj;
  325. List *ri_onConflictSetWhere;
  326. } ResultRelInfo;
  327. /* ----------------
  328. * EState information
  329. *
  330. * Master working state for an Executor invocation
  331. * ----------------
  332. */
  333. typedef struct EState
  334. {
  335. NodeTag type;
  336. /* Basic state for all query types: */
  337. ScanDirection es_direction; /* current scan direction */
  338. Snapshot es_snapshot; /* time qual to use */
  339. Snapshot es_crosscheck_snapshot; /* crosscheck time qual for RI */
  340. List *es_range_table; /* List of RangeTblEntry */
  341. PlannedStmt *es_plannedstmt; /* link to top of plan tree */
  342. JunkFilter *es_junkFilter; /* top-level junk filter, if any */
  343. /* If query can insert/delete tuples, the command ID to mark them with */
  344. CommandId es_output_cid;
  345. /* Info about target table(s) for insert/update/delete queries: */
  346. ResultRelInfo *es_result_relations; /* array of ResultRelInfos */
  347. int es_num_result_relations; /* length of array */
  348. ResultRelInfo *es_result_relation_info; /* currently active array elt */
  349. /* Stuff used for firing triggers: */
  350. List *es_trig_target_relations; /* trigger-only ResultRelInfos */
  351. TupleTableSlot *es_trig_tuple_slot; /* for trigger output tuples */
  352. TupleTableSlot *es_trig_oldtup_slot; /* for TriggerEnabled */
  353. TupleTableSlot *es_trig_newtup_slot; /* for TriggerEnabled */
  354. /* Parameter info: */
  355. ParamListInfo es_param_list_info; /* values of external params */
  356. ParamExecData *es_param_exec_vals; /* values of internal params */
  357. /* Other working state: */
  358. MemoryContext es_query_cxt; /* per-query context in which EState lives */
  359. List *es_tupleTable; /* List of TupleTableSlots */
  360. List *es_rowMarks; /* List of ExecRowMarks */
  361. uint64 es_processed; /* # of tuples processed */
  362. Oid es_lastoid; /* last oid processed (by INSERT) */
  363. int es_top_eflags; /* eflags passed to ExecutorStart */
  364. int es_instrument; /* OR of InstrumentOption flags */
  365. bool es_finished; /* true when ExecutorFinish is done */
  366. List *es_exprcontexts; /* List of ExprContexts within EState */
  367. List *es_subplanstates; /* List of PlanState for SubPlans */
  368. List *es_auxmodifytables; /* List of secondary ModifyTableStates */
  369. /*
  370. * this ExprContext is for per-output-tuple operations, such as constraint
  371. * checks and index-value computations. It will be reset for each output
  372. * tuple. Note that it will be created only if needed.
  373. */
  374. ExprContext *es_per_tuple_exprcontext;
  375. /*
  376. * These fields are for re-evaluating plan quals when an updated tuple is
  377. * substituted in READ COMMITTED mode. es_epqTuple[] contains tuples that
  378. * scan plan nodes should return instead of whatever they'd normally
  379. * return, or NULL if nothing to return; es_epqTupleSet[] is true if a
  380. * particular array entry is valid; and es_epqScanDone[] is state to
  381. * remember if the tuple has been returned already. Arrays are of size
  382. * list_length(es_range_table) and are indexed by scan node scanrelid - 1.
  383. */
  384. HeapTuple *es_epqTuple; /* array of EPQ substitute tuples */
  385. bool *es_epqTupleSet; /* true if EPQ tuple is provided */
  386. bool *es_epqScanDone; /* true if EPQ tuple has been fetched */
  387. } EState;
  388. /*
  389. * ExecRowMark -
  390. * runtime representation of FOR [KEY] UPDATE/SHARE clauses
  391. *
  392. * When doing UPDATE, DELETE, or SELECT FOR [KEY] UPDATE/SHARE, we will have an
  393. * ExecRowMark for each non-target relation in the query (except inheritance
  394. * parent RTEs, which can be ignored at runtime). Virtual relations such as
  395. * subqueries-in-FROM will have an ExecRowMark with relation == NULL. See
  396. * PlanRowMark for details about most of the fields. In addition to fields
  397. * directly derived from PlanRowMark, we store an activity flag (to denote
  398. * inactive children of inheritance trees), curCtid, which is used by the
  399. * WHERE CURRENT OF code, and ermExtra, which is available for use by the plan
  400. * node that sources the relation (e.g., for a foreign table the FDW can use
  401. * ermExtra to hold information).
  402. *
  403. * EState->es_rowMarks is a list of these structs.
  404. */
  405. typedef struct ExecRowMark
  406. {
  407. Relation relation; /* opened and suitably locked relation */
  408. Oid relid; /* its OID (or InvalidOid, if subquery) */
  409. Index rti; /* its range table index */
  410. Index prti; /* parent range table index, if child */
  411. Index rowmarkId; /* unique identifier for resjunk columns */
  412. RowMarkType markType; /* see enum in nodes/plannodes.h */
  413. LockClauseStrength strength; /* LockingClause's strength, or LCS_NONE */
  414. LockWaitPolicy waitPolicy; /* NOWAIT and SKIP LOCKED */
  415. bool ermActive; /* is this mark relevant for current tuple? */
  416. ItemPointerData curCtid; /* ctid of currently locked tuple, if any */
  417. void *ermExtra; /* available for use by relation source node */
  418. } ExecRowMark;
  419. /*
  420. * ExecAuxRowMark -
  421. * additional runtime representation of FOR [KEY] UPDATE/SHARE clauses
  422. *
  423. * Each LockRows and ModifyTable node keeps a list of the rowmarks it needs to
  424. * deal with. In addition to a pointer to the related entry in es_rowMarks,
  425. * this struct carries the column number(s) of the resjunk columns associated
  426. * with the rowmark (see comments for PlanRowMark for more detail). In the
  427. * case of ModifyTable, there has to be a separate ExecAuxRowMark list for
  428. * each child plan, because the resjunk columns could be at different physical
  429. * column positions in different subplans.
  430. */
  431. typedef struct ExecAuxRowMark
  432. {
  433. ExecRowMark *rowmark; /* related entry in es_rowMarks */
  434. AttrNumber ctidAttNo; /* resno of ctid junk attribute, if any */
  435. AttrNumber toidAttNo; /* resno of tableoid junk attribute, if any */
  436. AttrNumber wholeAttNo; /* resno of whole-row junk attribute, if any */
  437. } ExecAuxRowMark;
  438. /* ----------------------------------------------------------------
  439. * Tuple Hash Tables
  440. *
  441. * All-in-memory tuple hash tables are used for a number of purposes.
  442. *
  443. * Note: tab_hash_funcs are for the key datatype(s) stored in the table,
  444. * and tab_eq_funcs are non-cross-type equality operators for those types.
  445. * Normally these are the only functions used, but FindTupleHashEntry()
  446. * supports searching a hashtable using cross-data-type hashing. For that,
  447. * the caller must supply hash functions for the LHS datatype as well as
  448. * the cross-type equality operators to use. in_hash_funcs and cur_eq_funcs
  449. * are set to point to the caller's function arrays while doing such a search.
  450. * During LookupTupleHashEntry(), they point to tab_hash_funcs and
  451. * tab_eq_funcs respectively.
  452. * ----------------------------------------------------------------
  453. */
  454. typedef struct TupleHashEntryData *TupleHashEntry;
  455. typedef struct TupleHashTableData *TupleHashTable;
  456. typedef struct TupleHashEntryData
  457. {
  458. /* firstTuple must be the first field in this struct! */
  459. MinimalTuple firstTuple; /* copy of first tuple in this group */
  460. /* there may be additional data beyond the end of this struct */
  461. } TupleHashEntryData; /* VARIABLE LENGTH STRUCT */
  462. typedef struct TupleHashTableData
  463. {
  464. HTAB *hashtab; /* underlying dynahash table */
  465. int numCols; /* number of columns in lookup key */
  466. AttrNumber *keyColIdx; /* attr numbers of key columns */
  467. FmgrInfo *tab_hash_funcs; /* hash functions for table datatype(s) */
  468. FmgrInfo *tab_eq_funcs; /* equality functions for table datatype(s) */
  469. MemoryContext tablecxt; /* memory context containing table */
  470. MemoryContext tempcxt; /* context for function evaluations */
  471. Size entrysize; /* actual size to make each hash entry */
  472. TupleTableSlot *tableslot; /* slot for referencing table entries */
  473. /* The following fields are set transiently for each table search: */
  474. TupleTableSlot *inputslot; /* current input tuple's slot */
  475. FmgrInfo *in_hash_funcs; /* hash functions for input datatype(s) */
  476. FmgrInfo *cur_eq_funcs; /* equality functions for input vs. table */
  477. } TupleHashTableData;
  478. typedef HASH_SEQ_STATUS TupleHashIterator;
  479. /*
  480. * Use InitTupleHashIterator/TermTupleHashIterator for a read/write scan.
  481. * Use ResetTupleHashIterator if the table can be frozen (in this case no
  482. * explicit scan termination is needed).
  483. */
  484. #define InitTupleHashIterator(htable, iter) \
  485. hash_seq_init(iter, (htable)->hashtab)
  486. #define TermTupleHashIterator(iter) \
  487. hash_seq_term(iter)
  488. #define ResetTupleHashIterator(htable, iter) \
  489. do { \
  490. hash_freeze((htable)->hashtab); \
  491. hash_seq_init(iter, (htable)->hashtab); \
  492. } while (0)
  493. #define ScanTupleHashTable(iter) \
  494. ((TupleHashEntry) hash_seq_search(iter))
  495. /* ----------------------------------------------------------------
  496. * Expression State Trees
  497. *
  498. * Each executable expression tree has a parallel ExprState tree.
  499. *
  500. * Unlike PlanState, there is not an exact one-for-one correspondence between
  501. * ExprState node types and Expr node types. Many Expr node types have no
  502. * need for node-type-specific run-time state, and so they can use plain
  503. * ExprState or GenericExprState as their associated ExprState node type.
  504. * ----------------------------------------------------------------
  505. */
  506. /* ----------------
  507. * ExprState node
  508. *
  509. * ExprState is the common superclass for all ExprState-type nodes.
  510. *
  511. * It can also be instantiated directly for leaf Expr nodes that need no
  512. * local run-time state (such as Var, Const, or Param).
  513. *
  514. * To save on dispatch overhead, each ExprState node contains a function
  515. * pointer to the routine to execute to evaluate the node.
  516. * ----------------
  517. */
  518. typedef struct ExprState ExprState;
  519. typedef Datum (*ExprStateEvalFunc) (ExprState *expression,
  520. ExprContext *econtext,
  521. bool *isNull,
  522. ExprDoneCond *isDone);
  523. struct ExprState
  524. {
  525. NodeTag type;
  526. Expr *expr; /* associated Expr node */
  527. ExprStateEvalFunc evalfunc; /* routine to run to execute node */
  528. };
  529. /* ----------------
  530. * GenericExprState node
  531. *
  532. * This is used for Expr node types that need no local run-time state,
  533. * but have one child Expr node.
  534. * ----------------
  535. */
  536. typedef struct GenericExprState
  537. {
  538. ExprState xprstate;
  539. ExprState *arg; /* state of my child node */
  540. } GenericExprState;
  541. /* ----------------
  542. * WholeRowVarExprState node
  543. * ----------------
  544. */
  545. typedef struct WholeRowVarExprState
  546. {
  547. ExprState xprstate;
  548. struct PlanState *parent; /* parent PlanState, or NULL if none */
  549. TupleDesc wrv_tupdesc; /* descriptor for resulting tuples */
  550. JunkFilter *wrv_junkFilter; /* JunkFilter to remove resjunk cols */
  551. } WholeRowVarExprState;
  552. /* ----------------
  553. * AggrefExprState node
  554. * ----------------
  555. */
  556. typedef struct AggrefExprState
  557. {
  558. ExprState xprstate;
  559. int aggno; /* ID number for agg within its plan node */
  560. } AggrefExprState;
  561. /* ----------------
  562. * GroupingFuncExprState node
  563. *
  564. * The list of column numbers refers to the input tuples of the Agg node to
  565. * which the GroupingFunc belongs, and may contain 0 for references to columns
  566. * that are only present in grouping sets processed by different Agg nodes (and
  567. * which are therefore always considered "grouping" here).
  568. * ----------------
  569. */
  570. typedef struct GroupingFuncExprState
  571. {
  572. ExprState xprstate;
  573. struct AggState *aggstate;
  574. List *clauses; /* integer list of column numbers */
  575. } GroupingFuncExprState;
  576. /* ----------------
  577. * WindowFuncExprState node
  578. * ----------------
  579. */
  580. typedef struct WindowFuncExprState
  581. {
  582. ExprState xprstate;
  583. List *args; /* states of argument expressions */
  584. ExprState *aggfilter; /* FILTER expression */
  585. int wfuncno; /* ID number for wfunc within its plan node */
  586. } WindowFuncExprState;
  587. /* ----------------
  588. * ArrayRefExprState node
  589. *
  590. * Note: array types can be fixed-length (typlen > 0), but only when the
  591. * element type is itself fixed-length. Otherwise they are varlena structures
  592. * and have typlen = -1. In any case, an array type is never pass-by-value.
  593. * ----------------
  594. */
  595. typedef struct ArrayRefExprState
  596. {
  597. ExprState xprstate;
  598. List *refupperindexpr; /* states for child nodes */
  599. List *reflowerindexpr;
  600. ExprState *refexpr;
  601. ExprState *refassgnexpr;
  602. int16 refattrlength; /* typlen of array type */
  603. int16 refelemlength; /* typlen of the array element type */
  604. bool refelembyval; /* is the element type pass-by-value? */
  605. char refelemalign; /* typalign of the element type */
  606. } ArrayRefExprState;
  607. /* ----------------
  608. * FuncExprState node
  609. *
  610. * Although named for FuncExpr, this is also used for OpExpr, DistinctExpr,
  611. * and NullIf nodes; be careful to check what xprstate.expr is actually
  612. * pointing at!
  613. * ----------------
  614. */
  615. typedef struct FuncExprState
  616. {
  617. ExprState xprstate;
  618. List *args; /* states of argument expressions */
  619. /*
  620. * Function manager's lookup info for the target function. If func.fn_oid
  621. * is InvalidOid, we haven't initialized it yet (nor any of the following
  622. * fields).
  623. */
  624. FmgrInfo func;
  625. /*
  626. * For a set-returning function (SRF) that returns a tuplestore, we keep
  627. * the tuplestore here and dole out the result rows one at a time. The
  628. * slot holds the row currently being returned.
  629. */
  630. Tuplestorestate *funcResultStore;
  631. TupleTableSlot *funcResultSlot;
  632. /*
  633. * In some cases we need to compute a tuple descriptor for the function's
  634. * output. If so, it's stored here.
  635. */
  636. TupleDesc funcResultDesc;
  637. bool funcReturnsTuple; /* valid when funcResultDesc isn't
  638. * NULL */
  639. /*
  640. * setArgsValid is true when we are evaluating a set-returning function
  641. * that uses value-per-call mode and we are in the middle of a call
  642. * series; we want to pass the same argument values to the function again
  643. * (and again, until it returns ExprEndResult). This indicates that
  644. * fcinfo_data already contains valid argument data.
  645. */
  646. bool setArgsValid;
  647. /*
  648. * Flag to remember whether we found a set-valued argument to the
  649. * function. This causes the function result to be a set as well. Valid
  650. * only when setArgsValid is true or funcResultStore isn't NULL.
  651. */
  652. bool setHasSetArg; /* some argument returns a set */
  653. /*
  654. * Flag to remember whether we have registered a shutdown callback for
  655. * this FuncExprState. We do so only if funcResultStore or setArgsValid
  656. * has been set at least once (since all the callback is for is to release
  657. * the tuplestore or clear setArgsValid).
  658. */
  659. bool shutdown_reg; /* a shutdown callback is registered */
  660. /*
  661. * Call parameter structure for the function. This has been initialized
  662. * (by InitFunctionCallInfoData) if func.fn_oid is valid. It also saves
  663. * argument values between calls, when setArgsValid is true.
  664. */
  665. FunctionCallInfoData fcinfo_data;
  666. } FuncExprState;
  667. /* ----------------
  668. * ScalarArrayOpExprState node
  669. *
  670. * This is a FuncExprState plus some additional data.
  671. * ----------------
  672. */
  673. typedef struct ScalarArrayOpExprState
  674. {
  675. FuncExprState fxprstate;
  676. /* Cached info about array element type */
  677. Oid element_type;
  678. int16 typlen;
  679. bool typbyval;
  680. char typalign;
  681. } ScalarArrayOpExprState;
  682. /* ----------------
  683. * BoolExprState node
  684. * ----------------
  685. */
  686. typedef struct BoolExprState
  687. {
  688. ExprState xprstate;
  689. List *args; /* states of argument expression(s) */
  690. } BoolExprState;
  691. /* ----------------
  692. * SubPlanState node
  693. * ----------------
  694. */
  695. typedef struct SubPlanState
  696. {
  697. ExprState xprstate;
  698. struct PlanState *planstate; /* subselect plan's state tree */
  699. struct PlanState *parent; /* parent plan node's state tree */
  700. ExprState *testexpr; /* state of combining expression */
  701. List *args; /* states of argument expression(s) */
  702. HeapTuple curTuple; /* copy of most recent tuple from subplan */
  703. Datum curArray; /* most recent array from ARRAY() subplan */
  704. /* these are used when hashing the subselect's output: */
  705. ProjectionInfo *projLeft; /* for projecting lefthand exprs */
  706. ProjectionInfo *projRight; /* for projecting subselect output */
  707. TupleHashTable hashtable; /* hash table for no-nulls subselect rows */
  708. TupleHashTable hashnulls; /* hash table for rows with null(s) */
  709. bool havehashrows; /* TRUE if hashtable is not empty */
  710. bool havenullrows; /* TRUE if hashnulls is not empty */
  711. MemoryContext hashtablecxt; /* memory context containing hash tables */
  712. MemoryContext hashtempcxt; /* temp memory context for hash tables */
  713. ExprContext *innerecontext; /* econtext for computing inner tuples */
  714. AttrNumber *keyColIdx; /* control data for hash tables */
  715. FmgrInfo *tab_hash_funcs; /* hash functions for table datatype(s) */
  716. FmgrInfo *tab_eq_funcs; /* equality functions for table datatype(s) */
  717. FmgrInfo *lhs_hash_funcs; /* hash functions for lefthand datatype(s) */
  718. FmgrInfo *cur_eq_funcs; /* equality functions for LHS vs. table */
  719. } SubPlanState;
  720. /* ----------------
  721. * AlternativeSubPlanState node
  722. * ----------------
  723. */
  724. typedef struct AlternativeSubPlanState
  725. {
  726. ExprState xprstate;
  727. List *subplans; /* states of alternative subplans */
  728. int active; /* list index of the one we're using */
  729. } AlternativeSubPlanState;
  730. /* ----------------
  731. * FieldSelectState node
  732. * ----------------
  733. */
  734. typedef struct FieldSelectState
  735. {
  736. ExprState xprstate;
  737. ExprState *arg; /* input expression */
  738. TupleDesc argdesc; /* tupdesc for most recent input */
  739. } FieldSelectState;
  740. /* ----------------
  741. * FieldStoreState node
  742. * ----------------
  743. */
  744. typedef struct FieldStoreState
  745. {
  746. ExprState xprstate;
  747. ExprState *arg; /* input tuple value */
  748. List *newvals; /* new value(s) for field(s) */
  749. TupleDesc argdesc; /* tupdesc for most recent input */
  750. } FieldStoreState;
  751. /* ----------------
  752. * CoerceViaIOState node
  753. * ----------------
  754. */
  755. typedef struct CoerceViaIOState
  756. {
  757. ExprState xprstate;
  758. ExprState *arg; /* input expression */
  759. FmgrInfo outfunc; /* lookup info for source output function */
  760. FmgrInfo infunc; /* lookup info for result input function */
  761. Oid intypioparam; /* argument needed for input function */
  762. } CoerceViaIOState;
  763. /* ----------------
  764. * ArrayCoerceExprState node
  765. * ----------------
  766. */
  767. typedef struct ArrayCoerceExprState
  768. {
  769. ExprState xprstate;
  770. ExprState *arg; /* input array value */
  771. Oid resultelemtype; /* element type of result array */
  772. FmgrInfo elemfunc; /* lookup info for element coercion function */
  773. /* use struct pointer to avoid including array.h here */
  774. struct ArrayMapState *amstate; /* workspace for array_map */
  775. } ArrayCoerceExprState;
  776. /* ----------------
  777. * ConvertRowtypeExprState node
  778. * ----------------
  779. */
  780. typedef struct ConvertRowtypeExprState
  781. {
  782. ExprState xprstate;
  783. ExprState *arg; /* input tuple value */
  784. TupleDesc indesc; /* tupdesc for source rowtype */
  785. TupleDesc outdesc; /* tupdesc for result rowtype */
  786. /* use "struct" so we needn't include tupconvert.h here */
  787. struct TupleConversionMap *map;
  788. bool initialized;
  789. } ConvertRowtypeExprState;
  790. /* ----------------
  791. * CaseExprState node
  792. * ----------------
  793. */
  794. typedef struct CaseExprState
  795. {
  796. ExprState xprstate;
  797. ExprState *arg; /* implicit equality comparison argument */
  798. List *args; /* the arguments (list of WHEN clauses) */
  799. ExprState *defresult; /* the default result (ELSE clause) */
  800. int16 argtyplen; /* if arg is provided, its typlen */
  801. } CaseExprState;
  802. /* ----------------
  803. * CaseWhenState node
  804. * ----------------
  805. */
  806. typedef struct CaseWhenState
  807. {
  808. ExprState xprstate;
  809. ExprState *expr; /* condition expression */
  810. ExprState *result; /* substitution result */
  811. } CaseWhenState;
  812. /* ----------------
  813. * ArrayExprState node
  814. *
  815. * Note: ARRAY[] expressions always produce varlena arrays, never fixed-length
  816. * arrays.
  817. * ----------------
  818. */
  819. typedef struct ArrayExprState
  820. {
  821. ExprState xprstate;
  822. List *elements; /* states for child nodes */
  823. int16 elemlength; /* typlen of the array element type */
  824. bool elembyval; /* is the element type pass-by-value? */
  825. char elemalign; /* typalign of the element type */
  826. } ArrayExprState;
  827. /* ----------------
  828. * RowExprState node
  829. * ----------------
  830. */
  831. typedef struct RowExprState
  832. {
  833. ExprState xprstate;
  834. List *args; /* the arguments */
  835. TupleDesc tupdesc; /* descriptor for result tuples */
  836. } RowExprState;
  837. /* ----------------
  838. * RowCompareExprState node
  839. * ----------------
  840. */
  841. typedef struct RowCompareExprState
  842. {
  843. ExprState xprstate;
  844. List *largs; /* the left-hand input arguments */
  845. List *rargs; /* the right-hand input arguments */
  846. FmgrInfo *funcs; /* array of comparison function info */
  847. Oid *collations; /* array of collations to use */
  848. } RowCompareExprState;
  849. /* ----------------
  850. * CoalesceExprState node
  851. * ----------------
  852. */
  853. typedef struct CoalesceExprState
  854. {
  855. ExprState xprstate;
  856. List *args; /* the arguments */
  857. } CoalesceExprState;
  858. /* ----------------
  859. * MinMaxExprState node
  860. * ----------------
  861. */
  862. typedef struct MinMaxExprState
  863. {
  864. ExprState xprstate;
  865. List *args; /* the arguments */
  866. FmgrInfo cfunc; /* lookup info for comparison func */
  867. } MinMaxExprState;
  868. /* ----------------
  869. * XmlExprState node
  870. * ----------------
  871. */
  872. typedef struct XmlExprState
  873. {
  874. ExprState xprstate;
  875. List *named_args; /* ExprStates for named arguments */
  876. List *args; /* ExprStates for other arguments */
  877. } XmlExprState;
  878. /* ----------------
  879. * NullTestState node
  880. * ----------------
  881. */
  882. typedef struct NullTestState
  883. {
  884. ExprState xprstate;
  885. ExprState *arg; /* input expression */
  886. /* used only if input is of composite type: */
  887. TupleDesc argdesc; /* tupdesc for most recent input */
  888. } NullTestState;
  889. /* ----------------
  890. * CoerceToDomainState node
  891. * ----------------
  892. */
  893. typedef struct CoerceToDomainState
  894. {
  895. ExprState xprstate;
  896. ExprState *arg; /* input expression */
  897. /* Cached set of constraints that need to be checked */
  898. /* use struct pointer to avoid including typcache.h here */
  899. struct DomainConstraintRef *constraint_ref;
  900. } CoerceToDomainState;
  901. /*
  902. * DomainConstraintState - one item to check during CoerceToDomain
  903. *
  904. * Note: this is just a Node, and not an ExprState, because it has no
  905. * corresponding Expr to link to. Nonetheless it is part of an ExprState
  906. * tree, so we give it a name following the xxxState convention.
  907. */
  908. typedef enum DomainConstraintType
  909. {
  910. DOM_CONSTRAINT_NOTNULL,
  911. DOM_CONSTRAINT_CHECK
  912. } DomainConstraintType;
  913. typedef struct DomainConstraintState
  914. {
  915. NodeTag type;
  916. DomainConstraintType constrainttype; /* constraint type */
  917. char *name; /* name of constraint (for error msgs) */
  918. ExprState *check_expr; /* for CHECK, a boolean expression */
  919. } DomainConstraintState;
  920. /* ----------------------------------------------------------------
  921. * Executor State Trees
  922. *
  923. * An executing query has a PlanState tree paralleling the Plan tree
  924. * that describes the plan.
  925. * ----------------------------------------------------------------
  926. */
  927. /* ----------------
  928. * PlanState node
  929. *
  930. * We never actually instantiate any PlanState nodes; this is just the common
  931. * abstract superclass for all PlanState-type nodes.
  932. * ----------------
  933. */
  934. typedef struct PlanState
  935. {
  936. NodeTag type;
  937. Plan *plan; /* associated Plan node */
  938. EState *state; /* at execution time, states of individual
  939. * nodes point to one EState for the whole
  940. * top-level plan */
  941. Instrumentation *instrument; /* Optional runtime stats for this node */
  942. WorkerInstrumentation *worker_instrument; /* per-worker instrumentation */
  943. /*
  944. * Common structural data for all Plan types. These links to subsidiary
  945. * state trees parallel links in the associated plan tree (except for the
  946. * subPlan list, which does not exist in the plan tree).
  947. */
  948. List *targetlist; /* target list to be computed at this node */
  949. List *qual; /* implicitly-ANDed qual conditions */
  950. struct PlanState *lefttree; /* input plan tree(s) */
  951. struct PlanState *righttree;
  952. List *initPlan; /* Init SubPlanState nodes (un-correlated expr
  953. * subselects) */
  954. List *subPlan; /* SubPlanState nodes in my expressions */
  955. /*
  956. * State for management of parameter-change-driven rescanning
  957. */
  958. Bitmapset *chgParam; /* set of IDs of changed Params */
  959. /*
  960. * Other run-time state needed by most if not all node types.
  961. */
  962. TupleTableSlot *ps_ResultTupleSlot; /* slot for my result tuples */
  963. ExprContext *ps_ExprContext; /* node's expression-evaluation context */
  964. ProjectionInfo *ps_ProjInfo; /* info for doing tuple projection */
  965. bool ps_TupFromTlist;/* state flag for processing set-valued
  966. * functions in targetlist */
  967. } PlanState;
  968. /* ----------------
  969. * these are defined to avoid confusion problems with "left"
  970. * and "right" and "inner" and "outer". The convention is that
  971. * the "left" plan is the "outer" plan and the "right" plan is
  972. * the inner plan, but these make the code more readable.
  973. * ----------------
  974. */
  975. #define innerPlanState(node) (((PlanState *)(node))->righttree)
  976. #define outerPlanState(node) (((PlanState *)(node))->lefttree)
  977. /* Macros for inline access to certain instrumentation counters */
  978. #define InstrCountFiltered1(node, delta) \
  979. do { \
  980. if (((PlanState *)(node))->instrument) \
  981. ((PlanState *)(node))->instrument->nfiltered1 += (delta); \
  982. } while(0)
  983. #define InstrCountFiltered2(node, delta) \
  984. do { \
  985. if (((PlanState *)(node))->instrument) \
  986. ((PlanState *)(node))->instrument->nfiltered2 += (delta); \
  987. } while(0)
  988. /*
  989. * EPQState is state for executing an EvalPlanQual recheck on a candidate
  990. * tuple in ModifyTable or LockRows. The estate and planstate fields are
  991. * NULL if inactive.
  992. */
  993. typedef struct EPQState
  994. {
  995. EState *estate; /* subsidiary EState */
  996. PlanState *planstate; /* plan state tree ready to be executed */
  997. TupleTableSlot *origslot; /* original output tuple to be rechecked */
  998. Plan *plan; /* plan tree to be executed */
  999. List *arowMarks; /* ExecAuxRowMarks (non-locking only) */
  1000. int epqParam; /* ID of Param to force scan node re-eval */
  1001. } EPQState;
  1002. /* ----------------
  1003. * ResultState information
  1004. * ----------------
  1005. */
  1006. typedef struct ResultState
  1007. {
  1008. PlanState ps; /* its first field is NodeTag */
  1009. ExprState *resconstantqual;
  1010. bool rs_done; /* are we done? */
  1011. bool rs_checkqual; /* do we need to check the qual? */
  1012. } ResultState;
  1013. /* ----------------
  1014. * ModifyTableState information
  1015. * ----------------
  1016. */
  1017. typedef struct ModifyTableState
  1018. {
  1019. PlanState ps; /* its first field is NodeTag */
  1020. CmdType operation; /* INSERT, UPDATE, or DELETE */
  1021. bool canSetTag; /* do we set the command tag/es_processed? */
  1022. bool mt_done; /* are we done? */
  1023. PlanState **mt_plans; /* subplans (one per target rel) */
  1024. int mt_nplans; /* number of plans in the array */
  1025. int mt_whichplan; /* which one is being executed (0..n-1) */
  1026. ResultRelInfo *resultRelInfo; /* per-subplan target relations */
  1027. List **mt_arowmarks; /* per-subplan ExecAuxRowMark lists */
  1028. EPQState mt_epqstate; /* for evaluating EvalPlanQual rechecks */
  1029. bool fireBSTriggers; /* do we need to fire stmt triggers? */
  1030. OnConflictAction mt_onconflict; /* ON CONFLICT type */
  1031. List *mt_arbiterindexes; /* unique index OIDs to arbitrate
  1032. * taking alt path */
  1033. TupleTableSlot *mt_existing; /* slot to store existing target tuple in */
  1034. List *mt_excludedtlist; /* the excluded pseudo relation's
  1035. * tlist */
  1036. TupleTableSlot *mt_conflproj; /* CONFLICT ... SET ... projection
  1037. * target */
  1038. } ModifyTableState;
  1039. /* ----------------
  1040. * AppendState information
  1041. *
  1042. * nplans how many plans are in the array
  1043. * whichplan which plan is being executed (0 .. n-1)
  1044. * ----------------
  1045. */
  1046. typedef struct AppendState
  1047. {
  1048. PlanState ps; /* its first field is NodeTag */
  1049. PlanState **appendplans; /* array of PlanStates for my inputs */
  1050. int as_nplans;
  1051. int as_whichplan;
  1052. } AppendState;
  1053. /* ----------------
  1054. * MergeAppendState information
  1055. *
  1056. * nplans how many plans are in the array
  1057. * nkeys number of sort key columns
  1058. * sortkeys sort keys in SortSupport representation
  1059. * slots current output tuple of each subplan
  1060. * heap heap of active tuples
  1061. * initialized true if we have fetched first tuple from each subplan
  1062. * ----------------
  1063. */
  1064. typedef struct MergeAppendState
  1065. {
  1066. PlanState ps; /* its first field is NodeTag */
  1067. PlanState **mergeplans; /* array of PlanStates for my inputs */
  1068. int ms_nplans;
  1069. int ms_nkeys;
  1070. SortSupport ms_sortkeys; /* array of length ms_nkeys */
  1071. TupleTableSlot **ms_slots; /* array of length ms_nplans */
  1072. struct binaryheap *ms_heap; /* binary heap of slot indices */
  1073. bool ms_initialized; /* are subplans started? */
  1074. } MergeAppendState;
  1075. /* ----------------
  1076. * RecursiveUnionState information
  1077. *
  1078. * RecursiveUnionState is used for performing a recursive union.
  1079. *
  1080. * recursing T when we're done scanning the non-recursive term
  1081. * intermediate_empty T if intermediate_table is currently empty
  1082. * working_table working table (to be scanned by recursive term)
  1083. * intermediate_table current recursive output (next generation of WT)
  1084. * ----------------
  1085. */
  1086. typedef struct RecursiveUnionState
  1087. {
  1088. PlanState ps; /* its first field is NodeTag */
  1089. bool recursing;
  1090. bool intermediate_empty;
  1091. Tuplestorestate *working_table;
  1092. Tuplestorestate *intermediate_table;
  1093. /* Remaining fields are unused in UNION ALL case */
  1094. FmgrInfo *eqfunctions; /* per-grouping-field equality fns */
  1095. FmgrInfo *hashfunctions; /* per-grouping-field hash fns */
  1096. MemoryContext tempContext; /* short-term context for comparisons */
  1097. TupleHashTable hashtable; /* hash table for tuples already seen */
  1098. MemoryContext tableContext; /* memory context containing hash table */
  1099. } RecursiveUnionState;
  1100. /* ----------------
  1101. * BitmapAndState information
  1102. * ----------------
  1103. */
  1104. typedef struct BitmapAndState
  1105. {
  1106. PlanState ps; /* its first field is NodeTag */
  1107. PlanState **bitmapplans; /* array of PlanStates for my inputs */
  1108. int nplans; /* number of input plans */
  1109. } BitmapAndState;
  1110. /* ----------------
  1111. * BitmapOrState information
  1112. * ----------------
  1113. */
  1114. typedef struct BitmapOrState
  1115. {
  1116. PlanState ps; /* its first field is NodeTag */
  1117. PlanState **bitmapplans; /* array of PlanStates for my inputs */
  1118. int nplans; /* number of input plans */
  1119. } BitmapOrState;
  1120. /* ----------------------------------------------------------------
  1121. * Scan State Information
  1122. * ----------------------------------------------------------------
  1123. */
  1124. /* ----------------
  1125. * ScanState information
  1126. *
  1127. * ScanState extends PlanState for node types that represent
  1128. * scans of an underlying relation. It can also be used for nodes
  1129. * that scan the output of an underlying plan node --- in that case,
  1130. * only ScanTupleSlot is actually useful, and it refers to the tuple
  1131. * retrieved from the subplan.
  1132. *
  1133. * currentRelation relation being scanned (NULL if none)
  1134. * currentScanDesc current scan descriptor for scan (NULL if none)
  1135. * ScanTupleSlot pointer to slot in tuple table holding scan tuple
  1136. * ----------------
  1137. */
  1138. typedef struct ScanState
  1139. {
  1140. PlanState ps; /* its first field is NodeTag */
  1141. Relation ss_currentRelation;
  1142. HeapScanDesc ss_currentScanDesc;
  1143. TupleTableSlot *ss_ScanTupleSlot;
  1144. } ScanState;
  1145. /* ----------------
  1146. * SeqScanState information
  1147. * ----------------
  1148. */
  1149. typedef struct SeqScanState
  1150. {
  1151. ScanState ss; /* its first field is NodeTag */
  1152. Size pscan_len; /* size of parallel heap scan descriptor */
  1153. } SeqScanState;
  1154. /* ----------------
  1155. * SampleScanState information
  1156. * ----------------
  1157. */
  1158. typedef struct SampleScanState
  1159. {
  1160. ScanState ss;
  1161. List *args; /* expr states for TABLESAMPLE params */
  1162. ExprState *repeatable; /* expr state for REPEATABLE expr */
  1163. /* use struct pointer to avoid including tsmapi.h here */
  1164. struct TsmRoutine *tsmroutine; /* descriptor for tablesample method */
  1165. void *tsm_state; /* tablesample method can keep state here */
  1166. bool use_bulkread; /* use bulkread buffer access strategy? */
  1167. bool use_pagemode; /* use page-at-a-time visibility checking? */
  1168. bool begun; /* false means need to call BeginSampleScan */
  1169. uint32 seed; /* random seed */
  1170. } SampleScanState;
  1171. /*
  1172. * These structs store information about index quals that don't have simple
  1173. * constant right-hand sides. See comments for ExecIndexBuildScanKeys()
  1174. * for discussion.
  1175. */
  1176. typedef struct
  1177. {
  1178. ScanKey scan_key; /* scankey to put value into */
  1179. ExprState *key_expr; /* expr to evaluate to get value */
  1180. bool key_toastable; /* is expr's result a toastable datatype? */
  1181. } IndexRuntimeKeyInfo;
  1182. typedef struct
  1183. {
  1184. ScanKey scan_key; /* scankey to put value into */
  1185. ExprState *array_expr; /* expr to evaluate to get array value */
  1186. int next_elem; /* next array element to use */
  1187. int num_elems; /* number of elems in current array value */
  1188. Datum *elem_values; /* array of num_elems Datums */
  1189. bool *elem_nulls; /* array of num_elems is-null flags */
  1190. } IndexArrayKeyInfo;
  1191. /* ----------------
  1192. * IndexScanState information
  1193. *
  1194. * indexqualorig execution state for indexqualorig expressions
  1195. * indexorderbyorig execution state for indexorderbyorig expressions
  1196. * ScanKeys Skey structures for index quals
  1197. * NumScanKeys number of ScanKeys
  1198. * OrderByKeys Skey structures for index ordering operators
  1199. * NumOrderByKeys number of OrderByKeys
  1200. * RuntimeKeys info about Skeys that must be evaluated at runtime
  1201. * NumRuntimeKeys number of RuntimeKeys
  1202. * RuntimeKeysReady true if runtime Skeys have been computed
  1203. * RuntimeContext expr context for evaling runtime Skeys
  1204. * RelationDesc index relation descriptor
  1205. * ScanDesc index scan descriptor
  1206. *
  1207. * ReorderQueue tuples that need reordering due to re-check
  1208. * ReachedEnd have we fetched all tuples from index already?
  1209. * OrderByValues values of ORDER BY exprs of last fetched tuple
  1210. * OrderByNulls null flags for OrderByValues
  1211. * SortSupport for reordering ORDER BY exprs
  1212. * OrderByTypByVals is the datatype of order by expression pass-by-value?
  1213. * OrderByTypLens typlens of the datatypes of order by expressions
  1214. * ----------------
  1215. */
  1216. typedef struct IndexScanState
  1217. {
  1218. ScanState ss; /* its first field is NodeTag */
  1219. List *indexqualorig;
  1220. List *indexorderbyorig;
  1221. ScanKey iss_ScanKeys;
  1222. int iss_NumScanKeys;
  1223. ScanKey iss_OrderByKeys;
  1224. int iss_NumOrderByKeys;
  1225. IndexRuntimeKeyInfo *iss_RuntimeKeys;
  1226. int iss_NumRuntimeKeys;
  1227. bool iss_RuntimeKeysReady;
  1228. ExprContext *iss_RuntimeContext;
  1229. Relation iss_RelationDesc;
  1230. IndexScanDesc iss_ScanDesc;
  1231. /* These are needed for re-checking ORDER BY expr ordering */
  1232. pairingheap *iss_ReorderQueue;
  1233. bool iss_ReachedEnd;
  1234. Datum *iss_OrderByValues;
  1235. bool *iss_OrderByNulls;
  1236. SortSupport iss_SortSupport;
  1237. bool *iss_OrderByTypByVals;
  1238. int16 *iss_OrderByTypLens;
  1239. } IndexScanState;
  1240. /* ----------------
  1241. * IndexOnlyScanState information
  1242. *
  1243. * indexqual execution state for indexqual expressions
  1244. * ScanKeys Skey structures for index quals
  1245. * NumScanKeys number of ScanKeys
  1246. * OrderByKeys Skey structures for index ordering operators
  1247. * NumOrderByKeys number of OrderByKeys
  1248. * RuntimeKeys info about Skeys that must be evaluated at runtime
  1249. * NumRuntimeKeys number of RuntimeKeys
  1250. * RuntimeKeysReady true if runtime Skeys have been computed
  1251. * RuntimeContext expr context for evaling runtime Skeys
  1252. * RelationDesc index relation descriptor
  1253. * ScanDesc index scan descriptor
  1254. * VMBuffer buffer in use for visibility map testing, if any
  1255. * HeapFetches number of tuples we were forced to fetch from heap
  1256. * ----------------
  1257. */
  1258. typedef struct IndexOnlyScanState
  1259. {
  1260. ScanState ss; /* its first field is NodeTag */
  1261. List *indexqual;
  1262. ScanKey ioss_ScanKeys;
  1263. int ioss_NumScanKeys;
  1264. ScanKey ioss_OrderByKeys;
  1265. int ioss_NumOrderByKeys;
  1266. IndexRuntimeKeyInfo *ioss_RuntimeKeys;
  1267. int ioss_NumRuntimeKeys;
  1268. bool ioss_RuntimeKeysReady;
  1269. ExprContext *ioss_RuntimeContext;
  1270. Relation ioss_RelationDesc;
  1271. IndexScanDesc ioss_ScanDesc;
  1272. Buffer ioss_VMBuffer;
  1273. long ioss_HeapFetches;
  1274. } IndexOnlyScanState;
  1275. /* ----------------
  1276. * BitmapIndexScanState information
  1277. *
  1278. * result bitmap to return output into, or NULL
  1279. * ScanKeys Skey structures for index quals
  1280. * NumScanKeys number of ScanKeys
  1281. * RuntimeKeys info about Skeys that must be evaluated at runtime
  1282. * NumRuntimeKeys number of RuntimeKeys
  1283. * ArrayKeys info about Skeys that come from ScalarArrayOpExprs
  1284. * NumArrayKeys number of ArrayKeys
  1285. * RuntimeKeysReady true if runtime Skeys have been computed
  1286. * RuntimeContext expr context for evaling runtime Skeys
  1287. * RelationDesc index relation descriptor
  1288. * ScanDesc index scan descriptor
  1289. * ----------------
  1290. */
  1291. typedef struct BitmapIndexScanState
  1292. {
  1293. ScanState ss; /* its first field is NodeTag */
  1294. TIDBitmap *biss_result;
  1295. ScanKey biss_ScanKeys;
  1296. int biss_NumScanKeys;
  1297. IndexRuntimeKeyInfo *biss_RuntimeKeys;
  1298. int biss_NumRuntimeKeys;
  1299. IndexArrayKeyInfo *biss_ArrayKeys;
  1300. int biss_NumArrayKeys;
  1301. bool biss_RuntimeKeysReady;
  1302. ExprContext *biss_RuntimeContext;
  1303. Relation biss_RelationDesc;
  1304. IndexScanDesc biss_ScanDesc;
  1305. } BitmapIndexScanState;
  1306. /* ----------------
  1307. * BitmapHeapScanState information
  1308. *
  1309. * bitmapqualorig execution state for bitmapqualorig expressions
  1310. * tbm bitmap obtained from child index scan(s)
  1311. * tbmiterator iterator for scanning current pages
  1312. * tbmres current-page data
  1313. * exact_pages total number of exact pages retrieved
  1314. * lossy_pages total number of lossy pages retrieved
  1315. * prefetch_iterator iterator for prefetching ahead of current page
  1316. * prefetch_pages # pages prefetch iterator is ahead of current
  1317. * prefetch_target current target prefetch distance
  1318. * prefetch_maximum maximum value for prefetch_target
  1319. * ----------------
  1320. */
  1321. typedef struct BitmapHeapScanState
  1322. {
  1323. ScanState ss; /* its first field is NodeTag */
  1324. List *bitmapqualorig;
  1325. TIDBitmap *tbm;
  1326. TBMIterator *tbmiterator;
  1327. TBMIterateResult *tbmres;
  1328. long exact_pages;
  1329. long lossy_pages;
  1330. TBMIterator *prefetch_iterator;
  1331. int prefetch_pages;
  1332. int prefetch_target;
  1333. int prefetch_maximum;
  1334. } BitmapHeapScanState;
  1335. /* ----------------
  1336. * TidScanState information
  1337. *
  1338. * isCurrentOf scan has a CurrentOfExpr qual
  1339. * NumTids number of tids in this scan
  1340. * TidPtr index of currently fetched tid
  1341. * TidList evaluated item pointers (array of size NumTids)
  1342. * ----------------
  1343. */
  1344. typedef struct TidScanState
  1345. {
  1346. ScanState ss; /* its first field is NodeTag */
  1347. List *tss_tidquals; /* list of ExprState nodes */
  1348. bool tss_isCurrentOf;
  1349. int tss_NumTids;
  1350. int tss_TidPtr;
  1351. ItemPointerData *tss_TidList;
  1352. HeapTupleData tss_htup;
  1353. } TidScanState;
  1354. /* ----------------
  1355. * SubqueryScanState information
  1356. *
  1357. * SubqueryScanState is used for scanning a sub-query in the range table.
  1358. * ScanTupleSlot references the current output tuple of the sub-query.
  1359. * ----------------
  1360. */
  1361. typedef struct SubqueryScanState
  1362. {
  1363. ScanState ss; /* its first field is NodeTag */
  1364. PlanState *subplan;
  1365. } SubqueryScanState;
  1366. /* ----------------
  1367. * FunctionScanState information
  1368. *
  1369. * Function nodes are used to scan the results of a
  1370. * function appearing in FROM (typically a function returning set).
  1371. *
  1372. * eflags node's capability flags
  1373. * ordinality is this scan WITH ORDINALITY?
  1374. * simple true if we have 1 function and no ordinality
  1375. * ordinal current ordinal column value
  1376. * nfuncs number of functions being executed
  1377. * funcstates per-function execution states (private in
  1378. * nodeFunctionscan.c)
  1379. * argcontext memory context to evaluate function arguments in
  1380. * ----------------
  1381. */
  1382. struct FunctionScanPerFuncState;
  1383. typedef struct FunctionScanState
  1384. {
  1385. ScanState ss; /* its first field is NodeTag */
  1386. int eflags;
  1387. bool ordinality;
  1388. bool simple;
  1389. int64 ordinal;
  1390. int nfuncs;
  1391. struct FunctionScanPerFuncState *funcstates; /* array of length
  1392. * nfuncs */
  1393. MemoryContext argcontext;
  1394. } FunctionScanState;
  1395. /* ----------------
  1396. * ValuesScanState information
  1397. *
  1398. * ValuesScan nodes are used to scan the results of a VALUES list
  1399. *
  1400. * rowcontext per-expression-list context
  1401. * exprlists array of expression lists being evaluated
  1402. * array_len size of array
  1403. * curr_idx current array index (0-based)
  1404. *
  1405. * Note: ss.ps.ps_ExprContext is used to evaluate any qual or projection
  1406. * expressions attached to the node. We create a second ExprContext,
  1407. * rowcontext, in which to build the executor expression state for each
  1408. * Values sublist. Resetting this context lets us get rid of expression
  1409. * state for each row, avoiding major memory leakage over a long values list.
  1410. * ----------------
  1411. */
  1412. typedef struct ValuesScanState
  1413. {
  1414. ScanState ss; /* its first field is NodeTag */
  1415. ExprContext *rowcontext;
  1416. List **exprlists;
  1417. int array_len;
  1418. int curr_idx;
  1419. } ValuesScanState;
  1420. /* ----------------
  1421. * CteScanState information
  1422. *
  1423. * CteScan nodes are used to scan a CommonTableExpr query.
  1424. *
  1425. * Multiple CteScan nodes can read out from the same CTE query. We use
  1426. * a tuplestore to hold rows that have been read from the CTE query but
  1427. * not yet consumed by all readers.
  1428. * ----------------
  1429. */
  1430. typedef struct CteScanState
  1431. {
  1432. ScanState ss; /* its first field is NodeTag */
  1433. int eflags; /* capability flags to pass to tuplestore */
  1434. int readptr; /* index of my tuplestore read pointer */
  1435. PlanState *cteplanstate; /* PlanState for the CTE query itself */
  1436. /* Link to the "leader" CteScanState (possibly this same node) */
  1437. struct CteScanState *leader;
  1438. /* The remaining fields are only valid in the "leader" CteScanState */
  1439. Tuplestorestate *cte_table; /* rows already read from the CTE query */
  1440. bool eof_cte; /* reached end of CTE query? */
  1441. } CteScanState;
  1442. /* ----------------
  1443. * WorkTableScanState information
  1444. *
  1445. * WorkTableScan nodes are used to scan the work table created by
  1446. * a RecursiveUnion node. We locate the RecursiveUnion node
  1447. * during executor startup.
  1448. * ----------------
  1449. */
  1450. typedef struct WorkTableScanState
  1451. {
  1452. ScanState ss; /* its first field is NodeTag */
  1453. RecursiveUnionState *rustate;
  1454. } WorkTableScanState;
  1455. /* ----------------
  1456. * ForeignScanState information
  1457. *
  1458. * ForeignScan nodes are used to scan foreign-data tables.
  1459. * ----------------
  1460. */
  1461. typedef struct ForeignScanState
  1462. {
  1463. ScanState ss; /* its first field is NodeTag */
  1464. List *fdw_recheck_quals; /* original quals not in ss.ps.qual */
  1465. Size pscan_len; /* size of parallel coordination information */
  1466. /* use struct pointer to avoid including fdwapi.h here */
  1467. struct FdwRoutine *fdwroutine;
  1468. void *fdw_state; /* foreign-data wrapper can keep state here */
  1469. } ForeignScanState;
  1470. /* ----------------
  1471. * CustomScanState information
  1472. *
  1473. * CustomScan nodes are used to execute custom code within executor.
  1474. *
  1475. * Core code must avoid assuming that the CustomScanState is only as large as
  1476. * the structure declared here; providers are allowed to make it the first
  1477. * element in a larger structure, and typically would need to do so. The
  1478. * struct is actually allocated by the CreateCustomScanState method associated
  1479. * with the plan node. Any additional fields can be initialized there, or in
  1480. * the BeginCustomScan method.
  1481. * ----------------
  1482. */
  1483. struct CustomExecMethods;
  1484. typedef struct CustomScanState
  1485. {
  1486. ScanState ss;
  1487. uint32 flags; /* mask of CUSTOMPATH_* flags, see
  1488. * nodes/extensible.h */
  1489. List *custom_ps; /* list of child PlanState nodes, if any */
  1490. Size pscan_len; /* size of parallel coordination information */
  1491. const struct CustomExecMethods *methods;
  1492. } CustomScanState;
  1493. /* ----------------------------------------------------------------
  1494. * Join State Information
  1495. * ----------------------------------------------------------------
  1496. */
  1497. /* ----------------
  1498. * JoinState information
  1499. *
  1500. * Superclass for state nodes of join plans.
  1501. * ----------------
  1502. */
  1503. typedef struct JoinState
  1504. {
  1505. PlanState ps;
  1506. JoinType jointype;
  1507. List *joinqual; /* JOIN quals (in addition to ps.qual) */
  1508. } JoinState;
  1509. /* ----------------
  1510. * NestLoopState information
  1511. *
  1512. * NeedNewOuter true if need new outer tuple on next call
  1513. * MatchedOuter true if found a join match for current outer tuple
  1514. * NullInnerTupleSlot prepared null tuple for left outer joins
  1515. * ----------------
  1516. */
  1517. typedef struct NestLoopState
  1518. {
  1519. JoinState js; /* its first field is NodeTag */
  1520. bool nl_NeedNewOuter;
  1521. bool nl_MatchedOuter;
  1522. TupleTableSlot *nl_NullInnerTupleSlot;
  1523. } NestLoopState;
  1524. /* ----------------
  1525. * MergeJoinState information
  1526. *
  1527. * NumClauses number of mergejoinable join clauses
  1528. * Clauses info for each mergejoinable clause
  1529. * JoinState current state of ExecMergeJoin state machine
  1530. * ExtraMarks true to issue extra Mark operations on inner scan
  1531. * ConstFalseJoin true if we have a constant-false joinqual
  1532. * FillOuter true if should emit unjoined outer tuples anyway
  1533. * FillInner true if should emit unjoined inner tuples anyway
  1534. * MatchedOuter true if found a join match for current outer tuple
  1535. * MatchedInner true if found a join match for current inner tuple
  1536. * OuterTupleSlot slot in tuple table for cur outer tuple
  1537. * InnerTupleSlot slot in tuple table for cur inner tuple
  1538. * MarkedTupleSlot slot in tuple table for marked tuple
  1539. * NullOuterTupleSlot prepared null tuple for right outer joins
  1540. * NullInnerTupleSlot prepared null tuple for left outer joins
  1541. * OuterEContext workspace for computing outer tuple's join values
  1542. * InnerEContext workspace for computing inner tuple's join values
  1543. * ----------------
  1544. */
  1545. /* private in nodeMergejoin.c: */
  1546. typedef struct MergeJoinClauseData *MergeJoinClause;
  1547. typedef struct MergeJoinState
  1548. {
  1549. JoinState js; /* its first field is NodeTag */
  1550. int mj_NumClauses;
  1551. MergeJoinClause mj_Clauses; /* array of length mj_NumClauses */
  1552. int mj_JoinState;
  1553. bool mj_ExtraMarks;
  1554. bool mj_ConstFalseJoin;
  1555. bool mj_FillOuter;
  1556. bool mj_FillInner;
  1557. bool mj_MatchedOuter;
  1558. bool mj_MatchedInner;
  1559. TupleTableSlot *mj_OuterTupleSlot;
  1560. TupleTableSlot *mj_InnerTupleSlot;
  1561. TupleTableSlot *mj_MarkedTupleSlot;
  1562. TupleTableSlot *mj_NullOuterTupleSlot;
  1563. TupleTableSlot *mj_NullInnerTupleSlot;
  1564. ExprContext *mj_OuterEContext;
  1565. ExprContext *mj_InnerEContext;
  1566. } MergeJoinState;
  1567. /* ----------------
  1568. * HashJoinState information
  1569. *
  1570. * hashclauses original form of the hashjoin condition
  1571. * hj_OuterHashKeys the outer hash keys in the hashjoin condition
  1572. * hj_InnerHashKeys the inner hash keys in the hashjoin condition
  1573. * hj_HashOperators the join operators in the hashjoin condition
  1574. * hj_HashTable hash table for the hashjoin
  1575. * (NULL if table not built yet)
  1576. * hj_CurHashValue hash value for current outer tuple
  1577. * hj_CurBucketNo regular bucket# for current outer tuple
  1578. * hj_CurSkewBucketNo skew bucket# for current outer tuple
  1579. * hj_CurTuple last inner tuple matched to current outer
  1580. * tuple, or NULL if starting search
  1581. * (hj_CurXXX variables are undefined if
  1582. * OuterTupleSlot is empty!)
  1583. * hj_OuterTupleSlot tuple slot for outer tuples
  1584. * hj_HashTupleSlot tuple slot for inner (hashed) tuples
  1585. * hj_NullOuterTupleSlot prepared null tuple for right/full outer joins
  1586. * hj_NullInnerTupleSlot prepared null tuple for left/full outer joins
  1587. * hj_FirstOuterTupleSlot first tuple retrieved from outer plan
  1588. * hj_JoinState current state of ExecHashJoin state machine
  1589. * hj_MatchedOuter true if found a join match for current outer
  1590. * hj_OuterNotEmpty true if outer relation known not empty
  1591. * ----------------
  1592. */
  1593. /* these structs are defined in executor/hashjoin.h: */
  1594. typedef struct HashJoinTupleData *HashJoinTuple;
  1595. typedef struct HashJoinTableData *HashJoinTable;
  1596. typedef struct HashJoinState
  1597. {
  1598. JoinState js; /* its first field is NodeTag */
  1599. List *hashclauses; /* list of ExprState nodes */
  1600. List *hj_OuterHashKeys; /* list of ExprState nodes */
  1601. List *hj_InnerHashKeys; /* list of ExprState nodes */
  1602. List *hj_HashOperators; /* list of operator OIDs */
  1603. HashJoinTable hj_HashTable;
  1604. uint32 hj_CurHashValue;
  1605. int hj_CurBucketNo;
  1606. int hj_CurSkewBucketNo;
  1607. HashJoinTuple hj_CurTuple;
  1608. TupleTableSlot *hj_OuterTupleSlot;
  1609. TupleTableSlot *hj_HashTupleSlot;
  1610. TupleTableSlot *hj_NullOuterTupleSlot;
  1611. TupleTableSlot *hj_NullInnerTupleSlot;
  1612. TupleTableSlot *hj_FirstOuterTupleSlot;
  1613. int hj_JoinState;
  1614. bool hj_MatchedOuter;
  1615. bool hj_OuterNotEmpty;
  1616. } HashJoinState;
  1617. /* ----------------------------------------------------------------
  1618. * Materialization State Information
  1619. * ----------------------------------------------------------------
  1620. */
  1621. /* ----------------
  1622. * MaterialState information
  1623. *
  1624. * materialize nodes are used to materialize the results
  1625. * of a subplan into a temporary file.
  1626. *
  1627. * ss.ss_ScanTupleSlot refers to output of underlying plan.
  1628. * ----------------
  1629. */
  1630. typedef struct MaterialState
  1631. {
  1632. ScanState ss; /* its first field is NodeTag */
  1633. int eflags; /* capability flags to pass to tuplestore */
  1634. bool eof_underlying; /* reached end of underlying plan? */
  1635. Tuplestorestate *tuplestorestate;
  1636. } MaterialState;
  1637. /* ----------------
  1638. * SortState information
  1639. * ----------------
  1640. */
  1641. typedef struct SortState
  1642. {
  1643. ScanState ss; /* its first field is NodeTag */
  1644. bool randomAccess; /* need random access to sort output? */
  1645. bool bounded; /* is the result set bounded? */
  1646. int64 bound; /* if bounded, how many tuples are needed */
  1647. bool sort_Done; /* sort completed yet? */
  1648. bool bounded_Done; /* value of bounded we did the sort with */
  1649. int64 bound_Done; /* value of bound we did the sort with */
  1650. void *tuplesortstate; /* private state of tuplesort.c */
  1651. } SortState;
  1652. /* ---------------------
  1653. * GroupState information
  1654. * -------------------------
  1655. */
  1656. typedef struct GroupState
  1657. {
  1658. ScanState ss; /* its first field is NodeTag */
  1659. FmgrInfo *eqfunctions; /* per-field lookup data for equality fns */
  1660. bool grp_done; /* indicates completion of Group scan */
  1661. } GroupState;
  1662. /* ---------------------
  1663. * AggState information
  1664. *
  1665. * ss.ss_ScanTupleSlot refers to output of underlying plan.
  1666. *
  1667. * Note: ss.ps.ps_ExprContext contains ecxt_aggvalues and
  1668. * ecxt_aggnulls arrays, which hold the computed agg values for the current
  1669. * input group during evaluation of an Agg node's output tuple(s). We
  1670. * create a second ExprContext, tmpcontext, in which to evaluate input
  1671. * expressions and run the aggregate transition functions.
  1672. * -------------------------
  1673. */
  1674. /* these structs are private in nodeAgg.c: */
  1675. typedef struct AggStatePerAggData *AggStatePerAgg;
  1676. typedef struct AggStatePerTransData *AggStatePerTrans;
  1677. typedef struct AggStatePerGroupData *AggStatePerGroup;
  1678. typedef struct AggStatePerPhaseData *AggStatePerPhase;
  1679. typedef struct AggState
  1680. {
  1681. ScanState ss; /* its first field is NodeTag */
  1682. List *aggs; /* all Aggref nodes in targetlist & quals */
  1683. int numaggs; /* length of list (could be zero!) */
  1684. int numtrans; /* number of pertrans items */
  1685. AggSplit aggsplit; /* agg-splitting mode, see nodes.h */
  1686. AggStatePerPhase phase; /* pointer to current phase data */
  1687. int numphases; /* number of phases */
  1688. int current_phase; /* current phase number */
  1689. FmgrInfo *hashfunctions; /* per-grouping-field hash fns */
  1690. AggStatePerAgg peragg; /* per-Aggref information */
  1691. AggStatePerTrans pertrans; /* per-Trans state information */
  1692. ExprContext **aggcontexts; /* econtexts for long-lived data (per GS) */
  1693. ExprContext *tmpcontext; /* econtext for input expressions */
  1694. AggStatePerTrans curpertrans; /* currently active trans state */
  1695. bool input_done; /* indicates end of input */
  1696. bool agg_done; /* indicates completion of Agg scan */
  1697. int projected_set; /* The last projected grouping set */
  1698. int current_set; /* The current grouping set being evaluated */
  1699. Bitmapset *grouped_cols; /* grouped cols in current projection */
  1700. List *all_grouped_cols; /* list of all grouped cols in DESC
  1701. * order */
  1702. /* These fields are for grouping set phase data */
  1703. int maxsets; /* The max number of sets in any phase */
  1704. AggStatePerPhase phases; /* array of all phases */
  1705. Tuplesortstate *sort_in; /* sorted input to phases > 0 */
  1706. Tuplesortstate *sort_out; /* input is copied here for next phase */
  1707. TupleTableSlot *sort_slot; /* slot for sort results */
  1708. /* these fields are used in AGG_PLAIN and AGG_SORTED modes: */
  1709. AggStatePerGroup pergroup; /* per-Aggref-per-group working state */
  1710. HeapTuple grp_firstTuple; /* copy of first tuple of current group */
  1711. /* these fields are used in AGG_HASHED mode: */
  1712. TupleHashTable hashtable; /* hash table with one entry per group */
  1713. TupleTableSlot *hashslot; /* slot for loading hash table */
  1714. List *hash_needed; /* list of columns needed in hash table */
  1715. bool table_filled; /* hash table filled yet? */
  1716. TupleHashIterator hashiter; /* for iterating through hash table */
  1717. } AggState;
  1718. /* ----------------
  1719. * WindowAggState information
  1720. * ----------------
  1721. */
  1722. /* these structs are private in nodeWindowAgg.c: */
  1723. typedef struct WindowStatePerFuncData *WindowStatePerFunc;
  1724. typedef struct WindowStatePerAggData *WindowStatePerAgg;
  1725. typedef struct WindowAggState
  1726. {
  1727. ScanState ss; /* its first field is NodeTag */
  1728. /* these fields are filled in by ExecInitExpr: */
  1729. List *funcs; /* all WindowFunc nodes in targetlist */
  1730. int numfuncs; /* total number of window functions */
  1731. int numaggs; /* number that are plain aggregates */
  1732. WindowStatePerFunc perfunc; /* per-window-function information */
  1733. WindowStatePerAgg peragg; /* per-plain-aggregate information */
  1734. FmgrInfo *partEqfunctions; /* equality funcs for partition columns */
  1735. FmgrInfo *ordEqfunctions; /* equality funcs for ordering columns */
  1736. Tuplestorestate *buffer; /* stores rows of current partition */
  1737. int current_ptr; /* read pointer # for current */
  1738. int64 spooled_rows; /* total # of rows in buffer */
  1739. int64 currentpos; /* position of current row in partition */
  1740. int64 frameheadpos; /* current frame head position */
  1741. int64 frametailpos; /* current frame tail position */
  1742. /* use struct pointer to avoid including windowapi.h here */
  1743. struct WindowObjectData *agg_winobj; /* winobj for aggregate
  1744. * fetches */
  1745. int64 aggregatedbase; /* start row for current aggregates */
  1746. int64 aggregatedupto; /* rows before this one are aggregated */
  1747. int frameOptions; /* frame_clause options, see WindowDef */
  1748. ExprState *startOffset; /* expression for starting bound offset */
  1749. ExprState *endOffset; /* expression for ending bound offset */
  1750. Datum startOffsetValue; /* result of startOffset evaluation */
  1751. Datum endOffsetValue; /* result of endOffset evaluation */
  1752. MemoryContext partcontext; /* context for partition-lifespan data */
  1753. MemoryContext aggcontext; /* shared context for aggregate working data */
  1754. MemoryContext curaggcontext; /* current aggregate's working data */
  1755. ExprContext *tmpcontext; /* short-term evaluation context */
  1756. bool all_first; /* true if the scan is starting */
  1757. bool all_done; /* true if the scan is finished */
  1758. bool partition_spooled; /* true if all tuples in current
  1759. * partition have been spooled into
  1760. * tuplestore */
  1761. bool more_partitions;/* true if there's more partitions after this
  1762. * one */
  1763. bool framehead_valid;/* true if frameheadpos is known up to date
  1764. * for current row */
  1765. bool frametail_valid;/* true if frametailpos is known up to date
  1766. * for current row */
  1767. TupleTableSlot *first_part_slot; /* first tuple of current or next
  1768. * partition */
  1769. /* temporary slots for tuples fetched back from tuplestore */
  1770. TupleTableSlot *agg_row_slot;
  1771. TupleTableSlot *temp_slot_1;
  1772. TupleTableSlot *temp_slot_2;
  1773. } WindowAggState;
  1774. /* ----------------
  1775. * UniqueState information
  1776. *
  1777. * Unique nodes are used "on top of" sort nodes to discard
  1778. * duplicate tuples returned from the sort phase. Basically
  1779. * all it does is compare the current tuple from the subplan
  1780. * with the previously fetched tuple (stored in its result slot).
  1781. * If the two are identical in all interesting fields, then
  1782. * we just fetch another tuple from the sort and try again.
  1783. * ----------------
  1784. */
  1785. typedef struct UniqueState
  1786. {
  1787. PlanState ps; /* its first field is NodeTag */
  1788. FmgrInfo *eqfunctions; /* per-field lookup data for equality fns */
  1789. MemoryContext tempContext; /* short-term context for comparisons */
  1790. } UniqueState;
  1791. /* ----------------
  1792. * GatherState information
  1793. *
  1794. * Gather nodes launch 1 or more parallel workers, run a subplan
  1795. * in those workers, and collect the results.
  1796. * ----------------
  1797. */
  1798. typedef struct GatherState
  1799. {
  1800. PlanState ps; /* its first field is NodeTag */
  1801. bool initialized;
  1802. struct ParallelExecutorInfo *pei;
  1803. int nreaders;
  1804. int nextreader;
  1805. int nworkers_launched;
  1806. struct TupleQueueReader **reader;
  1807. TupleTableSlot *funnel_slot;
  1808. bool need_to_scan_locally;
  1809. } GatherState;
  1810. /* ----------------
  1811. * HashState information
  1812. * ----------------
  1813. */
  1814. typedef struct HashState
  1815. {
  1816. PlanState ps; /* its first field is NodeTag */
  1817. HashJoinTable hashtable; /* hash table for the hashjoin */
  1818. List *hashkeys; /* list of ExprState nodes */
  1819. /* hashkeys is same as parent's hj_InnerHashKeys */
  1820. } HashState;
  1821. /* ----------------
  1822. * SetOpState information
  1823. *
  1824. * Even in "sorted" mode, SetOp nodes are more complex than a simple
  1825. * Unique, since we have to count how many duplicates to return. But
  1826. * we also support hashing, so this is really more like a cut-down
  1827. * form of Agg.
  1828. * ----------------
  1829. */
  1830. /* this struct is private in nodeSetOp.c: */
  1831. typedef struct SetOpStatePerGroupData *SetOpStatePerGroup;
  1832. typedef struct SetOpState
  1833. {
  1834. PlanState ps; /* its first field is NodeTag */
  1835. FmgrInfo *eqfunctions; /* per-grouping-field equality fns */
  1836. FmgrInfo *hashfunctions; /* per-grouping-field hash fns */
  1837. bool setop_done; /* indicates completion of output scan */
  1838. long numOutput; /* number of dups left to output */
  1839. MemoryContext tempContext; /* short-term context for comparisons */
  1840. /* these fields are used in SETOP_SORTED mode: */
  1841. SetOpStatePerGroup pergroup; /* per-group working state */
  1842. HeapTuple grp_firstTuple; /* copy of first tuple of current group */
  1843. /* these fields are used in SETOP_HASHED mode: */
  1844. TupleHashTable hashtable; /* hash table with one entry per group */
  1845. MemoryContext tableContext; /* memory context containing hash table */
  1846. bool table_filled; /* hash table filled yet? */
  1847. TupleHashIterator hashiter; /* for iterating through hash table */
  1848. } SetOpState;
  1849. /* ----------------
  1850. * LockRowsState information
  1851. *
  1852. * LockRows nodes are used to enforce FOR [KEY] UPDATE/SHARE locking.
  1853. * ----------------
  1854. */
  1855. typedef struct LockRowsState
  1856. {
  1857. PlanState ps; /* its first field is NodeTag */
  1858. List *lr_arowMarks; /* List of ExecAuxRowMarks */
  1859. EPQState lr_epqstate; /* for evaluating EvalPlanQual rechecks */
  1860. HeapTuple *lr_curtuples; /* locked tuples (one entry per RT entry) */
  1861. int lr_ntables; /* length of lr_curtuples[] array */
  1862. } LockRowsState;
  1863. /* ----------------
  1864. * LimitState information
  1865. *
  1866. * Limit nodes are used to enforce LIMIT/OFFSET clauses.
  1867. * They just select the desired subrange of their subplan's output.
  1868. *
  1869. * offset is the number of initial tuples to skip (0 does nothing).
  1870. * count is the number of tuples to return after skipping the offset tuples.
  1871. * If no limit count was specified, count is undefined and noCount is true.
  1872. * When lstate == LIMIT_INITIAL, offset/count/noCount haven't been set yet.
  1873. * ----------------
  1874. */
  1875. typedef enum
  1876. {
  1877. LIMIT_INITIAL, /* initial state for LIMIT node */
  1878. LIMIT_RESCAN, /* rescan after recomputing parameters */
  1879. LIMIT_EMPTY, /* there are no returnable rows */
  1880. LIMIT_INWINDOW, /* have returned a row in the window */
  1881. LIMIT_SUBPLANEOF, /* at EOF of subplan (within window) */
  1882. LIMIT_WINDOWEND, /* stepped off end of window */
  1883. LIMIT_WINDOWSTART /* stepped off beginning of window */
  1884. } LimitStateCond;
  1885. typedef struct LimitState
  1886. {
  1887. PlanState ps; /* its first field is NodeTag */
  1888. ExprState *limitOffset; /* OFFSET parameter, or NULL if none */
  1889. ExprState *limitCount; /* COUNT parameter, or NULL if none */
  1890. int64 offset; /* current OFFSET value */
  1891. int64 count; /* current COUNT, if any */
  1892. bool noCount; /* if true, ignore count */
  1893. LimitStateCond lstate; /* state machine status, as above */
  1894. int64 position; /* 1-based index of last tuple returned */
  1895. TupleTableSlot *subSlot; /* tuple last obtained from subplan */
  1896. } LimitState;
  1897. #endif /* EXECNODES_H */