Commit cf68a686 authored by Tom Lane's avatar Tom Lane

Fix copying/equality-check bugs in GrantStmt and ConstraintsSetStmt,

per reports from Fernando Nasser.  Also, rearrange order of declarations
in parsenodes.h as suggested by Fernando.
parent 54f4136a
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.104 2002/03/06 06:09:36 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.105 2002/03/08 04:37:14 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1781,6 +1781,7 @@ DeferredTriggerSetState(ConstraintsSetStmt *stmt) ...@@ -1781,6 +1781,7 @@ DeferredTriggerSetState(ConstraintsSetStmt *stmt)
foreach(l, stmt->constraints) foreach(l, stmt->constraints)
{ {
char *cname = strVal(lfirst(l));
ScanKeyData skey; ScanKeyData skey;
SysScanDesc tgscan; SysScanDesc tgscan;
HeapTuple htup; HeapTuple htup;
...@@ -1788,7 +1789,7 @@ DeferredTriggerSetState(ConstraintsSetStmt *stmt) ...@@ -1788,7 +1789,7 @@ DeferredTriggerSetState(ConstraintsSetStmt *stmt)
/* /*
* Check that only named constraints are set explicitly * Check that only named constraints are set explicitly
*/ */
if (strcmp((char *) lfirst(l), "") == 0) if (strlen(cname) == 0)
elog(ERROR, "unnamed constraints cannot be set explicitly"); elog(ERROR, "unnamed constraints cannot be set explicitly");
/* /*
...@@ -1798,7 +1799,7 @@ DeferredTriggerSetState(ConstraintsSetStmt *stmt) ...@@ -1798,7 +1799,7 @@ DeferredTriggerSetState(ConstraintsSetStmt *stmt)
(bits16) 0x0, (bits16) 0x0,
(AttrNumber) Anum_pg_trigger_tgconstrname, (AttrNumber) Anum_pg_trigger_tgconstrname,
(RegProcedure) F_NAMEEQ, (RegProcedure) F_NAMEEQ,
PointerGetDatum((char *) lfirst(l))); PointerGetDatum(cname));
tgscan = systable_beginscan(tgrel, TriggerConstrNameIndex, true, tgscan = systable_beginscan(tgrel, TriggerConstrNameIndex, true,
SnapshotNow, 1, &skey); SnapshotNow, 1, &skey);
...@@ -1822,7 +1823,7 @@ DeferredTriggerSetState(ConstraintsSetStmt *stmt) ...@@ -1822,7 +1823,7 @@ DeferredTriggerSetState(ConstraintsSetStmt *stmt)
pg_trigger->tgfoid != F_RI_FKEY_RESTRICT_UPD && pg_trigger->tgfoid != F_RI_FKEY_RESTRICT_UPD &&
pg_trigger->tgfoid != F_RI_FKEY_RESTRICT_DEL) pg_trigger->tgfoid != F_RI_FKEY_RESTRICT_DEL)
elog(ERROR, "Constraint '%s' is not deferrable", elog(ERROR, "Constraint '%s' is not deferrable",
(char *) lfirst(l)); cname);
constr_oid = htup->t_data->t_oid; constr_oid = htup->t_data->t_oid;
loid = lappendi(loid, constr_oid); loid = lappendi(loid, constr_oid);
...@@ -1835,7 +1836,7 @@ DeferredTriggerSetState(ConstraintsSetStmt *stmt) ...@@ -1835,7 +1836,7 @@ DeferredTriggerSetState(ConstraintsSetStmt *stmt)
* Not found ? * Not found ?
*/ */
if (!found) if (!found)
elog(ERROR, "Constraint '%s' does not exist", (char *) lfirst(l)); elog(ERROR, "Constraint '%s' does not exist", cname);
} }
heap_close(tgrel, AccessShareLock); heap_close(tgrel, AccessShareLock);
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.167 2002/03/07 16:35:34 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.168 2002/03/08 04:37:16 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1898,7 +1898,7 @@ _copyGrantStmt(GrantStmt *from) ...@@ -1898,7 +1898,7 @@ _copyGrantStmt(GrantStmt *from)
newnode->is_grant = from->is_grant; newnode->is_grant = from->is_grant;
newnode->objtype = from->objtype; newnode->objtype = from->objtype;
Node_Copy(from, newnode, objects); Node_Copy(from, newnode, objects);
Node_Copy(from, newnode, privileges); newnode->privileges = listCopy(from->privileges);
Node_Copy(from, newnode, grantees); Node_Copy(from, newnode, grantees);
return newnode; return newnode;
...@@ -1924,8 +1924,6 @@ _copyFuncWithArgs(FuncWithArgs *from) ...@@ -1924,8 +1924,6 @@ _copyFuncWithArgs(FuncWithArgs *from)
if (from->funcname) if (from->funcname)
newnode->funcname = pstrdup(from->funcname); newnode->funcname = pstrdup(from->funcname);
else
newnode->funcname = NULL;
Node_Copy(from, newnode, funcargs); Node_Copy(from, newnode, funcargs);
return newnode; return newnode;
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.115 2002/03/07 16:35:34 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.116 2002/03/08 04:37:16 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -763,7 +763,7 @@ _equalGrantStmt(GrantStmt *a, GrantStmt *b) ...@@ -763,7 +763,7 @@ _equalGrantStmt(GrantStmt *a, GrantStmt *b)
return false; return false;
if (!equal(a->objects, b->objects)) if (!equal(a->objects, b->objects))
return false; return false;
if (!equal(a->privileges, b->privileges)) if (!equali(a->privileges, b->privileges))
return false; return false;
if (!equal(a->grantees, b->grantees)) if (!equal(a->grantees, b->grantees))
return false; return false;
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.287 2002/03/07 16:35:35 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.288 2002/03/08 04:37:17 tgl Exp $
* *
* HISTORY * HISTORY
* AUTHOR DATE MAJOR EVENT * AUTHOR DATE MAJOR EVENT
...@@ -286,7 +286,6 @@ static void doNegateFloat(Value *v); ...@@ -286,7 +286,6 @@ static void doNegateFloat(Value *v);
ConstraintTimeSpec ConstraintTimeSpec
%type <list> constraints_set_list %type <list> constraints_set_list
%type <list> constraints_set_namelist
%type <boolean> constraints_set_mode %type <boolean> constraints_set_mode
/* /*
...@@ -1034,37 +1033,12 @@ ConstraintsSetStmt: SET CONSTRAINTS constraints_set_list constraints_set_mode ...@@ -1034,37 +1033,12 @@ ConstraintsSetStmt: SET CONSTRAINTS constraints_set_list constraints_set_mode
} }
; ;
constraints_set_list: ALL { $$ = NIL; }
constraints_set_list: ALL | name_list { $$ = $1; }
{
$$ = NIL;
}
| constraints_set_namelist
{
$$ = $1;
}
; ;
constraints_set_mode: DEFERRED { $$ = TRUE; }
constraints_set_namelist: ColId | IMMEDIATE { $$ = FALSE; }
{
$$ = makeList1($1);
}
| constraints_set_namelist ',' ColId
{
$$ = lappend($1, $3);
}
;
constraints_set_mode: DEFERRED
{
$$ = TRUE;
}
| IMMEDIATE
{
$$ = FALSE;
}
; ;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: parsenodes.h,v 1.158 2002/03/07 16:35:40 momjian Exp $ * $Id: parsenodes.h,v 1.159 2002/03/08 04:37:18 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -16,6 +16,15 @@ ...@@ -16,6 +16,15 @@
#include "nodes/primnodes.h" #include "nodes/primnodes.h"
typedef enum InhOption
{
INH_NO, /* Do NOT scan child tables */
INH_YES, /* DO scan child tables */
INH_DEFAULT /* Use current SQL_inheritance option */
} InhOption;
/***************************************************************************** /*****************************************************************************
* Query Tree * Query Tree
*****************************************************************************/ *****************************************************************************/
...@@ -93,1308 +102,1294 @@ typedef struct Query ...@@ -93,1308 +102,1294 @@ typedef struct Query
} Query; } Query;
typedef enum InhOption /****************************************************************************
{ * Supporting data structures for Parse Trees
INH_NO, /* Do NOT scan child tables */
INH_YES, /* DO scan child tables */
INH_DEFAULT /* Use current SQL_inheritance option */
} InhOption;
/*****************************************************************************
* Other Statements (no optimizations required)
* *
* Some of them require a little bit of transformation (which is also * Most of these node types appear in raw parsetrees output by the grammar,
* done by transformStmt). The whole structure is then passed on to * and get transformed to something else by the analyzer. A few of them
* ProcessUtility (by-passing the optimization step) as the utilityStmt * are used as-is in transformed querytrees.
* field in Query. ****************************************************************************/
*****************************************************************************/
/* ---------------------- /*
* Alter Table * TypeName - specifies a type in definitions
*
* The fields are used in different ways by the different variants of
* this command.
* ----------------------
*/ */
typedef struct AlterTableStmt typedef struct TypeName
{ {
NodeTag type; NodeTag type;
char subtype; /*------------ char *name; /* name of the type */
* A = add column bool timezone; /* timezone specified? */
* T = alter column default bool setof; /* is a set? */
* S = alter column statistics int32 typmod; /* type modifier */
* M = alter column storage List *arrayBounds; /* array bounds */
* D = drop column char *attrname; /* field name when using %TYPE */
* C = add constraint } TypeName;
* X = drop constraint
* E = create toast table
* U = change owner
*------------
*/
char *relname; /* table to work on */
InhOption inhOpt; /* recursively act on children? */
char *name; /* column or constraint name to act on, or
* new owner */
Node *def; /* definition of new column or constraint */
int behavior; /* CASCADE or RESTRICT drop behavior */
} AlterTableStmt;
/* ---------------------- /*
* Grant Statement * ParamNo - specifies a parameter reference
* ----------------------
*/ */
typedef struct ParamNo
typedef struct GrantStmt
{ {
NodeTag type; NodeTag type;
bool is_grant; /* not revoke */ int number; /* the number of the parameter */
int objtype; TypeName *typename; /* the typecast */
List *objects; List *indirection; /* array references */
List *privileges; } ParamNo;
List *grantees;
} GrantStmt;
typedef struct PrivGrantee /*
* A_Expr - binary expressions
*/
typedef struct A_Expr
{ {
NodeTag type; NodeTag type;
char *username; /* if both are NULL then PUBLIC */ int oper; /* type of operation (OP,OR,AND,NOT) */
char *groupname; char *opname; /* name of operator */
} PrivGrantee; Node *lexpr; /* left argument */
Node *rexpr; /* right argument */
} A_Expr;
typedef struct FuncWithArgs /*
* Attr -
* specifies an Attribute (ie. a Column); could have nested dots or
* array references.
*
*/
typedef struct Attr
{ {
NodeTag type; NodeTag type;
char *funcname; char *relname; /* name of relation (can be "*") */
List *funcargs; ParamNo *paramNo; /* or a parameter */
} FuncWithArgs; List *attrs; /* attributes (possibly nested); list of
* Values (strings) */
List *indirection; /* array refs (list of A_Indices') */
} Attr;
/* This is only used internally in gram.y. */ /*
typedef struct PrivTarget * A_Const - a constant expression
*/
typedef struct A_Const
{ {
NodeTag type; NodeTag type;
int objtype; Value val; /* the value (with the tag) */
List *objs; TypeName *typename; /* typecast */
} PrivTarget; } A_Const;
/* ---------------------- /*
* Close Portal Statement * TypeCast - a CAST expression
* ---------------------- *
* NOTE: for mostly historical reasons, A_Const and ParamNo parsenodes contain
* room for a TypeName; we only generate a separate TypeCast node if the
* argument to be casted is neither of those kinds of nodes. In theory either
* representation would work, but it is convenient (especially for A_Const)
* to have the target type immediately available.
*/ */
typedef struct ClosePortalStmt typedef struct TypeCast
{ {
NodeTag type; NodeTag type;
char *portalname; /* name of the portal (cursor) */ Node *arg; /* the expression being casted */
} ClosePortalStmt; TypeName *typename; /* the target type */
} TypeCast;
/* ---------------------- /*
* Copy Statement * CaseExpr - a CASE expression
* ----------------------
*/ */
typedef struct CopyStmt typedef struct CaseExpr
{ {
NodeTag type; NodeTag type;
bool binary; /* is a binary copy? */ Oid casetype;
char *relname; /* the relation to copy */ Node *arg; /* implicit equality comparison argument */
bool oids; /* copy oid's? */ List *args; /* the arguments (list of WHEN clauses) */
int direction; /* TO or FROM */ Node *defresult; /* the default result (ELSE clause) */
char *filename; /* if NULL, use stdin/stdout */ } CaseExpr;
char *delimiter; /* delimiter character, \t by default */
char *null_print; /* how to print NULLs, `\N' by default */
} CopyStmt;
/* ---------------------- /*
* Create Table Statement * CaseWhen - an argument to a CASE expression
*
* NOTE: in the raw gram.y output, ColumnDef, Constraint, and FkConstraint
* nodes are intermixed in tableElts, and constraints is NIL. After parse
* analysis, tableElts contains just ColumnDefs, and constraints contains
* just Constraint nodes (in fact, only CONSTR_CHECK nodes, in the present
* implementation).
* ----------------------
*/ */
typedef struct CreateStmt typedef struct CaseWhen
{ {
NodeTag type; NodeTag type;
char *relname; /* name of relation to create */ Node *expr; /* comparison expression */
List *tableElts; /* column definitions (list of ColumnDef) */ Node *result; /* substitution result */
List *inhRelnames; /* relations to inherit from (list of } CaseWhen;
* T_String Values) */
List *constraints; /* constraints (list of Constraint nodes) */
bool istemp; /* is this a temp table? */
bool hasoids; /* should it have OIDs? */
} CreateStmt;
/* ---------- /* ----------------
* Definitions for plain (non-FOREIGN KEY) constraints in CreateStmt * NullTest
*
* XXX probably these ought to be unified with FkConstraints at some point?
*
* For constraints that use expressions (CONSTR_DEFAULT, CONSTR_CHECK)
* we may have the expression in either "raw" form (an untransformed
* parse tree) or "cooked" form (the nodeToString representation of
* an executable expression tree), depending on how this Constraint
* node was created (by parsing, or by inheritance from an existing
* relation). We should never have both in the same node!
* *
* Constraint attributes (DEFERRABLE etc) are initially represented as * NullTest represents the operation of testing a value for NULLness.
* separate Constraint nodes for simplicity of parsing. analyze.c makes * Currently, we only support scalar input values, but eventually a
* a pass through the constraints list to attach the info to the appropriate * row-constructor input should be supported.
* FkConstraint node (and, perhaps, someday to other kinds of constraints). * The appropriate test is performed and returned as a boolean Datum.
* ---------- * ----------------
*/ */
typedef enum ConstrType /* types of constraints */ typedef enum NullTestType
{ {
CONSTR_NULL, /* not SQL92, but a lot of people expect IS_NULL, IS_NOT_NULL
* it */ } NullTestType;
CONSTR_NOTNULL,
CONSTR_DEFAULT,
CONSTR_CHECK,
CONSTR_PRIMARY,
CONSTR_UNIQUE,
CONSTR_ATTR_DEFERRABLE, /* attributes for previous constraint node */
CONSTR_ATTR_NOT_DEFERRABLE,
CONSTR_ATTR_DEFERRED,
CONSTR_ATTR_IMMEDIATE
} ConstrType;
typedef struct Constraint typedef struct NullTest
{ {
NodeTag type; NodeTag type;
ConstrType contype; Node *arg; /* input expression */
char *name; /* name, or NULL if unnamed */ NullTestType nulltesttype; /* IS NULL, IS NOT NULL */
Node *raw_expr; /* expr, as untransformed parse tree */ } NullTest;
char *cooked_expr; /* expr, as nodeToString representation */
List *keys; /* Ident nodes naming referenced column(s) */
} Constraint;
/* ---------- /* ----------------
* Definitions for FOREIGN KEY constraints in CreateStmt * 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.
* ----------------
*/ */
#define FKCONSTR_ON_KEY_NOACTION 0x0000
#define FKCONSTR_ON_KEY_RESTRICT 0x0001
#define FKCONSTR_ON_KEY_CASCADE 0x0002
#define FKCONSTR_ON_KEY_SETNULL 0x0004
#define FKCONSTR_ON_KEY_SETDEFAULT 0x0008
#define FKCONSTR_ON_DELETE_MASK 0x000F typedef enum BoolTestType
#define FKCONSTR_ON_DELETE_SHIFT 0 {
IS_TRUE, IS_NOT_TRUE, IS_FALSE, IS_NOT_FALSE, IS_UNKNOWN, IS_NOT_UNKNOWN
#define FKCONSTR_ON_UPDATE_MASK 0x00F0 } BoolTestType;
#define FKCONSTR_ON_UPDATE_SHIFT 4
typedef struct FkConstraint typedef struct BooleanTest
{ {
NodeTag type; NodeTag type;
char *constr_name; /* Constraint name */ Node *arg; /* input expression */
char *pktable_name; /* Primary key table name */ BoolTestType booltesttype; /* test type */
List *fk_attrs; /* Attributes of foreign key */ } BooleanTest;
List *pk_attrs; /* Corresponding attrs in PK table */
char *match_type; /* FULL or PARTIAL */
int32 actions; /* ON DELETE/UPDATE actions */
bool deferrable; /* DEFERRABLE */
bool initdeferred; /* INITIALLY DEFERRED */
} FkConstraint;
/* ---------------------- /*
* Create/Drop TRIGGER Statements * ColumnDef - column definition (used in various creates)
* ---------------------- *
* If the column has a default value, we may have the value expression
* in either "raw" form (an untransformed parse tree) or "cooked" form
* (the nodeToString representation of an executable expression tree),
* depending on how this ColumnDef node was created (by parsing, or by
* inheritance from an existing relation). We should never have both
* in the same node!
*
* The constraints list may contain a CONSTR_DEFAULT item in a raw
* parsetree produced by gram.y, but transformCreateStmt will remove
* the item and set raw_default instead. CONSTR_DEFAULT items
* should not appear in any subsequent processing.
*/ */
typedef struct ColumnDef
typedef struct CreateTrigStmt
{ {
NodeTag type; NodeTag type;
char *trigname; /* TRIGGER' name */ char *colname; /* name of column */
char *relname; /* triggered relation */ TypeName *typename; /* type of column */
char *funcname; /* function to call (or NULL) */ bool is_not_null; /* NOT NULL constraint specified? */
List *args; /* list of (T_String) Values or NULL */ Node *raw_default; /* default value (untransformed parse
bool before; /* BEFORE/AFTER */ * tree) */
bool row; /* ROW/STATEMENT */ char *cooked_default; /* nodeToString representation */
char actions[4]; /* Insert, Update, Delete */ List *constraints; /* other constraints on column */
char *lang; /* currently not used, always NULL */ } ColumnDef;
char *text; /* AS 'text' */
List *attr; /* UPDATE OF a, b,... (NI) or NULL */
char *when; /* WHEN 'a > 10 ...' (NI) or NULL */
/* The following are used for referential */
/* integrity constraint triggers */
bool isconstraint; /* This is an RI trigger */
bool deferrable; /* [NOT] DEFERRABLE */
bool initdeferred; /* INITIALLY {DEFERRED|IMMEDIATE} */
char *constrrelname; /* opposite relation */
} CreateTrigStmt;
typedef struct DropTrigStmt /*
* Ident -
* an identifier (could be an attribute or a relation name). Depending
* on the context at transformStmt time, the identifier is treated as
* either a relation name (in which case, isRel will be set) or an
* attribute (in which case, it will be transformed into an Attr).
*/
typedef struct Ident
{ {
NodeTag type; NodeTag type;
char *trigname; /* TRIGGER' name */ char *name; /* its name */
char *relname; /* triggered relation */ List *indirection; /* array references */
} DropTrigStmt; bool isRel; /* is this a relation or a column? */
} Ident;
/* ---------------------- /*
* Create/Drop PROCEDURAL LANGUAGE Statement * FuncCall - a function or aggregate invocation
* ---------------------- *
* agg_star indicates we saw a 'foo(*)' construct, while agg_distinct
* indicates we saw 'foo(DISTINCT ...)'. In either case, the construct
* *must* be an aggregate call. Otherwise, it might be either an
* aggregate or some other kind of function.
*/ */
typedef struct CreatePLangStmt typedef struct FuncCall
{ {
NodeTag type; NodeTag type;
char *plname; /* PL name */ char *funcname; /* name of function */
char *plhandler; /* PL call handler function */ List *args; /* the arguments (list of exprs) */
char *plcompiler; /* lancompiler text */ bool agg_star; /* argument was really '*' */
bool pltrusted; /* PL is trusted */ bool agg_distinct; /* arguments were labeled DISTINCT */
} CreatePLangStmt; } FuncCall;
typedef struct DropPLangStmt /*
* A_Indices - array reference or bounds ([lidx:uidx] or [uidx])
*/
typedef struct A_Indices
{ {
NodeTag type; NodeTag type;
char *plname; /* PL name */ Node *lidx; /* could be NULL */
} DropPLangStmt; Node *uidx;
} A_Indices;
/* ---------------------- /*
* Create/Alter/Drop User Statements * ResTarget -
* ---------------------- * result target (used in target list of pre-transformed Parse trees)
*
* In a SELECT or INSERT target list, 'name' is either NULL or
* the column name assigned to the value. (If there is an 'AS ColumnLabel'
* clause, the grammar sets 'name' from it; otherwise 'name' is initially NULL
* and is filled in during the parse analysis phase.)
* The 'indirection' field is not used at all.
*
* In an UPDATE target list, 'name' is the name of the destination column,
* and 'indirection' stores any subscripts attached to the destination.
* That is, our representation is UPDATE table SET name [indirection] = val.
*/ */
typedef struct CreateUserStmt typedef struct ResTarget
{ {
NodeTag type; NodeTag type;
char *user; /* PostgreSQL user login name */ char *name; /* column name or NULL */
List *options; /* List of DefElem nodes */ List *indirection; /* subscripts for destination column, or
} CreateUserStmt; * NIL */
Node *val; /* the value expression to compute or
* assign */
} ResTarget;
typedef struct AlterUserStmt /*
* SortGroupBy - for ORDER BY clause
*/
typedef struct SortGroupBy
{ {
NodeTag type; NodeTag type;
char *user; /* PostgreSQL user login name */ char *useOp; /* operator to use */
List *options; /* List of DefElem nodes */ Node *node; /* Expression */
} AlterUserStmt; } SortGroupBy;
typedef struct AlterUserSetStmt /*
* RangeVar - range variable, used in FROM clauses
*/
typedef struct RangeVar
{ {
NodeTag type; NodeTag type;
char *user; char *relname; /* the relation name */
char *variable; InhOption inhOpt; /* expand rel by inheritance? */
List *value; Attr *name; /* optional table alias & column aliases */
} AlterUserSetStmt; } RangeVar;
typedef struct DropUserStmt /*
* RangeSubselect - subquery appearing in a FROM clause
*/
typedef struct RangeSubselect
{ {
NodeTag type; NodeTag type;
List *users; /* List of users to remove */ Node *subquery; /* the untransformed sub-select clause */
} DropUserStmt; Attr *name; /* table alias & optional column aliases */
} RangeSubselect;
/* ---------------------- /*
* Create/Alter/Drop Group Statements * IndexElem - index parameters (used in CREATE INDEX)
* ---------------------- *
* For a plain index, each 'name' is an attribute name in the heap relation,
* and 'args' is NIL. For a functional index, only one IndexElem is allowed.
* It has name = name of function and args = list of attribute names that
* are the function's arguments.
*/ */
typedef struct CreateGroupStmt typedef struct IndexElem
{ {
NodeTag type; NodeTag type;
char *name; /* name of the new group */ char *name; /* name of attribute to index, or function */
List *options; /* List of DefElem nodes */ List *args; /* list of names of function arguments */
} CreateGroupStmt; char *class; /* name of desired opclass; NULL = default */
} IndexElem;
typedef struct AlterGroupStmt /*
* DefElem -
* a definition (used in definition lists in the form of defname = arg)
*/
typedef struct DefElem
{ {
NodeTag type; NodeTag type;
char *name; /* name of group to alter */ char *defname;
int action; /* +1 = add, -1 = drop user */ Node *arg; /* a (Value *) or a (TypeName *) */
List *listUsers; /* list of users to add/drop */ } DefElem;
} AlterGroupStmt;
typedef struct DropGroupStmt
{
NodeTag type;
char *name;
} DropGroupStmt;
/****************************************************************************
* Nodes for a Query tree
****************************************************************************/
/* ---------------------- /*
* Create SEQUENCE Statement * TargetEntry -
* ---------------------- * a target entry (used in the transformed target list)
*
* one of resdom or fjoin is not NULL. a target list is
* ((<resdom | fjoin> expr) (<resdom | fjoin> expr) ...)
*/ */
typedef struct TargetEntry
typedef struct CreateSeqStmt
{ {
NodeTag type; NodeTag type;
char *seqname; /* the relation to create */ Resdom *resdom; /* fjoin overload this to be a list?? */
bool istemp; /* is this a temp sequence? */ Fjoin *fjoin;
List *options; Node *expr;
} CreateSeqStmt; } TargetEntry;
/* ---------------------- /*--------------------
* Create Version Statement * RangeTblEntry -
* ---------------------- * A range table is a List of RangeTblEntry nodes.
*
* Currently we use the same node type for both plain relation references
* and sub-selects in the FROM clause. It might be cleaner to abstract
* the common fields into a "superclass" nodetype.
*
* alias is an Attr node representing the AS alias-clause attached to the
* FROM expression, or NULL if no clause.
*
* eref is the table reference name and column reference names (either
* real or aliases). Note that system columns (OID etc) are not included
* in the column list.
* eref->relname is required to be present, and should generally be used
* to identify the RTE for error messages etc.
*
* inh is TRUE for relation references that should be expanded to include
* inheritance children, if the rel has any. This *must* be FALSE for
* subquery RTEs.
*
* inFromCl marks those range variables that are listed in the FROM clause.
* In SQL, the query can only refer to range variables listed in the
* FROM clause, but POSTQUEL allows you to refer to tables not listed,
* in which case a range table entry will be generated. We still support
* this POSTQUEL feature, although there is some doubt whether it's
* convenient or merely confusing. The flag is needed since an
* implicitly-added RTE shouldn't change the namespace for unqualified
* column names processed later, and it also shouldn't affect the
* expansion of '*'.
*
* checkForRead, checkForWrite, and checkAsUser control run-time access
* permissions checks. A rel will be checked for read or write access
* (or both, or neither) per checkForRead and checkForWrite. If
* checkAsUser is not InvalidOid, then do the permissions checks using
* the access rights of that user, not the current effective user ID.
* (This allows rules to act as setuid gateways.)
*--------------------
*/ */
typedef struct VersionStmt typedef struct RangeTblEntry
{ {
NodeTag type; NodeTag type;
char *relname; /* the new relation */
int direction; /* FORWARD | BACKWARD */
char *fromRelname; /* relation to create a version */
char *date; /* date of the snapshot */
} VersionStmt;
/* ---------------------- /*
* Create {Operator|Type|Aggregate} Statement * Fields valid for a plain relation RTE (else NULL/zero):
* ---------------------- */
char *relname; /* real name of the relation */
Oid relid; /* OID of the relation */
/*
* Fields valid for a subquery RTE (else NULL):
*/
Query *subquery; /* the sub-query */
/*
* Fields valid in all RTEs:
*/
Attr *alias; /* user-written alias clause, if any */
Attr *eref; /* expanded reference names */
bool inh; /* inheritance requested? */
bool inFromCl; /* present in FROM clause */
bool checkForRead; /* check rel for read access */
bool checkForWrite; /* check rel for write access */
Oid checkAsUser; /* if not zero, check access as this user */
} RangeTblEntry;
/*
* SortClause -
* representation of ORDER BY clauses
*
* tleSortGroupRef must match ressortgroupref of exactly one Resdom of the
* associated targetlist; that is the expression to be sorted (or grouped) by.
* sortop is the OID of the ordering operator.
*
* SortClauses are also used to identify Resdoms that we will do a "Unique"
* filter step on (for SELECT DISTINCT and SELECT DISTINCT ON). The
* distinctClause list is simply a copy of the relevant members of the
* sortClause list. Note that distinctClause can be a subset of sortClause,
* but cannot have members not present in sortClause; and the members that
* do appear must be in the same order as in sortClause.
*/ */
typedef struct DefineStmt typedef struct SortClause
{ {
NodeTag type; NodeTag type;
int defType; /* OPERATOR|P_TYPE|AGGREGATE */ Index tleSortGroupRef; /* reference into targetlist */
char *defname; Oid sortop; /* the sort operator to use */
List *definition; /* a list of DefElem */ } SortClause;
} DefineStmt;
/* ---------------------- /*
* Drop Table|Sequence|View|Index|Rule|Type Statement * GroupClause -
* ---------------------- * representation of GROUP BY clauses
*
* GroupClause is exactly like SortClause except for the nodetag value
* (it's probably not even really necessary to have two different
* nodetags...). We have routines that operate interchangeably on both.
*/ */
typedef SortClause GroupClause;
#define DROP_TABLE 1
#define DROP_SEQUENCE 2
#define DROP_VIEW 3
#define DROP_INDEX 4
#define DROP_RULE 5
#define DROP_TYPE_P 6
typedef struct DropStmt /*****************************************************************************
{ * Optimizable Statements
NodeTag type; *****************************************************************************/
List *names;
int removeType;
} DropStmt;
/* ---------------------- /* ----------------------
* Truncate Table Statement * Insert Statement
* ---------------------- * ----------------------
*/ */
typedef struct TruncateStmt typedef struct InsertStmt
{ {
NodeTag type; NodeTag type;
char *relName; /* relation to be truncated */ char *relname; /* relation to insert into */
} TruncateStmt; List *cols; /* optional: names of the target columns */
/* ---------------------- /*
* Comment On Statement * An INSERT statement has *either* VALUES or SELECT, never both. If
* ---------------------- * VALUES, a targetList is supplied (empty for DEFAULT VALUES). If
* SELECT, a complete SelectStmt (or set-operation tree) is supplied.
*/ */
typedef struct CommentStmt List *targetList; /* the target list (of ResTarget) */
{ Node *selectStmt; /* the source SELECT */
NodeTag type; } InsertStmt;
int objtype; /* Object's type */
char *objname; /* Name of the object */
char *objproperty; /* Property Id (such as column) */
List *objlist; /* Arguments for VAL objects */
char *comment; /* The comment to insert */
} CommentStmt;
/* ---------------------- /* ----------------------
* Begin Recipe Statement * Delete Statement
* ---------------------- * ----------------------
*/ */
typedef struct RecipeStmt typedef struct DeleteStmt
{ {
NodeTag type; NodeTag type;
char *recipeName; /* name of the recipe */ char *relname; /* relation to delete from */
} RecipeStmt; Node *whereClause; /* qualifications */
InhOption inhOpt; /* recursively act on children? */
} DeleteStmt;
/* ---------------------- /* ----------------------
* Fetch Statement * Update Statement
* ---------------------- * ----------------------
*/ */
typedef struct FetchStmt typedef struct UpdateStmt
{ {
NodeTag type; NodeTag type;
int direction; /* FORWARD or BACKWARD */ char *relname; /* relation to update */
int howMany; /* amount to fetch ("ALL" --> 0) */ List *targetList; /* the target list (of ResTarget) */
char *portalname; /* name of portal (cursor) */ Node *whereClause; /* qualifications */
bool ismove; /* TRUE if MOVE */ List *fromClause; /* the from clause */
} FetchStmt; InhOption inhOpt; /* recursively act on children? */
} UpdateStmt;
/* ---------------------- /* ----------------------
* Create Index Statement * Select Statement
*
* A "simple" SELECT is represented in the output of gram.y by a single
* SelectStmt node. A SELECT construct containing set operators (UNION,
* INTERSECT, EXCEPT) is represented by a tree of SelectStmt nodes, in
* which the leaf nodes are component SELECTs and the internal nodes
* represent UNION, INTERSECT, or EXCEPT operators. Using the same node
* type for both leaf and internal nodes allows gram.y to stick ORDER BY,
* LIMIT, etc, clause values into a SELECT statement without worrying
* whether it is a simple or compound SELECT.
* ---------------------- * ----------------------
*/ */
typedef struct IndexStmt typedef enum SetOperation
{
SETOP_NONE = 0,
SETOP_UNION,
SETOP_INTERSECT,
SETOP_EXCEPT
} SetOperation;
typedef struct SelectStmt
{ {
NodeTag type; NodeTag type;
char *idxname; /* name of the index */
char *relname; /* name of relation to index on */ /*
char *accessMethod; /* name of access method (eg. btree) */ * These fields are used only in "leaf" SelectStmts.
List *indexParams; /* a list of IndexElem */ */
Node *whereClause; /* qualification (partial-index predicate) */ List *distinctClause; /* NULL, list of DISTINCT ON exprs, or
List *rangetable; /* range table for qual, filled in by * lcons(NIL,NIL) for all (SELECT
* transformStmt() */ * DISTINCT) */
bool unique; /* is index unique? */ char *into; /* name of table (for select into table) */
bool primary; /* is index on primary key? */ bool istemp; /* into is a temp table? */
} IndexStmt; List *intoColNames; /* column names for into table */
List *targetList; /* the target list (of ResTarget) */
List *fromClause; /* the FROM clause */
Node *whereClause; /* WHERE qualification */
List *groupClause; /* GROUP BY clauses */
Node *havingClause; /* HAVING conditional-expression */
/*
* These fields are used in both "leaf" SelectStmts and upper-level
* SelectStmts. portalname/binary may only be set at the top level.
*/
List *sortClause; /* sort clause (a list of SortGroupBy's) */
char *portalname; /* the portal (cursor) to create */
bool binary; /* a binary (internal) portal? */
Node *limitOffset; /* # of result tuples to skip */
Node *limitCount; /* # of result tuples to return */
List *forUpdate; /* FOR UPDATE clause */
/*
* These fields are used only in upper-level SelectStmts.
*/
SetOperation op; /* type of set op */
bool all; /* ALL specified? */
struct SelectStmt *larg; /* left child */
struct SelectStmt *rarg; /* right child */
/* Eventually add fields for CORRESPONDING spec here */
} SelectStmt;
/* ---------------------- /* ----------------------
* Create Function Statement * Set Operation node for post-analysis query trees
*
* After parse analysis, a SELECT with set operations is represented by a
* top-level Query node containing the leaf SELECTs as subqueries in its
* range table. Its setOperations field shows the tree of set operations,
* with leaf SelectStmt nodes replaced by RangeTblRef nodes, and internal
* nodes replaced by SetOperationStmt nodes.
* ---------------------- * ----------------------
*/ */
typedef struct ProcedureStmt typedef struct SetOperationStmt
{ {
NodeTag type; NodeTag type;
bool replace; /* T => replace if already exists */ SetOperation op; /* type of set op */
char *funcname; /* name of function to create */ bool all; /* ALL specified? */
List *argTypes; /* list of argument types (TypeName nodes) */ Node *larg; /* left child */
Node *returnType; /* the return type (a TypeName node) */ Node *rarg; /* right child */
List *withClause; /* a list of DefElem */ /* Eventually add fields for CORRESPONDING spec here */
List *as; /* definition of function body */
char *language; /* C, SQL, etc */ /* Fields derived during parse analysis: */
} ProcedureStmt; List *colTypes; /* integer list of OIDs of output column
* types */
} SetOperationStmt;
/*****************************************************************************
* Other Statements (no optimizations required)
*
* Some of them require a little bit of transformation (which is also
* done by transformStmt). The whole structure is then passed on to
* ProcessUtility (by-passing the optimization step) as the utilityStmt
* field in Query.
*****************************************************************************/
/* ---------------------- /* ----------------------
* Drop Aggregate Statement * Alter Table
*
* The fields are used in different ways by the different variants of
* this command.
* ---------------------- * ----------------------
*/ */
typedef struct RemoveAggrStmt typedef struct AlterTableStmt
{ {
NodeTag type; NodeTag type;
char *aggname; /* aggregate to drop */ char subtype; /*------------
Node *aggtype; /* TypeName for input datatype, or NULL */ * A = add column
} RemoveAggrStmt; * T = alter column default
* S = alter column statistics
* M = alter column storage
* D = drop column
* C = add constraint
* X = drop constraint
* E = create toast table
* U = change owner
*------------
*/
char *relname; /* table to work on */
InhOption inhOpt; /* recursively act on children? */
char *name; /* column or constraint name to act on, or
* new owner */
Node *def; /* definition of new column or constraint */
int behavior; /* CASCADE or RESTRICT drop behavior */
} AlterTableStmt;
/* ---------------------- /* ----------------------
* Drop Function Statement * Grant Statement
* ---------------------- * ----------------------
*/ */
typedef struct RemoveFuncStmt
typedef struct GrantStmt
{ {
NodeTag type; NodeTag type;
char *funcname; /* function to drop */ bool is_grant; /* not revoke */
List *args; /* types of the arguments */ int objtype;
} RemoveFuncStmt; List *objects; /* list of names (as Value strings) */
List *privileges; /* integer list of privilege codes */
List *grantees; /* list of PrivGrantee nodes */
} GrantStmt;
/* ----------------------
* Drop Operator Statement typedef struct PrivGrantee
* ----------------------
*/
typedef struct RemoveOperStmt
{ {
NodeTag type; NodeTag type;
char *opname; /* operator to drop */ char *username; /* if both are NULL then PUBLIC */
List *args; /* types of the arguments */ char *groupname;
} RemoveOperStmt; } PrivGrantee;
/* ----------------------
* Alter Table Statement typedef struct FuncWithArgs
* ---------------------- {
*/ NodeTag type;
typedef struct RenameStmt char *funcname;
List *funcargs; /* list of Typename nodes */
} FuncWithArgs;
/* This is only used internally in gram.y. */
typedef struct PrivTarget
{ {
NodeTag type; NodeTag type;
char *relname; /* relation to be altered */ int objtype;
InhOption inhOpt; /* recursively act on children? */ List *objs;
char *column; /* if NULL, rename the relation name to } PrivTarget;
* the new name. Otherwise, rename this
* column name. */
char *newname; /* the new name */
} RenameStmt;
/* ---------------------- /* ----------------------
* Create Rule Statement * Close Portal Statement
* ---------------------- * ----------------------
*/ */
typedef struct RuleStmt typedef struct ClosePortalStmt
{ {
NodeTag type; NodeTag type;
char *rulename; /* name of the rule */ char *portalname; /* name of the portal (cursor) */
Node *whereClause; /* qualifications */ } ClosePortalStmt;
CmdType event; /* RETRIEVE */
struct Attr *object; /* object affected */
bool instead; /* is a 'do instead'? */
List *actions; /* the action statements */
} RuleStmt;
/* ---------------------- /* ----------------------
* Notify Statement * Copy Statement
* ---------------------- * ----------------------
*/ */
typedef struct NotifyStmt typedef struct CopyStmt
{ {
NodeTag type; NodeTag type;
char *relname; /* relation to notify */ bool binary; /* is a binary copy? */
} NotifyStmt; char *relname; /* the relation to copy */
bool oids; /* copy oid's? */
int direction; /* TO or FROM */
char *filename; /* if NULL, use stdin/stdout */
char *delimiter; /* delimiter character, \t by default */
char *null_print; /* how to print NULLs, `\N' by default */
} CopyStmt;
/* ---------------------- /* ----------------------
* Listen Statement * Create Table Statement
*
* NOTE: in the raw gram.y output, ColumnDef, Constraint, and FkConstraint
* nodes are intermixed in tableElts, and constraints is NIL. After parse
* analysis, tableElts contains just ColumnDefs, and constraints contains
* just Constraint nodes (in fact, only CONSTR_CHECK nodes, in the present
* implementation).
* ---------------------- * ----------------------
*/ */
typedef struct ListenStmt typedef struct CreateStmt
{ {
NodeTag type; NodeTag type;
char *relname; /* relation to listen on */ char *relname; /* name of relation to create */
} ListenStmt; List *tableElts; /* column definitions (list of ColumnDef) */
List *inhRelnames; /* relations to inherit from (list of
* T_String Values) */
List *constraints; /* constraints (list of Constraint nodes) */
bool istemp; /* is this a temp table? */
bool hasoids; /* should it have OIDs? */
} CreateStmt;
/* ---------------------- /* ----------
* Unlisten Statement * Definitions for plain (non-FOREIGN KEY) constraints in CreateStmt
* ---------------------- *
* XXX probably these ought to be unified with FkConstraints at some point?
*
* For constraints that use expressions (CONSTR_DEFAULT, CONSTR_CHECK)
* we may have the expression in either "raw" form (an untransformed
* parse tree) or "cooked" form (the nodeToString representation of
* an executable expression tree), depending on how this Constraint
* node was created (by parsing, or by inheritance from an existing
* relation). We should never have both in the same node!
*
* Constraint attributes (DEFERRABLE etc) are initially represented as
* separate Constraint nodes for simplicity of parsing. analyze.c makes
* a pass through the constraints list to attach the info to the appropriate
* FkConstraint node (and, perhaps, someday to other kinds of constraints).
* ----------
*/ */
typedef struct UnlistenStmt
typedef enum ConstrType /* types of constraints */
{ {
NodeTag type; CONSTR_NULL, /* not SQL92, but a lot of people expect
char *relname; /* relation to unlisten on */ * it */
} UnlistenStmt; CONSTR_NOTNULL,
CONSTR_DEFAULT,
CONSTR_CHECK,
CONSTR_PRIMARY,
CONSTR_UNIQUE,
CONSTR_ATTR_DEFERRABLE, /* attributes for previous constraint node */
CONSTR_ATTR_NOT_DEFERRABLE,
CONSTR_ATTR_DEFERRED,
CONSTR_ATTR_IMMEDIATE
} ConstrType;
/* ---------------------- typedef struct Constraint
* {Begin|Abort|End} Transaction Statement
* ----------------------
*/
typedef struct TransactionStmt
{ {
NodeTag type; NodeTag type;
int command; /* BEGIN|END|ABORT */ ConstrType contype;
} TransactionStmt; char *name; /* name, or NULL if unnamed */
Node *raw_expr; /* expr, as untransformed parse tree */
char *cooked_expr; /* expr, as nodeToString representation */
List *keys; /* Ident nodes naming referenced column(s) */
} Constraint;
/* ---------------------- /* ----------
* Create View Statement * Definitions for FOREIGN KEY constraints in CreateStmt
* ---------------------- * ----------
*/ */
typedef struct ViewStmt #define FKCONSTR_ON_KEY_NOACTION 0x0000
#define FKCONSTR_ON_KEY_RESTRICT 0x0001
#define FKCONSTR_ON_KEY_CASCADE 0x0002
#define FKCONSTR_ON_KEY_SETNULL 0x0004
#define FKCONSTR_ON_KEY_SETDEFAULT 0x0008
#define FKCONSTR_ON_DELETE_MASK 0x000F
#define FKCONSTR_ON_DELETE_SHIFT 0
#define FKCONSTR_ON_UPDATE_MASK 0x00F0
#define FKCONSTR_ON_UPDATE_SHIFT 4
typedef struct FkConstraint
{ {
NodeTag type; NodeTag type;
char *viewname; /* name of the view */ char *constr_name; /* Constraint name */
List *aliases; /* target column names */ char *pktable_name; /* Primary key table name */
Query *query; /* the SQL statement */ List *fk_attrs; /* Attributes of foreign key */
} ViewStmt; List *pk_attrs; /* Corresponding attrs in PK table */
char *match_type; /* FULL or PARTIAL */
int32 actions; /* ON DELETE/UPDATE actions */
bool deferrable; /* DEFERRABLE */
bool initdeferred; /* INITIALLY DEFERRED */
} FkConstraint;
/* ---------------------- /* ----------------------
* Load Statement * Create/Drop TRIGGER Statements
* ---------------------- * ----------------------
*/ */
typedef struct LoadStmt
typedef struct CreateTrigStmt
{ {
NodeTag type; NodeTag type;
char *filename; /* file to load */ char *trigname; /* TRIGGER' name */
} LoadStmt; char *relname; /* triggered relation */
char *funcname; /* function to call (or NULL) */
List *args; /* list of (T_String) Values or NULL */
bool before; /* BEFORE/AFTER */
bool row; /* ROW/STATEMENT */
char actions[4]; /* Insert, Update, Delete */
char *lang; /* currently not used, always NULL */
char *text; /* AS 'text' */
List *attr; /* UPDATE OF a, b,... (NI) or NULL */
char *when; /* WHEN 'a > 10 ...' (NI) or NULL */
/* ---------------------- /* The following are used for referential */
* Createdb Statement /* integrity constraint triggers */
* ---------------------- bool isconstraint; /* This is an RI trigger */
*/ bool deferrable; /* [NOT] DEFERRABLE */
typedef struct CreatedbStmt bool initdeferred; /* INITIALLY {DEFERRED|IMMEDIATE} */
char *constrrelname; /* opposite relation */
} CreateTrigStmt;
typedef struct DropTrigStmt
{ {
NodeTag type; NodeTag type;
char *dbname; /* name of database to create */ char *trigname; /* TRIGGER' name */
char *dbowner; /* name of owner (NULL = default) */ char *relname; /* triggered relation */
char *dbpath; /* location of database (NULL = default) */ } DropTrigStmt;
char *dbtemplate; /* template to use (NULL = default) */
int encoding; /* MULTIBYTE encoding (-1 = use default) */
} CreatedbStmt;
/* ---------------------- /* ----------------------
* Alter Database * Create/Drop PROCEDURAL LANGUAGE Statement
* ---------------------- * ----------------------
*/ */
typedef struct AlterDatabaseSetStmt typedef struct CreatePLangStmt
{ {
NodeTag type; NodeTag type;
char *dbname; char *plname; /* PL name */
char *variable; char *plhandler; /* PL call handler function */
List *value; char *plcompiler; /* lancompiler text */
} AlterDatabaseSetStmt; bool pltrusted; /* PL is trusted */
} CreatePLangStmt;
/* ---------------------- typedef struct DropPLangStmt
* Dropdb Statement
* ----------------------
*/
typedef struct DropdbStmt
{ {
NodeTag type; NodeTag type;
char *dbname; /* database to drop */ char *plname; /* PL name */
} DropdbStmt; } DropPLangStmt;
/* ---------------------- /* ----------------------
* Cluster Statement (support pbrown's cluster index implementation) * Create/Alter/Drop User Statements
* ---------------------- * ----------------------
*/ */
typedef struct ClusterStmt typedef struct CreateUserStmt
{ {
NodeTag type; NodeTag type;
char *relname; /* relation being indexed */ char *user; /* PostgreSQL user login name */
char *indexname; /* original index defined */ List *options; /* List of DefElem nodes */
} ClusterStmt; } CreateUserStmt;
/* ---------------------- typedef struct AlterUserStmt
* Vacuum and Analyze Statements
*
* Even though these are nominally two statements, it's convenient to use
* just one node type for both.
* ----------------------
*/
typedef struct VacuumStmt
{ {
NodeTag type; NodeTag type;
bool vacuum; /* do VACUUM step */ char *user; /* PostgreSQL user login name */
bool full; /* do FULL (non-concurrent) vacuum */ List *options; /* List of DefElem nodes */
bool analyze; /* do ANALYZE step */ } AlterUserStmt;
bool freeze; /* early-freeze option */
bool verbose; /* print progress info */
char *vacrel; /* name of single table to process, or
* NULL */
List *va_cols; /* list of column names, or NIL for all */
} VacuumStmt;
/* ---------------------- typedef struct AlterUserSetStmt
* Explain Statement
* ----------------------
*/
typedef struct ExplainStmt
{ {
NodeTag type; NodeTag type;
Query *query; /* the query */ char *user;
bool verbose; /* print plan info */ char *variable;
bool analyze; /* get statistics by executing plan */ List *value;
} ExplainStmt; } AlterUserSetStmt;
/* ---------------------- typedef struct DropUserStmt
* Checkpoint Statement
* ----------------------
*/
typedef struct CheckPointStmt
{ {
NodeTag type; NodeTag type;
} CheckPointStmt; List *users; /* List of users to remove */
} DropUserStmt;
/* ---------------------- /* ----------------------
* Set Statement * Create/Alter/Drop Group Statements
* ---------------------- * ----------------------
*/ */
typedef struct CreateGroupStmt
typedef struct VariableSetStmt
{ {
NodeTag type; NodeTag type;
char *name; char *name; /* name of the new group */
List *args; List *options; /* List of DefElem nodes */
} VariableSetStmt; } CreateGroupStmt;
/* ---------------------- typedef struct AlterGroupStmt
* Show Statement {
* ---------------------- NodeTag type;
*/ char *name; /* name of group to alter */
int action; /* +1 = add, -1 = drop user */
List *listUsers; /* list of users to add/drop */
} AlterGroupStmt;
typedef struct VariableShowStmt typedef struct DropGroupStmt
{ {
NodeTag type; NodeTag type;
char *name; char *name;
} VariableShowStmt; } DropGroupStmt;
/* ---------------------- /* ----------------------
* Reset Statement * Create SEQUENCE Statement
* ---------------------- * ----------------------
*/ */
typedef struct VariableResetStmt typedef struct CreateSeqStmt
{ {
NodeTag type; NodeTag type;
char *name; char *seqname; /* the relation to create */
} VariableResetStmt; bool istemp; /* is this a temp sequence? */
List *options;
} CreateSeqStmt;
/* ---------------------- /* ----------------------
* LOCK Statement * Create Version Statement
* ---------------------- * ----------------------
*/ */
typedef struct LockStmt typedef struct VersionStmt
{ {
NodeTag type; NodeTag type;
List *rellist; /* relations to lock */ char *relname; /* the new relation */
int mode; /* lock mode */ int direction; /* FORWARD | BACKWARD */
} LockStmt; char *fromRelname; /* relation to create a version */
char *date; /* date of the snapshot */
} VersionStmt;
/* ---------------------- /* ----------------------
* SET CONSTRAINTS Statement * Create {Operator|Type|Aggregate} Statement
* ---------------------- * ----------------------
*/ */
typedef struct ConstraintsSetStmt typedef struct DefineStmt
{ {
NodeTag type; NodeTag type;
List *constraints; int defType; /* OPERATOR|P_TYPE|AGGREGATE */
bool deferred; char *defname;
} ConstraintsSetStmt; List *definition; /* a list of DefElem */
} DefineStmt;
/* ---------------------- /* ----------------------
* REINDEX Statement * Drop Table|Sequence|View|Index|Rule|Type Statement
* ---------------------- * ----------------------
*/ */
typedef struct ReindexStmt
{
NodeTag type;
int reindexType; /* INDEX|TABLE|DATABASE */
const char *name; /* name to reindex */
bool force;
bool all;
} ReindexStmt;
/***************************************************************************** #define DROP_TABLE 1
* Optimizable Statements #define DROP_SEQUENCE 2
*****************************************************************************/ #define DROP_VIEW 3
#define DROP_INDEX 4
#define DROP_RULE 5
#define DROP_TYPE_P 6
/* ---------------------- typedef struct DropStmt
* Insert Statement
* ----------------------
*/
typedef struct InsertStmt
{ {
NodeTag type; NodeTag type;
char *relname; /* relation to insert into */ List *names;
List *cols; /* optional: names of the target columns */ int removeType;
} DropStmt;
/*
* An INSERT statement has *either* VALUES or SELECT, never both. If
* VALUES, a targetList is supplied (empty for DEFAULT VALUES). If
* SELECT, a complete SelectStmt (or set-operation tree) is supplied.
*/
List *targetList; /* the target list (of ResTarget) */
Node *selectStmt; /* the source SELECT */
} InsertStmt;
/* ---------------------- /* ----------------------
* Delete Statement * Truncate Table Statement
* ---------------------- * ----------------------
*/ */
typedef struct DeleteStmt typedef struct TruncateStmt
{ {
NodeTag type; NodeTag type;
char *relname; /* relation to delete from */ char *relName; /* relation to be truncated */
Node *whereClause; /* qualifications */ } TruncateStmt;
InhOption inhOpt; /* recursively act on children? */
} DeleteStmt;
/* ---------------------- /* ----------------------
* Update Statement * Comment On Statement
* ---------------------- * ----------------------
*/ */
typedef struct UpdateStmt typedef struct CommentStmt
{ {
NodeTag type; NodeTag type;
char *relname; /* relation to update */ int objtype; /* Object's type */
List *targetList; /* the target list (of ResTarget) */ char *objname; /* Name of the object */
Node *whereClause; /* qualifications */ char *objproperty; /* Property Id (such as column) */
List *fromClause; /* the from clause */ List *objlist; /* Arguments for VAL objects */
InhOption inhOpt; /* recursively act on children? */ char *comment; /* The comment to insert */
} UpdateStmt; } CommentStmt;
/* ---------------------- /* ----------------------
* Select Statement * Begin Recipe Statement
*
* A "simple" SELECT is represented in the output of gram.y by a single
* SelectStmt node. A SELECT construct containing set operators (UNION,
* INTERSECT, EXCEPT) is represented by a tree of SelectStmt nodes, in
* which the leaf nodes are component SELECTs and the internal nodes
* represent UNION, INTERSECT, or EXCEPT operators. Using the same node
* type for both leaf and internal nodes allows gram.y to stick ORDER BY,
* LIMIT, etc, clause values into a SELECT statement without worrying
* whether it is a simple or compound SELECT.
* ---------------------- * ----------------------
*/ */
typedef enum SetOperation typedef struct RecipeStmt
{
SETOP_NONE = 0,
SETOP_UNION,
SETOP_INTERSECT,
SETOP_EXCEPT
} SetOperation;
typedef struct SelectStmt
{ {
NodeTag type; NodeTag type;
char *recipeName; /* name of the recipe */
/* } RecipeStmt;
* These fields are used only in "leaf" SelectStmts.
*/
List *distinctClause; /* NULL, list of DISTINCT ON exprs, or
* lcons(NIL,NIL) for all (SELECT
* DISTINCT) */
char *into; /* name of table (for select into table) */
bool istemp; /* into is a temp table? */
List *intoColNames; /* column names for into table */
List *targetList; /* the target list (of ResTarget) */
List *fromClause; /* the FROM clause */
Node *whereClause; /* WHERE qualification */
List *groupClause; /* GROUP BY clauses */
Node *havingClause; /* HAVING conditional-expression */
/*
* These fields are used in both "leaf" SelectStmts and upper-level
* SelectStmts. portalname/binary may only be set at the top level.
*/
List *sortClause; /* sort clause (a list of SortGroupBy's) */
char *portalname; /* the portal (cursor) to create */
bool binary; /* a binary (internal) portal? */
Node *limitOffset; /* # of result tuples to skip */
Node *limitCount; /* # of result tuples to return */
List *forUpdate; /* FOR UPDATE clause */
/*
* These fields are used only in upper-level SelectStmts.
*/
SetOperation op; /* type of set op */
bool all; /* ALL specified? */
struct SelectStmt *larg; /* left child */
struct SelectStmt *rarg; /* right child */
/* Eventually add fields for CORRESPONDING spec here */
} SelectStmt;
/* ---------------------- /* ----------------------
* Set Operation node for post-analysis query trees * Fetch Statement
*
* After parse analysis, a SELECT with set operations is represented by a
* top-level Query node containing the leaf SELECTs as subqueries in its
* range table. Its setOperations field shows the tree of set operations,
* with leaf SelectStmt nodes replaced by RangeTblRef nodes, and internal
* nodes replaced by SetOperationStmt nodes.
* ---------------------- * ----------------------
*/ */
typedef struct SetOperationStmt typedef struct FetchStmt
{
NodeTag type;
SetOperation op; /* type of set op */
bool all; /* ALL specified? */
Node *larg; /* left child */
Node *rarg; /* right child */
/* Eventually add fields for CORRESPONDING spec here */
/* Fields derived during parse analysis: */
List *colTypes; /* integer list of OIDs of output column
* types */
} SetOperationStmt;
/****************************************************************************
* Supporting data structures for Parse Trees
*
* Most of these node types appear in raw parsetrees output by the grammar,
* and get transformed to something else by the analyzer. A few of them
* are used as-is in transformed querytrees.
****************************************************************************/
/*
* TypeName - specifies a type in definitions
*/
typedef struct TypeName
{
NodeTag type;
char *name; /* name of the type */
bool timezone; /* timezone specified? */
bool setof; /* is a set? */
int32 typmod; /* type modifier */
List *arrayBounds; /* array bounds */
char *attrname; /* field name when using %TYPE */
} TypeName;
/*
* ParamNo - specifies a parameter reference
*/
typedef struct ParamNo
{ {
NodeTag type; NodeTag type;
int number; /* the number of the parameter */ int direction; /* FORWARD or BACKWARD */
TypeName *typename; /* the typecast */ int howMany; /* amount to fetch ("ALL" --> 0) */
List *indirection; /* array references */ char *portalname; /* name of portal (cursor) */
} ParamNo; bool ismove; /* TRUE if MOVE */
} FetchStmt;
/* /* ----------------------
* A_Expr - binary expressions * Create Index Statement
* ----------------------
*/ */
typedef struct A_Expr typedef struct IndexStmt
{ {
NodeTag type; NodeTag type;
int oper; /* type of operation (OP,OR,AND,NOT) */ char *idxname; /* name of the index */
char *opname; /* name of operator */ char *relname; /* name of relation to index on */
Node *lexpr; /* left argument */ char *accessMethod; /* name of access method (eg. btree) */
Node *rexpr; /* right argument */ List *indexParams; /* a list of IndexElem */
} A_Expr; Node *whereClause; /* qualification (partial-index predicate) */
List *rangetable; /* range table for qual, filled in by
* transformStmt() */
bool unique; /* is index unique? */
bool primary; /* is index on primary key? */
} IndexStmt;
/* /* ----------------------
* Attr - * Create Function Statement
* specifies an Attribute (ie. a Column); could have nested dots or * ----------------------
* array references.
*
*/ */
typedef struct Attr typedef struct ProcedureStmt
{ {
NodeTag type; NodeTag type;
char *relname; /* name of relation (can be "*") */ bool replace; /* T => replace if already exists */
ParamNo *paramNo; /* or a parameter */ char *funcname; /* name of function to create */
List *attrs; /* attributes (possibly nested); list of List *argTypes; /* list of argument types (TypeName nodes) */
* Values (strings) */ Node *returnType; /* the return type (a TypeName node) */
List *indirection; /* array refs (list of A_Indices') */ List *withClause; /* a list of DefElem */
} Attr; List *as; /* definition of function body */
char *language; /* C, SQL, etc */
} ProcedureStmt;
/* /* ----------------------
* A_Const - a constant expression * Drop Aggregate Statement
* ----------------------
*/ */
typedef struct A_Const typedef struct RemoveAggrStmt
{ {
NodeTag type; NodeTag type;
Value val; /* the value (with the tag) */ char *aggname; /* aggregate to drop */
TypeName *typename; /* typecast */ Node *aggtype; /* TypeName for input datatype, or NULL */
} A_Const; } RemoveAggrStmt;
/* /* ----------------------
* TypeCast - a CAST expression * Drop Function Statement
* * ----------------------
* NOTE: for mostly historical reasons, A_Const and ParamNo parsenodes contain
* room for a TypeName; we only generate a separate TypeCast node if the
* argument to be casted is neither of those kinds of nodes. In theory either
* representation would work, but it is convenient (especially for A_Const)
* to have the target type immediately available.
*/ */
typedef struct TypeCast typedef struct RemoveFuncStmt
{ {
NodeTag type; NodeTag type;
Node *arg; /* the expression being casted */ char *funcname; /* function to drop */
TypeName *typename; /* the target type */ List *args; /* types of the arguments */
} TypeCast; } RemoveFuncStmt;
/* /* ----------------------
* CaseExpr - a CASE expression * Drop Operator Statement
* ----------------------
*/ */
typedef struct CaseExpr typedef struct RemoveOperStmt
{ {
NodeTag type; NodeTag type;
Oid casetype; char *opname; /* operator to drop */
Node *arg; /* implicit equality comparison argument */ List *args; /* types of the arguments */
List *args; /* the arguments (list of WHEN clauses) */ } RemoveOperStmt;
Node *defresult; /* the default result (ELSE clause) */
} CaseExpr;
/* /* ----------------------
* CaseWhen - an argument to a CASE expression * Alter Table Statement
* ----------------------
*/ */
typedef struct CaseWhen typedef struct RenameStmt
{ {
NodeTag type; NodeTag type;
Node *expr; /* comparison expression */ char *relname; /* relation to be altered */
Node *result; /* substitution result */ InhOption inhOpt; /* recursively act on children? */
} CaseWhen; char *column; /* if NULL, rename the relation name to
* the new name. Otherwise, rename this
* column name. */
char *newname; /* the new name */
} RenameStmt;
/* ---------------- /* ----------------------
* NullTest * Create Rule Statement
* * ----------------------
* NullTest represents the operation of testing a value for NULLness.
* Currently, we only support scalar input values, but eventually a
* row-constructor input should be supported.
* The appropriate test is performed and returned as a boolean Datum.
* ----------------
*/ */
typedef struct RuleStmt
typedef enum NullTestType
{
IS_NULL, IS_NOT_NULL
} NullTestType;
typedef struct NullTest
{ {
NodeTag type; NodeTag type;
Node *arg; /* input expression */ char *rulename; /* name of the rule */
NullTestType nulltesttype; /* IS NULL, IS NOT NULL */ Node *whereClause; /* qualifications */
} NullTest; CmdType event; /* RETRIEVE */
struct Attr *object; /* object affected */
bool instead; /* is a 'do instead'? */
List *actions; /* the action statements */
} RuleStmt;
/* ---------------- /* ----------------------
* BooleanTest * Notify Statement
* * ----------------------
* 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 struct NotifyStmt
typedef enum BoolTestType
{ {
IS_TRUE, IS_NOT_TRUE, IS_FALSE, IS_NOT_FALSE, IS_UNKNOWN, IS_NOT_UNKNOWN NodeTag type;
} BoolTestType; char *relname; /* relation to notify */
} NotifyStmt;
typedef struct BooleanTest /* ----------------------
* Listen Statement
* ----------------------
*/
typedef struct ListenStmt
{ {
NodeTag type; NodeTag type;
Node *arg; /* input expression */ char *relname; /* relation to listen on */
BoolTestType booltesttype; /* test type */ } ListenStmt;
} BooleanTest;
/* /* ----------------------
* ColumnDef - column definition (used in various creates) * Unlisten Statement
* * ----------------------
* If the column has a default value, we may have the value expression
* in either "raw" form (an untransformed parse tree) or "cooked" form
* (the nodeToString representation of an executable expression tree),
* depending on how this ColumnDef node was created (by parsing, or by
* inheritance from an existing relation). We should never have both
* in the same node!
*
* The constraints list may contain a CONSTR_DEFAULT item in a raw
* parsetree produced by gram.y, but transformCreateStmt will remove
* the item and set raw_default instead. CONSTR_DEFAULT items
* should not appear in any subsequent processing.
*/ */
typedef struct ColumnDef typedef struct UnlistenStmt
{ {
NodeTag type; NodeTag type;
char *colname; /* name of column */ char *relname; /* relation to unlisten on */
TypeName *typename; /* type of column */ } UnlistenStmt;
bool is_not_null; /* NOT NULL constraint specified? */
Node *raw_default; /* default value (untransformed parse
* tree) */
char *cooked_default; /* nodeToString representation */
List *constraints; /* other constraints on column */
} ColumnDef;
/* /* ----------------------
* Ident - * {Begin|Abort|End} Transaction Statement
* an identifier (could be an attribute or a relation name). Depending * ----------------------
* on the context at transformStmt time, the identifier is treated as
* either a relation name (in which case, isRel will be set) or an
* attribute (in which case, it will be transformed into an Attr).
*/ */
typedef struct Ident typedef struct TransactionStmt
{ {
NodeTag type; NodeTag type;
char *name; /* its name */ int command; /* BEGIN|END|ABORT */
List *indirection; /* array references */ } TransactionStmt;
bool isRel; /* is this a relation or a column? */
} Ident;
/* /* ----------------------
* FuncCall - a function or aggregate invocation * Create View Statement
* * ----------------------
* agg_star indicates we saw a 'foo(*)' construct, while agg_distinct
* indicates we saw 'foo(DISTINCT ...)'. In either case, the construct
* *must* be an aggregate call. Otherwise, it might be either an
* aggregate or some other kind of function.
*/ */
typedef struct FuncCall typedef struct ViewStmt
{ {
NodeTag type; NodeTag type;
char *funcname; /* name of function */ char *viewname; /* name of the view */
List *args; /* the arguments (list of exprs) */ List *aliases; /* target column names */
bool agg_star; /* argument was really '*' */ Query *query; /* the SQL statement */
bool agg_distinct; /* arguments were labeled DISTINCT */ } ViewStmt;
} FuncCall;
/* /* ----------------------
* A_Indices - array reference or bounds ([lidx:uidx] or [uidx]) * Load Statement
* ----------------------
*/ */
typedef struct A_Indices typedef struct LoadStmt
{ {
NodeTag type; NodeTag type;
Node *lidx; /* could be NULL */ char *filename; /* file to load */
Node *uidx; } LoadStmt;
} A_Indices;
/* ----------------------
/* * Createdb Statement
* ResTarget - * ----------------------
* result target (used in target list of pre-transformed Parse trees)
*
* In a SELECT or INSERT target list, 'name' is either NULL or
* the column name assigned to the value. (If there is an 'AS ColumnLabel'
* clause, the grammar sets 'name' from it; otherwise 'name' is initially NULL
* and is filled in during the parse analysis phase.)
* The 'indirection' field is not used at all.
*
* In an UPDATE target list, 'name' is the name of the destination column,
* and 'indirection' stores any subscripts attached to the destination.
* That is, our representation is UPDATE table SET name [indirection] = val.
*/ */
typedef struct ResTarget typedef struct CreatedbStmt
{ {
NodeTag type; NodeTag type;
char *name; /* column name or NULL */ char *dbname; /* name of database to create */
List *indirection; /* subscripts for destination column, or char *dbowner; /* name of owner (NULL = default) */
* NIL */ char *dbpath; /* location of database (NULL = default) */
Node *val; /* the value expression to compute or char *dbtemplate; /* template to use (NULL = default) */
* assign */ int encoding; /* MULTIBYTE encoding (-1 = use default) */
} ResTarget; } CreatedbStmt;
/* /* ----------------------
* SortGroupBy - for ORDER BY clause * Alter Database
* ----------------------
*/ */
typedef struct SortGroupBy typedef struct AlterDatabaseSetStmt
{ {
NodeTag type; NodeTag type;
char *useOp; /* operator to use */ char *dbname;
Node *node; /* Expression */ char *variable;
} SortGroupBy; List *value;
} AlterDatabaseSetStmt;
/* /* ----------------------
* RangeVar - range variable, used in FROM clauses * Dropdb Statement
* ----------------------
*/ */
typedef struct RangeVar typedef struct DropdbStmt
{ {
NodeTag type; NodeTag type;
char *relname; /* the relation name */ char *dbname; /* database to drop */
InhOption inhOpt; /* expand rel by inheritance? */ } DropdbStmt;
Attr *name; /* optional table alias & column aliases */
} RangeVar;
/* /* ----------------------
* RangeSubselect - subquery appearing in a FROM clause * Cluster Statement (support pbrown's cluster index implementation)
* ----------------------
*/ */
typedef struct RangeSubselect typedef struct ClusterStmt
{ {
NodeTag type; NodeTag type;
Node *subquery; /* the untransformed sub-select clause */ char *relname; /* relation being indexed */
Attr *name; /* table alias & optional column aliases */ char *indexname; /* original index defined */
} RangeSubselect; } ClusterStmt;
/* /* ----------------------
* IndexElem - index parameters (used in CREATE INDEX) * Vacuum and Analyze Statements
* *
* For a plain index, each 'name' is an attribute name in the heap relation, * Even though these are nominally two statements, it's convenient to use
* and 'args' is NIL. For a functional index, only one IndexElem is allowed. * just one node type for both.
* It has name = name of function and args = list of attribute names that * ----------------------
* are the function's arguments.
*/ */
typedef struct IndexElem typedef struct VacuumStmt
{ {
NodeTag type; NodeTag type;
char *name; /* name of attribute to index, or function */ bool vacuum; /* do VACUUM step */
List *args; /* list of names of function arguments */ bool full; /* do FULL (non-concurrent) vacuum */
char *class; /* name of desired opclass; NULL = default */ bool analyze; /* do ANALYZE step */
} IndexElem; bool freeze; /* early-freeze option */
bool verbose; /* print progress info */
char *vacrel; /* name of single table to process, or
* NULL */
List *va_cols; /* list of column names, or NIL for all */
} VacuumStmt;
/* /* ----------------------
* DefElem - * Explain Statement
* a definition (used in definition lists in the form of defname = arg) * ----------------------
*/ */
typedef struct DefElem typedef struct ExplainStmt
{ {
NodeTag type; NodeTag type;
char *defname; Query *query; /* the query */
Node *arg; /* a (Value *) or a (TypeName *) */ bool verbose; /* print plan info */
} DefElem; bool analyze; /* get statistics by executing plan */
} ExplainStmt;
/****************************************************************************
* Nodes for a Query tree
****************************************************************************/
/* /* ----------------------
* TargetEntry - * Checkpoint Statement
* a target entry (used in the transformed target list) * ----------------------
*
* one of resdom or fjoin is not NULL. a target list is
* ((<resdom | fjoin> expr) (<resdom | fjoin> expr) ...)
*/ */
typedef struct TargetEntry typedef struct CheckPointStmt
{ {
NodeTag type; NodeTag type;
Resdom *resdom; /* fjoin overload this to be a list?? */ } CheckPointStmt;
Fjoin *fjoin;
Node *expr;
} TargetEntry;
/*-------------------- /* ----------------------
* RangeTblEntry - * Set Statement
* A range table is a List of RangeTblEntry nodes. * ----------------------
*
* Currently we use the same node type for both plain relation references
* and sub-selects in the FROM clause. It might be cleaner to abstract
* the common fields into a "superclass" nodetype.
*
* alias is an Attr node representing the AS alias-clause attached to the
* FROM expression, or NULL if no clause.
*
* eref is the table reference name and column reference names (either
* real or aliases). Note that system columns (OID etc) are not included
* in the column list.
* eref->relname is required to be present, and should generally be used
* to identify the RTE for error messages etc.
*
* inh is TRUE for relation references that should be expanded to include
* inheritance children, if the rel has any. This *must* be FALSE for
* subquery RTEs.
*
* inFromCl marks those range variables that are listed in the FROM clause.
* In SQL, the query can only refer to range variables listed in the
* FROM clause, but POSTQUEL allows you to refer to tables not listed,
* in which case a range table entry will be generated. We still support
* this POSTQUEL feature, although there is some doubt whether it's
* convenient or merely confusing. The flag is needed since an
* implicitly-added RTE shouldn't change the namespace for unqualified
* column names processed later, and it also shouldn't affect the
* expansion of '*'.
*
* checkForRead, checkForWrite, and checkAsUser control run-time access
* permissions checks. A rel will be checked for read or write access
* (or both, or neither) per checkForRead and checkForWrite. If
* checkAsUser is not InvalidOid, then do the permissions checks using
* the access rights of that user, not the current effective user ID.
* (This allows rules to act as setuid gateways.)
*--------------------
*/ */
typedef struct RangeTblEntry
typedef struct VariableSetStmt
{ {
NodeTag type; NodeTag type;
char *name;
List *args;
} VariableSetStmt;
/* /* ----------------------
* Fields valid for a plain relation RTE (else NULL/zero): * Show Statement
* ----------------------
*/ */
char *relname; /* real name of the relation */
Oid relid; /* OID of the relation */
/* typedef struct VariableShowStmt
* Fields valid for a subquery RTE (else NULL): {
NodeTag type;
char *name;
} VariableShowStmt;
/* ----------------------
* Reset Statement
* ----------------------
*/ */
Query *subquery; /* the sub-query */
/* typedef struct VariableResetStmt
* Fields valid in all RTEs: {
NodeTag type;
char *name;
} VariableResetStmt;
/* ----------------------
* LOCK Statement
* ----------------------
*/ */
Attr *alias; /* user-written alias clause, if any */ typedef struct LockStmt
Attr *eref; /* expanded reference names */ {
bool inh; /* inheritance requested? */ NodeTag type;
bool inFromCl; /* present in FROM clause */ List *rellist; /* relations to lock */
bool checkForRead; /* check rel for read access */ int mode; /* lock mode */
bool checkForWrite; /* check rel for write access */ } LockStmt;
Oid checkAsUser; /* if not zero, check access as this user */
} RangeTblEntry;
/* /* ----------------------
* SortClause - * SET CONSTRAINTS Statement
* representation of ORDER BY clauses * ----------------------
*
* tleSortGroupRef must match ressortgroupref of exactly one Resdom of the
* associated targetlist; that is the expression to be sorted (or grouped) by.
* sortop is the OID of the ordering operator.
*
* SortClauses are also used to identify Resdoms that we will do a "Unique"
* filter step on (for SELECT DISTINCT and SELECT DISTINCT ON). The
* distinctClause list is simply a copy of the relevant members of the
* sortClause list. Note that distinctClause can be a subset of sortClause,
* but cannot have members not present in sortClause; and the members that
* do appear must be in the same order as in sortClause.
*/ */
typedef struct SortClause typedef struct ConstraintsSetStmt
{ {
NodeTag type; NodeTag type;
Index tleSortGroupRef; /* reference into targetlist */ List *constraints; /* List of names as Value strings */
Oid sortop; /* the sort operator to use */ bool deferred;
} SortClause; } ConstraintsSetStmt;
/* /* ----------------------
* GroupClause - * REINDEX Statement
* representation of GROUP BY clauses * ----------------------
*
* GroupClause is exactly like SortClause except for the nodetag value
* (it's probably not even really necessary to have two different
* nodetags...). We have routines that operate interchangeably on both.
*/ */
typedef SortClause GroupClause; typedef struct ReindexStmt
{
NodeTag type;
int reindexType; /* INDEX|TABLE|DATABASE */
const char *name; /* name to reindex */
bool force;
bool all;
} ReindexStmt;
#endif /* PARSENODES_H */ #endif /* PARSENODES_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment