Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
primnodes.h2042 linesDownload Raw Back to nodes
1/*-------------------------------------------------------------------------2 *3 * primnodes.h4 *	  Definitions for "primitive" node types, those that are used in more5 *	  than one of the parse/plan/execute stages of the query pipeline.6 *	  Currently, these are mostly nodes for executable expressions7 *	  and join trees.8 *9 *10 * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group11 * Portions Copyright (c) 1994, Regents of the University of California12 *13 * src/include/nodes/primnodes.h14 *15 *-------------------------------------------------------------------------16 */17#ifndef PRIMNODES_H18#define PRIMNODES_H19 20#include "access/attnum.h"21#include "nodes/bitmapset.h"22#include "nodes/pg_list.h"23 24 25/* ----------------------------------------------------------------26 *						node definitions27 * ----------------------------------------------------------------28 */29 30/*31 * Alias -32 *	  specifies an alias for a range variable; the alias might also33 *	  specify renaming of columns within the table.34 *35 * Note: colnames is a list of String nodes.  In Alias structs36 * associated with RTEs, there may be entries corresponding to dropped37 * columns; these are normally empty strings ("").  See parsenodes.h for info.38 */39typedef struct Alias40{41	NodeTag		type;42	char	   *aliasname;		/* aliased rel name (never qualified) */43	List	   *colnames;		/* optional list of column aliases */44} Alias;45 46/* What to do at commit time for temporary relations */47typedef enum OnCommitAction48{49	ONCOMMIT_NOOP,				/* No ON COMMIT clause (do nothing) */50	ONCOMMIT_PRESERVE_ROWS,		/* ON COMMIT PRESERVE ROWS (do nothing) */51	ONCOMMIT_DELETE_ROWS,		/* ON COMMIT DELETE ROWS */52	ONCOMMIT_DROP				/* ON COMMIT DROP */53} OnCommitAction;54 55/*56 * RangeVar - range variable, used in FROM clauses57 *58 * Also used to represent table names in utility statements; there, the alias59 * field is not used, and inh tells whether to apply the operation60 * recursively to child tables.  In some contexts it is also useful to carry61 * a TEMP table indication here.62 */63typedef struct RangeVar64{65	NodeTag		type;66 67	/* the catalog (database) name, or NULL */68	char	   *catalogname;69 70	/* the schema name, or NULL */71	char	   *schemaname;72 73	/* the relation/sequence name */74	char	   *relname;75 76	/* expand rel by inheritance? recursively act on children? */77	bool		inh;78 79	/* see RELPERSISTENCE_* in pg_class.h */80	char		relpersistence;81 82	/* table alias & optional column aliases */83	Alias	   *alias;84 85	/* token location, or -1 if unknown */86	int			location;87} RangeVar;88 89/*90 * TableFunc - node for a table function, such as XMLTABLE.91 *92 * Entries in the ns_names list are either String nodes containing93 * literal namespace names, or NULL pointers to represent DEFAULT.94 */95typedef struct TableFunc96{97	NodeTag		type;98	/* list of namespace URI expressions */99	List	   *ns_uris pg_node_attr(query_jumble_ignore);100	/* list of namespace names or NULL */101	List	   *ns_names pg_node_attr(query_jumble_ignore);102	/* input document expression */103	Node	   *docexpr;104	/* row filter expression */105	Node	   *rowexpr;106	/* column names (list of String) */107	List	   *colnames pg_node_attr(query_jumble_ignore);108	/* OID list of column type OIDs */109	List	   *coltypes pg_node_attr(query_jumble_ignore);110	/* integer list of column typmods */111	List	   *coltypmods pg_node_attr(query_jumble_ignore);112	/* OID list of column collation OIDs */113	List	   *colcollations pg_node_attr(query_jumble_ignore);114	/* list of column filter expressions */115	List	   *colexprs;116	/* list of column default expressions */117	List	   *coldefexprs pg_node_attr(query_jumble_ignore);118	/* nullability flag for each output column */119	Bitmapset  *notnulls pg_node_attr(query_jumble_ignore);120	/* counts from 0; -1 if none specified */121	int			ordinalitycol pg_node_attr(query_jumble_ignore);122	/* token location, or -1 if unknown */123	int			location;124} TableFunc;125 126/*127 * IntoClause - target information for SELECT INTO, CREATE TABLE AS, and128 * CREATE MATERIALIZED VIEW129 *130 * For CREATE MATERIALIZED VIEW, viewQuery is the parsed-but-not-rewritten131 * SELECT Query for the view; otherwise it's NULL.  This is irrelevant in132 * the query jumbling as CreateTableAsStmt already includes a reference to133 * its own Query, so ignore it.  (Although it's actually Query*, we declare134 * it as Node* to avoid a forward reference.)135 */136typedef struct IntoClause137{138	NodeTag		type;139 140	RangeVar   *rel;			/* target relation name */141	List	   *colNames;		/* column names to assign, or NIL */142	char	   *accessMethod;	/* table access method */143	List	   *options;		/* options from WITH clause */144	OnCommitAction onCommit;	/* what do we do at COMMIT? */145	char	   *tableSpaceName; /* table space to use, or NULL */146	/* materialized view's SELECT query */147	Node	   *viewQuery pg_node_attr(query_jumble_ignore);148	bool		skipData;		/* true for WITH NO DATA */149} IntoClause;150 151 152/* ----------------------------------------------------------------153 *					node types for executable expressions154 * ----------------------------------------------------------------155 */156 157/*158 * Expr - generic superclass for executable-expression nodes159 *160 * All node types that are used in executable expression trees should derive161 * from Expr (that is, have Expr as their first field).  Since Expr only162 * contains NodeTag, this is a formality, but it is an easy form of163 * documentation.  See also the ExprState node types in execnodes.h.164 */165typedef struct Expr166{167	pg_node_attr(abstract)168 169	NodeTag		type;170} Expr;171 172/*173 * Var - expression node representing a variable (ie, a table column)174 *175 * In the parser and planner, varno and varattno identify the semantic176 * referent, which is a base-relation column unless the reference is to a join177 * USING column that isn't semantically equivalent to either join input column178 * (because it is a FULL join or the input column requires a type coercion).179 * In those cases varno and varattno refer to the JOIN RTE.  (Early in the180 * planner, we replace such join references by the implied expression; but up181 * till then we want join reference Vars to keep their original identity for182 * query-printing purposes.)183 *184 * At the end of planning, Var nodes appearing in upper-level plan nodes are185 * reassigned to point to the outputs of their subplans; for example, in a186 * join node varno becomes INNER_VAR or OUTER_VAR and varattno becomes the187 * index of the proper element of that subplan's target list.  Similarly,188 * INDEX_VAR is used to identify Vars that reference an index column rather189 * than a heap column.  (In ForeignScan and CustomScan plan nodes, INDEX_VAR190 * is abused to signify references to columns of a custom scan tuple type.)191 *192 * ROWID_VAR is used in the planner to identify nonce variables that carry193 * row identity information during UPDATE/DELETE/MERGE.  This value should194 * never be seen outside the planner.195 *196 * varnullingrels is the set of RT indexes of outer joins that can force197 * the Var's value to null (at the point where it appears in the query).198 * See optimizer/README for discussion of that.199 *200 * varlevelsup is greater than zero in Vars that represent outer references.201 * Note that it affects the meaning of all of varno, varnullingrels, and202 * varnosyn, all of which refer to the range table of that query level.203 *204 * In the parser, varnosyn and varattnosyn are either identical to205 * varno/varattno, or they specify the column's position in an aliased JOIN206 * RTE that hides the semantic referent RTE's refname.  This is a syntactic207 * identifier as opposed to the semantic identifier; it tells ruleutils.c208 * how to print the Var properly.  varnosyn/varattnosyn retain their values209 * throughout planning and execution, so they are particularly helpful to210 * identify Vars when debugging.  Note, however, that a Var that is generated211 * in the planner and doesn't correspond to any simple relation column may212 * have varnosyn = varattnosyn = 0.213 */214#define    INNER_VAR		(-1)	/* reference to inner subplan */215#define    OUTER_VAR		(-2)	/* reference to outer subplan */216#define    INDEX_VAR		(-3)	/* reference to index column */217#define    ROWID_VAR		(-4)	/* row identity column during planning */218 219#define IS_SPECIAL_VARNO(varno)		((int) (varno) < 0)220 221/* Symbols for the indexes of the special RTE entries in rules */222#define    PRS2_OLD_VARNO			1223#define    PRS2_NEW_VARNO			2224 225typedef struct Var226{227	Expr		xpr;228 229	/*230	 * index of this var's relation in the range table, or231	 * INNER_VAR/OUTER_VAR/etc232	 */233	int			varno;234 235	/*236	 * attribute number of this var, or zero for all attrs ("whole-row Var")237	 */238	AttrNumber	varattno;239 240	/* pg_type OID for the type of this var */241	Oid			vartype pg_node_attr(query_jumble_ignore);242	/* pg_attribute typmod value */243	int32		vartypmod pg_node_attr(query_jumble_ignore);244	/* OID of collation, or InvalidOid if none */245	Oid			varcollid pg_node_attr(query_jumble_ignore);246 247	/*248	 * RT indexes of outer joins that can replace the Var's value with null.249	 * We can omit varnullingrels in the query jumble, because it's fully250	 * determined by varno/varlevelsup plus the Var's query location.251	 */252	Bitmapset  *varnullingrels pg_node_attr(query_jumble_ignore);253 254	/*255	 * for subquery variables referencing outer relations; 0 in a normal var,256	 * >0 means N levels up257	 */258	Index		varlevelsup;259 260	/*261	 * varnosyn/varattnosyn are ignored for equality, because Vars with262	 * different syntactic identifiers are semantically the same as long as263	 * their varno/varattno match.264	 */265	/* syntactic relation index (0 if unknown) */266	Index		varnosyn pg_node_attr(equal_ignore, query_jumble_ignore);267	/* syntactic attribute number */268	AttrNumber	varattnosyn pg_node_attr(equal_ignore, query_jumble_ignore);269 270	/* token location, or -1 if unknown */271	int			location;272} Var;273 274/*275 * Const276 *277 * Note: for varlena data types, we make a rule that a Const node's value278 * must be in non-extended form (4-byte header, no compression or external279 * references).  This ensures that the Const node is self-contained and makes280 * it more likely that equal() will see logically identical values as equal.281 *282 * Only the constant type OID is relevant for the query jumbling.283 */284typedef struct Const285{286	pg_node_attr(custom_copy_equal, custom_read_write)287 288	Expr		xpr;289	/* pg_type OID of the constant's datatype */290	Oid			consttype;291	/* typmod value, if any */292	int32		consttypmod pg_node_attr(query_jumble_ignore);293	/* OID of collation, or InvalidOid if none */294	Oid			constcollid pg_node_attr(query_jumble_ignore);295	/* typlen of the constant's datatype */296	int			constlen pg_node_attr(query_jumble_ignore);297	/* the constant's value */298	Datum		constvalue pg_node_attr(query_jumble_ignore);299	/* whether the constant is null (if true, constvalue is undefined) */300	bool		constisnull pg_node_attr(query_jumble_ignore);301 302	/*303	 * Whether this datatype is passed by value.  If true, then all the304	 * information is stored in the Datum.  If false, then the Datum contains305	 * a pointer to the information.306	 */307	bool		constbyval pg_node_attr(query_jumble_ignore);308 309	/*310	 * token location, or -1 if unknown.  All constants are tracked as311	 * locations in query jumbling, to be marked as parameters.312	 */313	int			location pg_node_attr(query_jumble_location);314} Const;315 316/*317 * Param318 *319 *		paramkind specifies the kind of parameter. The possible values320 *		for this field are:321 *322 *		PARAM_EXTERN:  The parameter value is supplied from outside the plan.323 *				Such parameters are numbered from 1 to n.324 *325 *		PARAM_EXEC:  The parameter is an internal executor parameter, used326 *				for passing values into and out of sub-queries or from327 *				nestloop joins to their inner scans.328 *				For historical reasons, such parameters are numbered from 0.329 *				These numbers are independent of PARAM_EXTERN numbers.330 *331 *		PARAM_SUBLINK:	The parameter represents an output column of a SubLink332 *				node's sub-select.  The column number is contained in the333 *				`paramid' field.  (This type of Param is converted to334 *				PARAM_EXEC during planning.)335 *336 *		PARAM_MULTIEXPR:  Like PARAM_SUBLINK, the parameter represents an337 *				output column of a SubLink node's sub-select, but here, the338 *				SubLink is always a MULTIEXPR SubLink.  The high-order 16 bits339 *				of the `paramid' field contain the SubLink's subLinkId, and340 *				the low-order 16 bits contain the column number.  (This type341 *				of Param is also converted to PARAM_EXEC during planning.)342 */343typedef enum ParamKind344{345	PARAM_EXTERN,346	PARAM_EXEC,347	PARAM_SUBLINK,348	PARAM_MULTIEXPR349} ParamKind;350 351typedef struct Param352{353	Expr		xpr;354	ParamKind	paramkind;		/* kind of parameter. See above */355	int			paramid;		/* numeric ID for parameter */356	Oid			paramtype;		/* pg_type OID of parameter's datatype */357	/* typmod value, if known */358	int32		paramtypmod pg_node_attr(query_jumble_ignore);359	/* OID of collation, or InvalidOid if none */360	Oid			paramcollid pg_node_attr(query_jumble_ignore);361	/* token location, or -1 if unknown */362	int			location;363} Param;364 365/*366 * Aggref367 *368 * The aggregate's args list is a targetlist, ie, a list of TargetEntry nodes.369 *370 * For a normal (non-ordered-set) aggregate, the non-resjunk TargetEntries371 * represent the aggregate's regular arguments (if any) and resjunk TLEs can372 * be added at the end to represent ORDER BY expressions that are not also373 * arguments.  As in a top-level Query, the TLEs can be marked with374 * ressortgroupref indexes to let them be referenced by SortGroupClause375 * entries in the aggorder and/or aggdistinct lists.  This represents ORDER BY376 * and DISTINCT operations to be applied to the aggregate input rows before377 * they are passed to the transition function.  The grammar only allows a378 * simple "DISTINCT" specifier for the arguments, but we use the full379 * query-level representation to allow more code sharing.380 *381 * For an ordered-set aggregate, the args list represents the WITHIN GROUP382 * (aggregated) arguments, all of which will be listed in the aggorder list.383 * DISTINCT is not supported in this case, so aggdistinct will be NIL.384 * The direct arguments appear in aggdirectargs (as a list of plain385 * expressions, not TargetEntry nodes).386 *387 * aggtranstype is the data type of the state transition values for this388 * aggregate (resolved to an actual type, if agg's transtype is polymorphic).389 * This is determined during planning and is InvalidOid before that.390 *391 * aggargtypes is an OID list of the data types of the direct and regular392 * arguments.  Normally it's redundant with the aggdirectargs and args lists,393 * but in a combining aggregate, it's not because the args list has been394 * replaced with a single argument representing the partial-aggregate395 * transition values.396 *397 * aggpresorted is set by the query planner for ORDER BY and DISTINCT398 * aggregates where the chosen plan provides presorted input for this399 * aggregate during execution.400 *401 * aggsplit indicates the expected partial-aggregation mode for the Aggref's402 * parent plan node.  It's always set to AGGSPLIT_SIMPLE in the parser, but403 * the planner might change it to something else.  We use this mainly as404 * a crosscheck that the Aggrefs match the plan; but note that when aggsplit405 * indicates a non-final mode, aggtype reflects the transition data type406 * not the SQL-level output type of the aggregate.407 *408 * aggno and aggtransno are -1 in the parse stage, and are set in planning.409 * Aggregates with the same 'aggno' represent the same aggregate expression,410 * and can share the result.  Aggregates with same 'transno' but different411 * 'aggno' can share the same transition state, only the final function needs412 * to be called separately.413 *414 * Information related to collations, transition types and internal states415 * are irrelevant for the query jumbling.416 */417typedef struct Aggref418{419	Expr		xpr;420 421	/* pg_proc Oid of the aggregate */422	Oid			aggfnoid;423 424	/* type Oid of result of the aggregate */425	Oid			aggtype pg_node_attr(query_jumble_ignore);426 427	/* OID of collation of result */428	Oid			aggcollid pg_node_attr(query_jumble_ignore);429 430	/* OID of collation that function should use */431	Oid			inputcollid pg_node_attr(query_jumble_ignore);432 433	/*434	 * type Oid of aggregate's transition value; ignored for equal since it435	 * might not be set yet436	 */437	Oid			aggtranstype pg_node_attr(equal_ignore, query_jumble_ignore);438 439	/* type Oids of direct and aggregated args */440	List	   *aggargtypes pg_node_attr(query_jumble_ignore);441 442	/* direct arguments, if an ordered-set agg */443	List	   *aggdirectargs;444 445	/* aggregated arguments and sort expressions */446	List	   *args;447 448	/* ORDER BY (list of SortGroupClause) */449	List	   *aggorder;450 451	/* DISTINCT (list of SortGroupClause) */452	List	   *aggdistinct;453 454	/* FILTER expression, if any */455	Expr	   *aggfilter;456 457	/* true if argument list was really '*' */458	bool		aggstar pg_node_attr(query_jumble_ignore);459 460	/*461	 * true if variadic arguments have been combined into an array last462	 * argument463	 */464	bool		aggvariadic pg_node_attr(query_jumble_ignore);465 466	/* aggregate kind (see pg_aggregate.h) */467	char		aggkind pg_node_attr(query_jumble_ignore);468 469	/* aggregate input already sorted */470	bool		aggpresorted pg_node_attr(equal_ignore, query_jumble_ignore);471 472	/* > 0 if agg belongs to outer query */473	Index		agglevelsup pg_node_attr(query_jumble_ignore);474 475	/* expected agg-splitting mode of parent Agg */476	AggSplit	aggsplit pg_node_attr(query_jumble_ignore);477 478	/* unique ID within the Agg node */479	int			aggno pg_node_attr(query_jumble_ignore);480 481	/* unique ID of transition state in the Agg */482	int			aggtransno pg_node_attr(query_jumble_ignore);483 484	/* token location, or -1 if unknown */485	int			location;486} Aggref;487 488/*489 * GroupingFunc490 *491 * A GroupingFunc is a GROUPING(...) expression, which behaves in many ways492 * like an aggregate function (e.g. it "belongs" to a specific query level,493 * which might not be the one immediately containing it), but also differs in494 * an important respect: it never evaluates its arguments, they merely495 * designate expressions from the GROUP BY clause of the query level to which496 * it belongs.497 *498 * The spec defines the evaluation of GROUPING() purely by syntactic499 * replacement, but we make it a real expression for optimization purposes so500 * that one Agg node can handle multiple grouping sets at once.  Evaluating the501 * result only needs the column positions to check against the grouping set502 * being projected.  However, for EXPLAIN to produce meaningful output, we have503 * to keep the original expressions around, since expression deparse does not504 * give us any feasible way to get at the GROUP BY clause.505 *506 * Also, we treat two GroupingFunc nodes as equal if they have equal arguments507 * lists and agglevelsup, without comparing the refs and cols annotations.508 *509 * In raw parse output we have only the args list; parse analysis fills in the510 * refs list, and the planner fills in the cols list.511 *512 * All the fields used as information for an internal state are irrelevant513 * for the query jumbling.514 */515typedef struct GroupingFunc516{517	Expr		xpr;518 519	/* arguments, not evaluated but kept for benefit of EXPLAIN etc. */520	List	   *args pg_node_attr(query_jumble_ignore);521 522	/* ressortgrouprefs of arguments */523	List	   *refs pg_node_attr(equal_ignore);524 525	/* actual column positions set by planner */526	List	   *cols pg_node_attr(equal_ignore, query_jumble_ignore);527 528	/* same as Aggref.agglevelsup */529	Index		agglevelsup;530 531	/* token location */532	int			location;533} GroupingFunc;534 535/*536 * WindowFunc537 *538 * Collation information is irrelevant for the query jumbling, as is the539 * internal state information of the node like "winstar" and "winagg".540 */541typedef struct WindowFunc542{543	Expr		xpr;544	/* pg_proc Oid of the function */545	Oid			winfnoid;546	/* type Oid of result of the window function */547	Oid			wintype pg_node_attr(query_jumble_ignore);548	/* OID of collation of result */549	Oid			wincollid pg_node_attr(query_jumble_ignore);550	/* OID of collation that function should use */551	Oid			inputcollid pg_node_attr(query_jumble_ignore);552	/* arguments to the window function */553	List	   *args;554	/* FILTER expression, if any */555	Expr	   *aggfilter;556	/* index of associated WindowClause */557	Index		winref;558	/* true if argument list was really '*' */559	bool		winstar pg_node_attr(query_jumble_ignore);560	/* is function a simple aggregate? */561	bool		winagg pg_node_attr(query_jumble_ignore);562	/* token location, or -1 if unknown */563	int			location;564} WindowFunc;565 566/*567 * SubscriptingRef: describes a subscripting operation over a container568 * (array, etc).569 *570 * A SubscriptingRef can describe fetching a single element from a container,571 * fetching a part of a container (e.g. an array slice), storing a single572 * element into a container, or storing a slice.  The "store" cases work with573 * an initial container value and a source value that is inserted into the574 * appropriate part of the container; the result of the operation is an575 * entire new modified container value.576 *577 * If reflowerindexpr = NIL, then we are fetching or storing a single container578 * element at the subscripts given by refupperindexpr. Otherwise we are579 * fetching or storing a container slice, that is a rectangular subcontainer580 * with lower and upper bounds given by the index expressions.581 * reflowerindexpr must be the same length as refupperindexpr when it582 * is not NIL.583 *584 * In the slice case, individual expressions in the subscript lists can be585 * NULL, meaning "substitute the array's current lower or upper bound".586 * (Non-array containers may or may not support this.)587 *588 * refcontainertype is the actual container type that determines the589 * subscripting semantics.  (This will generally be either the exposed type of590 * refexpr, or the base type if that is a domain.)  refelemtype is the type of591 * the container's elements; this is saved for the use of the subscripting592 * functions, but is not used by the core code.  refrestype, reftypmod, and593 * refcollid describe the type of the SubscriptingRef's result.  In a store594 * expression, refrestype will always match refcontainertype; in a fetch,595 * it could be refelemtype for an element fetch, or refcontainertype for a596 * slice fetch, or possibly something else as determined by type-specific597 * subscripting logic.  Likewise, reftypmod and refcollid will match the598 * container's properties in a store, but could be different in a fetch.599 *600 * Any internal state data is ignored for the query jumbling.601 *602 * Note: for the cases where a container is returned, if refexpr yields a R/W603 * expanded container, then the implementation is allowed to modify that604 * object in-place and return the same object.605 */606typedef struct SubscriptingRef607{608	Expr		xpr;609	/* type of the container proper */610	Oid			refcontainertype pg_node_attr(query_jumble_ignore);611	/* the container type's pg_type.typelem */612	Oid			refelemtype pg_node_attr(query_jumble_ignore);613	/* type of the SubscriptingRef's result */614	Oid			refrestype pg_node_attr(query_jumble_ignore);615	/* typmod of the result */616	int32		reftypmod pg_node_attr(query_jumble_ignore);617	/* collation of result, or InvalidOid if none */618	Oid			refcollid pg_node_attr(query_jumble_ignore);619	/* expressions that evaluate to upper container indexes */620	List	   *refupperindexpr;621 622	/*623	 * expressions that evaluate to lower container indexes, or NIL for single624	 * container element.625	 */626	List	   *reflowerindexpr;627	/* the expression that evaluates to a container value */628	Expr	   *refexpr;629	/* expression for the source value, or NULL if fetch */630	Expr	   *refassgnexpr;631} SubscriptingRef;632 633/*634 * CoercionContext - distinguishes the allowed set of type casts635 *636 * NB: ordering of the alternatives is significant; later (larger) values637 * allow more casts than earlier ones.638 */639typedef enum CoercionContext640{641	COERCION_IMPLICIT,			/* coercion in context of expression */642	COERCION_ASSIGNMENT,		/* coercion in context of assignment */643	COERCION_PLPGSQL,			/* if no assignment cast, use CoerceViaIO */644	COERCION_EXPLICIT			/* explicit cast operation */645} CoercionContext;646 647/*648 * CoercionForm - how to display a FuncExpr or related node649 *650 * "Coercion" is a bit of a misnomer, since this value records other651 * special syntaxes besides casts, but for now we'll keep this naming.652 *653 * NB: equal() ignores CoercionForm fields, therefore this *must* not carry654 * any semantically significant information.  We need that behavior so that655 * the planner will consider equivalent implicit and explicit casts to be656 * equivalent.  In cases where those actually behave differently, the coercion657 * function's arguments will be different.658 */659typedef enum CoercionForm660{661	COERCE_EXPLICIT_CALL,		/* display as a function call */662	COERCE_EXPLICIT_CAST,		/* display as an explicit cast */663	COERCE_IMPLICIT_CAST,		/* implicit cast, so hide it */664	COERCE_SQL_SYNTAX			/* display with SQL-mandated special syntax */665} CoercionForm;666 667/*668 * FuncExpr - expression node for a function call669 *670 * Collation information is irrelevant for the query jumbling, only the671 * arguments and the function OID matter.672 */673typedef struct FuncExpr674{675	Expr		xpr;676	/* PG_PROC OID of the function */677	Oid			funcid;678	/* PG_TYPE OID of result value */679	Oid			funcresulttype pg_node_attr(query_jumble_ignore);680	/* true if function returns set */681	bool		funcretset pg_node_attr(query_jumble_ignore);682 683	/*684	 * true if variadic arguments have been combined into an array last685	 * argument686	 */687	bool		funcvariadic pg_node_attr(query_jumble_ignore);688	/* how to display this function call */689	CoercionForm funcformat pg_node_attr(query_jumble_ignore);690	/* OID of collation of result */691	Oid			funccollid pg_node_attr(query_jumble_ignore);692	/* OID of collation that function should use */693	Oid			inputcollid pg_node_attr(query_jumble_ignore);694	/* arguments to the function */695	List	   *args;696	/* token location, or -1 if unknown */697	int			location;698} FuncExpr;699 700/*701 * NamedArgExpr - a named argument of a function702 *703 * This node type can only appear in the args list of a FuncCall or FuncExpr704 * node.  We support pure positional call notation (no named arguments),705 * named notation (all arguments are named), and mixed notation (unnamed706 * arguments followed by named ones).707 *708 * Parse analysis sets argnumber to the positional index of the argument,709 * but doesn't rearrange the argument list.710 *711 * The planner will convert argument lists to pure positional notation712 * during expression preprocessing, so execution never sees a NamedArgExpr.713 */714typedef struct NamedArgExpr715{716	Expr		xpr;717	/* the argument expression */718	Expr	   *arg;719	/* the name */720	char	   *name pg_node_attr(query_jumble_ignore);721	/* argument's number in positional notation */722	int			argnumber;723	/* argument name location, or -1 if unknown */724	int			location;725} NamedArgExpr;726 727/*728 * OpExpr - expression node for an operator invocation729 *730 * Semantically, this is essentially the same as a function call.731 *732 * Note that opfuncid is not necessarily filled in immediately on creation733 * of the node.  The planner makes sure it is valid before passing the node734 * tree to the executor, but during parsing/planning opfuncid can be 0.735 * Therefore, equal() will accept a zero value as being equal to other values.736 *737 * Internal state information and collation data is irrelevant for the query738 * jumbling.739 */740typedef struct OpExpr741{742	Expr		xpr;743 744	/* PG_OPERATOR OID of the operator */745	Oid			opno;746 747	/* PG_PROC OID of underlying function */748	Oid			opfuncid pg_node_attr(equal_ignore_if_zero, query_jumble_ignore);749 750	/* PG_TYPE OID of result value */751	Oid			opresulttype pg_node_attr(query_jumble_ignore);752 753	/* true if operator returns set */754	bool		opretset pg_node_attr(query_jumble_ignore);755 756	/* OID of collation of result */757	Oid			opcollid pg_node_attr(query_jumble_ignore);758 759	/* OID of collation that operator should use */760	Oid			inputcollid pg_node_attr(query_jumble_ignore);761 762	/* arguments to the operator (1 or 2) */763	List	   *args;764 765	/* token location, or -1 if unknown */766	int			location;767} OpExpr;768 769/*770 * DistinctExpr - expression node for "x IS DISTINCT FROM y"771 *772 * Except for the nodetag, this is represented identically to an OpExpr773 * referencing the "=" operator for x and y.774 * We use "=", not the more obvious "<>", because more datatypes have "="775 * than "<>".  This means the executor must invert the operator result.776 * Note that the operator function won't be called at all if either input777 * is NULL, since then the result can be determined directly.778 */779typedef OpExpr DistinctExpr;780 781/*782 * NullIfExpr - a NULLIF expression783 *784 * Like DistinctExpr, this is represented the same as an OpExpr referencing785 * the "=" operator for x and y.786 */787typedef OpExpr NullIfExpr;788 789/*790 * ScalarArrayOpExpr - expression node for "scalar op ANY/ALL (array)"791 *792 * The operator must yield boolean.  It is applied to the left operand793 * and each element of the righthand array, and the results are combined794 * with OR or AND (for ANY or ALL respectively).  The node representation795 * is almost the same as for the underlying operator, but we need a useOr796 * flag to remember whether it's ANY or ALL, and we don't have to store797 * the result type (or the collation) because it must be boolean.798 *799 * A ScalarArrayOpExpr with a valid hashfuncid is evaluated during execution800 * by building a hash table containing the Const values from the RHS arg.801 * This table is probed during expression evaluation.  The planner will set802 * hashfuncid to the hash function which must be used to build and probe the803 * hash table.  The executor determines if it should use hash-based checks or804 * the more traditional means based on if the hashfuncid is set or not.805 *806 * When performing hashed NOT IN, the negfuncid will also be set to the807 * equality function which the hash table must use to build and probe the hash808 * table.  opno and opfuncid will remain set to the <> operator and its809 * corresponding function and won't be used during execution.  For810 * non-hashtable based NOT INs, negfuncid will be set to InvalidOid.  See811 * convert_saop_to_hashed_saop().812 *813 * Similar to OpExpr, opfuncid, hashfuncid, and negfuncid are not necessarily814 * filled in right away, so will be ignored for equality if they are not set815 * yet.816 *817 * OID entries of the internal function types are irrelevant for the query818 * jumbling, but the operator OID and the arguments are.819 */820typedef struct ScalarArrayOpExpr821{822	Expr		xpr;823 824	/* PG_OPERATOR OID of the operator */825	Oid			opno;826 827	/* PG_PROC OID of comparison function */828	Oid			opfuncid pg_node_attr(equal_ignore_if_zero, query_jumble_ignore);829 830	/* PG_PROC OID of hash func or InvalidOid */831	Oid			hashfuncid pg_node_attr(equal_ignore_if_zero, query_jumble_ignore);832 833	/* PG_PROC OID of negator of opfuncid function or InvalidOid.  See above */834	Oid			negfuncid pg_node_attr(equal_ignore_if_zero, query_jumble_ignore);835 836	/* true for ANY, false for ALL */837	bool		useOr;838 839	/* OID of collation that operator should use */840	Oid			inputcollid pg_node_attr(query_jumble_ignore);841 842	/* the scalar and array operands */843	List	   *args;844 845	/* token location, or -1 if unknown */846	int			location;847} ScalarArrayOpExpr;848 849/*850 * BoolExpr - expression node for the basic Boolean operators AND, OR, NOT851 *852 * Notice the arguments are given as a List.  For NOT, of course the list853 * must always have exactly one element.  For AND and OR, there can be two854 * or more arguments.855 */856typedef enum BoolExprType857{858	AND_EXPR, OR_EXPR, NOT_EXPR859} BoolExprType;860 861typedef struct BoolExpr862{863	pg_node_attr(custom_read_write)864 865	Expr		xpr;866	BoolExprType boolop;867	List	   *args;			/* arguments to this expression */868	int			location;		/* token location, or -1 if unknown */869} BoolExpr;870 871/*872 * SubLink873 *874 * A SubLink represents a subselect appearing in an expression, and in some875 * cases also the combining operator(s) just above it.  The subLinkType876 * indicates the form of the expression represented:877 *	EXISTS_SUBLINK		EXISTS(SELECT ...)878 *	ALL_SUBLINK			(lefthand) op ALL (SELECT ...)879 *	ANY_SUBLINK			(lefthand) op ANY (SELECT ...)880 *	ROWCOMPARE_SUBLINK	(lefthand) op (SELECT ...)881 *	EXPR_SUBLINK		(SELECT with single targetlist item ...)882 *	MULTIEXPR_SUBLINK	(SELECT with multiple targetlist items ...)883 *	ARRAY_SUBLINK		ARRAY(SELECT with single targetlist item ...)884 *	CTE_SUBLINK			WITH query (never actually part of an expression)885 * For ALL, ANY, and ROWCOMPARE, the lefthand is a list of expressions of the886 * same length as the subselect's targetlist.  ROWCOMPARE will *always* have887 * a list with more than one entry; if the subselect has just one target888 * then the parser will create an EXPR_SUBLINK instead (and any operator889 * above the subselect will be represented separately).890 * ROWCOMPARE, EXPR, and MULTIEXPR require the subselect to deliver at most891 * one row (if it returns no rows, the result is NULL).892 * ALL, ANY, and ROWCOMPARE require the combining operators to deliver boolean893 * results.  ALL and ANY combine the per-row results using AND and OR894 * semantics respectively.895 * ARRAY requires just one target column, and creates an array of the target896 * column's type using any number of rows resulting from the subselect.897 *898 * SubLink is classed as an Expr node, but it is not actually executable;899 * it must be replaced in the expression tree by a SubPlan node during900 * planning.901 *902 * NOTE: in the raw output of gram.y, testexpr contains just the raw form903 * of the lefthand expression (if any), and operName is the String name of904 * the combining operator.  Also, subselect is a raw parsetree.  During parse905 * analysis, the parser transforms testexpr into a complete boolean expression906 * that compares the lefthand value(s) to PARAM_SUBLINK nodes representing the907 * output columns of the subselect.  And subselect is transformed to a Query.908 * This is the representation seen in saved rules and in the rewriter.909 *910 * In EXISTS, EXPR, MULTIEXPR, and ARRAY SubLinks, testexpr and operName911 * are unused and are always null.912 *913 * subLinkId is currently used only for MULTIEXPR SubLinks, and is zero in914 * other SubLinks.  This number identifies different multiple-assignment915 * subqueries within an UPDATE statement's SET list.  It is unique only916 * within a particular targetlist.  The output column(s) of the MULTIEXPR917 * are referenced by PARAM_MULTIEXPR Params appearing elsewhere in the tlist.918 *919 * The CTE_SUBLINK case never occurs in actual SubLink nodes, but it is used920 * in SubPlans generated for WITH subqueries.921 */922typedef enum SubLinkType923{924	EXISTS_SUBLINK,925	ALL_SUBLINK,926	ANY_SUBLINK,927	ROWCOMPARE_SUBLINK,928	EXPR_SUBLINK,929	MULTIEXPR_SUBLINK,930	ARRAY_SUBLINK,931	CTE_SUBLINK					/* for SubPlans only */932} SubLinkType;933 934 935typedef struct SubLink936{937	Expr		xpr;938	SubLinkType subLinkType;	/* see above */939	int			subLinkId;		/* ID (1..n); 0 if not MULTIEXPR */940	Node	   *testexpr;		/* outer-query test for ALL/ANY/ROWCOMPARE */941	/* originally specified operator name */942	List	   *operName pg_node_attr(query_jumble_ignore);943	/* subselect as Query* or raw parsetree */944	Node	   *subselect;945	int			location;		/* token location, or -1 if unknown */946} SubLink;947 948/*949 * SubPlan - executable expression node for a subplan (sub-SELECT)950 *951 * The planner replaces SubLink nodes in expression trees with SubPlan952 * nodes after it has finished planning the subquery.  SubPlan references953 * a sub-plantree stored in the subplans list of the toplevel PlannedStmt.954 * (We avoid a direct link to make it easier to copy expression trees955 * without causing multiple processing of the subplan.)956 *957 * In an ordinary subplan, testexpr points to an executable expression958 * (OpExpr, an AND/OR tree of OpExprs, or RowCompareExpr) for the combining959 * operator(s); the left-hand arguments are the original lefthand expressions,960 * and the right-hand arguments are PARAM_EXEC Param nodes representing the961 * outputs of the sub-select.  (NOTE: runtime coercion functions may be962 * inserted as well.)  This is just the same expression tree as testexpr in963 * the original SubLink node, but the PARAM_SUBLINK nodes are replaced by964 * suitably numbered PARAM_EXEC nodes.965 *966 * If the sub-select becomes an initplan rather than a subplan, the executable967 * expression is part of the outer plan's expression tree (and the SubPlan968 * node itself is not, but rather is found in the outer plan's initPlan969 * list).  In this case testexpr is NULL to avoid duplication.970 *971 * The planner also derives lists of the values that need to be passed into972 * and out of the subplan.  Input values are represented as a list "args" of973 * expressions to be evaluated in the outer-query context (currently these974 * args are always just Vars, but in principle they could be any expression).975 * The values are assigned to the global PARAM_EXEC params indexed by parParam976 * (the parParam and args lists must have the same ordering).  setParam is a977 * list of the PARAM_EXEC params that are computed by the sub-select, if it978 * is an initplan or MULTIEXPR plan; they are listed in order by sub-select979 * output column position.  (parParam and setParam are integer Lists, not980 * Bitmapsets, because their ordering is significant.)981 *982 * Also, the planner computes startup and per-call costs for use of the983 * SubPlan.  Note that these include the cost of the subquery proper,984 * evaluation of the testexpr if any, and any hashtable management overhead.985 */986typedef struct SubPlan987{988	pg_node_attr(no_query_jumble)989 990	Expr		xpr;991	/* Fields copied from original SubLink: */992	SubLinkType subLinkType;	/* see above */993	/* The combining operators, transformed to an executable expression: */994	Node	   *testexpr;		/* OpExpr or RowCompareExpr expression tree */995	List	   *paramIds;		/* IDs of Params embedded in the above */996	/* Identification of the Plan tree to use: */997	int			plan_id;		/* Index (from 1) in PlannedStmt.subplans */998	/* Identification of the SubPlan for EXPLAIN and debugging purposes: */999	char	   *plan_name;		/* A name assigned during planning */1000	/* Extra data useful for determining subplan's output type: */1001	Oid			firstColType;	/* Type of first column of subplan result */1002	int32		firstColTypmod; /* Typmod of first column of subplan result */1003	Oid			firstColCollation;	/* Collation of first column of subplan1004									 * result */1005	/* Information about execution strategy: */1006	bool		useHashTable;	/* true to store subselect output in a hash1007								 * table (implies we are doing "IN") */1008	bool		unknownEqFalse; /* true if it's okay to return FALSE when the1009								 * spec result is UNKNOWN; this allows much1010								 * simpler handling of null values */1011	bool		parallel_safe;	/* is the subplan parallel-safe? */1012	/* Note: parallel_safe does not consider contents of testexpr or args */1013	/* Information for passing params into and out of the subselect: */1014	/* setParam and parParam are lists of integers (param IDs) */1015	List	   *setParam;		/* initplan and MULTIEXPR subqueries have to1016								 * set these Params for parent plan */1017	List	   *parParam;		/* indices of input Params from parent plan */1018	List	   *args;			/* exprs to pass as parParam values */1019	/* Estimated execution costs: */1020	Cost		startup_cost;	/* one-time setup cost */1021	Cost		per_call_cost;	/* cost for each subplan evaluation */1022} SubPlan;1023 1024/*1025 * AlternativeSubPlan - expression node for a choice among SubPlans1026 *1027 * This is used only transiently during planning: by the time the plan1028 * reaches the executor, all AlternativeSubPlan nodes have been removed.1029 *1030 * The subplans are given as a List so that the node definition need not1031 * change if there's ever more than two alternatives.  For the moment,1032 * though, there are always exactly two; and the first one is the fast-start1033 * plan.1034 */1035typedef struct AlternativeSubPlan1036{1037	pg_node_attr(no_query_jumble)1038 1039	Expr		xpr;1040	List	   *subplans;		/* SubPlan(s) with equivalent results */1041} AlternativeSubPlan;1042 1043/* ----------------1044 * FieldSelect1045 *1046 * FieldSelect represents the operation of extracting one field from a tuple1047 * value.  At runtime, the input expression is expected to yield a rowtype1048 * Datum.  The specified field number is extracted and returned as a Datum.1049 * ----------------1050 */1051 1052typedef struct FieldSelect1053{1054	Expr		xpr;1055	Expr	   *arg;			/* input expression */1056	AttrNumber	fieldnum;		/* attribute number of field to extract */1057	/* type of the field (result type of this node) */1058	Oid			resulttype pg_node_attr(query_jumble_ignore);1059	/* output typmod (usually -1) */1060	int32		resulttypmod pg_node_attr(query_jumble_ignore);1061	/* OID of collation of the field */1062	Oid			resultcollid pg_node_attr(query_jumble_ignore);1063} FieldSelect;1064 1065/* ----------------1066 * FieldStore1067 *1068 * FieldStore represents the operation of modifying one field in a tuple1069 * value, yielding a new tuple value (the input is not touched!).  Like1070 * the assign case of SubscriptingRef, this is used to implement UPDATE of a1071 * portion of a column.1072 *1073 * resulttype is always a named composite type (not a domain).  To update1074 * a composite domain value, apply CoerceToDomain to the FieldStore.1075 *1076 * A single FieldStore can actually represent updates of several different1077 * fields.  The parser only generates FieldStores with single-element lists,1078 * but the planner will collapse multiple updates of the same base column1079 * into one FieldStore.1080 * ----------------1081 */1082 1083typedef struct FieldStore1084{1085	Expr		xpr;1086	Expr	   *arg;			/* input tuple value */1087	List	   *newvals;		/* new value(s) for field(s) */1088	/* integer list of field attnums */1089	List	   *fieldnums pg_node_attr(query_jumble_ignore);1090	/* type of result (same as type of arg) */1091	Oid			resulttype pg_node_attr(query_jumble_ignore);1092	/* Like RowExpr, we deliberately omit a typmod and collation here */1093} FieldStore;1094 1095/* ----------------1096 * RelabelType1097 *1098 * RelabelType represents a "dummy" type coercion between two binary-1099 * compatible datatypes, such as reinterpreting the result of an OID1100 * expression as an int4.  It is a no-op at runtime; we only need it1101 * to provide a place to store the correct type to be attributed to1102 * the expression result during type resolution.  (We can't get away1103 * with just overwriting the type field of the input expression node,1104 * so we need a separate node to show the coercion's result type.)1105 * ----------------1106 */1107 1108typedef struct RelabelType1109{1110	Expr		xpr;1111	Expr	   *arg;			/* input expression */1112	Oid			resulttype;		/* output type of coercion expression */1113	/* output typmod (usually -1) */1114	int32		resulttypmod pg_node_attr(query_jumble_ignore);1115	/* OID of collation, or InvalidOid if none */1116	Oid			resultcollid pg_node_attr(query_jumble_ignore);1117	/* how to display this node */1118	CoercionForm relabelformat pg_node_attr(query_jumble_ignore);1119	int			location;		/* token location, or -1 if unknown */1120} RelabelType;1121 1122/* ----------------1123 * CoerceViaIO1124 *1125 * CoerceViaIO represents a type coercion between two types whose textual1126 * representations are compatible, implemented by invoking the source type's1127 * typoutput function then the destination type's typinput function.1128 * ----------------1129 */1130 1131typedef struct CoerceViaIO1132{1133	Expr		xpr;1134	Expr	   *arg;			/* input expression */1135	Oid			resulttype;		/* output type of coercion */1136	/* output typmod is not stored, but is presumed -1 */1137	/* OID of collation, or InvalidOid if none */1138	Oid			resultcollid pg_node_attr(query_jumble_ignore);1139	/* how to display this node */1140	CoercionForm coerceformat pg_node_attr(query_jumble_ignore);1141	int			location;		/* token location, or -1 if unknown */1142} CoerceViaIO;1143 1144/* ----------------1145 * ArrayCoerceExpr1146 *1147 * ArrayCoerceExpr represents a type coercion from one array type to another,1148 * which is implemented by applying the per-element coercion expression1149 * "elemexpr" to each element of the source array.  Within elemexpr, the1150 * source element is represented by a CaseTestExpr node.  Note that even if1151 * elemexpr is a no-op (that is, just CaseTestExpr + RelabelType), the1152 * coercion still requires some effort: we have to fix the element type OID1153 * stored in the array header.1154 * ----------------1155 */1156 1157typedef struct ArrayCoerceExpr1158{1159	Expr		xpr;1160	Expr	   *arg;			/* input expression (yields an array) */1161	Expr	   *elemexpr;		/* expression representing per-element work */1162	Oid			resulttype;		/* output type of coercion (an array type) */1163	/* output typmod (also element typmod) */1164	int32		resulttypmod pg_node_attr(query_jumble_ignore);1165	/* OID of collation, or InvalidOid if none */1166	Oid			resultcollid pg_node_attr(query_jumble_ignore);1167	/* how to display this node */1168	CoercionForm coerceformat pg_node_attr(query_jumble_ignore);1169	int			location;		/* token location, or -1 if unknown */1170} ArrayCoerceExpr;1171 1172/* ----------------1173 * ConvertRowtypeExpr1174 *1175 * ConvertRowtypeExpr represents a type coercion from one composite type1176 * to another, where the source type is guaranteed to contain all the columns1177 * needed for the destination type plus possibly others; the columns need not1178 * be in the same positions, but are matched up by name.  This is primarily1179 * used to convert a whole-row value of an inheritance child table into a1180 * valid whole-row value of its parent table's rowtype.  Both resulttype1181 * and the exposed type of "arg" must be named composite types (not domains).1182 * ----------------1183 */1184 1185typedef struct ConvertRowtypeExpr1186{1187	Expr		xpr;1188	Expr	   *arg;			/* input expression */1189	Oid			resulttype;		/* output type (always a composite type) */1190	/* Like RowExpr, we deliberately omit a typmod and collation here */1191	/* how to display this node */1192	CoercionForm convertformat pg_node_attr(query_jumble_ignore);1193	int			location;		/* token location, or -1 if unknown */1194} ConvertRowtypeExpr;1195 1196/*----------1197 * CollateExpr - COLLATE1198 *1199 * The planner replaces CollateExpr with RelabelType during expression1200 * preprocessing, so execution never sees a CollateExpr.

Showing the first 1,200 of 2042 lines. Download the file for the rest.

codekingpro/portable-devtools · Team Ai