1996-08-28 03:59:28 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* primnodes.h
|
2000-09-12 23:07:18 +02:00
|
|
|
* 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.
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
*
|
2001-01-24 20:43:33 +01:00
|
|
|
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
2001-11-05 18:46:40 +01:00
|
|
|
* $Id: primnodes.h,v 1.57 2001/11/05 17:46:34 momjian Exp $
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef PRIMNODES_H
|
1997-09-07 07:04:48 +02:00
|
|
|
#define PRIMNODES_H
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1999-07-16 01:04:24 +02:00
|
|
|
#include "access/attnum.h"
|
|
|
|
#include "nodes/pg_list.h"
|
2000-08-24 05:29:15 +02:00
|
|
|
|
|
|
|
/* FunctionCache is declared in utils/fcache.h */
|
|
|
|
typedef struct FunctionCache *FunctionCachePtr;
|
|
|
|
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/* ----------------------------------------------------------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* node definitions
|
1996-08-28 03:59:28 +02:00
|
|
|
* ----------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2001-02-14 22:35:07 +01:00
|
|
|
/*--------------------
|
1996-08-28 03:59:28 +02:00
|
|
|
* Resdom (Result Domain)
|
|
|
|
*
|
1999-08-21 05:49:17 +02:00
|
|
|
* Notes:
|
|
|
|
* ressortgroupref is the parse/plan-time representation of ORDER BY and
|
2000-04-12 19:17:23 +02:00
|
|
|
* GROUP BY items. Targetlist entries with ressortgroupref=0 are not
|
1999-08-21 05:49:17 +02:00
|
|
|
* sort/group items. If ressortgroupref>0, then this item is an ORDER BY or
|
2000-04-12 19:17:23 +02:00
|
|
|
* GROUP BY value. No two entries in a targetlist may have the same nonzero
|
1999-08-21 05:49:17 +02:00
|
|
|
* ressortgroupref --- but there is no particular meaning to the nonzero
|
2000-04-12 19:17:23 +02:00
|
|
|
* values, except as tags. (For example, one must not assume that lower
|
|
|
|
* ressortgroupref means a more significant sort key.) The order of the
|
1999-08-21 05:49:17 +02:00
|
|
|
* associated SortClause or GroupClause lists determine the semantics.
|
|
|
|
*
|
|
|
|
* reskey and reskeyop are the execution-time representation of sorting.
|
|
|
|
* reskey must be zero in any non-sort-key item. The reskey of sort key
|
|
|
|
* targetlist items for a sort plan node is 1,2,...,n for the n sort keys.
|
2001-05-07 02:43:27 +02:00
|
|
|
* The reskeyop of each such targetlist item is the sort operator's OID.
|
|
|
|
* reskeyop will be zero in non-sort-key items.
|
1999-08-21 05:49:17 +02:00
|
|
|
*
|
|
|
|
* Both reskey and reskeyop are typically zero during parse/plan stages.
|
|
|
|
* The executor does not pay any attention to ressortgroupref.
|
2001-02-14 22:35:07 +01:00
|
|
|
*--------------------
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct Resdom
|
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
NodeTag type;
|
|
|
|
AttrNumber resno; /* attribute number */
|
|
|
|
Oid restype; /* type of the value */
|
|
|
|
int32 restypmod; /* type-specific modifier of the value */
|
|
|
|
char *resname; /* name of the resdom (could be NULL) */
|
1999-08-21 05:49:17 +02:00
|
|
|
Index ressortgroupref;
|
2001-03-22 05:01:46 +01:00
|
|
|
/* nonzero if referenced by a sort/group clause */
|
|
|
|
Index reskey; /* order of key in a sort (for those > 0) */
|
2001-05-07 02:43:27 +02:00
|
|
|
Oid reskeyop; /* sort operator's Oid */
|
2001-03-22 05:01:46 +01:00
|
|
|
bool resjunk; /* set to true to eliminate the attribute
|
|
|
|
* from final target list */
|
1997-09-08 23:56:23 +02:00
|
|
|
} Resdom;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2001-01-17 07:41:31 +01:00
|
|
|
/*
|
1996-08-28 03:59:28 +02:00
|
|
|
* Fjoin
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct Fjoin
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
NodeTag type;
|
2001-03-22 05:01:46 +01:00
|
|
|
bool fj_initialized; /* true if the Fjoin has already been
|
|
|
|
* initialized for the current target list
|
|
|
|
* evaluation */
|
|
|
|
int fj_nNodes; /* The number of Iter nodes returning sets
|
|
|
|
* that the node will flatten */
|
2001-01-17 07:41:31 +01:00
|
|
|
List *fj_innerNode; /* exactly one Iter node. We eval every
|
|
|
|
* node in the outerList once then eval
|
|
|
|
* the inner node to completion pair the
|
|
|
|
* outerList result vector with each inner
|
2001-03-22 05:01:46 +01:00
|
|
|
* result to form the full result. When
|
2001-01-17 07:41:31 +01:00
|
|
|
* the inner has been exhausted, we get
|
|
|
|
* the next outer result vector and reset
|
2001-03-22 05:01:46 +01:00
|
|
|
* the inner. */
|
2001-01-17 07:41:31 +01:00
|
|
|
DatumPtr fj_results; /* The complete (flattened) result vector */
|
|
|
|
BoolPtr fj_alwaysDone; /* a null vector to indicate sets with a
|
|
|
|
* cardinality of 0, we treat them as the
|
2001-03-22 05:01:46 +01:00
|
|
|
* set {NULL}. */
|
1997-09-08 23:56:23 +02:00
|
|
|
} Fjoin;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2000-09-12 23:07:18 +02:00
|
|
|
|
|
|
|
/* ----------------------------------------------------------------
|
|
|
|
* node types for executable expressions
|
|
|
|
* ----------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2001-01-17 07:41:31 +01:00
|
|
|
/*
|
1996-08-28 03:59:28 +02:00
|
|
|
* Expr
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef enum OpType
|
|
|
|
{
|
2001-10-28 07:26:15 +01:00
|
|
|
OP_EXPR, FUNC_EXPR, OR_EXPR, AND_EXPR, NOT_EXPR, SUBPLAN_EXPR
|
1997-09-08 23:56:23 +02:00
|
|
|
} OpType;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct Expr
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
NodeTag type;
|
2001-03-22 05:01:46 +01:00
|
|
|
Oid typeOid; /* oid of the type of this expression */
|
|
|
|
OpType opType; /* type of this expression */
|
|
|
|
Node *oper; /* operator node if needed (Oper, Func, or
|
|
|
|
* SubPlan) */
|
|
|
|
List *args; /* arguments to this expression */
|
1997-09-08 23:56:23 +02:00
|
|
|
} Expr;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2001-01-17 07:41:31 +01:00
|
|
|
/*
|
1996-08-28 03:59:28 +02:00
|
|
|
* Var
|
1999-08-22 22:15:04 +02:00
|
|
|
*
|
|
|
|
* 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 or OUTER 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.
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
#define INNER 65000
|
|
|
|
#define OUTER 65001
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2000-06-12 21:40:58 +02:00
|
|
|
#define PRS2_OLD_VARNO 1
|
|
|
|
#define PRS2_NEW_VARNO 2
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct Var
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
NodeTag type;
|
2001-03-22 05:01:46 +01:00
|
|
|
Index varno; /* index of this var's relation in the
|
|
|
|
* range table (could also be INNER or
|
|
|
|
* OUTER) */
|
|
|
|
AttrNumber varattno; /* attribute number of this var, or zero
|
|
|
|
* for all */
|
|
|
|
Oid vartype; /* pg_type tuple OID for the type of this
|
|
|
|
* var */
|
|
|
|
int32 vartypmod; /* pg_attribute typmod value */
|
2000-09-12 23:07:18 +02:00
|
|
|
Index varlevelsup;
|
2001-03-22 05:01:46 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* for subquery variables referencing outer relations; 0 in a normal
|
|
|
|
* var, >0 means N levels up
|
|
|
|
*/
|
|
|
|
Index varnoold; /* original value of varno, for debugging */
|
|
|
|
AttrNumber varoattno; /* original value of varattno */
|
1997-09-08 23:56:23 +02:00
|
|
|
} Var;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2001-02-14 22:35:07 +01:00
|
|
|
/*--------------------
|
1996-08-28 03:59:28 +02:00
|
|
|
* Oper
|
|
|
|
*
|
|
|
|
* NOTE: in the good old days 'opno' used to be both (or either, or
|
1997-09-07 07:04:48 +02:00
|
|
|
* neither) the pg_operator oid, and/or the pg_proc oid depending
|
1996-08-28 03:59:28 +02:00
|
|
|
* on the postgres module in question (parser->pg_operator,
|
|
|
|
* executor->pg_proc, planner->both), the mood of the programmer,
|
|
|
|
* and the phase of the moon (rumors that it was also depending on the day
|
|
|
|
* of the week are probably false). To make things even more postgres-like
|
|
|
|
* (i.e. a mess) some comments were referring to 'opno' using the name
|
|
|
|
* 'opid'. Anyway, now we have two separate fields, and of course that
|
1997-09-07 07:04:48 +02:00
|
|
|
* immediately removes all bugs from the code... [ sp :-) ].
|
2000-08-08 17:43:12 +02:00
|
|
|
*
|
|
|
|
* Note also that opid 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 opid is typically 0.
|
2001-02-14 22:35:07 +01:00
|
|
|
*--------------------
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct Oper
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
NodeTag type;
|
2001-03-22 05:01:46 +01:00
|
|
|
Oid opno; /* PG_OPERATOR OID of the operator */
|
|
|
|
Oid opid; /* PG_PROC OID for the operator's
|
|
|
|
* underlying function */
|
1997-09-08 04:41:22 +02:00
|
|
|
Oid opresulttype;
|
2001-03-22 05:01:46 +01:00
|
|
|
/* PG_TYPE OID of the operator's return value */
|
1997-09-07 07:04:48 +02:00
|
|
|
FunctionCachePtr op_fcache;
|
2001-03-22 05:01:46 +01:00
|
|
|
/* runtime state while running the function */
|
1997-09-08 23:56:23 +02:00
|
|
|
} Oper;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
|
2001-01-17 07:41:31 +01:00
|
|
|
/*
|
1996-08-28 03:59:28 +02:00
|
|
|
* Const
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct Const
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
NodeTag type;
|
2001-01-17 07:41:31 +01:00
|
|
|
Oid consttype; /* PG_TYPE OID of the constant's value */
|
|
|
|
int constlen; /* length in bytes of the constant's value */
|
|
|
|
Datum constvalue; /* the constant's value */
|
|
|
|
bool constisnull; /* whether the constant is null (if true,
|
|
|
|
* the other fields are undefined) */
|
|
|
|
bool constbyval; /* whether the information in constvalue
|
2001-03-22 05:01:46 +01:00
|
|
|
* if passed by value. If true, then all
|
2001-01-17 07:41:31 +01:00
|
|
|
* the information is stored in the datum.
|
2001-03-22 05:01:46 +01:00
|
|
|
* If false, then the datum contains a
|
|
|
|
* pointer to the information. */
|
|
|
|
bool constisset; /* whether the const represents a set. The
|
|
|
|
* const value corresponding will be the
|
2001-01-17 07:41:31 +01:00
|
|
|
* query that defines the set. */
|
1997-09-08 04:41:22 +02:00
|
|
|
bool constiscast;
|
1997-09-08 23:56:23 +02:00
|
|
|
} Const;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* Param
|
1997-09-07 07:04:48 +02:00
|
|
|
* paramkind - specifies the kind of parameter. The possible values
|
|
|
|
* for this field are specified in "params.h", and they are:
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* PARAM_NAMED: The parameter has a name, i.e. something
|
|
|
|
* like `$.salary' or `$.foobar'.
|
|
|
|
* In this case field `paramname' must be a valid Name.
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* PARAM_NUM: The parameter has only a numeric identifier,
|
|
|
|
* i.e. something like `$1', `$2' etc.
|
|
|
|
* The number is contained in the `paramid' field.
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* PARAM_NEW: Used in PRS2 rule, similar to PARAM_NAMED.
|
|
|
|
* The `paramname' and `paramid' refer to the "NEW" tuple
|
|
|
|
* The `pramname' is the attribute name and `paramid'
|
|
|
|
* is the attribute number.
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* PARAM_OLD: Same as PARAM_NEW, but in this case we refer to
|
|
|
|
* the "OLD" tuple.
|
1996-08-28 03:59:28 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct Param
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
NodeTag type;
|
2001-03-22 05:01:46 +01:00
|
|
|
int paramkind; /* specifies the kind of parameter. See
|
|
|
|
* above */
|
|
|
|
AttrNumber paramid; /* numeric identifier for literal-constant
|
|
|
|
* parameters ("$1") */
|
|
|
|
char *paramname; /* attribute name for tuple-substitution
|
|
|
|
* parameters ("$.foo") */
|
|
|
|
Oid paramtype; /* PG_TYPE OID of the parameter's value */
|
1997-09-08 23:56:23 +02:00
|
|
|
} Param;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
|
2001-01-17 07:41:31 +01:00
|
|
|
/*
|
1996-08-28 03:59:28 +02:00
|
|
|
* Func
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct Func
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
NodeTag type;
|
2001-03-22 05:01:46 +01:00
|
|
|
Oid funcid; /* PG_PROC OID of the function */
|
|
|
|
Oid functype; /* PG_TYPE OID of the function's return
|
|
|
|
* value */
|
1997-09-07 07:04:48 +02:00
|
|
|
FunctionCachePtr func_fcache;
|
2001-03-22 05:01:46 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* runtime state while running this function. Where we are in the
|
|
|
|
* execution of the function if it returns more than one value, etc.
|
|
|
|
* See utils/fcache.h
|
|
|
|
*/
|
1997-09-08 23:56:23 +02:00
|
|
|
} Func;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1999-08-16 04:17:58 +02:00
|
|
|
/* ----------------
|
|
|
|
* Iter
|
|
|
|
* can anyone explain what this is for? Seems to have something to do
|
|
|
|
* with evaluation of functions that return sets...
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
typedef struct Iter
|
|
|
|
{
|
|
|
|
NodeTag type;
|
|
|
|
Node *iterexpr;
|
|
|
|
Oid itertype; /* type of the iter expr (use for type
|
|
|
|
* checking) */
|
|
|
|
} Iter;
|
|
|
|
|
2001-01-17 07:41:31 +01:00
|
|
|
/*
|
1999-01-24 01:28:37 +01:00
|
|
|
* Aggref
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
1999-01-24 01:28:37 +01:00
|
|
|
typedef struct Aggref
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
NodeTag type;
|
2001-03-22 05:01:46 +01:00
|
|
|
char *aggname; /* name of the aggregate */
|
|
|
|
Oid basetype; /* base type Oid of the aggregate (ie,
|
|
|
|
* input type) */
|
|
|
|
Oid aggtype; /* type Oid of final result of the
|
|
|
|
* aggregate */
|
|
|
|
Node *target; /* attribute or expression we are
|
|
|
|
* aggregating on */
|
|
|
|
bool aggstar; /* TRUE if argument was really '*' */
|
|
|
|
bool aggdistinct; /* TRUE if it's agg(DISTINCT ...) */
|
|
|
|
int aggno; /* workspace for executor (see nodeAgg.c) */
|
1999-05-26 00:43:53 +02:00
|
|
|
} Aggref;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1998-01-17 05:53:46 +01:00
|
|
|
/* ----------------
|
|
|
|
* SubLink
|
1999-08-26 01:21:43 +02:00
|
|
|
*
|
1999-11-15 03:00:15 +01:00
|
|
|
* A SubLink represents a subselect appearing in an expression, and in some
|
2000-04-12 19:17:23 +02:00
|
|
|
* cases also the combining operator(s) just above it. The subLinkType
|
1999-11-15 03:00:15 +01:00
|
|
|
* indicates the form of the expression represented:
|
|
|
|
* EXISTS_SUBLINK EXISTS(SELECT ...)
|
|
|
|
* ALL_SUBLINK (lefthand) op ALL (SELECT ...)
|
|
|
|
* ANY_SUBLINK (lefthand) op ANY (SELECT ...)
|
|
|
|
* MULTIEXPR_SUBLINK (lefthand) op (SELECT ...)
|
|
|
|
* EXPR_SUBLINK (SELECT with single targetlist item ...)
|
|
|
|
* For ALL, ANY, and MULTIEXPR, the lefthand is a list of expressions of the
|
|
|
|
* same length as the subselect's targetlist. MULTIEXPR 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
|
|
|
|
* MULTIEXPR and EXPR require the subselect to deliver only one row.
|
|
|
|
* ALL, ANY, and MULTIEXPR require the combining operators to deliver boolean
|
|
|
|
* results. These are reduced to one result per row using OR or AND semantics
|
|
|
|
* depending on the "useor" flag. ALL and ANY combine the per-row results
|
|
|
|
* using AND and OR semantics respectively.
|
|
|
|
*
|
1999-08-26 01:21:43 +02:00
|
|
|
* NOTE: lefthand and oper have varying meanings depending on where you look
|
|
|
|
* in the parse/plan pipeline:
|
|
|
|
* 1. gram.y delivers a list of the (untransformed) lefthand expressions in
|
2000-05-26 00:42:19 +02:00
|
|
|
* lefthand, and sets oper to a single A_Expr (not a list!) containing
|
|
|
|
* the string name of the operator, but no arguments.
|
1999-08-26 01:21:43 +02:00
|
|
|
* 2. The parser's expression transformation transforms lefthand normally,
|
2000-04-12 19:17:23 +02:00
|
|
|
* and replaces oper with a list of Oper nodes, one per lefthand
|
|
|
|
* expression. These nodes represent the parser's resolution of exactly
|
|
|
|
* which operator to apply to each pair of lefthand and targetlist
|
|
|
|
* expressions. However, we have not constructed actual Expr trees for
|
|
|
|
* these operators yet. This is the representation seen in saved rules
|
|
|
|
* and in the rewriter.
|
1999-08-26 01:21:43 +02:00
|
|
|
* 3. Finally, the planner converts the oper list to a list of normal Expr
|
2000-04-12 19:17:23 +02:00
|
|
|
* nodes representing the application of the operator(s) to the lefthand
|
|
|
|
* expressions and values from the inner targetlist. The inner
|
|
|
|
* targetlist items are represented by placeholder Param or Const nodes.
|
|
|
|
* The lefthand field is set to NIL, since its expressions are now in
|
|
|
|
* the Expr list. This representation is passed to the executor.
|
1999-08-26 01:21:43 +02:00
|
|
|
*
|
|
|
|
* Planner routines that might see either representation 2 or 3 can tell
|
|
|
|
* the difference by checking whether lefthand is NIL or not. Also,
|
|
|
|
* representation 2 appears in a "bare" SubLink, while representation 3 is
|
|
|
|
* found in SubLinks that are children of SubPlan nodes.
|
|
|
|
*
|
1999-11-15 03:00:15 +01:00
|
|
|
* In EXISTS and EXPR SubLinks, both lefthand and oper are unused and are
|
2000-04-12 19:17:23 +02:00
|
|
|
* always NIL. useor is not significant either for these sublink types.
|
1998-01-17 05:53:46 +01:00
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
typedef enum SubLinkType
|
|
|
|
{
|
2001-10-28 07:26:15 +01:00
|
|
|
EXISTS_SUBLINK, ALL_SUBLINK, ANY_SUBLINK, MULTIEXPR_SUBLINK, EXPR_SUBLINK
|
1998-01-17 05:53:46 +01:00
|
|
|
} SubLinkType;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct SubLink
|
|
|
|
{
|
|
|
|
NodeTag type;
|
2001-03-22 05:01:46 +01:00
|
|
|
SubLinkType subLinkType; /* EXISTS, ALL, ANY, MULTIEXPR, EXPR */
|
|
|
|
bool useor; /* TRUE to combine column results with
|
|
|
|
* "OR" not "AND" */
|
|
|
|
List *lefthand; /* list of outer-query expressions on the
|
|
|
|
* left */
|
|
|
|
List *oper; /* list of Oper nodes for combining
|
|
|
|
* operators */
|
|
|
|
Node *subselect; /* subselect as Query* or parsetree */
|
1998-01-17 05:53:46 +01:00
|
|
|
} SubLink;
|
|
|
|
|
1996-08-28 03:59:28 +02:00
|
|
|
/* ----------------
|
1999-07-18 05:45:01 +02:00
|
|
|
* 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
|
2000-07-22 06:22:47 +02:00
|
|
|
* appropriate part of the array; the result of the operation is an
|
|
|
|
* entire new modified array value.
|
1999-07-18 05:45:01 +02:00
|
|
|
*
|
|
|
|
* If reflowerindexpr = NIL, then we are fetching or storing a single array
|
2000-04-12 19:17:23 +02:00
|
|
|
* element at the subscripts given by refupperindexpr. Otherwise we are
|
1999-07-18 05:45:01 +02:00
|
|
|
* 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: array types can be fixed-length (refattrlength > 0), but only
|
|
|
|
* when the element type is itself fixed-length. Otherwise they are
|
2000-04-12 19:17:23 +02:00
|
|
|
* varlena structures and have refattrlength = -1. In any case,
|
1999-07-18 05:45:01 +02:00
|
|
|
* an array type is never pass-by-value.
|
|
|
|
*
|
|
|
|
* Note: currently, refelemtype is NOT the element type, but the array type,
|
|
|
|
* when doing subarray fetch or either type of store. It would be cleaner
|
|
|
|
* to add more fields so we can distinguish the array element type from the
|
2000-07-22 06:22:47 +02:00
|
|
|
* result type of the ArrayRef operator...
|
1996-08-28 03:59:28 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct ArrayRef
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
NodeTag type;
|
2001-03-22 05:01:46 +01:00
|
|
|
int refattrlength; /* typlen of array type */
|
|
|
|
int refelemlength; /* typlen of the array element type */
|
|
|
|
Oid refelemtype; /* type of the result of the ArrayRef
|
|
|
|
* operation */
|
|
|
|
bool refelembyval; /* is the element type pass-by-value? */
|
|
|
|
List *refupperindexpr;/* expressions that evaluate to upper
|
|
|
|
* array indexes */
|
|
|
|
List *reflowerindexpr;/* expressions that evaluate to lower
|
|
|
|
* array indexes */
|
|
|
|
Node *refexpr; /* the expression that evaluates to an
|
|
|
|
* array value */
|
|
|
|
Node *refassgnexpr; /* expression for the source value, or
|
|
|
|
* NULL if fetch */
|
1997-09-08 22:59:27 +02:00
|
|
|
} ArrayRef;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2000-08-08 17:43:12 +02:00
|
|
|
/* ----------------
|
|
|
|
* FieldSelect
|
|
|
|
*
|
|
|
|
* FieldSelect represents the operation of extracting one field from a tuple
|
|
|
|
* value. At runtime, the input expression is expected to yield a Datum
|
|
|
|
* that contains a pointer-to-TupleTableSlot. The specified field number
|
|
|
|
* is extracted and returned as a Datum.
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef struct FieldSelect
|
|
|
|
{
|
|
|
|
NodeTag type;
|
2001-01-17 07:41:31 +01:00
|
|
|
Node *arg; /* input expression */
|
|
|
|
AttrNumber fieldnum; /* attribute number of field to extract */
|
|
|
|
Oid resulttype; /* type of the field (result type of this
|
|
|
|
* node) */
|
|
|
|
int32 resulttypmod; /* output typmod (usually -1) */
|
2000-08-08 17:43:12 +02:00
|
|
|
} FieldSelect;
|
|
|
|
|
2000-02-20 22:32:16 +01:00
|
|
|
/* ----------------
|
|
|
|
* 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
|
|
|
|
{
|
|
|
|
NodeTag type;
|
2001-01-17 07:41:31 +01:00
|
|
|
Node *arg; /* input expression */
|
|
|
|
Oid resulttype; /* output type of coercion expression */
|
|
|
|
int32 resulttypmod; /* output typmod (usually -1) */
|
2000-02-20 22:32:16 +01:00
|
|
|
} RelabelType;
|
|
|
|
|
2000-09-12 23:07:18 +02:00
|
|
|
|
|
|
|
/* ----------------------------------------------------------------
|
|
|
|
* 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
|
2000-09-29 20:21:41 +02:00
|
|
|
* 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. Also, there is an
|
|
|
|
* implementation-defined difference: the planner is allowed to join the
|
|
|
|
* children of a FromExpr using whatever join order seems good to it.
|
|
|
|
* At present, JoinExpr nodes are always joined in exactly the order
|
|
|
|
* implied by the jointree structure (except the planner may choose to
|
|
|
|
* swap inner and outer members of a join pair).
|
|
|
|
*
|
|
|
|
* 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.
|
2000-09-12 23:07:18 +02:00
|
|
|
*
|
|
|
|
* NOTE: the qualification expressions present in JoinExpr nodes are
|
2000-09-29 20:21:41 +02:00
|
|
|
* *in addition to* the query's main WHERE clause, which appears as the
|
2001-03-22 05:01:46 +01:00
|
|
|
* qual of the top-level FromExpr. The reason for associating quals with
|
2000-09-29 20:21:41 +02:00
|
|
|
* 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.
|
2000-09-12 23:07:18 +02:00
|
|
|
*
|
|
|
|
* NOTE: in the raw output of gram.y, a join tree contains RangeVar and
|
|
|
|
* RangeSubselect nodes, which are both replaced by RangeTblRef nodes
|
2000-09-29 20:21:41 +02:00
|
|
|
* during the parse analysis phase. Also, the top-level FromExpr is added
|
|
|
|
* during parse analysis; the grammar regards FROM and WHERE as separate.
|
2000-09-12 23:07:18 +02:00
|
|
|
* ----------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*
|
2001-03-22 05:01:46 +01:00
|
|
|
* isNatural, using, and quals are interdependent. The user can write only
|
2000-09-12 23:07:18 +02:00
|
|
|
* 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.
|
2001-03-22 05:01:46 +01:00
|
|
|
* If he writes ON() then only "quals" is set. Note that NATURAL/USING
|
2000-09-12 23:07:18 +02:00
|
|
|
* are not equivalent to ON() since they also affect the output column list.
|
|
|
|
*
|
|
|
|
* alias is an Attr node representing the AS alias-clause attached to the
|
2001-02-14 22:35:07 +01:00
|
|
|
* 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, colnames is filled with a list of String nodes
|
|
|
|
* giving the column names (real or alias) of the output of the join,
|
|
|
|
* and colvars is filled with a list of expressions that can be copied to
|
|
|
|
* reference the output columns.
|
2000-09-12 23:07:18 +02:00
|
|
|
*----------
|
|
|
|
*/
|
|
|
|
typedef struct JoinExpr
|
|
|
|
{
|
|
|
|
NodeTag type;
|
|
|
|
JoinType jointype; /* type of join */
|
|
|
|
bool isNatural; /* Natural join? Will need to shape table */
|
|
|
|
Node *larg; /* left subtree */
|
|
|
|
Node *rarg; /* right subtree */
|
|
|
|
List *using; /* USING clause, if any (list of String) */
|
|
|
|
Node *quals; /* qualifiers on join, if any */
|
|
|
|
struct Attr *alias; /* user-written alias clause, if any */
|
|
|
|
List *colnames; /* output column names (list of String) */
|
2001-03-22 05:01:46 +01:00
|
|
|
List *colvars; /* output column nodes (list of
|
|
|
|
* expressions) */
|
2000-09-12 23:07:18 +02:00
|
|
|
} JoinExpr;
|
|
|
|
|
2000-09-29 20:21:41 +02:00
|
|
|
/*----------
|
|
|
|
* 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; /* List of join subtrees */
|
|
|
|
Node *quals; /* qualifiers on join, if any */
|
|
|
|
} FromExpr;
|
2001-10-28 07:26:15 +01:00
|
|
|
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* PRIMNODES_H */
|