4
4
* definitions for parse tree nodes
7
* Portions Copyright (c) 2003-2008, PgPool Global Development Group
8
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
6
* Many of the node types used in parsetrees include a "location" field.
7
* This is a byte (not character) offset in the original source text, to be
8
* used for positioning an error cursor when there is an error related to
9
* the node. Access to the original source text is needed to make use of
13
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
14
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
9
15
* Portions Copyright (c) 1994, Regents of the University of California
11
* $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.353 2007/09/03 18:46:30 tgl Exp $
17
* $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.393 2009/04/04 21:12:31 tgl Exp $
13
19
*-------------------------------------------------------------------------
15
21
#ifndef PARSENODES_H
16
22
#define PARSENODES_H
24
#include "../pool_type.h"
18
25
#include "primnodes.h"
28
/* include/nodes/bitmapset.h start */
29
typedef uint32 bitmapword; /* must be an unsigned type */
31
typedef struct Bitmapset
33
int nwords; /* number of words in array */
34
bitmapword words[1]; /* really [nwords] */
35
} Bitmapset; /* VARIABLE LENGTH STRUCT */
37
extern Bitmapset *bms_copy(const Bitmapset *a);
38
/* include/nodes/bitmapset.h end */
21
41
/* Possible sources of a Query */
22
42
typedef enum QuerySource
270
290
List *args; /* the arguments (list of exprs) */
271
291
bool agg_star; /* argument was really '*' */
272
292
bool agg_distinct; /* arguments were labeled DISTINCT */
293
bool func_variadic; /* last argument was labeled VARIADIC */
294
struct WindowDef *over; /* OVER clause, if any */
273
295
int location; /* token location, or -1 if unknown */
277
* A_Indices - array reference or bounds ([lidx:uidx] or [uidx])
299
* A_Star - '*' representing all columns of a table or compound field
301
* This can appear within ColumnRef.fields, A_Indirection.indirection, and
302
* ResTarget.indirection lists.
304
typedef struct A_Star
310
* A_Indices - array subscript or slice bounds ([lidx:uidx] or [uidx])
279
312
typedef struct A_Indices
282
Node *lidx; /* could be NULL */
315
Node *lidx; /* NULL if it's a single subscript */
287
320
* A_Indirection - select a field and/or array element from an expression
289
* The indirection list can contain both A_Indices nodes (representing
290
* subscripting) and string Value nodes (representing field selection
291
* --- the string value is the name of the field to select). For example,
292
* a complex selection operation like
322
* The indirection list can contain A_Indices nodes (representing
323
* subscripting), string Value nodes (representing field selection --- the
324
* string value is the name of the field to select), and A_Star nodes
325
* (representing selection of all fields of a composite type).
326
* For example, a complex selection operation like
293
327
* (foo).field1[42][7].field2
294
328
* would be represented with a single A_Indirection node having a 4-element
295
329
* indirection list.
297
* Note: as of Postgres 8.0, we don't support arrays of composite values,
298
* so cases in which a field select follows a subscript aren't actually
299
* semantically legal. However the parser is prepared to handle such.
331
* Currently, A_Star must appear only as the last list element --- the grammar
332
* is responsible for enforcing this!
301
334
typedef struct A_Indirection
304
337
Node *arg; /* the thing being selected from */
305
List *indirection; /* subscripts and/or field names */
338
List *indirection; /* subscripts and/or field names and/or * */
342
* A_ArrayExpr - an ARRAY[] construct
344
typedef struct A_ArrayExpr
347
List *elements; /* array element expressions */
348
int location; /* token location, or -1 if unknown */
310
353
* result target (used in target list of pre-transformed parse trees)
338
381
typedef struct SortBy
341
SortByDir sortby_dir; /* ASC/DESC/USING */
342
SortByNulls sortby_nulls; /* NULLS FIRST/LAST */
384
Node *node; /* expression to sort on */
385
SortByDir sortby_dir; /* ASC/DESC/USING/default */
386
SortByNulls sortby_nulls; /* NULLS FIRST/LAST */
343
387
List *useOp; /* name of op to use, if SORTBY_USING */
344
Node *node; /* expression to sort on */
388
int location; /* operator location, or -1 if none/unknown */
392
* WindowDef - raw representation of WINDOW and OVER clauses
394
* For entries in a WINDOW list, "name" is the window name being defined.
395
* For OVER clauses, we use "name" for the "OVER window" syntax, or "refname"
396
* for the "OVER (window)" syntax, which is subtly different --- the latter
397
* implies overriding the window frame clause.
399
typedef struct WindowDef
402
char *name; /* window's own name */
403
char *refname; /* referenced window name, if any */
404
List *partitionClause; /* PARTITION BY expression list */
405
List *orderClause; /* ORDER BY (list of SortBy) */
406
int frameOptions; /* frame_clause options, see below */
407
int location; /* parse location, or -1 if none/unknown */
411
* frameOptions is an OR of these bits. The NONDEFAULT and BETWEEN bits are
412
* used so that ruleutils.c can tell which properties were specified and
413
* which were defaulted; the correct behavioral bits must be set either way.
414
* The START_foo and END_foo options must come in pairs of adjacent bits for
415
* the convenience of gram.y, even though some of them are useless/invalid.
416
* We will need more bits (and fields) to cover the full SQL:2008 option set.
418
#define FRAMEOPTION_NONDEFAULT 0x00001 /* any specified? */
419
#define FRAMEOPTION_RANGE 0x00002 /* RANGE behavior */
420
#define FRAMEOPTION_ROWS 0x00004 /* ROWS behavior */
421
#define FRAMEOPTION_BETWEEN 0x00008 /* BETWEEN given? */
422
#define FRAMEOPTION_START_UNBOUNDED_PRECEDING 0x00010 /* start is U. P. */
423
#define FRAMEOPTION_END_UNBOUNDED_PRECEDING 0x00020 /* (disallowed) */
424
#define FRAMEOPTION_START_UNBOUNDED_FOLLOWING 0x00040 /* (disallowed) */
425
#define FRAMEOPTION_END_UNBOUNDED_FOLLOWING 0x00080 /* end is U. F. */
426
#define FRAMEOPTION_START_CURRENT_ROW 0x00100 /* start is C. R. */
427
#define FRAMEOPTION_END_CURRENT_ROW 0x00200 /* end is C. R. */
429
#define FRAMEOPTION_DEFAULTS \
430
(FRAMEOPTION_RANGE | FRAMEOPTION_START_UNBOUNDED_PRECEDING | \
431
FRAMEOPTION_END_CURRENT_ROW)
348
434
* RangeSubselect - subquery appearing in a FROM clause
350
436
typedef struct RangeSubselect
428
514
Node *expr; /* expression to index, or NULL */
429
515
List *opclass; /* name of desired opclass; NIL = default */
430
516
SortByDir ordering; /* ASC/DESC/default */
431
SortByNulls nulls_ordering; /* FIRST/LAST/default */
517
SortByNulls nulls_ordering; /* FIRST/LAST/default */
436
* a definition (used in definition lists in the form of defname = arg)
521
* DefElem - a generic "name = value" option definition
523
* In some contexts the name can be qualified. Also, certain SQL commands
524
* allow a SET/ADD/DROP action to be attached to option settings, so it's
525
* convenient to carry a field for that too. (Note: currently, it is our
526
* practice that the grammar allows namespace and action only in statements
527
* where they are relevant; C code can just ignore those fields in other
530
typedef enum DefElemAction
532
DEFELEM_UNSPEC, /* no action given */
438
538
typedef struct DefElem
541
char *defnamespace; /* NULL if unqualified name */
442
543
Node *arg; /* a (Value *) or a (TypeName *) */
544
DefElemAction defaction; /* unspecified action, or SET/ADD/DROP */
446
548
* LockingClause - raw representation of FOR UPDATE/SHARE options
448
550
* Note: lockedRels == NIL means "all relations in query". Otherwise it
449
* is a list of String nodes giving relation eref names.
551
* is a list of RangeVar nodes. (We use RangeVar mainly because it carries
552
* a location field --- currently, parse analysis insists on unqualified
553
* names in LockingClause.)
451
555
typedef struct LockingClause
603
727
bool inFromCl; /* present in FROM clause? */
604
728
AclMode requiredPerms; /* bitmask of required access permissions */
605
729
Oid checkAsUser; /* if valid, check access as this role */
730
Bitmapset *selectedCols; /* columns needing SELECT permission */
731
Bitmapset *modifiedCols; /* columns needing INSERT/UPDATE permission */
610
* representation of ORDER BY clauses
736
* representation of ORDER BY, GROUP BY, PARTITION BY,
737
* DISTINCT, DISTINCT ON items
739
* You might think that ORDER BY is only interested in defining ordering,
740
* and GROUP/DISTINCT are only interested in defining equality. However,
741
* one way to implement grouping is to sort and then apply a "uniq"-like
742
* filter. So it's also interesting to keep track of possible sort operators
743
* for GROUP/DISTINCT, and in particular to try to sort for the grouping
744
* in a way that will also yield a requested ORDER BY ordering. So we need
745
* to be able to compare ORDER BY and GROUP/DISTINCT lists, which motivates
746
* the decision to give them the same representation.
612
748
* tleSortGroupRef must match ressortgroupref of exactly one entry of the
613
* associated targetlist; that is the expression to be sorted (or grouped) by.
614
* sortop is the OID of the ordering operator (a "<" or ">" operator).
615
* nulls_first does about what you'd expect.
617
* SortClauses are also used to identify targets that we will do a "Unique"
618
* filter step on (for SELECT DISTINCT and SELECT DISTINCT ON). The
619
* distinctClause list is simply a copy of the relevant members of the
620
* sortClause list. Note that distinctClause can be a subset of sortClause,
621
* but cannot have members not present in sortClause; and the members that
622
* do appear must be in the same order as in sortClause.
749
* query's targetlist; that is the expression to be sorted or grouped by.
750
* eqop is the OID of the equality operator.
751
* sortop is the OID of the ordering operator (a "<" or ">" operator),
752
* or InvalidOid if not available.
753
* nulls_first means about what you'd expect. If sortop is InvalidOid
754
* then nulls_first is meaningless and should be set to false.
756
* In an ORDER BY item, all fields must be valid. (The eqop isn't essential
757
* here, but it's cheap to get it along with the sortop, and requiring it
758
* to be valid eases comparisons to grouping items.)
760
* In a grouping item, eqop must be valid. If the eqop is a btree equality
761
* operator, then sortop should be set to a compatible ordering operator.
762
* We prefer to set eqop/sortop/nulls_first to match any ORDER BY item that
763
* the query presents for the same tlist item. If there is none, we just
764
* use the default ordering op for the datatype.
766
* If the tlist item's type has a hash opclass but no btree opclass, then
767
* we will set eqop to the hash equality operator, sortop to InvalidOid,
768
* and nulls_first to false. A grouping item of this kind can only be
769
* implemented by hashing, and of course it'll never match an ORDER BY item.
771
* A query might have both ORDER BY and DISTINCT (or DISTINCT ON) clauses.
772
* In SELECT DISTINCT, the distinctClause list is as long or longer than the
773
* sortClause list, while in SELECT DISTINCT ON it's typically shorter.
774
* The two lists must match up to the end of the shorter one --- the parser
775
* rearranges the distinctClause if necessary to make this true. (This
776
* restriction ensures that only one sort step is needed to both satisfy the
777
* ORDER BY and set up for the Unique step. This is semantically necessary
778
* for DISTINCT ON, and presents no real drawback for DISTINCT.)
624
typedef struct SortClause
780
typedef struct SortGroupClause
627
783
Index tleSortGroupRef; /* reference into targetlist */
628
Oid sortop; /* the ordering operator ('<' op) */
629
bool nulls_first; /* do NULLs come before normal values? */
784
Oid eqop; /* the equality operator ('=' op) */
785
Oid sortop; /* the ordering operator ('<' op), or 0 */
786
bool nulls_first; /* do NULLs come before normal values? */
634
* representation of GROUP BY clauses
636
* GroupClause is exactly like SortClause except for the nodetag value.
637
* We have routines that operate interchangeably on both.
639
* XXX SortClause overspecifies the semantics so far as GROUP BY is concerned
640
* (ditto for DISTINCT). It'd be better to specify an equality operator not
641
* an ordering operator. However, the two implementations are tightly entwined
642
* at the moment ... breaking them apart is work for another day.
791
* transformed representation of WINDOW and OVER clauses
793
* A parsed Query's windowClause list contains these structs. "name" is set
794
* if the clause originally came from WINDOW, and is NULL if it originally
795
* was an OVER clause (but note that we collapse out duplicate OVERs).
796
* partitionClause and orderClause are lists of SortGroupClause structs.
797
* winref is an ID number referenced by WindowFunc nodes; it must be unique
798
* among the members of a Query's windowClause list.
799
* When refname isn't null, the partitionClause is always copied from there;
800
* the orderClause might or might not be copied (see copiedOrder); the framing
801
* options are never copied, per spec.
644
typedef SortClause GroupClause;
803
typedef struct WindowClause
806
char *name; /* window name (NULL in an OVER clause) */
807
char *refname; /* referenced window name, if any */
808
List *partitionClause; /* PARTITION BY list */
809
List *orderClause; /* ORDER BY list */
810
int frameOptions; /* frame_clause options, see WindowDef */
811
Index winref; /* ID referenced by window functions */
812
bool copiedOrder; /* did we copy orderClause from refname? */
647
816
* RowMarkClause -
648
817
* representation of FOR UPDATE/SHARE clauses
650
* We create a separate RowMarkClause node for each target relation
819
* We create a separate RowMarkClause node for each target relation. In the
820
* output of the parser and rewriter, all RowMarkClauses have rti == prti and
821
* isParent == false. When the planner discovers that a target relation
822
* is the root of an inheritance tree, it sets isParent true, and adds an
823
* additional RowMarkClause to the list for each child relation (including
824
* the target rel itself in its role as a child). The child entries have
825
* rti == child rel's RT index, prti == parent's RT index, and can therefore
826
* be recognized as children by the fact that prti != rti.
652
828
typedef struct RowMarkClause
655
831
Index rti; /* range table index of target relation */
832
Index prti; /* range table index of parent relation */
656
833
bool forUpdate; /* true = FOR UPDATE, false = FOR SHARE */
657
834
bool noWait; /* NOWAIT option */
835
bool isParent; /* set by planner when expanding inheritance */
840
* representation of WITH clause
842
* Note: WithClause does not propagate into the Query representation;
843
* but CommonTableExpr does.
845
typedef struct WithClause
848
List *ctes; /* list of CommonTableExprs */
849
bool recursive; /* true = WITH RECURSIVE */
850
int location; /* token location, or -1 if unknown */
855
* representation of WITH list element
857
* We don't currently support the SEARCH or CYCLE clause.
859
typedef struct CommonTableExpr
862
char *ctename; /* query name (never qualified) */
863
List *aliascolnames; /* optional list of column names */
864
Node *ctequery; /* subquery (SelectStmt or Query) */
865
int location; /* token location, or -1 if unknown */
866
/* These fields are set during parse analysis: */
867
bool cterecursive; /* is this CTE actually recursive? */
868
int cterefcount; /* number of RTEs referencing this CTE
869
* (excluding internal self-references) */
870
List *ctecolnames; /* list of output column names */
871
List *ctecoltypes; /* OID list of output column type OIDs */
872
List *ctecoltypmods; /* integer list of output column typmods */
660
875
/*****************************************************************************
661
876
* Optimizable Statements
662
877
*****************************************************************************/
1221
1461
} DropTableSpaceStmt;
1223
1463
/* ----------------------
1464
* Create/Drop FOREIGN DATA WRAPPER Statements
1465
* ----------------------
1468
typedef struct CreateFdwStmt
1471
char *fdwname; /* foreign-data wrapper name */
1472
List *validator; /* optional validator function (qual. name) */
1473
List *options; /* generic options to FDW */
1476
typedef struct AlterFdwStmt
1479
char *fdwname; /* foreign-data wrapper name */
1480
List *validator; /* optional validator function (qual. name) */
1481
bool change_validator;
1482
List *options; /* generic options to FDW */
1485
typedef struct DropFdwStmt
1488
char *fdwname; /* foreign-data wrapper name */
1489
bool missing_ok; /* don't complain if missing */
1490
DropBehavior behavior; /* drop behavior - cascade/restrict */
1493
/* ----------------------
1494
* Create/Drop FOREIGN SERVER Statements
1495
* ----------------------
1498
typedef struct CreateForeignServerStmt
1501
char *servername; /* server name */
1502
char *servertype; /* optional server type */
1503
char *version; /* optional server version */
1504
char *fdwname; /* FDW name */
1505
List *options; /* generic options to server */
1506
} CreateForeignServerStmt;
1508
typedef struct AlterForeignServerStmt
1511
char *servername; /* server name */
1512
char *version; /* optional server version */
1513
List *options; /* generic options to server */
1514
bool has_version; /* version specified */
1515
} AlterForeignServerStmt;
1517
typedef struct DropForeignServerStmt
1520
char *servername; /* server name */
1521
bool missing_ok; /* ignore missing servers */
1522
DropBehavior behavior; /* drop behavior - cascade/restrict */
1523
} DropForeignServerStmt;
1525
/* ----------------------
1526
* Create/Drop USER MAPPING Statements
1527
* ----------------------
1530
typedef struct CreateUserMappingStmt
1533
char *username; /* username or PUBLIC/CURRENT_USER */
1534
char *servername; /* server name */
1535
List *options; /* generic options to server */
1536
} CreateUserMappingStmt;
1538
typedef struct AlterUserMappingStmt
1541
char *username; /* username or PUBLIC/CURRENT_USER */
1542
char *servername; /* server name */
1543
List *options; /* generic options to server */
1544
} AlterUserMappingStmt;
1546
typedef struct DropUserMappingStmt
1549
char *username; /* username or PUBLIC/CURRENT_USER */
1550
char *servername; /* server name */
1551
bool missing_ok; /* ignore missing mappings */
1552
} DropUserMappingStmt;
1554
/* ----------------------
1224
1555
* Create/Drop TRIGGER Statements
1225
1556
* ----------------------