execnodes.h 100 KB

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