*
* primnodes.h
* Definitions for "primitive" node types, those that are used in more
* than one of the parse/plan/execute stages of the query pipeline.
* Currently, these are mostly nodes for executable expressions
* and join trees.
*
*
* Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
* Portions Copyright (c) 2010-2012 Postgres-XC Development Group
* Portions Copyright (c) 2021, openGauss Contributors
*
* src/include/nodes/primnodes.h
*
* -------------------------------------------------------------------------
*/
#ifndef PRIMNODES_H
#define PRIMNODES_H
#include "access/attnum.h"
#include "nodes/pg_list.h"
#include "nodes/params.h"
#include "db4ai/db4ai.h"
* node definitions
* ----------------------------------------------------------------
*/
* Alias -
* specifies an alias for a range variable; the alias might also
* specify renaming of columns within the table.
*
* Note: colnames is a list of Value nodes (always strings). In Alias structs
* associated with RTEs, there may be entries corresponding to dropped
* columns; these are normally empty strings (""). See parsenodes.h for info.
*/
typedef struct Alias {
NodeTag type;
char* aliasname;
List* colnames;
} Alias;
typedef enum InhOption {
INH_NO,
INH_YES,
INH_DEFAULT
} InhOption;
typedef enum OnCommitAction {
ONCOMMIT_NOOP,
ONCOMMIT_PRESERVE_ROWS,
ONCOMMIT_DELETE_ROWS,
ONCOMMIT_DROP
} OnCommitAction;
typedef enum OptCompress {
COMPRESS_NO = 0,
COMPRESS_LOW,
COMPRESS_MIDDLE,
COMPRESS_HIGH,
} OptCompress;
typedef enum OnDuplicateAction {
DUPLICATE_ERROR = 0,
DUPLICATE_IGNORE,
DUPLICATE_REPLACE
} OnDuplicate;
* RangeVar - range variable, used in FROM clauses
*
* Also used to represent table names in utility statements; there, the alias
* field is not used, and inhOpt shows whether to apply the operation
* recursively to child tables. In some contexts it is also useful to carry
* a TEMP table indication here.
*/
typedef struct RangeVar {
NodeTag type;
char* catalogname;
char* schemaname;
char* relname;
char* partitionname;
char* subpartitionname;
InhOption inhOpt;
* on children? */
char relpersistence;
Alias* alias;
int location;
bool ispartition;
bool issubpartition;
List* partitionKeyValuesList;
bool isbucket;
List* buckets;
int length;
#ifdef ENABLE_MOT
Oid foreignOid;
#endif
bool withVerExpr;
List* partitionNameList;
List* indexhints;
} RangeVar;
* IntoClause - target information for SELECT INTO, CREATE TABLE AS, and
* CREATE MATERIALIZED VIEW
*/
typedef struct IntoClause {
NodeTag type;
RangeVar* rel;
List* colNames;
List* options;
OnCommitAction onCommit;
int8 row_compress;
char* tableSpaceName;
bool skipData;
bool ivm;
char relkind;
List* userVarList;
List* copyOption;
char* filename;
bool is_outfile;
#ifdef PGXC
struct DistributeBy* distributeby;
struct PGXCSubCluster* subcluster;
#endif
List* tableElts;
Node *autoIncStart;
OnDuplicateAction onduplicate;
} IntoClause;
* node types for executable expressions
* ----------------------------------------------------------------
*/
* Expr - generic superclass for executable-expression nodes
*
* All node types that are used in executable expression trees should derive
* from Expr (that is, have Expr as their first field). Since Expr only
* contains NodeTag, this is a formality, but it is an easy form of
* documentation. See also the ExprState node types in execnodes.h.
*/
typedef struct Expr {
NodeTag type;
double selec;
} Expr;
* Var - expression node representing a variable (ie, a table column)
*
* Note: during parsing/planning, varnoold/varoattno are always just copies
* of varno/varattno. At the tail end of planning, Var nodes appearing in
* upper-level plan nodes are reassigned to point to the outputs of their
* subplans; for example, in a join node varno becomes INNER_VAR or OUTER_VAR
* and varattno becomes the index of the proper element of that subplan's
* target list. But varnoold/varoattno continue to hold the original values.
* The code doesn't really need varnoold/varoattno, but they are very useful
* for debugging and interpreting completed plans, so we keep them around.
*/
#define INNER_VAR 65000
#define OUTER_VAR 65001
#define INDEX_VAR 65002
#define MERGEJOIN_VAR 65003
#define IS_SPECIAL_VARNO(varno) ((varno) >= INNER_VAR)
#define PRS2_OLD_VARNO 1
#define PRS2_NEW_VARNO 2
typedef struct Var {
Expr xpr;
Index varno;
* table, or INNER_VAR/OUTER_VAR/INDEX_VAR */
AttrNumber varattno;
* all */
Oid vartype;
int32 vartypmod;
Oid varcollid;
Index varlevelsup;
* relations; 0 in a normal var, >0 means N
* levels up */
Index varnoold;
AttrNumber varoattno;
int location;
} Var;
* Const
*/
typedef struct Const {
Expr xpr;
Oid consttype;
int32 consttypmod;
Oid constcollid;
int constlen;
Datum constvalue;
bool constisnull;
* constvalue is undefined) */
bool constbyval;
* If true, then all the information is stored
* in the Datum. If false, then the Datum
* contains a pointer to the information. */
int location;
bool ismaxvalue;
Cursor_Data cursor_data;
} Const;
* Param
* paramkind - specifies the kind of parameter. The possible values
* for this field are:
*
* PARAM_EXTERN: The parameter value is supplied from outside the plan.
* Such parameters are numbered from 1 to n.
*
* PARAM_EXEC: The parameter is an internal executor parameter, used
* for passing values into and out of sub-queries or from
* nestloop joins to their inner scans.
* For historical reasons, such parameters are numbered from 0.
* These numbers are independent of PARAM_EXTERN numbers.
*
* PARAM_SUBLINK: The parameter represents an output column of a SubLink
* node's sub-select. The column number is contained in the
* `paramid' field. (This type of Param is converted to
* PARAM_EXEC during planning.)
*
* Note: currently, paramtypmod is valid for PARAM_SUBLINK Params, and for
* PARAM_EXEC Params generated from them; it is always -1 for PARAM_EXTERN
* params, since the APIs that supply values for such parameters don't carry
* any typmod info.
* ----------------
*/
typedef enum ParamKind { PARAM_EXTERN, PARAM_EXEC, PARAM_SUBLINK } ParamKind;
typedef struct Param {
Expr xpr;
ParamKind paramkind;
int paramid;
Oid paramtype;
int32 paramtypmod;
Oid paramcollid;
int location;
Oid tableOfIndexType;
Oid recordVarTypOid;
List* tableOfIndexTypeList;
bool is_bind_param;
char* name;
bool is_pkg_var;
List* args;
} Param;
* Aggref
*
* The aggregate's args list is a targetlist, ie, a list of TargetEntry nodes
* (before Postgres 9.0 it was just bare expressions). The non-resjunk TLEs
* represent the aggregate's regular arguments (if any) and resjunk TLEs can
* be added at the end to represent ORDER BY expressions that are not also
* arguments. As in a top-level Query, the TLEs can be marked with
* ressortgroupref indexes to let them be referenced by SortGroupClause
* entries in the aggorder and/or aggdistinct lists. This represents ORDER BY
* and DISTINCT operations to be applied to the aggregate input rows before
* they are passed to the transition function. The grammar only allows a
* simple "DISTINCT" specifier for the arguments, but we use the full
* query-level representation to allow more code sharing.
*/
typedef struct Aggref {
Expr xpr;
Oid aggfnoid;
Oid aggtype;
Oid aggcollid;
Oid inputcollid;
#ifdef PGXC
Oid aggtrantype;
bool agghas_collectfn;
int8 aggstage;
#endif
#ifdef USE_SPQ
AggSplit aggsplittype;
#endif
List* aggdirectargs;
List* args;
List* aggorder;
List* aggdistinct;
bool aggiskeep;
bool aggkpfirst;
bool aggstar;
bool aggvariadic;
* combined into an array last argument */
char aggkind;
Index agglevelsup;
int location;
List* aggargtypes;
int aggsplit;
Oid aggtranstype;
Expr *aggfilter;
} Aggref;
* GroupingFunc
*
* A GroupingFunc is a GROUPING(...) expression, which behaves in many ways
* like an aggregate function (e.g. it "belongs" to a specific query level,
* which might not be the one immediately containing it), but also differs in
* an important respect: it never evaluates its arguments, they merely
* designate expressions from the GROUP BY clause of the query level to which
* it belongs.
*
* The spec defines the evaluation of GROUPING() purely by syntactic
* replacement, but we make it a real expression for optimization purposes so
* that one Agg node can handle multiple grouping sets at once. Evaluating the
* result only needs the column positions to check against the grouping set
* being projected. However, for EXPLAIN to produce meaningful output, we have
* to keep the original expressions around, since expression deparse does not
* give us any feasible way to get at the GROUP BY clause.
*
* Also, we treat two GroupingFunc nodes as equal if they have equal arguments
* lists and agglevelsup, without comparing the refs and cols annotations.
*
* In raw parse output we have only the args list; parse analysis fills in the
* refs list, and the planner fills in the cols list.
*/
typedef struct GroupingFunc {
Expr xpr;
List* args;
* benefit of EXPLAIN etc. */
List* refs;
List* cols;
Index agglevelsup;
int location;
} GroupingFunc;
typedef struct GroupingId {
Expr xpr;
} GroupingId;
* WindowFunc
*/
typedef struct WindowFunc {
Expr xpr;
Oid winfnoid;
Oid wintype;
Oid wincollid;
Oid inputcollid;
List* args;
Index winref;
bool winstar;
bool winagg;
int location;
List* keep_args;
List* winkporder;
bool winkpfirst;
#ifdef USE_SPQ
bool windistinct;
#endif
bool is_from_last;
bool is_ignore_nulls;
} WindowFunc;
* pseudo-column "ROWNUM"
*/
typedef struct Rownum {
Expr xpr;
Oid rownumcollid;
int location;
} Rownum;
typedef struct PriorExpr {
Expr xpr;
Node *node;
} PriorExpr;
* ArrayRef: describes an array subscripting operation
*
* An ArrayRef can describe fetching a single element from an array,
* fetching a subarray (array slice), storing a single element into
* an array, or storing a slice. The "store" cases work with an
* initial array value and a source value that is inserted into the
* appropriate part of the array; the result of the operation is an
* entire new modified array value.
*
* If reflowerindexpr = NIL, then we are fetching or storing a single array
* element at the subscripts given by refupperindexpr. Otherwise we are
* fetching or storing an array slice, that is a rectangular subarray
* with lower and upper bounds given by the index expressions.
* reflowerindexpr must be the same length as refupperindexpr when it
* is not NIL.
*
* Note: the result datatype is the element type when fetching a single
* element; but it is the array type when doing subarray fetch or either
* type of store.
* ----------------
*/
typedef struct ArrayRef {
Expr xpr;
Oid refarraytype;
Oid refelemtype;
int32 reftypmod;
Oid refcollid;
List* refupperindexpr;
* indexes */
List* reflowerindexpr;
* indexes */
Expr* refexpr;
* value */
Expr* refassgnexpr;
* fetch */
} ArrayRef;
* CoercionContext - distinguishes the allowed set of type casts
*
* NB: ordering of the alternatives is significant; later (larger) values
* allow more casts than earlier ones.
*/
typedef enum CoercionContext {
COERCION_IMPLICIT,
COERCION_ASSIGNMENT,
COERCION_EXPLICIT,
COERCION_UNKNOWN = 0xFFFFFFFE
} CoercionContext;
* CoercionForm - information showing how to display a function-call node
*
* NB: equal() ignores CoercionForm fields, therefore this *must* not carry
* any semantically significant information. We need that behavior so that
* the planner will consider equivalent implicit and explicit casts to be
* equivalent. In cases where those actually behave differently, the coercion
* function's arguments will be different.
*/
typedef enum CoercionForm {
COERCE_EXPLICIT_CALL,
COERCE_EXPLICIT_CAST,
COERCE_IMPLICIT_CAST,
COERCE_DONTCARE
} CoercionForm;
* FuncExpr - expression node for a function call
*/
typedef struct FuncExpr {
Expr xpr;
Oid funcid;
Oid funcresulttype;
int32 funcresulttype_orig;
bool funcretset;
bool funcvariadic;
CoercionForm funcformat;
Oid funccollid;
Oid inputcollid;
char* fmtstr;
char* nlsfmtstr;
List* args;
int location;
Oid refSynOid;
} FuncExpr;
* NamedArgExpr - a named argument of a function
*
* This node type can only appear in the args list of a FuncCall or FuncExpr
* node. We support pure positional call notation (no named arguments),
* named notation (all arguments are named), and mixed notation (unnamed
* arguments followed by named ones).
*
* Parse analysis sets argnumber to the positional index of the argument,
* but doesn't rearrange the argument list.
*
* The planner will convert argument lists to pure positional notation
* during expression preprocessing, so execution never sees a NamedArgExpr.
*/
typedef struct NamedArgExpr {
Expr xpr;
Expr* arg;
char* name;
int argnumber;
int location;
} NamedArgExpr;
* OpExpr - expression node for an operator invocation
*
* Semantically, this is essentially the same as a function call.
*
* Note that opfuncid is not necessarily filled in immediately on creation
* of the node. The planner makes sure it is valid before passing the node
* tree to the executor, but during parsing/planning opfuncid can be 0.
*/
typedef struct OpExpr {
Expr xpr;
Oid opno;
Oid opfuncid;
Oid opresulttype;
bool opretset;
Oid opcollid;
Oid inputcollid;
List* args;
int location;
} OpExpr;
* DistinctExpr - expression node for "x IS DISTINCT FROM y"
*
* Except for the nodetag, this is represented identically to an OpExpr
* referencing the "=" operator for x and y.
* We use "=", not the more obvious "<>", because more datatypes have "="
* than "<>". This means the executor must invert the operator result.
* Note that the operator function won't be called at all if either input
* is NULL, since then the result can be determined directly.
*/
typedef OpExpr DistinctExpr;
* NullIfExpr - a NULLIF expression
*
* Like DistinctExpr, this is represented the same as an OpExpr referencing
* the "=" operator for x and y.
*/
typedef OpExpr NullIfExpr;
* ScalarArrayOpExpr - expression node for "scalar op ANY/ALL (array)"
*
* The operator must yield boolean. It is applied to the left operand
* and each element of the righthand array, and the results are combined
* with OR or AND (for ANY or ALL respectively). The node representation
* is almost the same as for the underlying operator, but we need a useOr
* flag to remember whether it's ANY or ALL, and we don't have to store
* the result type (or the collation) because it must be boolean.
*
* A ScalarArrayOpExpr with a valid hashfuncid is evaluated during execution
* by building a hash table containing the Const values from the rhs arg.
* This table is probed during expression evaluation. Only useOr=true
* ScalarArrayOpExpr with Const arrays on the rhs can have the hashfuncid
* field set. See convert_saop_to_hashed_saop().
* by building a hash table containing the Const values from the RHS arg.
* This table is probed during expression evaluation. The planner will set
* hashfuncid to the hash function which must be used to build and probe the
* hash table. The executor determines if it should use hash-based checks or
* the more traditional means based on if the hashfuncid is set or not.
*
* When performing hashed NOT IN, the negfuncid will also be set to the
* equality function which the hash table must use to build and probe the hash
* table. opno and opfuncid will remain set to the <> operator and its
* corresponding function and won't be used during execution. For
* non-hashtable based NOT INs, negfuncid will be set to InvalidOid. See
* convert_saop_to_hashed_saop().
*/
typedef struct ScalarArrayOpExpr {
Expr xpr;
Oid opno;
Oid opfuncid;
Oid hashfuncid;
Oid negfuncid;
bool useOr;
Oid inputcollid;
List* args;
int location;
} ScalarArrayOpExpr;
* BoolExpr - expression node for the basic Boolean operators AND, OR, NOT
*
* Notice the arguments are given as a List. For NOT, of course the list
* must always have exactly one element. For AND and OR, the executor can
* handle any number of arguments. The parser generally treats AND and OR
* as binary and so it typically only produces two-element lists, but the
* optimizer will flatten trees of AND and OR nodes to produce longer lists
* when possible. There are also a few special cases where more arguments
* can appear before optimization.
*/
typedef enum BoolExprType { AND_EXPR, OR_EXPR, NOT_EXPR } BoolExprType;
typedef struct BoolExpr {
Expr xpr;
BoolExprType boolop;
List* args;
int location;
} BoolExpr;
* SubLink
*
* A SubLink represents a subselect appearing in an expression, and in some
* cases also the combining operator(s) just above it. The subLinkType
* indicates the form of the expression represented:
* EXISTS_SUBLINK EXISTS(SELECT ...)
* ALL_SUBLINK (lefthand) op ALL (SELECT ...)
* ANY_SUBLINK (lefthand) op ANY (SELECT ...)
* ROWCOMPARE_SUBLINK (lefthand) op (SELECT ...)
* EXPR_SUBLINK (SELECT with single targetlist item ...)
* ARRAY_SUBLINK ARRAY(SELECT with single targetlist item ...)
* CTE_SUBLINK WITH query (never actually part of an expression)
* For ALL, ANY, and ROWCOMPARE, the lefthand is a list of expressions of the
* same length as the subselect's targetlist. ROWCOMPARE will *always* have
* a list with more than one entry; if the subselect has just one target
* then the parser will create an EXPR_SUBLINK instead (and any operator
* above the subselect will be represented separately). Note that both
* ROWCOMPARE and EXPR require the subselect to deliver only one row.
* ALL, ANY, and ROWCOMPARE require the combining operators to deliver boolean
* results. ALL and ANY combine the per-row results using AND and OR
* semantics respectively.
* ARRAY requires just one target column, and creates an array of the target
* column's type using any number of rows resulting from the subselect.
*
* SubLink is classed as an Expr node, but it is not actually executable;
* it must be replaced in the expression tree by a SubPlan node during
* planning.
*
* NOTE: in the raw output of gram.y, testexpr contains just the raw form
* of the lefthand expression (if any), and operName is the String name of
* the combining operator. Also, subselect is a raw parsetree. During parse
* analysis, the parser transforms testexpr into a complete boolean expression
* that compares the lefthand value(s) to PARAM_SUBLINK nodes representing the
* output columns of the subselect. And subselect is transformed to a Query.
* This is the representation seen in saved rules and in the rewriter.
*
* In EXISTS, EXPR, and ARRAY SubLinks, testexpr and operName are unused and
* are always null.
*
* The CTE_SUBLINK case never occurs in actual SubLink nodes, but it is used
* in SubPlans generated for WITH subqueries.
*/
typedef enum SubLinkType {
EXISTS_SUBLINK,
ALL_SUBLINK,
ANY_SUBLINK,
ROWCOMPARE_SUBLINK,
EXPR_SUBLINK,
ARRAY_SUBLINK,
#ifdef USE_SPQ
NOT_EXISTS_SUBLINK,
#endif
CTE_SUBLINK
} SubLinkType;
typedef struct SubLink {
Expr xpr;
SubLinkType subLinkType;
Node* testexpr;
List* operName;
Node* subselect;
int location;
} SubLink;
* SubPlan - executable expression node for a subplan (sub-SELECT)
*
* The planner replaces SubLink nodes in expression trees with SubPlan
* nodes after it has finished planning the subquery. SubPlan references
* a sub-plantree stored in the subplans list of the toplevel PlannedStmt.
* (We avoid a direct link to make it easier to copy expression trees
* without causing multiple processing of the subplan.)
*
* In an ordinary subplan, testexpr points to an executable expression
* (OpExpr, an AND/OR tree of OpExprs, or RowCompareExpr) for the combining
* operator(s); the left-hand arguments are the original lefthand expressions,
* and the right-hand arguments are PARAM_EXEC Param nodes representing the
* outputs of the sub-select. (NOTE: runtime coercion functions may be
* inserted as well.) This is just the same expression tree as testexpr in
* the original SubLink node, but the PARAM_SUBLINK nodes are replaced by
* suitably numbered PARAM_EXEC nodes.
*
* If the sub-select becomes an initplan rather than a subplan, the executable
* expression is part of the outer plan's expression tree (and the SubPlan
* node itself is not, but rather is found in the outer plan's initPlan
* list). In this case testexpr is NULL to avoid duplication.
*
* The planner also derives lists of the values that need to be passed into
* and out of the subplan. Input values are represented as a list "args" of
* expressions to be evaluated in the outer-query context (currently these
* args are always just Vars, but in principle they could be any expression).
* The values are assigned to the global PARAM_EXEC params indexed by parParam
* (the parParam and args lists must have the same ordering). setParam is a
* list of the PARAM_EXEC params that are computed by the sub-select, if it
* is an initplan; they are listed in order by sub-select output column
* position. (parParam and setParam are integer Lists, not Bitmapsets,
* because their ordering is significant.)
*
* Also, the planner computes startup and per-call costs for use of the
* SubPlan. Note that these include the cost of the subquery proper,
* evaluation of the testexpr if any, and any hashtable management overhead.
*/
typedef struct SubPlan {
Expr xpr;
SubLinkType subLinkType;
Node* testexpr;
List* paramIds;
int plan_id;
char* plan_name;
Oid firstColType;
int32 firstColTypmod;
Oid firstColCollation;
bool useHashTable;
bool unknownEqFalse;
List* setParam;
List* parParam;
List* args;
Cost startup_cost;
Cost per_call_cost;
#ifdef USE_SPQ
bool is_initplan;
bool is_multirow;
#endif
} SubPlan;
* AlternativeSubPlan - expression node for a choice among SubPlans
*
* The subplans are given as a List so that the node definition need not
* change if there's ever more than two alternatives. For the moment,
* though, there are always exactly two; and the first one is the fast-start
* plan.
*/
typedef struct AlternativeSubPlan {
Expr xpr;
List* subplans;
} AlternativeSubPlan;
* FieldSelect
*
* FieldSelect represents the operation of extracting one field from a tuple
* value. At runtime, the input expression is expected to yield a rowtype
* Datum. The specified field number is extracted and returned as a Datum.
* ----------------
*/
typedef struct FieldSelect {
Expr xpr;
Expr* arg;
AttrNumber fieldnum;
Oid resulttype;
* node) */
int32 resulttypmod;
Oid resultcollid;
} FieldSelect;
* FieldStore
*
* FieldStore represents the operation of modifying one field in a tuple
* value, yielding a new tuple value (the input is not touched!). Like
* the assign case of ArrayRef, this is used to implement UPDATE of a
* portion of a column.
*
* A single FieldStore can actually represent updates of several different
* fields. The parser only generates FieldStores with single-element lists,
* but the planner will collapse multiple updates of the same base column
* into one FieldStore.
* ----------------
*/
typedef struct FieldStore {
Expr xpr;
Expr* arg;
List* newvals;
List* fieldnums;
Oid resulttype;
} FieldStore;
* RelabelType
*
* RelabelType represents a "dummy" type coercion between two binary-
* compatible datatypes, such as reinterpreting the result of an OID
* expression as an int4. It is a no-op at runtime; we only need it
* to provide a place to store the correct type to be attributed to
* the expression result during type resolution. (We can't get away
* with just overwriting the type field of the input expression node,
* so we need a separate node to show the coercion's result type.)
* ----------------
*/
typedef struct RelabelType {
Expr xpr;
Expr* arg;
Oid resulttype;
int32 resulttypmod;
Oid resultcollid;
CoercionForm relabelformat;
int location;
} RelabelType;
* CoerceViaIO
*
* CoerceViaIO represents a type coercion between two types whose textual
* representations are compatible, implemented by invoking the source type's
* typoutput function then the destination type's typinput function.
* ----------------
*/
typedef struct CoerceViaIO {
Expr xpr;
Expr* arg;
char* fmtstr;
char* nlsfmtstr;
Oid resulttype;
Oid resultcollid;
CoercionForm coerceformat;
int location;
} CoerceViaIO;
* ArrayCoerceExpr
*
* ArrayCoerceExpr represents a type coercion from one array type to another,
* which is implemented by applying the indicated element-type coercion
* function to each element of the source array. If elemfuncid is InvalidOid
* then the element types are binary-compatible, but the coercion still
* requires some effort (we have to fix the element type ID stored in the
* array header).
* ----------------
*/
typedef struct ArrayCoerceExpr {
Expr xpr;
Expr* arg;
char* fmtstr;
char* nlsfmtstr;
Oid elemfuncid;
Oid resulttype;
int32 resulttypmod;
Oid resultcollid;
bool isExplicit;
CoercionForm coerceformat;
int location;
} ArrayCoerceExpr;
* ConvertRowtypeExpr
*
* ConvertRowtypeExpr represents a type coercion from one composite type
* to another, where the source type is guaranteed to contain all the columns
* needed for the destination type plus possibly others; the columns need not
* be in the same positions, but are matched up by name. This is primarily
* used to convert a whole-row value of an inheritance child table into a
* valid whole-row value of its parent table's rowtype.
* ----------------
*/
typedef struct ConvertRowtypeExpr {
Expr xpr;
Expr* arg;
Oid resulttype;
CoercionForm convertformat;
int location;
} ConvertRowtypeExpr;
* CollateExpr - COLLATE
*
* The planner replaces CollateExpr with RelabelType during expression
* preprocessing, so execution never sees a CollateExpr.
* ----------
*/
typedef struct CollateExpr {
Expr xpr;
Expr* arg;
Oid collOid;
int location;
} CollateExpr;
* CaseExpr - a CASE expression
*
* We support two distinct forms of CASE expression:
* CASE WHEN boolexpr THEN expr [ WHEN boolexpr THEN expr ... ]
* CASE testexpr WHEN compexpr THEN expr [ WHEN compexpr THEN expr ... ]
* These are distinguishable by the "arg" field being NULL in the first case
* and the testexpr in the second case.
*
* In the raw grammar output for the second form, the condition expressions
* of the WHEN clauses are just the comparison values. Parse analysis
* converts these to valid boolean expressions of the form
* CaseTestExpr '=' compexpr
* where the CaseTestExpr node is a placeholder that emits the correct
* value at runtime. This structure is used so that the testexpr need be
* evaluated only once. Note that after parse analysis, the condition
* expressions always yield boolean.
*
* Note: we can test whether a CaseExpr has been through parse analysis
* yet by checking whether casetype is InvalidOid or not.
* ----------
*/
typedef struct CaseExpr {
Expr xpr;
Oid casetype;
Oid casecollid;
Expr* arg;
List* args;
Expr* defresult;
int location;
bool fromDecode;
} CaseExpr;
* CaseWhen - one arm of a CASE expression
*/
typedef struct CaseWhen {
Expr xpr;
Expr* expr;
Expr* result;
int location;
} CaseWhen;
* Placeholder node for the test value to be processed by a CASE expression.
* This is effectively like a Param, but can be implemented more simply
* since we need only one replacement value at a time.
*
* We also use this in nested UPDATE expressions.
* See transformAssignmentIndirection().
*/
typedef struct CaseTestExpr {
Expr xpr;
Oid typeId;
int32 typeMod;
Oid collation;
} CaseTestExpr;
* ArrayExpr - an ARRAY[] expression
*
* Note: if multidims is false, the constituent expressions all yield the
* scalar type identified by element_typeid. If multidims is true, the
* constituent expressions all yield arrays of element_typeid (ie, the same
* type as array_typeid); at runtime we must check for compatible subscripts.
*/
typedef struct ArrayExpr {
Expr xpr;
Oid array_typeid;
Oid array_collid;
Oid element_typeid;
List* elements;
bool multidims;
int location;
} ArrayExpr;
* RowExpr - a ROW() expression
*
* Note: the list of fields must have a one-for-one correspondence with
* physical fields of the associated rowtype, although it is okay for it
* to be shorter than the rowtype. That is, the N'th list element must
* match up with the N'th physical field. When the N'th physical field
* is a dropped column (attisdropped) then the N'th list element can just
* be a NULL constant. (This case can only occur for named composite types,
* not RECORD types, since those are built from the RowExpr itself rather
* than vice versa.) It is important not to assume that length(args) is
* the same as the number of columns logically present in the rowtype.
*
* colnames provides field names in cases where the names can't easily be
* obtained otherwise. Names *must* be provided if row_typeid is RECORDOID.
* If row_typeid identifies a known composite type, colnames can be NIL to
* indicate the type's cataloged field names apply. Note that colnames can
* be non-NIL even for a composite type, and typically is when the RowExpr
* was created by expanding a whole-row Var. This is so that we can retain
* the column alias names of the RTE that the Var referenced (which would
* otherwise be very difficult to extract from the parsetree). Like the
* args list, colnames is one-for-one with physical fields of the rowtype.
*/
typedef struct RowExpr {
Expr xpr;
List* args;
Oid row_typeid;
* Note: we deliberately do NOT store a typmod. Although a typmod will be
* associated with specific RECORD types at runtime, it will differ for
* different backends, and so cannot safely be stored in stored
* parsetrees. We must assume typmod -1 for a RowExpr node.
*
* We don't need to store a collation either. The result type is
* necessarily composite, and composite types never have a collation.
*/
CoercionForm row_format;
List* colnames;
int location;
} RowExpr;
* RowCompareExpr - row-wise comparison, such as (a, b) <= (1, 2)
*
* We support row comparison for any operator that can be determined to
* act like =, <>, <, <=, >, or >= (we determine this by looking for the
* operator in btree opfamilies). Note that the same operator name might
* map to a different operator for each pair of row elements, since the
* element datatypes can vary.
*
* A RowCompareExpr node is only generated for the < <= > >= cases;
* the = and <> cases are translated to simple AND or OR combinations
* of the pairwise comparisons. However, we include = and <> in the
* RowCompareType enum for the convenience of parser logic.
*/
typedef enum RowCompareType {
ROWCOMPARE_LT = 1,
ROWCOMPARE_LE = 2,
ROWCOMPARE_EQ = 3,
ROWCOMPARE_GE = 4,
ROWCOMPARE_GT = 5,
ROWCOMPARE_NE = 6
} RowCompareType;
typedef struct RowCompareExpr {
Expr xpr;
RowCompareType rctype;
List* opnos;
List* opfamilies;
List* inputcollids;
List* largs;
List* rargs;
} RowCompareExpr;
* CoalesceExpr - a COALESCE expression
*/
typedef struct CoalesceExpr {
Expr xpr;
Oid coalescetype;
Oid coalescecollid;
List* args;
int location;
bool isnvl;
} CoalesceExpr;
* MinMaxExpr - a GREATEST or LEAST function
*/
typedef enum MinMaxOp { IS_GREATEST, IS_LEAST } MinMaxOp;
typedef struct MinMaxExpr {
Expr xpr;
Oid minmaxtype;
Oid minmaxcollid;
Oid inputcollid;
MinMaxOp op;
List* args;
int location;
Oid cmptype;
List* cmpargs;
} MinMaxExpr;
* XmlExpr - various SQL/XML functions requiring special grammar productions
*
* 'name' carries the "NAME foo" argument (already XML-escaped).
* 'named_args' and 'arg_names' represent an xml_attribute list.
* 'args' carries all other arguments.
*
* Note: result type/typmod/collation are not stored, but can be deduced
* from the XmlExprOp. The type/typmod fields are just used for display
* purposes, and are NOT necessarily the true result type of the node.
* (We also use type == InvalidOid to mark a not-yet-parse-analyzed XmlExpr.)
*/
typedef enum XmlExprOp {
IS_XMLCONCAT,
IS_XMLELEMENT,
IS_XMLFOREST,
IS_XMLPARSE,
IS_XMLPI,
IS_XMLROOT,
IS_XMLSERIALIZE,
IS_DOCUMENT
} XmlExprOp;
typedef enum { XMLOPTION_DOCUMENT, XMLOPTION_CONTENT } XmlOptionType;
typedef struct XmlExpr {
Expr xpr;
XmlExprOp op;
char* name;
List* named_args;
List* arg_names;
List* args;
XmlOptionType xmloption;
Oid type;
int32 typmod;
int location;
} XmlExpr;
typedef struct PrefixKey {
Expr xpr;
Expr* arg;
int length;
} PrefixKey;
* NullTest
*
* NullTest represents the operation of testing a value for NULLness.
* The appropriate test is performed and returned as a boolean Datum.
*
* When argisrow is false, this simply represents a test for the null value.
*
* When argisrow is true, the input expression must yield a rowtype, and
* the node implements "row IS [NOT] NULL" per the SQL standard. This
* includes checking individual fields for NULLness when the row datum
* itself isn't NULL.
*
* NOTE: the combination of a rowtype input and argisrow==false does NOT
* correspond to the SQL notation "row IS [NOT] NULL"; instead, this case
* represents the SQL notation "row IS [NOT] DISTINCT FROM NULL".
* ----------------
*/
typedef enum NullTestType { IS_NULL, IS_NOT_NULL } NullTestType;
typedef struct NullTest {
Expr xpr;
Expr* arg;
NullTestType nulltesttype;
bool argisrow;
} NullTest;
* NanTest
*
* NanTest represents the operation of testing a value for Nan.
* The appropriate test is performed and returned as a boolean Datum.
* ----------------
*/
typedef enum NanTestType { IS_NAN, IS_NOT_NAN } NanTestType;
typedef struct NanTest {
Expr xpr;
Expr* arg;
NanTestType nantesttype;
} NanTest;
* InfiniteTest
*
* InfiniteTest represents the operation of testing a value for Infinite.
* The appropriate test is performed and returned as a boolean Datum.
* ----------------
*/
typedef enum InfiniteTestType { IS_INFINITE, IS_NOT_INFINITE } InfiniteTestType;
typedef struct InfiniteTest {
Expr xpr;
Expr* arg;
InfiniteTestType infinitetesttype;
} InfiniteTest;
* BooleanTest
*
* BooleanTest represents the operation of determining whether a boolean
* is TRUE, FALSE, or UNKNOWN (ie, NULL). All six meaningful combinations
* are supported. Note that a NULL input does *not* cause a NULL result.
* The appropriate test is performed and returned as a boolean Datum.
*/
typedef enum BoolTestType { IS_TRUE, IS_NOT_TRUE, IS_FALSE, IS_NOT_FALSE, IS_UNKNOWN, IS_NOT_UNKNOWN } BoolTestType;
typedef struct BooleanTest {
Expr xpr;
Expr* arg;
BoolTestType booltesttype;
} BooleanTest;
typedef struct HashFilter {
Expr xpr;
List* arg;
List* typeOids;
List* nodeList;
} HashFilter;
* EstSPNode
*
* For some expression, we can't estimate them though vars under them. Therefore,
* we should keep them and get the vars under them to get an overall estimation.
*/
typedef struct EstSPNode {
Expr xpr;
Node* expr;
List* varlist;
} EstSPNode;
* CoerceToDomain
*
* CoerceToDomain represents the operation of coercing a value to a domain
* type. At runtime (and not before) the precise set of constraints to be
* checked will be determined. If the value passes, it is returned as the
* result; if not, an error is raised. Note that this is equivalent to
* RelabelType in the scenario where no constraints are applied.
*/
typedef struct CoerceToDomain {
Expr xpr;
Expr* arg;
Oid resulttype;
int32 resulttypmod;
Oid resultcollid;
CoercionForm coercionformat;
int location;
} CoerceToDomain;
* Placeholder node for the value to be processed by a domain's check
* constraint. This is effectively like a Param, but can be implemented more
* simply since we need only one replacement value at a time.
*
* Note: the typeId/typeMod/collation will be set from the domain's base type,
* not the domain itself. This is because we shouldn't consider the value
* to be a member of the domain if we haven't yet checked its constraints.
*/
typedef struct CoerceToDomainValue {
Expr xpr;
Oid typeId;
int32 typeMod;
Oid collation;
int location;
} CoerceToDomainValue;
* Placeholder node for a DEFAULT marker in an INSERT or UPDATE command.
*
* This is not an executable expression: it must be replaced by the actual
* column default expression during rewriting. But it is convenient to
* treat it as an expression node during parsing and rewriting.
*/
typedef struct SetToDefault {
Expr xpr;
Oid typeId;
int32 typeMod;
Oid collation;
int location;
bool lrchild_unknown;
} SetToDefault;
typedef struct ExprWithComma {
NodeTag type;
Expr *xpr;
int comma_before_loc;
} ExprWithComma;
* Node representing [WHERE] CURRENT OF cursor_name
*
* CURRENT OF is a bit like a Var, in that it carries the rangetable index
* of the target relation being constrained; this aids placing the expression
* correctly during planning. We can assume however that its "levelsup" is
* always zero, due to the syntactic constraints on where it can appear.
*
* The referenced cursor can be represented either as a hardwired string
* or as a reference to a run-time parameter of type REFCURSOR. The latter
* case is for the convenience of plpgsql.
*/
typedef struct CurrentOfExpr {
Expr xpr;
Index cvarno;
char* cursor_name;
int cursor_param;
} CurrentOfExpr;
typedef struct {
Expr xpr;
char* name;
Expr* value;
bool is_session;
bool is_global;
} SetVariableExpr;
* TargetEntry -
* a target entry (used in query target lists)
*
* Strictly speaking, a TargetEntry isn't an expression node (since it can't
* be evaluated by ExecEvalExpr). But we treat it as one anyway, since in
* very many places it's convenient to process a whole query targetlist as a
* single expression tree.
*
* In a SELECT's targetlist, resno should always be equal to the item's
* ordinal position (counting from 1). However, in an INSERT or UPDATE
* targetlist, resno represents the attribute number of the destination
* column for the item; so there may be missing or out-of-order resnos.
* It is even legal to have duplicated resnos; consider
* UPDATE table SET arraycol[1] = ..., arraycol[2] = ..., ...
* The two meanings come together in the executor, because the planner
* transforms INSERT/UPDATE tlists into a normalized form with exactly
* one entry for each column of the destination table. Before that's
* happened, however, it is risky to assume that resno == position.
* Generally get_tle_by_resno() should be used rather than list_nth()
* to fetch tlist entries by resno, and only in SELECT should you assume
* that resno is a unique identifier.
*
* resname is required to represent the correct column name in non-resjunk
* entries of top-level SELECT targetlists, since it will be used as the
* column title sent to the frontend. In most other contexts it is only
* a debugging aid, and may be wrong or even NULL. (In particular, it may
* be wrong in a tlist from a stored rule, if the referenced column has been
* renamed by ALTER TABLE since the rule was made. Also, the planner tends
* to store NULL rather than look up a valid name for tlist entries in
* non-toplevel plan nodes.) In resjunk entries, resname should be either
* a specific system-generated name (such as "ctid") or NULL; anything else
* risks confusing ExecGetJunkAttribute!
*
* ressortgroupref is used in the representation of ORDER BY, GROUP BY, and
* DISTINCT items. Targetlist entries with ressortgroupref=0 are not
* sort/group items. If ressortgroupref>0, then this item is an ORDER BY,
* GROUP BY, and/or DISTINCT target value. No two entries in a targetlist
* may have the same nonzero ressortgroupref --- but there is no particular
* meaning to the nonzero values, except as tags. (For example, one must
* not assume that lower ressortgroupref means a more significant sort key.)
* The order of the associated SortGroupClause lists determine the semantics.
*
* resorigtbl/resorigcol identify the source of the column, if it is a
* simple reference to a column of a base table (or view). If it is not
* a simple reference, these fields are zeroes.
*
* If resjunk is true then the column is a working column (such as a sort key)
* that should be removed from the final output of the query. Resjunk columns
* must have resnos that cannot duplicate any regular column's resno. Also
* note that there are places that assume resjunk columns come after non-junk
* columns.
* --------------------
*/
typedef struct TargetEntry {
Expr xpr;
Expr* expr;
AttrNumber resno;
char* resname;
Index ressortgroupref;
* clause */
Oid resorigtbl;
AttrNumber resorigcol;
bool resjunk;
* final target list */
Index rtindex;
* to which this TLE belongs. */
bool isStartWithPseudo;
} TargetEntry;
typedef struct PseudoTargetEntry {
NodeTag type;
TargetEntry *tle;
TargetEntry *srctle;
} PseudoTargetEntry;
* node types for join trees
*
* The leaves of a join tree structure are RangeTblRef nodes. Above
* these, JoinExpr nodes can appear to denote a specific kind of join
* or qualified join. Also, FromExpr nodes can appear to denote an
* ordinary cross-product join ("FROM foo, bar, baz WHERE ...").
* FromExpr is like a JoinExpr of jointype JOIN_INNER, except that it
* may have any number of child nodes, not just two.
*
* NOTE: the top level of a Query's jointree is always a FromExpr.
* Even if the jointree contains no rels, there will be a FromExpr.
*
* NOTE: the qualification expressions present in JoinExpr nodes are
* *in addition to* the query's main WHERE clause, which appears as the
* qual of the top-level FromExpr. The reason for associating quals with
* specific nodes in the jointree is that the position of a qual is critical
* when outer joins are present. (If we enforce a qual too soon or too late,
* that may cause the outer join to produce the wrong set of NULL-extended
* rows.) If all joins are inner joins then all the qual positions are
* semantically interchangeable.
*
* NOTE: in the raw output of gram.y, a join tree contains RangeVar,
* RangeSubselect, and RangeFunction nodes, which are all replaced by
* RangeTblRef nodes during the parse analysis phase. Also, the top-level
* FromExpr is added during parse analysis; the grammar regards FROM and
* WHERE as separate.
* ----------------------------------------------------------------
*/
* RangeTblRef - reference to an entry in the query's rangetable
*
* We could use direct pointers to the RT entries and skip having these
* nodes, but multiple pointers to the same node in a querytree cause
* lots of headaches, so it seems better to store an index into the RT.
*/
typedef struct RangeTblRef {
NodeTag type;
int rtindex;
} RangeTblRef;
* JoinExpr - for SQL JOIN expressions
*
* isNatural, usingClause, and quals are interdependent. The user can write
* only one of NATURAL, USING(), or ON() (this is enforced by the grammar).
* If he writes NATURAL then parse analysis generates the equivalent USING()
* list, and from that fills in "quals" with the right equality comparisons.
* If he writes USING() then "quals" is filled with equality comparisons.
* If he writes ON() then only "quals" is set. Note that NATURAL/USING
* are not equivalent to ON() since they also affect the output column list.
*
* alias is an Alias node representing the AS alias-clause attached to the
* join expression, or NULL if no clause. NB: presence or absence of the
* alias has a critical impact on semantics, because a join with an alias
* restricts visibility of the tables/columns inside it.
*
* During parse analysis, an RTE is created for the Join, and its index
* is filled into rtindex. This RTE is present mainly so that Vars can
* be created that refer to the outputs of the join. The planner sometimes
* generates JoinExprs internally; these can have rtindex = 0 if there are
* no join alias variables referencing such joins.
* ----------
*/
typedef struct JoinExpr {
NodeTag type;
JoinType jointype;
bool isNatural;
bool isAsof;
Node* larg;
Node* rarg;
List* usingClause;
Node* quals;
Alias* alias;
int rtindex;
bool is_straight_join;
bool is_apply_join;
} JoinExpr;
* FromExpr - represents a FROM ... WHERE ... construct
*
* This is both more flexible than a JoinExpr (it can have any number of
* children, including zero) and less so --- we don't need to deal with
* aliases and so on. The output column set is implicitly just the union
* of the outputs of the children.
* ----------
*/
typedef struct FromExpr {
NodeTag type;
List* fromlist;
Node* quals;
} FromExpr;
#ifdef PGXC
* DistributionType - how to distribute the data
*
* ----------
*/
typedef enum DistributionType {
DISTTYPE_REPLICATION,
DISTTYPE_HASH,
DISTTYPE_ROUNDROBIN,
DISTTYPE_MODULO,
DISTTYPE_HIDETAG,
DISTTYPE_LIST,
DISTTYPE_RANGE
} DistributionType;
typedef struct ListSliceDefState {
NodeTag type;
char* name;
List* boundaries;
char* datanode_name;
} ListSliceDefState;
typedef struct DistState {
NodeTag type;
* 'r' range slice
* 'l' list slice
*/
char strategy;
* ListSliceDefState or RangePartitionDefState or RangePartitionStartEndDefState
*/
List* sliceList;
char* refTableName;
} DistState;
* DistributeBy - represents a DISTRIBUTE BY clause in a CREATE TABLE statement
*
* ----------
*/
typedef struct DistributeBy {
NodeTag type;
DistributionType disttype;
List* colname;
DistState* distState;
Oid referenceoid;
} DistributeBy;
* SubClusterType - type of subcluster used
*
* ----------
*/
typedef enum PGXCSubClusterType { SUBCLUSTER_NONE, SUBCLUSTER_NODE, SUBCLUSTER_GROUP } PGXCSubClusterType;
* PGXCSubCluster - Subcluster on which a table can be created
*
* ----------
*/
typedef struct PGXCSubCluster {
NodeTag type;
PGXCSubClusterType clustertype;
List* members;
} PGXCSubCluster;
#endif
typedef struct {
NodeTag type;
Oid relid;
AttrNumber attno;
char* relname;
char* attname;
bool indexcol;
List* indexoids;
bool indexpath;
} IndexVar;
typedef struct UpsertExpr {
NodeTag type;
UpsertAction upsertAction;
List* updateTlist;
List* exclRelTlist;
int exclRelIndex;
Node* upsertWhere;
} UpsertExpr;
#ifdef USE_SPQ
* DMLActionExpr
*
* Represents the expression which introduces the action in a SplitUpdate statement
*/
typedef struct DMLActionExpr {
Expr xpr;
} DMLActionExpr;
#endif
* DB4AI
*/
#define DB4AI_SNAPSHOT_VERSION_DELIMITER 1
#define DB4AI_SNAPSHOT_VERSION_SEPARATOR 2
#endif