relation.h 86 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057
  1. /*-------------------------------------------------------------------------
  2. *
  3. * relation.h
  4. * Definitions for planner's internal data structures.
  5. *
  6. *
  7. * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
  8. * Portions Copyright (c) 1994, Regents of the University of California
  9. *
  10. * src/include/nodes/relation.h
  11. *
  12. *-------------------------------------------------------------------------
  13. */
  14. #ifndef RELATION_H
  15. #define RELATION_H
  16. #include "access/sdir.h"
  17. #include "lib/stringinfo.h"
  18. #include "nodes/params.h"
  19. #include "nodes/parsenodes.h"
  20. #include "storage/block.h"
  21. /*
  22. * Relids
  23. * Set of relation identifiers (indexes into the rangetable).
  24. */
  25. typedef Bitmapset *Relids;
  26. /*
  27. * When looking for a "cheapest path", this enum specifies whether we want
  28. * cheapest startup cost or cheapest total cost.
  29. */
  30. typedef enum CostSelector
  31. {
  32. STARTUP_COST, TOTAL_COST
  33. } CostSelector;
  34. /*
  35. * The cost estimate produced by cost_qual_eval() includes both a one-time
  36. * (startup) cost, and a per-tuple cost.
  37. */
  38. typedef struct QualCost
  39. {
  40. Cost startup; /* one-time cost */
  41. Cost per_tuple; /* per-evaluation cost */
  42. } QualCost;
  43. /*
  44. * Costing aggregate function execution requires these statistics about
  45. * the aggregates to be executed by a given Agg node. Note that the costs
  46. * include the execution costs of the aggregates' argument expressions as
  47. * well as the aggregate functions themselves. Also, the fields must be
  48. * defined so that initializing the struct to zeroes with memset is correct.
  49. */
  50. typedef struct AggClauseCosts
  51. {
  52. int numAggs; /* total number of aggregate functions */
  53. int numOrderedAggs; /* number w/ DISTINCT/ORDER BY/WITHIN GROUP */
  54. bool hasNonPartial; /* does any agg not support partial mode? */
  55. bool hasNonSerial; /* is any partial agg non-serializable? */
  56. QualCost transCost; /* total per-input-row execution costs */
  57. Cost finalCost; /* total per-aggregated-row costs */
  58. Size transitionSpace; /* space for pass-by-ref transition data */
  59. } AggClauseCosts;
  60. /*
  61. * This enum identifies the different types of "upper" (post-scan/join)
  62. * relations that we might deal with during planning.
  63. */
  64. typedef enum UpperRelationKind
  65. {
  66. UPPERREL_SETOP, /* result of UNION/INTERSECT/EXCEPT, if any */
  67. UPPERREL_GROUP_AGG, /* result of grouping/aggregation, if any */
  68. UPPERREL_WINDOW, /* result of window functions, if any */
  69. UPPERREL_DISTINCT, /* result of "SELECT DISTINCT", if any */
  70. UPPERREL_ORDERED, /* result of ORDER BY, if any */
  71. UPPERREL_FINAL /* result of any remaining top-level actions */
  72. /* NB: UPPERREL_FINAL must be last enum entry; it's used to size arrays */
  73. } UpperRelationKind;
  74. /*----------
  75. * PlannerGlobal
  76. * Global information for planning/optimization
  77. *
  78. * PlannerGlobal holds state for an entire planner invocation; this state
  79. * is shared across all levels of sub-Queries that exist in the command being
  80. * planned.
  81. *----------
  82. */
  83. typedef struct PlannerGlobal
  84. {
  85. NodeTag type;
  86. ParamListInfo boundParams; /* Param values provided to planner() */
  87. List *subplans; /* Plans for SubPlan nodes */
  88. List *subroots; /* PlannerInfos for SubPlan nodes */
  89. Bitmapset *rewindPlanIDs; /* indices of subplans that require REWIND */
  90. List *finalrtable; /* "flat" rangetable for executor */
  91. List *finalrowmarks; /* "flat" list of PlanRowMarks */
  92. List *resultRelations; /* "flat" list of integer RT indexes */
  93. List *relationOids; /* OIDs of relations the plan depends on */
  94. List *invalItems; /* other dependencies, as PlanInvalItems */
  95. int nParamExec; /* number of PARAM_EXEC Params used */
  96. Index lastPHId; /* highest PlaceHolderVar ID assigned */
  97. Index lastRowMarkId; /* highest PlanRowMark ID assigned */
  98. int lastPlanNodeId; /* highest plan node ID assigned */
  99. bool transientPlan; /* redo plan when TransactionXmin changes? */
  100. bool dependsOnRole; /* is plan specific to current role? */
  101. bool parallelModeOK; /* parallel mode potentially OK? */
  102. bool parallelModeNeeded; /* parallel mode actually required? */
  103. } PlannerGlobal;
  104. /* macro for fetching the Plan associated with a SubPlan node */
  105. #define planner_subplan_get_plan(root, subplan) \
  106. ((Plan *) list_nth((root)->glob->subplans, (subplan)->plan_id - 1))
  107. /*----------
  108. * PlannerInfo
  109. * Per-query information for planning/optimization
  110. *
  111. * This struct is conventionally called "root" in all the planner routines.
  112. * It holds links to all of the planner's working state, in addition to the
  113. * original Query. Note that at present the planner extensively modifies
  114. * the passed-in Query data structure; someday that should stop.
  115. *----------
  116. */
  117. typedef struct PlannerInfo
  118. {
  119. NodeTag type;
  120. Query *parse; /* the Query being planned */
  121. PlannerGlobal *glob; /* global info for current planner run */
  122. Index query_level; /* 1 at the outermost Query */
  123. struct PlannerInfo *parent_root; /* NULL at outermost Query */
  124. /*
  125. * plan_params contains the expressions that this query level needs to
  126. * make available to a lower query level that is currently being planned.
  127. * outer_params contains the paramIds of PARAM_EXEC Params that outer
  128. * query levels will make available to this query level.
  129. */
  130. List *plan_params; /* list of PlannerParamItems, see below */
  131. Bitmapset *outer_params;
  132. /*
  133. * simple_rel_array holds pointers to "base rels" and "other rels" (see
  134. * comments for RelOptInfo for more info). It is indexed by rangetable
  135. * index (so entry 0 is always wasted). Entries can be NULL when an RTE
  136. * does not correspond to a base relation, such as a join RTE or an
  137. * unreferenced view RTE; or if the RelOptInfo hasn't been made yet.
  138. */
  139. struct RelOptInfo **simple_rel_array; /* All 1-rel RelOptInfos */
  140. int simple_rel_array_size; /* allocated size of array */
  141. /*
  142. * simple_rte_array is the same length as simple_rel_array and holds
  143. * pointers to the associated rangetable entries. This lets us avoid
  144. * rt_fetch(), which can be a bit slow once large inheritance sets have
  145. * been expanded.
  146. */
  147. RangeTblEntry **simple_rte_array; /* rangetable as an array */
  148. /*
  149. * all_baserels is a Relids set of all base relids (but not "other"
  150. * relids) in the query; that is, the Relids identifier of the final join
  151. * we need to form. This is computed in make_one_rel, just before we
  152. * start making Paths.
  153. */
  154. Relids all_baserels;
  155. /*
  156. * nullable_baserels is a Relids set of base relids that are nullable by
  157. * some outer join in the jointree; these are rels that are potentially
  158. * nullable below the WHERE clause, SELECT targetlist, etc. This is
  159. * computed in deconstruct_jointree.
  160. */
  161. Relids nullable_baserels;
  162. /*
  163. * join_rel_list is a list of all join-relation RelOptInfos we have
  164. * considered in this planning run. For small problems we just scan the
  165. * list to do lookups, but when there are many join relations we build a
  166. * hash table for faster lookups. The hash table is present and valid
  167. * when join_rel_hash is not NULL. Note that we still maintain the list
  168. * even when using the hash table for lookups; this simplifies life for
  169. * GEQO.
  170. */
  171. List *join_rel_list; /* list of join-relation RelOptInfos */
  172. struct HTAB *join_rel_hash; /* optional hashtable for join relations */
  173. /*
  174. * When doing a dynamic-programming-style join search, join_rel_level[k]
  175. * is a list of all join-relation RelOptInfos of level k, and
  176. * join_cur_level is the current level. New join-relation RelOptInfos are
  177. * automatically added to the join_rel_level[join_cur_level] list.
  178. * join_rel_level is NULL if not in use.
  179. */
  180. List **join_rel_level; /* lists of join-relation RelOptInfos */
  181. int join_cur_level; /* index of list being extended */
  182. List *init_plans; /* init SubPlans for query */
  183. List *cte_plan_ids; /* per-CTE-item list of subplan IDs */
  184. List *multiexpr_params; /* List of Lists of Params for
  185. * MULTIEXPR subquery outputs */
  186. List *eq_classes; /* list of active EquivalenceClasses */
  187. List *canon_pathkeys; /* list of "canonical" PathKeys */
  188. List *left_join_clauses; /* list of RestrictInfos for
  189. * mergejoinable outer join clauses
  190. * w/nonnullable var on left */
  191. List *right_join_clauses; /* list of RestrictInfos for
  192. * mergejoinable outer join clauses
  193. * w/nonnullable var on right */
  194. List *full_join_clauses; /* list of RestrictInfos for
  195. * mergejoinable full join clauses */
  196. List *join_info_list; /* list of SpecialJoinInfos */
  197. List *append_rel_list; /* list of AppendRelInfos */
  198. List *rowMarks; /* list of PlanRowMarks */
  199. List *placeholder_list; /* list of PlaceHolderInfos */
  200. List *fkey_list; /* list of ForeignKeyOptInfos */
  201. List *query_pathkeys; /* desired pathkeys for query_planner() */
  202. List *group_pathkeys; /* groupClause pathkeys, if any */
  203. List *window_pathkeys; /* pathkeys of bottom window, if any */
  204. List *distinct_pathkeys; /* distinctClause pathkeys, if any */
  205. List *sort_pathkeys; /* sortClause pathkeys, if any */
  206. List *initial_rels; /* RelOptInfos we are now trying to join */
  207. /* Use fetch_upper_rel() to get any particular upper rel */
  208. List *upper_rels[UPPERREL_FINAL + 1]; /* upper-rel RelOptInfos */
  209. /* Result tlists chosen by grouping_planner for upper-stage processing */
  210. struct PathTarget *upper_targets[UPPERREL_FINAL + 1];
  211. /*
  212. * grouping_planner passes back its final processed targetlist here, for
  213. * use in relabeling the topmost tlist of the finished Plan.
  214. */
  215. List *processed_tlist;
  216. /* Fields filled during create_plan() for use in setrefs.c */
  217. AttrNumber *grouping_map; /* for GroupingFunc fixup */
  218. List *minmax_aggs; /* List of MinMaxAggInfos */
  219. MemoryContext planner_cxt; /* context holding PlannerInfo */
  220. double total_table_pages; /* # of pages in all tables of query */
  221. double tuple_fraction; /* tuple_fraction passed to query_planner */
  222. double limit_tuples; /* limit_tuples passed to query_planner */
  223. bool hasInheritedTarget; /* true if parse->resultRelation is an
  224. * inheritance child rel */
  225. bool hasJoinRTEs; /* true if any RTEs are RTE_JOIN kind */
  226. bool hasLateralRTEs; /* true if any RTEs are marked LATERAL */
  227. bool hasDeletedRTEs; /* true if any RTE was deleted from jointree */
  228. bool hasHavingQual; /* true if havingQual was non-null */
  229. bool hasPseudoConstantQuals; /* true if any RestrictInfo has
  230. * pseudoconstant = true */
  231. bool hasRecursion; /* true if planning a recursive WITH item */
  232. /* These fields are used only when hasRecursion is true: */
  233. int wt_param_id; /* PARAM_EXEC ID for the work table */
  234. struct Path *non_recursive_path; /* a path for non-recursive term */
  235. /* These fields are workspace for createplan.c */
  236. Relids curOuterRels; /* outer rels above current node */
  237. List *curOuterParams; /* not-yet-assigned NestLoopParams */
  238. /* optional private data for join_search_hook, e.g., GEQO */
  239. void *join_search_private;
  240. } PlannerInfo;
  241. /*
  242. * In places where it's known that simple_rte_array[] must have been prepared
  243. * already, we just index into it to fetch RTEs. In code that might be
  244. * executed before or after entering query_planner(), use this macro.
  245. */
  246. #define planner_rt_fetch(rti, root) \
  247. ((root)->simple_rte_array ? (root)->simple_rte_array[rti] : \
  248. rt_fetch(rti, (root)->parse->rtable))
  249. /*----------
  250. * RelOptInfo
  251. * Per-relation information for planning/optimization
  252. *
  253. * For planning purposes, a "base rel" is either a plain relation (a table)
  254. * or the output of a sub-SELECT or function that appears in the range table.
  255. * In either case it is uniquely identified by an RT index. A "joinrel"
  256. * is the joining of two or more base rels. A joinrel is identified by
  257. * the set of RT indexes for its component baserels. We create RelOptInfo
  258. * nodes for each baserel and joinrel, and store them in the PlannerInfo's
  259. * simple_rel_array and join_rel_list respectively.
  260. *
  261. * Note that there is only one joinrel for any given set of component
  262. * baserels, no matter what order we assemble them in; so an unordered
  263. * set is the right datatype to identify it with.
  264. *
  265. * We also have "other rels", which are like base rels in that they refer to
  266. * single RT indexes; but they are not part of the join tree, and are given
  267. * a different RelOptKind to identify them.
  268. * Currently the only kind of otherrels are those made for member relations
  269. * of an "append relation", that is an inheritance set or UNION ALL subquery.
  270. * An append relation has a parent RTE that is a base rel, which represents
  271. * the entire append relation. The member RTEs are otherrels. The parent
  272. * is present in the query join tree but the members are not. The member
  273. * RTEs and otherrels are used to plan the scans of the individual tables or
  274. * subqueries of the append set; then the parent baserel is given Append
  275. * and/or MergeAppend paths comprising the best paths for the individual
  276. * member rels. (See comments for AppendRelInfo for more information.)
  277. *
  278. * At one time we also made otherrels to represent join RTEs, for use in
  279. * handling join alias Vars. Currently this is not needed because all join
  280. * alias Vars are expanded to non-aliased form during preprocess_expression.
  281. *
  282. * There is also a RelOptKind for "upper" relations, which are RelOptInfos
  283. * that describe post-scan/join processing steps, such as aggregation.
  284. * Many of the fields in these RelOptInfos are meaningless, but their Path
  285. * fields always hold Paths showing ways to do that processing step.
  286. *
  287. * Lastly, there is a RelOptKind for "dead" relations, which are base rels
  288. * that we have proven we don't need to join after all.
  289. *
  290. * Parts of this data structure are specific to various scan and join
  291. * mechanisms. It didn't seem worth creating new node types for them.
  292. *
  293. * relids - Set of base-relation identifiers; it is a base relation
  294. * if there is just one, a join relation if more than one
  295. * rows - estimated number of tuples in the relation after restriction
  296. * clauses have been applied (ie, output rows of a plan for it)
  297. * consider_startup - true if there is any value in keeping plain paths for
  298. * this rel on the basis of having cheap startup cost
  299. * consider_param_startup - the same for parameterized paths
  300. * reltarget - Default Path output tlist for this rel; normally contains
  301. * Var and PlaceHolderVar nodes for the values we need to
  302. * output from this relation.
  303. * List is in no particular order, but all rels of an
  304. * appendrel set must use corresponding orders.
  305. * NOTE: in an appendrel child relation, may contain
  306. * arbitrary expressions pulled up from a subquery!
  307. * pathlist - List of Path nodes, one for each potentially useful
  308. * method of generating the relation
  309. * ppilist - ParamPathInfo nodes for parameterized Paths, if any
  310. * cheapest_startup_path - the pathlist member with lowest startup cost
  311. * (regardless of ordering) among the unparameterized paths;
  312. * or NULL if there is no unparameterized path
  313. * cheapest_total_path - the pathlist member with lowest total cost
  314. * (regardless of ordering) among the unparameterized paths;
  315. * or if there is no unparameterized path, the path with lowest
  316. * total cost among the paths with minimum parameterization
  317. * cheapest_unique_path - for caching cheapest path to produce unique
  318. * (no duplicates) output from relation; NULL if not yet requested
  319. * cheapest_parameterized_paths - best paths for their parameterizations;
  320. * always includes cheapest_total_path, even if that's unparameterized
  321. * direct_lateral_relids - rels this rel has direct LATERAL references to
  322. * lateral_relids - required outer rels for LATERAL, as a Relids set
  323. * (includes both direct and indirect lateral references)
  324. *
  325. * If the relation is a base relation it will have these fields set:
  326. *
  327. * relid - RTE index (this is redundant with the relids field, but
  328. * is provided for convenience of access)
  329. * rtekind - distinguishes plain relation, subquery, or function RTE
  330. * min_attr, max_attr - range of valid AttrNumbers for rel
  331. * attr_needed - array of bitmapsets indicating the highest joinrel
  332. * in which each attribute is needed; if bit 0 is set then
  333. * the attribute is needed as part of final targetlist
  334. * attr_widths - cache space for per-attribute width estimates;
  335. * zero means not computed yet
  336. * lateral_vars - lateral cross-references of rel, if any (list of
  337. * Vars and PlaceHolderVars)
  338. * lateral_referencers - relids of rels that reference this one laterally
  339. * (includes both direct and indirect lateral references)
  340. * indexlist - list of IndexOptInfo nodes for relation's indexes
  341. * (always NIL if it's not a table)
  342. * pages - number of disk pages in relation (zero if not a table)
  343. * tuples - number of tuples in relation (not considering restrictions)
  344. * allvisfrac - fraction of disk pages that are marked all-visible
  345. * subroot - PlannerInfo for subquery (NULL if it's not a subquery)
  346. * subplan_params - list of PlannerParamItems to be passed to subquery
  347. *
  348. * Note: for a subquery, tuples and subroot are not set immediately
  349. * upon creation of the RelOptInfo object; they are filled in when
  350. * set_subquery_pathlist processes the object.
  351. *
  352. * For otherrels that are appendrel members, these fields are filled
  353. * in just as for a baserel, except we don't bother with lateral_vars.
  354. *
  355. * If the relation is either a foreign table or a join of foreign tables that
  356. * all belong to the same foreign server and are assigned to the same user to
  357. * check access permissions as (cf checkAsUser), these fields will be set:
  358. *
  359. * serverid - OID of foreign server, if foreign table (else InvalidOid)
  360. * userid - OID of user to check access as (InvalidOid means current user)
  361. * useridiscurrent - we've assumed that userid equals current user
  362. * fdwroutine - function hooks for FDW, if foreign table (else NULL)
  363. * fdw_private - private state for FDW, if foreign table (else NULL)
  364. *
  365. * The presence of the remaining fields depends on the restrictions
  366. * and joins that the relation participates in:
  367. *
  368. * baserestrictinfo - List of RestrictInfo nodes, containing info about
  369. * each non-join qualification clause in which this relation
  370. * participates (only used for base rels)
  371. * baserestrictcost - Estimated cost of evaluating the baserestrictinfo
  372. * clauses at a single tuple (only used for base rels)
  373. * joininfo - List of RestrictInfo nodes, containing info about each
  374. * join clause in which this relation participates (but
  375. * note this excludes clauses that might be derivable from
  376. * EquivalenceClasses)
  377. * has_eclass_joins - flag that EquivalenceClass joins are possible
  378. *
  379. * Note: Keeping a restrictinfo list in the RelOptInfo is useful only for
  380. * base rels, because for a join rel the set of clauses that are treated as
  381. * restrict clauses varies depending on which sub-relations we choose to join.
  382. * (For example, in a 3-base-rel join, a clause relating rels 1 and 2 must be
  383. * treated as a restrictclause if we join {1} and {2 3} to make {1 2 3}; but
  384. * if we join {1 2} and {3} then that clause will be a restrictclause in {1 2}
  385. * and should not be processed again at the level of {1 2 3}.) Therefore,
  386. * the restrictinfo list in the join case appears in individual JoinPaths
  387. * (field joinrestrictinfo), not in the parent relation. But it's OK for
  388. * the RelOptInfo to store the joininfo list, because that is the same
  389. * for a given rel no matter how we form it.
  390. *
  391. * We store baserestrictcost in the RelOptInfo (for base relations) because
  392. * we know we will need it at least once (to price the sequential scan)
  393. * and may need it multiple times to price index scans.
  394. *----------
  395. */
  396. typedef enum RelOptKind
  397. {
  398. RELOPT_BASEREL,
  399. RELOPT_JOINREL,
  400. RELOPT_OTHER_MEMBER_REL,
  401. RELOPT_UPPER_REL,
  402. RELOPT_DEADREL
  403. } RelOptKind;
  404. typedef struct RelOptInfo
  405. {
  406. NodeTag type;
  407. RelOptKind reloptkind;
  408. /* all relations included in this RelOptInfo */
  409. Relids relids; /* set of base relids (rangetable indexes) */
  410. /* size estimates generated by planner */
  411. double rows; /* estimated number of result tuples */
  412. /* per-relation planner control flags */
  413. bool consider_startup; /* keep cheap-startup-cost paths? */
  414. bool consider_param_startup; /* ditto, for parameterized paths? */
  415. bool consider_parallel; /* consider parallel paths? */
  416. /* default result targetlist for Paths scanning this relation */
  417. struct PathTarget *reltarget; /* list of Vars/Exprs, cost, width */
  418. /* materialization information */
  419. List *pathlist; /* Path structures */
  420. List *ppilist; /* ParamPathInfos used in pathlist */
  421. List *partial_pathlist; /* partial Paths */
  422. struct Path *cheapest_startup_path;
  423. struct Path *cheapest_total_path;
  424. struct Path *cheapest_unique_path;
  425. List *cheapest_parameterized_paths;
  426. /* parameterization information needed for both base rels and join rels */
  427. /* (see also lateral_vars and lateral_referencers) */
  428. Relids direct_lateral_relids; /* rels directly laterally referenced */
  429. Relids lateral_relids; /* minimum parameterization of rel */
  430. /* information about a base rel (not set for join rels!) */
  431. Index relid;
  432. Oid reltablespace; /* containing tablespace */
  433. RTEKind rtekind; /* RELATION, SUBQUERY, or FUNCTION */
  434. AttrNumber min_attr; /* smallest attrno of rel (often <0) */
  435. AttrNumber max_attr; /* largest attrno of rel */
  436. Relids *attr_needed; /* array indexed [min_attr .. max_attr] */
  437. int32 *attr_widths; /* array indexed [min_attr .. max_attr] */
  438. List *lateral_vars; /* LATERAL Vars and PHVs referenced by rel */
  439. Relids lateral_referencers; /* rels that reference me laterally */
  440. List *indexlist; /* list of IndexOptInfo */
  441. BlockNumber pages; /* size estimates derived from pg_class */
  442. double tuples;
  443. double allvisfrac;
  444. PlannerInfo *subroot; /* if subquery */
  445. List *subplan_params; /* if subquery */
  446. int rel_parallel_workers; /* wanted number of parallel workers */
  447. /* Information about foreign tables and foreign joins */
  448. Oid serverid; /* identifies server for the table or join */
  449. Oid userid; /* identifies user to check access as */
  450. bool useridiscurrent; /* join is only valid for current user */
  451. /* use "struct FdwRoutine" to avoid including fdwapi.h here */
  452. struct FdwRoutine *fdwroutine;
  453. void *fdw_private;
  454. /* used by various scans and joins: */
  455. List *baserestrictinfo; /* RestrictInfo structures (if base
  456. * rel) */
  457. QualCost baserestrictcost; /* cost of evaluating the above */
  458. List *joininfo; /* RestrictInfo structures for join clauses
  459. * involving this rel */
  460. bool has_eclass_joins; /* T means joininfo is incomplete */
  461. } RelOptInfo;
  462. /*
  463. * IndexOptInfo
  464. * Per-index information for planning/optimization
  465. *
  466. * indexkeys[], indexcollations[], opfamily[], and opcintype[]
  467. * each have ncolumns entries.
  468. *
  469. * sortopfamily[], reverse_sort[], and nulls_first[] likewise have
  470. * ncolumns entries, if the index is ordered; but if it is unordered,
  471. * those pointers are NULL.
  472. *
  473. * Zeroes in the indexkeys[] array indicate index columns that are
  474. * expressions; there is one element in indexprs for each such column.
  475. *
  476. * For an ordered index, reverse_sort[] and nulls_first[] describe the
  477. * sort ordering of a forward indexscan; we can also consider a backward
  478. * indexscan, which will generate the reverse ordering.
  479. *
  480. * The indexprs and indpred expressions have been run through
  481. * prepqual.c and eval_const_expressions() for ease of matching to
  482. * WHERE clauses. indpred is in implicit-AND form.
  483. *
  484. * indextlist is a TargetEntry list representing the index columns.
  485. * It provides an equivalent base-relation Var for each simple column,
  486. * and links to the matching indexprs element for each expression column.
  487. *
  488. * While most of these fields are filled when the IndexOptInfo is created
  489. * (by plancat.c), indrestrictinfo and predOK are set later, in
  490. * check_index_predicates().
  491. */
  492. typedef struct IndexOptInfo
  493. {
  494. NodeTag type;
  495. Oid indexoid; /* OID of the index relation */
  496. Oid reltablespace; /* tablespace of index (not table) */
  497. RelOptInfo *rel; /* back-link to index's table */
  498. /* index-size statistics (from pg_class and elsewhere) */
  499. BlockNumber pages; /* number of disk pages in index */
  500. double tuples; /* number of index tuples in index */
  501. int tree_height; /* index tree height, or -1 if unknown */
  502. /* index descriptor information */
  503. int ncolumns; /* number of columns in index */
  504. int *indexkeys; /* column numbers of index's keys, or 0 */
  505. Oid *indexcollations; /* OIDs of collations of index columns */
  506. Oid *opfamily; /* OIDs of operator families for columns */
  507. Oid *opcintype; /* OIDs of opclass declared input data types */
  508. Oid *sortopfamily; /* OIDs of btree opfamilies, if orderable */
  509. bool *reverse_sort; /* is sort order descending? */
  510. bool *nulls_first; /* do NULLs come first in the sort order? */
  511. bool *canreturn; /* which index cols can be returned in an
  512. * index-only scan? */
  513. Oid relam; /* OID of the access method (in pg_am) */
  514. List *indexprs; /* expressions for non-simple index columns */
  515. List *indpred; /* predicate if a partial index, else NIL */
  516. List *indextlist; /* targetlist representing index columns */
  517. List *indrestrictinfo;/* parent relation's baserestrictinfo list,
  518. * less any conditions implied by the index's
  519. * predicate (unless it's a target rel, see
  520. * comments in check_index_predicates()) */
  521. bool predOK; /* true if index predicate matches query */
  522. bool unique; /* true if a unique index */
  523. bool immediate; /* is uniqueness enforced immediately? */
  524. bool hypothetical; /* true if index doesn't really exist */
  525. /* Remaining fields are copied from the index AM's API struct: */
  526. bool amcanorderbyop; /* does AM support order by operator result? */
  527. bool amoptionalkey; /* can query omit key for the first column? */
  528. bool amsearcharray; /* can AM handle ScalarArrayOpExpr quals? */
  529. bool amsearchnulls; /* can AM search for NULL/NOT NULL entries? */
  530. bool amhasgettuple; /* does AM have amgettuple interface? */
  531. bool amhasgetbitmap; /* does AM have amgetbitmap interface? */
  532. /* Rather than include amapi.h here, we declare amcostestimate like this */
  533. void (*amcostestimate) (); /* AM's cost estimator */
  534. } IndexOptInfo;
  535. /*
  536. * ForeignKeyOptInfo
  537. * Per-foreign-key information for planning/optimization
  538. *
  539. * The per-FK-column arrays can be fixed-size because we allow at most
  540. * INDEX_MAX_KEYS columns in a foreign key constraint. Each array has
  541. * nkeys valid entries.
  542. */
  543. typedef struct ForeignKeyOptInfo
  544. {
  545. NodeTag type;
  546. /* Basic data about the foreign key (fetched from catalogs): */
  547. Index con_relid; /* RT index of the referencing table */
  548. Index ref_relid; /* RT index of the referenced table */
  549. int nkeys; /* number of columns in the foreign key */
  550. AttrNumber conkey[INDEX_MAX_KEYS]; /* cols in referencing table */
  551. AttrNumber confkey[INDEX_MAX_KEYS]; /* cols in referenced table */
  552. Oid conpfeqop[INDEX_MAX_KEYS]; /* PK = FK operator OIDs */
  553. /* Derived info about whether FK's equality conditions match the query: */
  554. int nmatched_ec; /* # of FK cols matched by ECs */
  555. int nmatched_rcols; /* # of FK cols matched by non-EC rinfos */
  556. int nmatched_ri; /* total # of non-EC rinfos matched to FK */
  557. /* Pointer to eclass matching each column's condition, if there is one */
  558. struct EquivalenceClass *eclass[INDEX_MAX_KEYS];
  559. /* List of non-EC RestrictInfos matching each column's condition */
  560. List *rinfos[INDEX_MAX_KEYS];
  561. } ForeignKeyOptInfo;
  562. /*
  563. * EquivalenceClasses
  564. *
  565. * Whenever we can determine that a mergejoinable equality clause A = B is
  566. * not delayed by any outer join, we create an EquivalenceClass containing
  567. * the expressions A and B to record this knowledge. If we later find another
  568. * equivalence B = C, we add C to the existing EquivalenceClass; this may
  569. * require merging two existing EquivalenceClasses. At the end of the qual
  570. * distribution process, we have sets of values that are known all transitively
  571. * equal to each other, where "equal" is according to the rules of the btree
  572. * operator family(s) shown in ec_opfamilies, as well as the collation shown
  573. * by ec_collation. (We restrict an EC to contain only equalities whose
  574. * operators belong to the same set of opfamilies. This could probably be
  575. * relaxed, but for now it's not worth the trouble, since nearly all equality
  576. * operators belong to only one btree opclass anyway. Similarly, we suppose
  577. * that all or none of the input datatypes are collatable, so that a single
  578. * collation value is sufficient.)
  579. *
  580. * We also use EquivalenceClasses as the base structure for PathKeys, letting
  581. * us represent knowledge about different sort orderings being equivalent.
  582. * Since every PathKey must reference an EquivalenceClass, we will end up
  583. * with single-member EquivalenceClasses whenever a sort key expression has
  584. * not been equivalenced to anything else. It is also possible that such an
  585. * EquivalenceClass will contain a volatile expression ("ORDER BY random()"),
  586. * which is a case that can't arise otherwise since clauses containing
  587. * volatile functions are never considered mergejoinable. We mark such
  588. * EquivalenceClasses specially to prevent them from being merged with
  589. * ordinary EquivalenceClasses. Also, for volatile expressions we have
  590. * to be careful to match the EquivalenceClass to the correct targetlist
  591. * entry: consider SELECT random() AS a, random() AS b ... ORDER BY b,a.
  592. * So we record the SortGroupRef of the originating sort clause.
  593. *
  594. * We allow equality clauses appearing below the nullable side of an outer join
  595. * to form EquivalenceClasses, but these have a slightly different meaning:
  596. * the included values might be all NULL rather than all the same non-null
  597. * values. See src/backend/optimizer/README for more on that point.
  598. *
  599. * NB: if ec_merged isn't NULL, this class has been merged into another, and
  600. * should be ignored in favor of using the pointed-to class.
  601. */
  602. typedef struct EquivalenceClass
  603. {
  604. NodeTag type;
  605. List *ec_opfamilies; /* btree operator family OIDs */
  606. Oid ec_collation; /* collation, if datatypes are collatable */
  607. List *ec_members; /* list of EquivalenceMembers */
  608. List *ec_sources; /* list of generating RestrictInfos */
  609. List *ec_derives; /* list of derived RestrictInfos */
  610. Relids ec_relids; /* all relids appearing in ec_members, except
  611. * for child members (see below) */
  612. bool ec_has_const; /* any pseudoconstants in ec_members? */
  613. bool ec_has_volatile; /* the (sole) member is a volatile expr */
  614. bool ec_below_outer_join; /* equivalence applies below an OJ */
  615. bool ec_broken; /* failed to generate needed clauses? */
  616. Index ec_sortref; /* originating sortclause label, or 0 */
  617. struct EquivalenceClass *ec_merged; /* set if merged into another EC */
  618. } EquivalenceClass;
  619. /*
  620. * If an EC contains a const and isn't below-outer-join, any PathKey depending
  621. * on it must be redundant, since there's only one possible value of the key.
  622. */
  623. #define EC_MUST_BE_REDUNDANT(eclass) \
  624. ((eclass)->ec_has_const && !(eclass)->ec_below_outer_join)
  625. /*
  626. * EquivalenceMember - one member expression of an EquivalenceClass
  627. *
  628. * em_is_child signifies that this element was built by transposing a member
  629. * for an appendrel parent relation to represent the corresponding expression
  630. * for an appendrel child. These members are used for determining the
  631. * pathkeys of scans on the child relation and for explicitly sorting the
  632. * child when necessary to build a MergeAppend path for the whole appendrel
  633. * tree. An em_is_child member has no impact on the properties of the EC as a
  634. * whole; in particular the EC's ec_relids field does NOT include the child
  635. * relation. An em_is_child member should never be marked em_is_const nor
  636. * cause ec_has_const or ec_has_volatile to be set, either. Thus, em_is_child
  637. * members are not really full-fledged members of the EC, but just reflections
  638. * or doppelgangers of real members. Most operations on EquivalenceClasses
  639. * should ignore em_is_child members, and those that don't should test
  640. * em_relids to make sure they only consider relevant members.
  641. *
  642. * em_datatype is usually the same as exprType(em_expr), but can be
  643. * different when dealing with a binary-compatible opfamily; in particular
  644. * anyarray_ops would never work without this. Use em_datatype when
  645. * looking up a specific btree operator to work with this expression.
  646. */
  647. typedef struct EquivalenceMember
  648. {
  649. NodeTag type;
  650. Expr *em_expr; /* the expression represented */
  651. Relids em_relids; /* all relids appearing in em_expr */
  652. Relids em_nullable_relids; /* nullable by lower outer joins */
  653. bool em_is_const; /* expression is pseudoconstant? */
  654. bool em_is_child; /* derived version for a child relation? */
  655. Oid em_datatype; /* the "nominal type" used by the opfamily */
  656. } EquivalenceMember;
  657. /*
  658. * PathKeys
  659. *
  660. * The sort ordering of a path is represented by a list of PathKey nodes.
  661. * An empty list implies no known ordering. Otherwise the first item
  662. * represents the primary sort key, the second the first secondary sort key,
  663. * etc. The value being sorted is represented by linking to an
  664. * EquivalenceClass containing that value and including pk_opfamily among its
  665. * ec_opfamilies. The EquivalenceClass tells which collation to use, too.
  666. * This is a convenient method because it makes it trivial to detect
  667. * equivalent and closely-related orderings. (See optimizer/README for more
  668. * information.)
  669. *
  670. * Note: pk_strategy is either BTLessStrategyNumber (for ASC) or
  671. * BTGreaterStrategyNumber (for DESC). We assume that all ordering-capable
  672. * index types will use btree-compatible strategy numbers.
  673. */
  674. typedef struct PathKey
  675. {
  676. NodeTag type;
  677. EquivalenceClass *pk_eclass; /* the value that is ordered */
  678. Oid pk_opfamily; /* btree opfamily defining the ordering */
  679. int pk_strategy; /* sort direction (ASC or DESC) */
  680. bool pk_nulls_first; /* do NULLs come before normal values? */
  681. } PathKey;
  682. /*
  683. * PathTarget
  684. *
  685. * This struct contains what we need to know during planning about the
  686. * targetlist (output columns) that a Path will compute. Each RelOptInfo
  687. * includes a default PathTarget, which its individual Paths may simply
  688. * reference. However, in some cases a Path may compute outputs different
  689. * from other Paths, and in that case we make a custom PathTarget for it.
  690. * For example, an indexscan might return index expressions that would
  691. * otherwise need to be explicitly calculated. (Note also that "upper"
  692. * relations generally don't have useful default PathTargets.)
  693. *
  694. * exprs contains bare expressions; they do not have TargetEntry nodes on top,
  695. * though those will appear in finished Plans.
  696. *
  697. * sortgrouprefs[] is an array of the same length as exprs, containing the
  698. * corresponding sort/group refnos, or zeroes for expressions not referenced
  699. * by sort/group clauses. If sortgrouprefs is NULL (which it generally is in
  700. * RelOptInfo.reltarget targets; only upper-level Paths contain this info),
  701. * we have not identified sort/group columns in this tlist. This allows us to
  702. * deal with sort/group refnos when needed with less expense than including
  703. * TargetEntry nodes in the exprs list.
  704. */
  705. typedef struct PathTarget
  706. {
  707. NodeTag type;
  708. List *exprs; /* list of expressions to be computed */
  709. Index *sortgrouprefs; /* corresponding sort/group refnos, or 0 */
  710. QualCost cost; /* cost of evaluating the expressions */
  711. int width; /* estimated avg width of result tuples */
  712. } PathTarget;
  713. /* Convenience macro to get a sort/group refno from a PathTarget */
  714. #define get_pathtarget_sortgroupref(target, colno) \
  715. ((target)->sortgrouprefs ? (target)->sortgrouprefs[colno] : (Index) 0)
  716. /*
  717. * ParamPathInfo
  718. *
  719. * All parameterized paths for a given relation with given required outer rels
  720. * link to a single ParamPathInfo, which stores common information such as
  721. * the estimated rowcount for this parameterization. We do this partly to
  722. * avoid recalculations, but mostly to ensure that the estimated rowcount
  723. * is in fact the same for every such path.
  724. *
  725. * Note: ppi_clauses is only used in ParamPathInfos for base relation paths;
  726. * in join cases it's NIL because the set of relevant clauses varies depending
  727. * on how the join is formed. The relevant clauses will appear in each
  728. * parameterized join path's joinrestrictinfo list, instead.
  729. */
  730. typedef struct ParamPathInfo
  731. {
  732. NodeTag type;
  733. Relids ppi_req_outer; /* rels supplying parameters used by path */
  734. double ppi_rows; /* estimated number of result tuples */
  735. List *ppi_clauses; /* join clauses available from outer rels */
  736. } ParamPathInfo;
  737. /*
  738. * Type "Path" is used as-is for sequential-scan paths, as well as some other
  739. * simple plan types that we don't need any extra information in the path for.
  740. * For other path types it is the first component of a larger struct.
  741. *
  742. * "pathtype" is the NodeTag of the Plan node we could build from this Path.
  743. * It is partially redundant with the Path's NodeTag, but allows us to use
  744. * the same Path type for multiple Plan types when there is no need to
  745. * distinguish the Plan type during path processing.
  746. *
  747. * "parent" identifies the relation this Path scans, and "pathtarget"
  748. * describes the precise set of output columns the Path would compute.
  749. * In simple cases all Paths for a given rel share the same targetlist,
  750. * which we represent by having path->pathtarget equal to parent->reltarget.
  751. *
  752. * "param_info", if not NULL, links to a ParamPathInfo that identifies outer
  753. * relation(s) that provide parameter values to each scan of this path.
  754. * That means this path can only be joined to those rels by means of nestloop
  755. * joins with this path on the inside. Also note that a parameterized path
  756. * is responsible for testing all "movable" joinclauses involving this rel
  757. * and the specified outer rel(s).
  758. *
  759. * "rows" is the same as parent->rows in simple paths, but in parameterized
  760. * paths and UniquePaths it can be less than parent->rows, reflecting the
  761. * fact that we've filtered by extra join conditions or removed duplicates.
  762. *
  763. * "pathkeys" is a List of PathKey nodes (see above), describing the sort
  764. * ordering of the path's output rows.
  765. */
  766. typedef struct Path
  767. {
  768. NodeTag type;
  769. NodeTag pathtype; /* tag identifying scan/join method */
  770. RelOptInfo *parent; /* the relation this path can build */
  771. PathTarget *pathtarget; /* list of Vars/Exprs, cost, width */
  772. ParamPathInfo *param_info; /* parameterization info, or NULL if none */
  773. bool parallel_aware; /* engage parallel-aware logic? */
  774. bool parallel_safe; /* OK to use as part of parallel plan? */
  775. int parallel_workers; /* desired # of workers; 0 = not
  776. * parallel */
  777. /* estimated size/costs for path (see costsize.c for more info) */
  778. double rows; /* estimated number of result tuples */
  779. Cost startup_cost; /* cost expended before fetching any tuples */
  780. Cost total_cost; /* total cost (assuming all tuples fetched) */
  781. List *pathkeys; /* sort ordering of path's output */
  782. /* pathkeys is a List of PathKey nodes; see above */
  783. } Path;
  784. /* Macro for extracting a path's parameterization relids; beware double eval */
  785. #define PATH_REQ_OUTER(path) \
  786. ((path)->param_info ? (path)->param_info->ppi_req_outer : (Relids) NULL)
  787. /*----------
  788. * IndexPath represents an index scan over a single index.
  789. *
  790. * This struct is used for both regular indexscans and index-only scans;
  791. * path.pathtype is T_IndexScan or T_IndexOnlyScan to show which is meant.
  792. *
  793. * 'indexinfo' is the index to be scanned.
  794. *
  795. * 'indexclauses' is a list of index qualification clauses, with implicit
  796. * AND semantics across the list. Each clause is a RestrictInfo node from
  797. * the query's WHERE or JOIN conditions. An empty list implies a full
  798. * index scan.
  799. *
  800. * 'indexquals' has the same structure as 'indexclauses', but it contains
  801. * the actual index qual conditions that can be used with the index.
  802. * In simple cases this is identical to 'indexclauses', but when special
  803. * indexable operators appear in 'indexclauses', they are replaced by the
  804. * derived indexscannable conditions in 'indexquals'.
  805. *
  806. * 'indexqualcols' is an integer list of index column numbers (zero-based)
  807. * of the same length as 'indexquals', showing which index column each qual
  808. * is meant to be used with. 'indexquals' is required to be ordered by
  809. * index column, so 'indexqualcols' must form a nondecreasing sequence.
  810. * (The order of multiple quals for the same index column is unspecified.)
  811. *
  812. * 'indexorderbys', if not NIL, is a list of ORDER BY expressions that have
  813. * been found to be usable as ordering operators for an amcanorderbyop index.
  814. * The list must match the path's pathkeys, ie, one expression per pathkey
  815. * in the same order. These are not RestrictInfos, just bare expressions,
  816. * since they generally won't yield booleans. Also, unlike the case for
  817. * quals, it's guaranteed that each expression has the index key on the left
  818. * side of the operator.
  819. *
  820. * 'indexorderbycols' is an integer list of index column numbers (zero-based)
  821. * of the same length as 'indexorderbys', showing which index column each
  822. * ORDER BY expression is meant to be used with. (There is no restriction
  823. * on which index column each ORDER BY can be used with.)
  824. *
  825. * 'indexscandir' is one of:
  826. * ForwardScanDirection: forward scan of an ordered index
  827. * BackwardScanDirection: backward scan of an ordered index
  828. * NoMovementScanDirection: scan of an unordered index, or don't care
  829. * (The executor doesn't care whether it gets ForwardScanDirection or
  830. * NoMovementScanDirection for an indexscan, but the planner wants to
  831. * distinguish ordered from unordered indexes for building pathkeys.)
  832. *
  833. * 'indextotalcost' and 'indexselectivity' are saved in the IndexPath so that
  834. * we need not recompute them when considering using the same index in a
  835. * bitmap index/heap scan (see BitmapHeapPath). The costs of the IndexPath
  836. * itself represent the costs of an IndexScan or IndexOnlyScan plan type.
  837. *----------
  838. */
  839. typedef struct IndexPath
  840. {
  841. Path path;
  842. IndexOptInfo *indexinfo;
  843. List *indexclauses;
  844. List *indexquals;
  845. List *indexqualcols;
  846. List *indexorderbys;
  847. List *indexorderbycols;
  848. ScanDirection indexscandir;
  849. Cost indextotalcost;
  850. Selectivity indexselectivity;
  851. } IndexPath;
  852. /*
  853. * BitmapHeapPath represents one or more indexscans that generate TID bitmaps
  854. * instead of directly accessing the heap, followed by AND/OR combinations
  855. * to produce a single bitmap, followed by a heap scan that uses the bitmap.
  856. * Note that the output is always considered unordered, since it will come
  857. * out in physical heap order no matter what the underlying indexes did.
  858. *
  859. * The individual indexscans are represented by IndexPath nodes, and any
  860. * logic on top of them is represented by a tree of BitmapAndPath and
  861. * BitmapOrPath nodes. Notice that we can use the same IndexPath node both
  862. * to represent a regular (or index-only) index scan plan, and as the child
  863. * of a BitmapHeapPath that represents scanning the same index using a
  864. * BitmapIndexScan. The startup_cost and total_cost figures of an IndexPath
  865. * always represent the costs to use it as a regular (or index-only)
  866. * IndexScan. The costs of a BitmapIndexScan can be computed using the
  867. * IndexPath's indextotalcost and indexselectivity.
  868. */
  869. typedef struct BitmapHeapPath
  870. {
  871. Path path;
  872. Path *bitmapqual; /* IndexPath, BitmapAndPath, BitmapOrPath */
  873. } BitmapHeapPath;
  874. /*
  875. * BitmapAndPath represents a BitmapAnd plan node; it can only appear as
  876. * part of the substructure of a BitmapHeapPath. The Path structure is
  877. * a bit more heavyweight than we really need for this, but for simplicity
  878. * we make it a derivative of Path anyway.
  879. */
  880. typedef struct BitmapAndPath
  881. {
  882. Path path;
  883. List *bitmapquals; /* IndexPaths and BitmapOrPaths */
  884. Selectivity bitmapselectivity;
  885. } BitmapAndPath;
  886. /*
  887. * BitmapOrPath represents a BitmapOr plan node; it can only appear as
  888. * part of the substructure of a BitmapHeapPath. The Path structure is
  889. * a bit more heavyweight than we really need for this, but for simplicity
  890. * we make it a derivative of Path anyway.
  891. */
  892. typedef struct BitmapOrPath
  893. {
  894. Path path;
  895. List *bitmapquals; /* IndexPaths and BitmapAndPaths */
  896. Selectivity bitmapselectivity;
  897. } BitmapOrPath;
  898. /*
  899. * TidPath represents a scan by TID
  900. *
  901. * tidquals is an implicitly OR'ed list of qual expressions of the form
  902. * "CTID = pseudoconstant" or "CTID = ANY(pseudoconstant_array)".
  903. * Note they are bare expressions, not RestrictInfos.
  904. */
  905. typedef struct TidPath
  906. {
  907. Path path;
  908. List *tidquals; /* qual(s) involving CTID = something */
  909. } TidPath;
  910. /*
  911. * SubqueryScanPath represents a scan of an unflattened subquery-in-FROM
  912. *
  913. * Note that the subpath comes from a different planning domain; for example
  914. * RTE indexes within it mean something different from those known to the
  915. * SubqueryScanPath. path.parent->subroot is the planning context needed to
  916. * interpret the subpath.
  917. */
  918. typedef struct SubqueryScanPath
  919. {
  920. Path path;
  921. Path *subpath; /* path representing subquery execution */
  922. } SubqueryScanPath;
  923. /*
  924. * ForeignPath represents a potential scan of a foreign table, foreign join
  925. * or foreign upper-relation.
  926. *
  927. * fdw_private stores FDW private data about the scan. While fdw_private is
  928. * not actually touched by the core code during normal operations, it's
  929. * generally a good idea to use a representation that can be dumped by
  930. * nodeToString(), so that you can examine the structure during debugging
  931. * with tools like pprint().
  932. */
  933. typedef struct ForeignPath
  934. {
  935. Path path;
  936. Path *fdw_outerpath;
  937. List *fdw_private;
  938. } ForeignPath;
  939. /*
  940. * CustomPath represents a table scan done by some out-of-core extension.
  941. *
  942. * We provide a set of hooks here - which the provider must take care to set
  943. * up correctly - to allow extensions to supply their own methods of scanning
  944. * a relation. For example, a provider might provide GPU acceleration, a
  945. * cache-based scan, or some other kind of logic we haven't dreamed up yet.
  946. *
  947. * CustomPaths can be injected into the planning process for a relation by
  948. * set_rel_pathlist_hook functions.
  949. *
  950. * Core code must avoid assuming that the CustomPath is only as large as
  951. * the structure declared here; providers are allowed to make it the first
  952. * element in a larger structure. (Since the planner never copies Paths,
  953. * this doesn't add any complication.) However, for consistency with the
  954. * FDW case, we provide a "custom_private" field in CustomPath; providers
  955. * may prefer to use that rather than define another struct type.
  956. */
  957. struct CustomPathMethods;
  958. typedef struct CustomPath
  959. {
  960. Path path;
  961. uint32 flags; /* mask of CUSTOMPATH_* flags, see
  962. * nodes/extensible.h */
  963. List *custom_paths; /* list of child Path nodes, if any */
  964. List *custom_private;
  965. const struct CustomPathMethods *methods;
  966. } CustomPath;
  967. /*
  968. * AppendPath represents an Append plan, ie, successive execution of
  969. * several member plans.
  970. *
  971. * Note: it is possible for "subpaths" to contain only one, or even no,
  972. * elements. These cases are optimized during create_append_plan.
  973. * In particular, an AppendPath with no subpaths is a "dummy" path that
  974. * is created to represent the case that a relation is provably empty.
  975. */
  976. typedef struct AppendPath
  977. {
  978. Path path;
  979. List *subpaths; /* list of component Paths */
  980. } AppendPath;
  981. #define IS_DUMMY_PATH(p) \
  982. (IsA((p), AppendPath) && ((AppendPath *) (p))->subpaths == NIL)
  983. /* A relation that's been proven empty will have one path that is dummy */
  984. #define IS_DUMMY_REL(r) \
  985. ((r)->cheapest_total_path != NULL && \
  986. IS_DUMMY_PATH((r)->cheapest_total_path))
  987. /*
  988. * MergeAppendPath represents a MergeAppend plan, ie, the merging of sorted
  989. * results from several member plans to produce similarly-sorted output.
  990. */
  991. typedef struct MergeAppendPath
  992. {
  993. Path path;
  994. List *subpaths; /* list of component Paths */
  995. double limit_tuples; /* hard limit on output tuples, or -1 */
  996. } MergeAppendPath;
  997. /*
  998. * ResultPath represents use of a Result plan node to compute a variable-free
  999. * targetlist with no underlying tables (a "SELECT expressions" query).
  1000. * The query could have a WHERE clause, too, represented by "quals".
  1001. *
  1002. * Note that quals is a list of bare clauses, not RestrictInfos.
  1003. */
  1004. typedef struct ResultPath
  1005. {
  1006. Path path;
  1007. List *quals;
  1008. } ResultPath;
  1009. /*
  1010. * MaterialPath represents use of a Material plan node, i.e., caching of
  1011. * the output of its subpath. This is used when the subpath is expensive
  1012. * and needs to be scanned repeatedly, or when we need mark/restore ability
  1013. * and the subpath doesn't have it.
  1014. */
  1015. typedef struct MaterialPath
  1016. {
  1017. Path path;
  1018. Path *subpath;
  1019. } MaterialPath;
  1020. /*
  1021. * UniquePath represents elimination of distinct rows from the output of
  1022. * its subpath.
  1023. *
  1024. * This can represent significantly different plans: either hash-based or
  1025. * sort-based implementation, or a no-op if the input path can be proven
  1026. * distinct already. The decision is sufficiently localized that it's not
  1027. * worth having separate Path node types. (Note: in the no-op case, we could
  1028. * eliminate the UniquePath node entirely and just return the subpath; but
  1029. * it's convenient to have a UniquePath in the path tree to signal upper-level
  1030. * routines that the input is known distinct.)
  1031. */
  1032. typedef enum
  1033. {
  1034. UNIQUE_PATH_NOOP, /* input is known unique already */
  1035. UNIQUE_PATH_HASH, /* use hashing */
  1036. UNIQUE_PATH_SORT /* use sorting */
  1037. } UniquePathMethod;
  1038. typedef struct UniquePath
  1039. {
  1040. Path path;
  1041. Path *subpath;
  1042. UniquePathMethod umethod;
  1043. List *in_operators; /* equality operators of the IN clause */
  1044. List *uniq_exprs; /* expressions to be made unique */
  1045. } UniquePath;
  1046. /*
  1047. * GatherPath runs several copies of a plan in parallel and collects the
  1048. * results. The parallel leader may also execute the plan, unless the
  1049. * single_copy flag is set.
  1050. */
  1051. typedef struct GatherPath
  1052. {
  1053. Path path;
  1054. Path *subpath; /* path for each worker */
  1055. bool single_copy; /* path must not be executed >1x */
  1056. int num_workers; /* number of workers sought to help */
  1057. } GatherPath;
  1058. /*
  1059. * All join-type paths share these fields.
  1060. */
  1061. typedef struct JoinPath
  1062. {
  1063. Path path;
  1064. JoinType jointype;
  1065. Path *outerjoinpath; /* path for the outer side of the join */
  1066. Path *innerjoinpath; /* path for the inner side of the join */
  1067. List *joinrestrictinfo; /* RestrictInfos to apply to join */
  1068. /*
  1069. * See the notes for RelOptInfo and ParamPathInfo to understand why
  1070. * joinrestrictinfo is needed in JoinPath, and can't be merged into the
  1071. * parent RelOptInfo.
  1072. */
  1073. } JoinPath;
  1074. /*
  1075. * A nested-loop path needs no special fields.
  1076. */
  1077. typedef JoinPath NestPath;
  1078. /*
  1079. * A mergejoin path has these fields.
  1080. *
  1081. * Unlike other path types, a MergePath node doesn't represent just a single
  1082. * run-time plan node: it can represent up to four. Aside from the MergeJoin
  1083. * node itself, there can be a Sort node for the outer input, a Sort node
  1084. * for the inner input, and/or a Material node for the inner input. We could
  1085. * represent these nodes by separate path nodes, but considering how many
  1086. * different merge paths are investigated during a complex join problem,
  1087. * it seems better to avoid unnecessary palloc overhead.
  1088. *
  1089. * path_mergeclauses lists the clauses (in the form of RestrictInfos)
  1090. * that will be used in the merge.
  1091. *
  1092. * Note that the mergeclauses are a subset of the parent relation's
  1093. * restriction-clause list. Any join clauses that are not mergejoinable
  1094. * appear only in the parent's restrict list, and must be checked by a
  1095. * qpqual at execution time.
  1096. *
  1097. * outersortkeys (resp. innersortkeys) is NIL if the outer path
  1098. * (resp. inner path) is already ordered appropriately for the
  1099. * mergejoin. If it is not NIL then it is a PathKeys list describing
  1100. * the ordering that must be created by an explicit Sort node.
  1101. *
  1102. * materialize_inner is TRUE if a Material node should be placed atop the
  1103. * inner input. This may appear with or without an inner Sort step.
  1104. */
  1105. typedef struct MergePath
  1106. {
  1107. JoinPath jpath;
  1108. List *path_mergeclauses; /* join clauses to be used for merge */
  1109. List *outersortkeys; /* keys for explicit sort, if any */
  1110. List *innersortkeys; /* keys for explicit sort, if any */
  1111. bool materialize_inner; /* add Materialize to inner? */
  1112. } MergePath;
  1113. /*
  1114. * A hashjoin path has these fields.
  1115. *
  1116. * The remarks above for mergeclauses apply for hashclauses as well.
  1117. *
  1118. * Hashjoin does not care what order its inputs appear in, so we have
  1119. * no need for sortkeys.
  1120. */
  1121. typedef struct HashPath
  1122. {
  1123. JoinPath jpath;
  1124. List *path_hashclauses; /* join clauses used for hashing */
  1125. int num_batches; /* number of batches expected */
  1126. } HashPath;
  1127. /*
  1128. * ProjectionPath represents a projection (that is, targetlist computation)
  1129. *
  1130. * Nominally, this path node represents using a Result plan node to do a
  1131. * projection step. However, if the input plan node supports projection,
  1132. * we can just modify its output targetlist to do the required calculations
  1133. * directly, and not need a Result. In some places in the planner we can just
  1134. * jam the desired PathTarget into the input path node (and adjust its cost
  1135. * accordingly), so we don't need a ProjectionPath. But in other places
  1136. * it's necessary to not modify the input path node, so we need a separate
  1137. * ProjectionPath node, which is marked dummy to indicate that we intend to
  1138. * assign the work to the input plan node. The estimated cost for the
  1139. * ProjectionPath node will account for whether a Result will be used or not.
  1140. */
  1141. typedef struct ProjectionPath
  1142. {
  1143. Path path;
  1144. Path *subpath; /* path representing input source */
  1145. bool dummypp; /* true if no separate Result is needed */
  1146. } ProjectionPath;
  1147. /*
  1148. * SortPath represents an explicit sort step
  1149. *
  1150. * The sort keys are, by definition, the same as path.pathkeys.
  1151. *
  1152. * Note: the Sort plan node cannot project, so path.pathtarget must be the
  1153. * same as the input's pathtarget.
  1154. */
  1155. typedef struct SortPath
  1156. {
  1157. Path path;
  1158. Path *subpath; /* path representing input source */
  1159. } SortPath;
  1160. /*
  1161. * GroupPath represents grouping (of presorted input)
  1162. *
  1163. * groupClause represents the columns to be grouped on; the input path
  1164. * must be at least that well sorted.
  1165. *
  1166. * We can also apply a qual to the grouped rows (equivalent of HAVING)
  1167. */
  1168. typedef struct GroupPath
  1169. {
  1170. Path path;
  1171. Path *subpath; /* path representing input source */
  1172. List *groupClause; /* a list of SortGroupClause's */
  1173. List *qual; /* quals (HAVING quals), if any */
  1174. } GroupPath;
  1175. /*
  1176. * UpperUniquePath represents adjacent-duplicate removal (in presorted input)
  1177. *
  1178. * The columns to be compared are the first numkeys columns of the path's
  1179. * pathkeys. The input is presumed already sorted that way.
  1180. */
  1181. typedef struct UpperUniquePath
  1182. {
  1183. Path path;
  1184. Path *subpath; /* path representing input source */
  1185. int numkeys; /* number of pathkey columns to compare */
  1186. } UpperUniquePath;
  1187. /*
  1188. * AggPath represents generic computation of aggregate functions
  1189. *
  1190. * This may involve plain grouping (but not grouping sets), using either
  1191. * sorted or hashed grouping; for the AGG_SORTED case, the input must be
  1192. * appropriately presorted.
  1193. */
  1194. typedef struct AggPath
  1195. {
  1196. Path path;
  1197. Path *subpath; /* path representing input source */
  1198. AggStrategy aggstrategy; /* basic strategy, see nodes.h */
  1199. AggSplit aggsplit; /* agg-splitting mode, see nodes.h */
  1200. double numGroups; /* estimated number of groups in input */
  1201. List *groupClause; /* a list of SortGroupClause's */
  1202. List *qual; /* quals (HAVING quals), if any */
  1203. } AggPath;
  1204. /*
  1205. * GroupingSetsPath represents a GROUPING SETS aggregation
  1206. *
  1207. * Currently we only support this in sorted not hashed form, so the input
  1208. * must always be appropriately presorted.
  1209. */
  1210. typedef struct GroupingSetsPath
  1211. {
  1212. Path path;
  1213. Path *subpath; /* path representing input source */
  1214. List *rollup_groupclauses; /* list of lists of SortGroupClause's */
  1215. List *rollup_lists; /* parallel list of lists of grouping sets */
  1216. List *qual; /* quals (HAVING quals), if any */
  1217. } GroupingSetsPath;
  1218. /*
  1219. * MinMaxAggPath represents computation of MIN/MAX aggregates from indexes
  1220. */
  1221. typedef struct MinMaxAggPath
  1222. {
  1223. Path path;
  1224. List *mmaggregates; /* list of MinMaxAggInfo */
  1225. List *quals; /* HAVING quals, if any */
  1226. } MinMaxAggPath;
  1227. /*
  1228. * WindowAggPath represents generic computation of window functions
  1229. *
  1230. * Note: winpathkeys is separate from path.pathkeys because the actual sort
  1231. * order might be an extension of winpathkeys; but createplan.c needs to
  1232. * know exactly how many pathkeys match the window clause.
  1233. */
  1234. typedef struct WindowAggPath
  1235. {
  1236. Path path;
  1237. Path *subpath; /* path representing input source */
  1238. WindowClause *winclause; /* WindowClause we'll be using */
  1239. List *winpathkeys; /* PathKeys for PARTITION keys + ORDER keys */
  1240. } WindowAggPath;
  1241. /*
  1242. * SetOpPath represents a set-operation, that is INTERSECT or EXCEPT
  1243. */
  1244. typedef struct SetOpPath
  1245. {
  1246. Path path;
  1247. Path *subpath; /* path representing input source */
  1248. SetOpCmd cmd; /* what to do, see nodes.h */
  1249. SetOpStrategy strategy; /* how to do it, see nodes.h */
  1250. List *distinctList; /* SortGroupClauses identifying target cols */
  1251. AttrNumber flagColIdx; /* where is the flag column, if any */
  1252. int firstFlag; /* flag value for first input relation */
  1253. double numGroups; /* estimated number of groups in input */
  1254. } SetOpPath;
  1255. /*
  1256. * RecursiveUnionPath represents a recursive UNION node
  1257. */
  1258. typedef struct RecursiveUnionPath
  1259. {
  1260. Path path;
  1261. Path *leftpath; /* paths representing input sources */
  1262. Path *rightpath;
  1263. List *distinctList; /* SortGroupClauses identifying target cols */
  1264. int wtParam; /* ID of Param representing work table */
  1265. double numGroups; /* estimated number of groups in input */
  1266. } RecursiveUnionPath;
  1267. /*
  1268. * LockRowsPath represents acquiring row locks for SELECT FOR UPDATE/SHARE
  1269. */
  1270. typedef struct LockRowsPath
  1271. {
  1272. Path path;
  1273. Path *subpath; /* path representing input source */
  1274. List *rowMarks; /* a list of PlanRowMark's */
  1275. int epqParam; /* ID of Param for EvalPlanQual re-eval */
  1276. } LockRowsPath;
  1277. /*
  1278. * ModifyTablePath represents performing INSERT/UPDATE/DELETE modifications
  1279. *
  1280. * We represent most things that will be in the ModifyTable plan node
  1281. * literally, except we have child Path(s) not Plan(s). But analysis of the
  1282. * OnConflictExpr is deferred to createplan.c, as is collection of FDW data.
  1283. */
  1284. typedef struct ModifyTablePath
  1285. {
  1286. Path path;
  1287. CmdType operation; /* INSERT, UPDATE, or DELETE */
  1288. bool canSetTag; /* do we set the command tag/es_processed? */
  1289. Index nominalRelation; /* Parent RT index for use of EXPLAIN */
  1290. List *resultRelations; /* integer list of RT indexes */
  1291. List *subpaths; /* Path(s) producing source data */
  1292. List *subroots; /* per-target-table PlannerInfos */
  1293. List *withCheckOptionLists; /* per-target-table WCO lists */
  1294. List *returningLists; /* per-target-table RETURNING tlists */
  1295. List *rowMarks; /* PlanRowMarks (non-locking only) */
  1296. OnConflictExpr *onconflict; /* ON CONFLICT clause, or NULL */
  1297. int epqParam; /* ID of Param for EvalPlanQual re-eval */
  1298. } ModifyTablePath;
  1299. /*
  1300. * LimitPath represents applying LIMIT/OFFSET restrictions
  1301. */
  1302. typedef struct LimitPath
  1303. {
  1304. Path path;
  1305. Path *subpath; /* path representing input source */
  1306. Node *limitOffset; /* OFFSET parameter, or NULL if none */
  1307. Node *limitCount; /* COUNT parameter, or NULL if none */
  1308. } LimitPath;
  1309. /*
  1310. * Restriction clause info.
  1311. *
  1312. * We create one of these for each AND sub-clause of a restriction condition
  1313. * (WHERE or JOIN/ON clause). Since the restriction clauses are logically
  1314. * ANDed, we can use any one of them or any subset of them to filter out
  1315. * tuples, without having to evaluate the rest. The RestrictInfo node itself
  1316. * stores data used by the optimizer while choosing the best query plan.
  1317. *
  1318. * If a restriction clause references a single base relation, it will appear
  1319. * in the baserestrictinfo list of the RelOptInfo for that base rel.
  1320. *
  1321. * If a restriction clause references more than one base rel, it will
  1322. * appear in the joininfo list of every RelOptInfo that describes a strict
  1323. * subset of the base rels mentioned in the clause. The joininfo lists are
  1324. * used to drive join tree building by selecting plausible join candidates.
  1325. * The clause cannot actually be applied until we have built a join rel
  1326. * containing all the base rels it references, however.
  1327. *
  1328. * When we construct a join rel that includes all the base rels referenced
  1329. * in a multi-relation restriction clause, we place that clause into the
  1330. * joinrestrictinfo lists of paths for the join rel, if neither left nor
  1331. * right sub-path includes all base rels referenced in the clause. The clause
  1332. * will be applied at that join level, and will not propagate any further up
  1333. * the join tree. (Note: the "predicate migration" code was once intended to
  1334. * push restriction clauses up and down the plan tree based on evaluation
  1335. * costs, but it's dead code and is unlikely to be resurrected in the
  1336. * foreseeable future.)
  1337. *
  1338. * Note that in the presence of more than two rels, a multi-rel restriction
  1339. * might reach different heights in the join tree depending on the join
  1340. * sequence we use. So, these clauses cannot be associated directly with
  1341. * the join RelOptInfo, but must be kept track of on a per-join-path basis.
  1342. *
  1343. * RestrictInfos that represent equivalence conditions (i.e., mergejoinable
  1344. * equalities that are not outerjoin-delayed) are handled a bit differently.
  1345. * Initially we attach them to the EquivalenceClasses that are derived from
  1346. * them. When we construct a scan or join path, we look through all the
  1347. * EquivalenceClasses and generate derived RestrictInfos representing the
  1348. * minimal set of conditions that need to be checked for this particular scan
  1349. * or join to enforce that all members of each EquivalenceClass are in fact
  1350. * equal in all rows emitted by the scan or join.
  1351. *
  1352. * When dealing with outer joins we have to be very careful about pushing qual
  1353. * clauses up and down the tree. An outer join's own JOIN/ON conditions must
  1354. * be evaluated exactly at that join node, unless they are "degenerate"
  1355. * conditions that reference only Vars from the nullable side of the join.
  1356. * Quals appearing in WHERE or in a JOIN above the outer join cannot be pushed
  1357. * down below the outer join, if they reference any nullable Vars.
  1358. * RestrictInfo nodes contain a flag to indicate whether a qual has been
  1359. * pushed down to a lower level than its original syntactic placement in the
  1360. * join tree would suggest. If an outer join prevents us from pushing a qual
  1361. * down to its "natural" semantic level (the level associated with just the
  1362. * base rels used in the qual) then we mark the qual with a "required_relids"
  1363. * value including more than just the base rels it actually uses. By
  1364. * pretending that the qual references all the rels required to form the outer
  1365. * join, we prevent it from being evaluated below the outer join's joinrel.
  1366. * When we do form the outer join's joinrel, we still need to distinguish
  1367. * those quals that are actually in that join's JOIN/ON condition from those
  1368. * that appeared elsewhere in the tree and were pushed down to the join rel
  1369. * because they used no other rels. That's what the is_pushed_down flag is
  1370. * for; it tells us that a qual is not an OUTER JOIN qual for the set of base
  1371. * rels listed in required_relids. A clause that originally came from WHERE
  1372. * or an INNER JOIN condition will *always* have its is_pushed_down flag set.
  1373. * It's possible for an OUTER JOIN clause to be marked is_pushed_down too,
  1374. * if we decide that it can be pushed down into the nullable side of the join.
  1375. * In that case it acts as a plain filter qual for wherever it gets evaluated.
  1376. * (In short, is_pushed_down is only false for non-degenerate outer join
  1377. * conditions. Possibly we should rename it to reflect that meaning?)
  1378. *
  1379. * RestrictInfo nodes also contain an outerjoin_delayed flag, which is true
  1380. * if the clause's applicability must be delayed due to any outer joins
  1381. * appearing below it (ie, it has to be postponed to some join level higher
  1382. * than the set of relations it actually references).
  1383. *
  1384. * There is also an outer_relids field, which is NULL except for outer join
  1385. * clauses; for those, it is the set of relids on the outer side of the
  1386. * clause's outer join. (These are rels that the clause cannot be applied to
  1387. * in parameterized scans, since pushing it into the join's outer side would
  1388. * lead to wrong answers.)
  1389. *
  1390. * There is also a nullable_relids field, which is the set of rels the clause
  1391. * references that can be forced null by some outer join below the clause.
  1392. *
  1393. * outerjoin_delayed = true is subtly different from nullable_relids != NULL:
  1394. * a clause might reference some nullable rels and yet not be
  1395. * outerjoin_delayed because it also references all the other rels of the
  1396. * outer join(s). A clause that is not outerjoin_delayed can be enforced
  1397. * anywhere it is computable.
  1398. *
  1399. * In general, the referenced clause might be arbitrarily complex. The
  1400. * kinds of clauses we can handle as indexscan quals, mergejoin clauses,
  1401. * or hashjoin clauses are limited (e.g., no volatile functions). The code
  1402. * for each kind of path is responsible for identifying the restrict clauses
  1403. * it can use and ignoring the rest. Clauses not implemented by an indexscan,
  1404. * mergejoin, or hashjoin will be placed in the plan qual or joinqual field
  1405. * of the finished Plan node, where they will be enforced by general-purpose
  1406. * qual-expression-evaluation code. (But we are still entitled to count
  1407. * their selectivity when estimating the result tuple count, if we
  1408. * can guess what it is...)
  1409. *
  1410. * When the referenced clause is an OR clause, we generate a modified copy
  1411. * in which additional RestrictInfo nodes are inserted below the top-level
  1412. * OR/AND structure. This is a convenience for OR indexscan processing:
  1413. * indexquals taken from either the top level or an OR subclause will have
  1414. * associated RestrictInfo nodes.
  1415. *
  1416. * The can_join flag is set true if the clause looks potentially useful as
  1417. * a merge or hash join clause, that is if it is a binary opclause with
  1418. * nonoverlapping sets of relids referenced in the left and right sides.
  1419. * (Whether the operator is actually merge or hash joinable isn't checked,
  1420. * however.)
  1421. *
  1422. * The pseudoconstant flag is set true if the clause contains no Vars of
  1423. * the current query level and no volatile functions. Such a clause can be
  1424. * pulled out and used as a one-time qual in a gating Result node. We keep
  1425. * pseudoconstant clauses in the same lists as other RestrictInfos so that
  1426. * the regular clause-pushing machinery can assign them to the correct join
  1427. * level, but they need to be treated specially for cost and selectivity
  1428. * estimates. Note that a pseudoconstant clause can never be an indexqual
  1429. * or merge or hash join clause, so it's of no interest to large parts of
  1430. * the planner.
  1431. *
  1432. * When join clauses are generated from EquivalenceClasses, there may be
  1433. * several equally valid ways to enforce join equivalence, of which we need
  1434. * apply only one. We mark clauses of this kind by setting parent_ec to
  1435. * point to the generating EquivalenceClass. Multiple clauses with the same
  1436. * parent_ec in the same join are redundant.
  1437. */
  1438. typedef struct RestrictInfo
  1439. {
  1440. NodeTag type;
  1441. Expr *clause; /* the represented clause of WHERE or JOIN */
  1442. bool is_pushed_down; /* TRUE if clause was pushed down in level */
  1443. bool outerjoin_delayed; /* TRUE if delayed by lower outer join */
  1444. bool can_join; /* see comment above */
  1445. bool pseudoconstant; /* see comment above */
  1446. /* The set of relids (varnos) actually referenced in the clause: */
  1447. Relids clause_relids;
  1448. /* The set of relids required to evaluate the clause: */
  1449. Relids required_relids;
  1450. /* If an outer-join clause, the outer-side relations, else NULL: */
  1451. Relids outer_relids;
  1452. /* The relids used in the clause that are nullable by lower outer joins: */
  1453. Relids nullable_relids;
  1454. /* These fields are set for any binary opclause: */
  1455. Relids left_relids; /* relids in left side of clause */
  1456. Relids right_relids; /* relids in right side of clause */
  1457. /* This field is NULL unless clause is an OR clause: */
  1458. Expr *orclause; /* modified clause with RestrictInfos */
  1459. /* This field is NULL unless clause is potentially redundant: */
  1460. EquivalenceClass *parent_ec; /* generating EquivalenceClass */
  1461. /* cache space for cost and selectivity */
  1462. QualCost eval_cost; /* eval cost of clause; -1 if not yet set */
  1463. Selectivity norm_selec; /* selectivity for "normal" (JOIN_INNER)
  1464. * semantics; -1 if not yet set; >1 means a
  1465. * redundant clause */
  1466. Selectivity outer_selec; /* selectivity for outer join semantics; -1 if
  1467. * not yet set */
  1468. /* valid if clause is mergejoinable, else NIL */
  1469. List *mergeopfamilies; /* opfamilies containing clause operator */
  1470. /* cache space for mergeclause processing; NULL if not yet set */
  1471. EquivalenceClass *left_ec; /* EquivalenceClass containing lefthand */
  1472. EquivalenceClass *right_ec; /* EquivalenceClass containing righthand */
  1473. EquivalenceMember *left_em; /* EquivalenceMember for lefthand */
  1474. EquivalenceMember *right_em; /* EquivalenceMember for righthand */
  1475. List *scansel_cache; /* list of MergeScanSelCache structs */
  1476. /* transient workspace for use while considering a specific join path */
  1477. bool outer_is_left; /* T = outer var on left, F = on right */
  1478. /* valid if clause is hashjoinable, else InvalidOid: */
  1479. Oid hashjoinoperator; /* copy of clause operator */
  1480. /* cache space for hashclause processing; -1 if not yet set */
  1481. Selectivity left_bucketsize; /* avg bucketsize of left side */
  1482. Selectivity right_bucketsize; /* avg bucketsize of right side */
  1483. } RestrictInfo;
  1484. /*
  1485. * Since mergejoinscansel() is a relatively expensive function, and would
  1486. * otherwise be invoked many times while planning a large join tree,
  1487. * we go out of our way to cache its results. Each mergejoinable
  1488. * RestrictInfo carries a list of the specific sort orderings that have
  1489. * been considered for use with it, and the resulting selectivities.
  1490. */
  1491. typedef struct MergeScanSelCache
  1492. {
  1493. /* Ordering details (cache lookup key) */
  1494. Oid opfamily; /* btree opfamily defining the ordering */
  1495. Oid collation; /* collation for the ordering */
  1496. int strategy; /* sort direction (ASC or DESC) */
  1497. bool nulls_first; /* do NULLs come before normal values? */
  1498. /* Results */
  1499. Selectivity leftstartsel; /* first-join fraction for clause left side */
  1500. Selectivity leftendsel; /* last-join fraction for clause left side */
  1501. Selectivity rightstartsel; /* first-join fraction for clause right side */
  1502. Selectivity rightendsel; /* last-join fraction for clause right side */
  1503. } MergeScanSelCache;
  1504. /*
  1505. * Placeholder node for an expression to be evaluated below the top level
  1506. * of a plan tree. This is used during planning to represent the contained
  1507. * expression. At the end of the planning process it is replaced by either
  1508. * the contained expression or a Var referring to a lower-level evaluation of
  1509. * the contained expression. Typically the evaluation occurs below an outer
  1510. * join, and Var references above the outer join might thereby yield NULL
  1511. * instead of the expression value.
  1512. *
  1513. * Although the planner treats this as an expression node type, it is not
  1514. * recognized by the parser or executor, so we declare it here rather than
  1515. * in primnodes.h.
  1516. */
  1517. typedef struct PlaceHolderVar
  1518. {
  1519. Expr xpr;
  1520. Expr *phexpr; /* the represented expression */
  1521. Relids phrels; /* base relids syntactically within expr src */
  1522. Index phid; /* ID for PHV (unique within planner run) */
  1523. Index phlevelsup; /* > 0 if PHV belongs to outer query */
  1524. } PlaceHolderVar;
  1525. /*
  1526. * "Special join" info.
  1527. *
  1528. * One-sided outer joins constrain the order of joining partially but not
  1529. * completely. We flatten such joins into the planner's top-level list of
  1530. * relations to join, but record information about each outer join in a
  1531. * SpecialJoinInfo struct. These structs are kept in the PlannerInfo node's
  1532. * join_info_list.
  1533. *
  1534. * Similarly, semijoins and antijoins created by flattening IN (subselect)
  1535. * and EXISTS(subselect) clauses create partial constraints on join order.
  1536. * These are likewise recorded in SpecialJoinInfo structs.
  1537. *
  1538. * We make SpecialJoinInfos for FULL JOINs even though there is no flexibility
  1539. * of planning for them, because this simplifies make_join_rel()'s API.
  1540. *
  1541. * min_lefthand and min_righthand are the sets of base relids that must be
  1542. * available on each side when performing the special join. lhs_strict is
  1543. * true if the special join's condition cannot succeed when the LHS variables
  1544. * are all NULL (this means that an outer join can commute with upper-level
  1545. * outer joins even if it appears in their RHS). We don't bother to set
  1546. * lhs_strict for FULL JOINs, however.
  1547. *
  1548. * It is not valid for either min_lefthand or min_righthand to be empty sets;
  1549. * if they were, this would break the logic that enforces join order.
  1550. *
  1551. * syn_lefthand and syn_righthand are the sets of base relids that are
  1552. * syntactically below this special join. (These are needed to help compute
  1553. * min_lefthand and min_righthand for higher joins.)
  1554. *
  1555. * delay_upper_joins is set TRUE if we detect a pushed-down clause that has
  1556. * to be evaluated after this join is formed (because it references the RHS).
  1557. * Any outer joins that have such a clause and this join in their RHS cannot
  1558. * commute with this join, because that would leave noplace to check the
  1559. * pushed-down clause. (We don't track this for FULL JOINs, either.)
  1560. *
  1561. * For a semijoin, we also extract the join operators and their RHS arguments
  1562. * and set semi_operators, semi_rhs_exprs, semi_can_btree, and semi_can_hash.
  1563. * This is done in support of possibly unique-ifying the RHS, so we don't
  1564. * bother unless at least one of semi_can_btree and semi_can_hash can be set
  1565. * true. (You might expect that this information would be computed during
  1566. * join planning; but it's helpful to have it available during planning of
  1567. * parameterized table scans, so we store it in the SpecialJoinInfo structs.)
  1568. *
  1569. * jointype is never JOIN_RIGHT; a RIGHT JOIN is handled by switching
  1570. * the inputs to make it a LEFT JOIN. So the allowed values of jointype
  1571. * in a join_info_list member are only LEFT, FULL, SEMI, or ANTI.
  1572. *
  1573. * For purposes of join selectivity estimation, we create transient
  1574. * SpecialJoinInfo structures for regular inner joins; so it is possible
  1575. * to have jointype == JOIN_INNER in such a structure, even though this is
  1576. * not allowed within join_info_list. We also create transient
  1577. * SpecialJoinInfos with jointype == JOIN_INNER for outer joins, since for
  1578. * cost estimation purposes it is sometimes useful to know the join size under
  1579. * plain innerjoin semantics. Note that lhs_strict, delay_upper_joins, and
  1580. * of course the semi_xxx fields are not set meaningfully within such structs.
  1581. */
  1582. typedef struct SpecialJoinInfo
  1583. {
  1584. NodeTag type;
  1585. Relids min_lefthand; /* base relids in minimum LHS for join */
  1586. Relids min_righthand; /* base relids in minimum RHS for join */
  1587. Relids syn_lefthand; /* base relids syntactically within LHS */
  1588. Relids syn_righthand; /* base relids syntactically within RHS */
  1589. JoinType jointype; /* always INNER, LEFT, FULL, SEMI, or ANTI */
  1590. bool lhs_strict; /* joinclause is strict for some LHS rel */
  1591. bool delay_upper_joins; /* can't commute with upper RHS */
  1592. /* Remaining fields are set only for JOIN_SEMI jointype: */
  1593. bool semi_can_btree; /* true if semi_operators are all btree */
  1594. bool semi_can_hash; /* true if semi_operators are all hash */
  1595. List *semi_operators; /* OIDs of equality join operators */
  1596. List *semi_rhs_exprs; /* righthand-side expressions of these ops */
  1597. } SpecialJoinInfo;
  1598. /*
  1599. * Append-relation info.
  1600. *
  1601. * When we expand an inheritable table or a UNION-ALL subselect into an
  1602. * "append relation" (essentially, a list of child RTEs), we build an
  1603. * AppendRelInfo for each child RTE. The list of AppendRelInfos indicates
  1604. * which child RTEs must be included when expanding the parent, and each
  1605. * node carries information needed to translate Vars referencing the parent
  1606. * into Vars referencing that child.
  1607. *
  1608. * These structs are kept in the PlannerInfo node's append_rel_list.
  1609. * Note that we just throw all the structs into one list, and scan the
  1610. * whole list when desiring to expand any one parent. We could have used
  1611. * a more complex data structure (eg, one list per parent), but this would
  1612. * be harder to update during operations such as pulling up subqueries,
  1613. * and not really any easier to scan. Considering that typical queries
  1614. * will not have many different append parents, it doesn't seem worthwhile
  1615. * to complicate things.
  1616. *
  1617. * Note: after completion of the planner prep phase, any given RTE is an
  1618. * append parent having entries in append_rel_list if and only if its
  1619. * "inh" flag is set. We clear "inh" for plain tables that turn out not
  1620. * to have inheritance children, and (in an abuse of the original meaning
  1621. * of the flag) we set "inh" for subquery RTEs that turn out to be
  1622. * flattenable UNION ALL queries. This lets us avoid useless searches
  1623. * of append_rel_list.
  1624. *
  1625. * Note: the data structure assumes that append-rel members are single
  1626. * baserels. This is OK for inheritance, but it prevents us from pulling
  1627. * up a UNION ALL member subquery if it contains a join. While that could
  1628. * be fixed with a more complex data structure, at present there's not much
  1629. * point because no improvement in the plan could result.
  1630. */
  1631. typedef struct AppendRelInfo
  1632. {
  1633. NodeTag type;
  1634. /*
  1635. * These fields uniquely identify this append relationship. There can be
  1636. * (in fact, always should be) multiple AppendRelInfos for the same
  1637. * parent_relid, but never more than one per child_relid, since a given
  1638. * RTE cannot be a child of more than one append parent.
  1639. */
  1640. Index parent_relid; /* RT index of append parent rel */
  1641. Index child_relid; /* RT index of append child rel */
  1642. /*
  1643. * For an inheritance appendrel, the parent and child are both regular
  1644. * relations, and we store their rowtype OIDs here for use in translating
  1645. * whole-row Vars. For a UNION-ALL appendrel, the parent and child are
  1646. * both subqueries with no named rowtype, and we store InvalidOid here.
  1647. */
  1648. Oid parent_reltype; /* OID of parent's composite type */
  1649. Oid child_reltype; /* OID of child's composite type */
  1650. /*
  1651. * The N'th element of this list is a Var or expression representing the
  1652. * child column corresponding to the N'th column of the parent. This is
  1653. * used to translate Vars referencing the parent rel into references to
  1654. * the child. A list element is NULL if it corresponds to a dropped
  1655. * column of the parent (this is only possible for inheritance cases, not
  1656. * UNION ALL). The list elements are always simple Vars for inheritance
  1657. * cases, but can be arbitrary expressions in UNION ALL cases.
  1658. *
  1659. * Notice we only store entries for user columns (attno > 0). Whole-row
  1660. * Vars are special-cased, and system columns (attno < 0) need no special
  1661. * translation since their attnos are the same for all tables.
  1662. *
  1663. * Caution: the Vars have varlevelsup = 0. Be careful to adjust as needed
  1664. * when copying into a subquery.
  1665. */
  1666. List *translated_vars; /* Expressions in the child's Vars */
  1667. /*
  1668. * We store the parent table's OID here for inheritance, or InvalidOid for
  1669. * UNION ALL. This is only needed to help in generating error messages if
  1670. * an attempt is made to reference a dropped parent column.
  1671. */
  1672. Oid parent_reloid; /* OID of parent relation */
  1673. } AppendRelInfo;
  1674. /*
  1675. * For each distinct placeholder expression generated during planning, we
  1676. * store a PlaceHolderInfo node in the PlannerInfo node's placeholder_list.
  1677. * This stores info that is needed centrally rather than in each copy of the
  1678. * PlaceHolderVar. The phid fields identify which PlaceHolderInfo goes with
  1679. * each PlaceHolderVar. Note that phid is unique throughout a planner run,
  1680. * not just within a query level --- this is so that we need not reassign ID's
  1681. * when pulling a subquery into its parent.
  1682. *
  1683. * The idea is to evaluate the expression at (only) the ph_eval_at join level,
  1684. * then allow it to bubble up like a Var until the ph_needed join level.
  1685. * ph_needed has the same definition as attr_needed for a regular Var.
  1686. *
  1687. * The PlaceHolderVar's expression might contain LATERAL references to vars
  1688. * coming from outside its syntactic scope. If so, those rels are *not*
  1689. * included in ph_eval_at, but they are recorded in ph_lateral.
  1690. *
  1691. * Notice that when ph_eval_at is a join rather than a single baserel, the
  1692. * PlaceHolderInfo may create constraints on join order: the ph_eval_at join
  1693. * has to be formed below any outer joins that should null the PlaceHolderVar.
  1694. *
  1695. * We create a PlaceHolderInfo only after determining that the PlaceHolderVar
  1696. * is actually referenced in the plan tree, so that unreferenced placeholders
  1697. * don't result in unnecessary constraints on join order.
  1698. */
  1699. typedef struct PlaceHolderInfo
  1700. {
  1701. NodeTag type;
  1702. Index phid; /* ID for PH (unique within planner run) */
  1703. PlaceHolderVar *ph_var; /* copy of PlaceHolderVar tree */
  1704. Relids ph_eval_at; /* lowest level we can evaluate value at */
  1705. Relids ph_lateral; /* relids of contained lateral refs, if any */
  1706. Relids ph_needed; /* highest level the value is needed at */
  1707. int32 ph_width; /* estimated attribute width */
  1708. } PlaceHolderInfo;
  1709. /*
  1710. * This struct describes one potentially index-optimizable MIN/MAX aggregate
  1711. * function. MinMaxAggPath contains a list of these, and if we accept that
  1712. * path, the list is stored into root->minmax_aggs for use during setrefs.c.
  1713. */
  1714. typedef struct MinMaxAggInfo
  1715. {
  1716. NodeTag type;
  1717. Oid aggfnoid; /* pg_proc Oid of the aggregate */
  1718. Oid aggsortop; /* Oid of its sort operator */
  1719. Expr *target; /* expression we are aggregating on */
  1720. PlannerInfo *subroot; /* modified "root" for planning the subquery */
  1721. Path *path; /* access path for subquery */
  1722. Cost pathcost; /* estimated cost to fetch first row */
  1723. Param *param; /* param for subplan's output */
  1724. } MinMaxAggInfo;
  1725. /*
  1726. * At runtime, PARAM_EXEC slots are used to pass values around from one plan
  1727. * node to another. They can be used to pass values down into subqueries (for
  1728. * outer references in subqueries), or up out of subqueries (for the results
  1729. * of a subplan), or from a NestLoop plan node into its inner relation (when
  1730. * the inner scan is parameterized with values from the outer relation).
  1731. * The planner is responsible for assigning nonconflicting PARAM_EXEC IDs to
  1732. * the PARAM_EXEC Params it generates.
  1733. *
  1734. * Outer references are managed via root->plan_params, which is a list of
  1735. * PlannerParamItems. While planning a subquery, each parent query level's
  1736. * plan_params contains the values required from it by the current subquery.
  1737. * During create_plan(), we use plan_params to track values that must be
  1738. * passed from outer to inner sides of NestLoop plan nodes.
  1739. *
  1740. * The item a PlannerParamItem represents can be one of three kinds:
  1741. *
  1742. * A Var: the slot represents a variable of this level that must be passed
  1743. * down because subqueries have outer references to it, or must be passed
  1744. * from a NestLoop node to its inner scan. The varlevelsup value in the Var
  1745. * will always be zero.
  1746. *
  1747. * A PlaceHolderVar: this works much like the Var case, except that the
  1748. * entry is a PlaceHolderVar node with a contained expression. The PHV
  1749. * will have phlevelsup = 0, and the contained expression is adjusted
  1750. * to match in level.
  1751. *
  1752. * An Aggref (with an expression tree representing its argument): the slot
  1753. * represents an aggregate expression that is an outer reference for some
  1754. * subquery. The Aggref itself has agglevelsup = 0, and its argument tree
  1755. * is adjusted to match in level.
  1756. *
  1757. * Note: we detect duplicate Var and PlaceHolderVar parameters and coalesce
  1758. * them into one slot, but we do not bother to do that for Aggrefs.
  1759. * The scope of duplicate-elimination only extends across the set of
  1760. * parameters passed from one query level into a single subquery, or for
  1761. * nestloop parameters across the set of nestloop parameters used in a single
  1762. * query level. So there is no possibility of a PARAM_EXEC slot being used
  1763. * for conflicting purposes.
  1764. *
  1765. * In addition, PARAM_EXEC slots are assigned for Params representing outputs
  1766. * from subplans (values that are setParam items for those subplans). These
  1767. * IDs need not be tracked via PlannerParamItems, since we do not need any
  1768. * duplicate-elimination nor later processing of the represented expressions.
  1769. * Instead, we just record the assignment of the slot number by incrementing
  1770. * root->glob->nParamExec.
  1771. */
  1772. typedef struct PlannerParamItem
  1773. {
  1774. NodeTag type;
  1775. Node *item; /* the Var, PlaceHolderVar, or Aggref */
  1776. int paramId; /* its assigned PARAM_EXEC slot number */
  1777. } PlannerParamItem;
  1778. /*
  1779. * When making cost estimates for a SEMI or ANTI join, there are some
  1780. * correction factors that are needed in both nestloop and hash joins
  1781. * to account for the fact that the executor can stop scanning inner rows
  1782. * as soon as it finds a match to the current outer row. These numbers
  1783. * depend only on the selected outer and inner join relations, not on the
  1784. * particular paths used for them, so it's worthwhile to calculate them
  1785. * just once per relation pair not once per considered path. This struct
  1786. * is filled by compute_semi_anti_join_factors and must be passed along
  1787. * to the join cost estimation functions.
  1788. *
  1789. * outer_match_frac is the fraction of the outer tuples that are
  1790. * expected to have at least one match.
  1791. * match_count is the average number of matches expected for
  1792. * outer tuples that have at least one match.
  1793. */
  1794. typedef struct SemiAntiJoinFactors
  1795. {
  1796. Selectivity outer_match_frac;
  1797. Selectivity match_count;
  1798. } SemiAntiJoinFactors;
  1799. /*
  1800. * Struct for extra information passed to subroutines of add_paths_to_joinrel
  1801. *
  1802. * restrictlist contains all of the RestrictInfo nodes for restriction
  1803. * clauses that apply to this join
  1804. * mergeclause_list is a list of RestrictInfo nodes for available
  1805. * mergejoin clauses in this join
  1806. * sjinfo is extra info about special joins for selectivity estimation
  1807. * semifactors is as shown above (only valid for SEMI or ANTI joins)
  1808. * param_source_rels are OK targets for parameterization of result paths
  1809. */
  1810. typedef struct JoinPathExtraData
  1811. {
  1812. List *restrictlist;
  1813. List *mergeclause_list;
  1814. SpecialJoinInfo *sjinfo;
  1815. SemiAntiJoinFactors semifactors;
  1816. Relids param_source_rels;
  1817. } JoinPathExtraData;
  1818. /*
  1819. * For speed reasons, cost estimation for join paths is performed in two
  1820. * phases: the first phase tries to quickly derive a lower bound for the
  1821. * join cost, and then we check if that's sufficient to reject the path.
  1822. * If not, we come back for a more refined cost estimate. The first phase
  1823. * fills a JoinCostWorkspace struct with its preliminary cost estimates
  1824. * and possibly additional intermediate values. The second phase takes
  1825. * these values as inputs to avoid repeating work.
  1826. *
  1827. * (Ideally we'd declare this in cost.h, but it's also needed in pathnode.h,
  1828. * so seems best to put it here.)
  1829. */
  1830. typedef struct JoinCostWorkspace
  1831. {
  1832. /* Preliminary cost estimates --- must not be larger than final ones! */
  1833. Cost startup_cost; /* cost expended before fetching any tuples */
  1834. Cost total_cost; /* total cost (assuming all tuples fetched) */
  1835. /* Fields below here should be treated as private to costsize.c */
  1836. Cost run_cost; /* non-startup cost components */
  1837. /* private for cost_nestloop code */
  1838. Cost inner_run_cost; /* also used by cost_mergejoin code */
  1839. Cost inner_rescan_run_cost;
  1840. /* private for cost_mergejoin code */
  1841. double outer_rows;
  1842. double inner_rows;
  1843. double outer_skip_rows;
  1844. double inner_skip_rows;
  1845. /* private for cost_hashjoin code */
  1846. int numbuckets;
  1847. int numbatches;
  1848. } JoinCostWorkspace;
  1849. #endif /* RELATION_H */