forked from postgres/postgres
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprimnodes.h
2339 lines (2127 loc) · 81.6 KB
/
primnodes.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*-------------------------------------------------------------------------
*
* primnodes.h
* Definitions for "primitive" node types, those that are used in more
* than one of the parse/plan/execute stages of the query pipeline.
* Currently, these are mostly nodes for executable expressions
* and join trees.
*
*
* Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* src/include/nodes/primnodes.h
*
*-------------------------------------------------------------------------
*/
#ifndef PRIMNODES_H
#define PRIMNODES_H
#include "access/attnum.h"
#include "nodes/bitmapset.h"
#include "nodes/pg_list.h"
typedef enum OverridingKind
{
OVERRIDING_NOT_SET = 0,
OVERRIDING_USER_VALUE,
OVERRIDING_SYSTEM_VALUE,
} OverridingKind;
/* ----------------------------------------------------------------
* node definitions
* ----------------------------------------------------------------
*/
/*
* Alias -
* specifies an alias for a range variable; the alias might also
* specify renaming of columns within the table.
*
* Note: colnames is a list of String nodes. In Alias structs
* associated with RTEs, there may be entries corresponding to dropped
* columns; these are normally empty strings (""). See parsenodes.h for info.
*/
typedef struct Alias
{
NodeTag type;
char *aliasname; /* aliased rel name (never qualified) */
List *colnames; /* optional list of column aliases */
} Alias;
/* What to do at commit time for temporary relations */
typedef enum OnCommitAction
{
ONCOMMIT_NOOP, /* No ON COMMIT clause (do nothing) */
ONCOMMIT_PRESERVE_ROWS, /* ON COMMIT PRESERVE ROWS (do nothing) */
ONCOMMIT_DELETE_ROWS, /* ON COMMIT DELETE ROWS */
ONCOMMIT_DROP, /* ON COMMIT DROP */
} OnCommitAction;
/*
* RangeVar - range variable, used in FROM clauses
*
* Also used to represent table names in utility statements; there, the alias
* field is not used, and inh tells whether to apply the operation
* recursively to child tables. In some contexts it is also useful to carry
* a TEMP table indication here.
*/
typedef struct RangeVar
{
NodeTag type;
/* the catalog (database) name, or NULL */
char *catalogname;
/* the schema name, or NULL */
char *schemaname;
/* the relation/sequence name */
char *relname;
/* expand rel by inheritance? recursively act on children? */
bool inh;
/* see RELPERSISTENCE_* in pg_class.h */
char relpersistence;
/* table alias & optional column aliases */
Alias *alias;
/* token location, or -1 if unknown */
ParseLoc location;
} RangeVar;
typedef enum TableFuncType
{
TFT_XMLTABLE,
TFT_JSON_TABLE,
} TableFuncType;
/*
* TableFunc - node for a table function, such as XMLTABLE and JSON_TABLE.
*
* Entries in the ns_names list are either String nodes containing
* literal namespace names, or NULL pointers to represent DEFAULT.
*/
typedef struct TableFunc
{
NodeTag type;
/* XMLTABLE or JSON_TABLE */
TableFuncType functype;
/* list of namespace URI expressions */
List *ns_uris pg_node_attr(query_jumble_ignore);
/* list of namespace names or NULL */
List *ns_names pg_node_attr(query_jumble_ignore);
/* input document expression */
Node *docexpr;
/* row filter expression */
Node *rowexpr;
/* column names (list of String) */
List *colnames pg_node_attr(query_jumble_ignore);
/* OID list of column type OIDs */
List *coltypes pg_node_attr(query_jumble_ignore);
/* integer list of column typmods */
List *coltypmods pg_node_attr(query_jumble_ignore);
/* OID list of column collation OIDs */
List *colcollations pg_node_attr(query_jumble_ignore);
/* list of column filter expressions */
List *colexprs;
/* list of column default expressions */
List *coldefexprs pg_node_attr(query_jumble_ignore);
/* JSON_TABLE: list of column value expressions */
List *colvalexprs pg_node_attr(query_jumble_ignore);
/* JSON_TABLE: list of PASSING argument expressions */
List *passingvalexprs pg_node_attr(query_jumble_ignore);
/* nullability flag for each output column */
Bitmapset *notnulls pg_node_attr(query_jumble_ignore);
/* JSON_TABLE plan */
Node *plan pg_node_attr(query_jumble_ignore);
/* counts from 0; -1 if none specified */
int ordinalitycol pg_node_attr(query_jumble_ignore);
/* token location, or -1 if unknown */
ParseLoc location;
} TableFunc;
/*
* IntoClause - target information for SELECT INTO, CREATE TABLE AS, and
* CREATE MATERIALIZED VIEW
*
* For CREATE MATERIALIZED VIEW, viewQuery is the parsed-but-not-rewritten
* SELECT Query for the view; otherwise it's NULL. This is irrelevant in
* the query jumbling as CreateTableAsStmt already includes a reference to
* its own Query, so ignore it. (We declare it as struct Query* to avoid a
* forward reference.)
*/
typedef struct IntoClause
{
NodeTag type;
RangeVar *rel; /* target relation name */
List *colNames; /* column names to assign, or NIL */
char *accessMethod; /* table access method */
List *options; /* options from WITH clause */
OnCommitAction onCommit; /* what do we do at COMMIT? */
char *tableSpaceName; /* table space to use, or NULL */
/* materialized view's SELECT query */
struct Query *viewQuery pg_node_attr(query_jumble_ignore);
bool skipData; /* true for WITH NO DATA */
} IntoClause;
/* ----------------------------------------------------------------
* node types for executable expressions
* ----------------------------------------------------------------
*/
/*
* Expr - generic superclass for executable-expression nodes
*
* All node types that are used in executable expression trees should derive
* from Expr (that is, have Expr as their first field). Since Expr only
* contains NodeTag, this is a formality, but it is an easy form of
* documentation. See also the ExprState node types in execnodes.h.
*/
typedef struct Expr
{
pg_node_attr(abstract)
NodeTag type;
} Expr;
/*
* Var - expression node representing a variable (ie, a table column)
*
* In the parser and planner, varno and varattno identify the semantic
* referent, which is a base-relation column unless the reference is to a join
* USING column that isn't semantically equivalent to either join input column
* (because it is a FULL join or the input column requires a type coercion).
* In those cases varno and varattno refer to the JOIN RTE. (Early in the
* planner, we replace such join references by the implied expression; but up
* till then we want join reference Vars to keep their original identity for
* query-printing purposes.)
*
* At the end of planning, Var nodes appearing in upper-level plan nodes are
* reassigned to point to the outputs of their subplans; for example, in a
* join node varno becomes INNER_VAR or OUTER_VAR and varattno becomes the
* index of the proper element of that subplan's target list. Similarly,
* INDEX_VAR is used to identify Vars that reference an index column rather
* than a heap column. (In ForeignScan and CustomScan plan nodes, INDEX_VAR
* is abused to signify references to columns of a custom scan tuple type.)
*
* ROWID_VAR is used in the planner to identify nonce variables that carry
* row identity information during UPDATE/DELETE/MERGE. This value should
* never be seen outside the planner.
*
* varnullingrels is the set of RT indexes of outer joins that can force
* the Var's value to null (at the point where it appears in the query).
* See optimizer/README for discussion of that.
*
* varlevelsup is greater than zero in Vars that represent outer references.
* Note that it affects the meaning of all of varno, varnullingrels, and
* varnosyn, all of which refer to the range table of that query level.
*
* In the parser, varnosyn and varattnosyn are either identical to
* varno/varattno, or they specify the column's position in an aliased JOIN
* RTE that hides the semantic referent RTE's refname. This is a syntactic
* identifier as opposed to the semantic identifier; it tells ruleutils.c
* how to print the Var properly. varnosyn/varattnosyn retain their values
* throughout planning and execution, so they are particularly helpful to
* identify Vars when debugging. Note, however, that a Var that is generated
* in the planner and doesn't correspond to any simple relation column may
* have varnosyn = varattnosyn = 0.
*/
#define INNER_VAR (-1) /* reference to inner subplan */
#define OUTER_VAR (-2) /* reference to outer subplan */
#define INDEX_VAR (-3) /* reference to index column */
#define ROWID_VAR (-4) /* row identity column during planning */
#define IS_SPECIAL_VARNO(varno) ((int) (varno) < 0)
/* Symbols for the indexes of the special RTE entries in rules */
#define PRS2_OLD_VARNO 1
#define PRS2_NEW_VARNO 2
typedef struct Var
{
Expr xpr;
/*
* index of this var's relation in the range table, or
* INNER_VAR/OUTER_VAR/etc
*/
int varno;
/*
* attribute number of this var, or zero for all attrs ("whole-row Var")
*/
AttrNumber varattno;
/* pg_type OID for the type of this var */
Oid vartype pg_node_attr(query_jumble_ignore);
/* pg_attribute typmod value */
int32 vartypmod pg_node_attr(query_jumble_ignore);
/* OID of collation, or InvalidOid if none */
Oid varcollid pg_node_attr(query_jumble_ignore);
/*
* RT indexes of outer joins that can replace the Var's value with null.
* We can omit varnullingrels in the query jumble, because it's fully
* determined by varno/varlevelsup plus the Var's query location.
*/
Bitmapset *varnullingrels pg_node_attr(query_jumble_ignore);
/*
* for subquery variables referencing outer relations; 0 in a normal var,
* >0 means N levels up
*/
Index varlevelsup;
/*
* varnosyn/varattnosyn are ignored for equality, because Vars with
* different syntactic identifiers are semantically the same as long as
* their varno/varattno match.
*/
/* syntactic relation index (0 if unknown) */
Index varnosyn pg_node_attr(equal_ignore, query_jumble_ignore);
/* syntactic attribute number */
AttrNumber varattnosyn pg_node_attr(equal_ignore, query_jumble_ignore);
/* token location, or -1 if unknown */
ParseLoc location;
} Var;
/*
* Const
*
* Note: for varlena data types, we make a rule that a Const node's value
* must be in non-extended form (4-byte header, no compression or external
* references). This ensures that the Const node is self-contained and makes
* it more likely that equal() will see logically identical values as equal.
*
* Only the constant type OID is relevant for the query jumbling.
*/
typedef struct Const
{
pg_node_attr(custom_copy_equal, custom_read_write)
Expr xpr;
/* pg_type OID of the constant's datatype */
Oid consttype;
/* typmod value, if any */
int32 consttypmod pg_node_attr(query_jumble_ignore);
/* OID of collation, or InvalidOid if none */
Oid constcollid pg_node_attr(query_jumble_ignore);
/* typlen of the constant's datatype */
int constlen pg_node_attr(query_jumble_ignore);
/* the constant's value */
Datum constvalue pg_node_attr(query_jumble_ignore);
/* whether the constant is null (if true, constvalue is undefined) */
bool constisnull pg_node_attr(query_jumble_ignore);
/*
* Whether this datatype is passed by value. If true, then all the
* information is stored in the Datum. If false, then the Datum contains
* a pointer to the information.
*/
bool constbyval pg_node_attr(query_jumble_ignore);
/*
* token location, or -1 if unknown. All constants are tracked as
* locations in query jumbling, to be marked as parameters.
*/
ParseLoc location pg_node_attr(query_jumble_location);
} Const;
/*
* Param
*
* paramkind specifies the kind of parameter. The possible values
* for this field are:
*
* PARAM_EXTERN: The parameter value is supplied from outside the plan.
* Such parameters are numbered from 1 to n.
*
* PARAM_EXEC: The parameter is an internal executor parameter, used
* for passing values into and out of sub-queries or from
* nestloop joins to their inner scans.
* For historical reasons, such parameters are numbered from 0.
* These numbers are independent of PARAM_EXTERN numbers.
*
* PARAM_SUBLINK: The parameter represents an output column of a SubLink
* node's sub-select. The column number is contained in the
* `paramid' field. (This type of Param is converted to
* PARAM_EXEC during planning.)
*
* PARAM_MULTIEXPR: Like PARAM_SUBLINK, the parameter represents an
* output column of a SubLink node's sub-select, but here, the
* SubLink is always a MULTIEXPR SubLink. The high-order 16 bits
* of the `paramid' field contain the SubLink's subLinkId, and
* the low-order 16 bits contain the column number. (This type
* of Param is also converted to PARAM_EXEC during planning.)
*/
typedef enum ParamKind
{
PARAM_EXTERN,
PARAM_EXEC,
PARAM_SUBLINK,
PARAM_MULTIEXPR,
} ParamKind;
typedef struct Param
{
Expr xpr;
ParamKind paramkind; /* kind of parameter. See above */
int paramid; /* numeric ID for parameter */
Oid paramtype; /* pg_type OID of parameter's datatype */
/* typmod value, if known */
int32 paramtypmod pg_node_attr(query_jumble_ignore);
/* OID of collation, or InvalidOid if none */
Oid paramcollid pg_node_attr(query_jumble_ignore);
/* token location, or -1 if unknown */
ParseLoc location;
} Param;
/*
* Aggref
*
* The aggregate's args list is a targetlist, ie, a list of TargetEntry nodes.
*
* For a normal (non-ordered-set) aggregate, the non-resjunk TargetEntries
* represent the aggregate's regular arguments (if any) and resjunk TLEs can
* be added at the end to represent ORDER BY expressions that are not also
* arguments. As in a top-level Query, the TLEs can be marked with
* ressortgroupref indexes to let them be referenced by SortGroupClause
* entries in the aggorder and/or aggdistinct lists. This represents ORDER BY
* and DISTINCT operations to be applied to the aggregate input rows before
* they are passed to the transition function. The grammar only allows a
* simple "DISTINCT" specifier for the arguments, but we use the full
* query-level representation to allow more code sharing.
*
* For an ordered-set aggregate, the args list represents the WITHIN GROUP
* (aggregated) arguments, all of which will be listed in the aggorder list.
* DISTINCT is not supported in this case, so aggdistinct will be NIL.
* The direct arguments appear in aggdirectargs (as a list of plain
* expressions, not TargetEntry nodes).
*
* aggtranstype is the data type of the state transition values for this
* aggregate (resolved to an actual type, if agg's transtype is polymorphic).
* This is determined during planning and is InvalidOid before that.
*
* aggargtypes is an OID list of the data types of the direct and regular
* arguments. Normally it's redundant with the aggdirectargs and args lists,
* but in a combining aggregate, it's not because the args list has been
* replaced with a single argument representing the partial-aggregate
* transition values.
*
* aggpresorted is set by the query planner for ORDER BY and DISTINCT
* aggregates where the chosen plan provides presorted input for this
* aggregate during execution.
*
* aggsplit indicates the expected partial-aggregation mode for the Aggref's
* parent plan node. It's always set to AGGSPLIT_SIMPLE in the parser, but
* the planner might change it to something else. We use this mainly as
* a crosscheck that the Aggrefs match the plan; but note that when aggsplit
* indicates a non-final mode, aggtype reflects the transition data type
* not the SQL-level output type of the aggregate.
*
* aggno and aggtransno are -1 in the parse stage, and are set in planning.
* Aggregates with the same 'aggno' represent the same aggregate expression,
* and can share the result. Aggregates with same 'transno' but different
* 'aggno' can share the same transition state, only the final function needs
* to be called separately.
*
* Information related to collations, transition types and internal states
* are irrelevant for the query jumbling.
*/
typedef struct Aggref
{
Expr xpr;
/* pg_proc Oid of the aggregate */
Oid aggfnoid;
/* type Oid of result of the aggregate */
Oid aggtype pg_node_attr(query_jumble_ignore);
/* OID of collation of result */
Oid aggcollid pg_node_attr(query_jumble_ignore);
/* OID of collation that function should use */
Oid inputcollid pg_node_attr(query_jumble_ignore);
/*
* type Oid of aggregate's transition value; ignored for equal since it
* might not be set yet
*/
Oid aggtranstype pg_node_attr(equal_ignore, query_jumble_ignore);
/* type Oids of direct and aggregated args */
List *aggargtypes pg_node_attr(query_jumble_ignore);
/* direct arguments, if an ordered-set agg */
List *aggdirectargs;
/* aggregated arguments and sort expressions */
List *args;
/* ORDER BY (list of SortGroupClause) */
List *aggorder;
/* DISTINCT (list of SortGroupClause) */
List *aggdistinct;
/* FILTER expression, if any */
Expr *aggfilter;
/* true if argument list was really '*' */
bool aggstar pg_node_attr(query_jumble_ignore);
/*
* true if variadic arguments have been combined into an array last
* argument
*/
bool aggvariadic pg_node_attr(query_jumble_ignore);
/* aggregate kind (see pg_aggregate.h) */
char aggkind pg_node_attr(query_jumble_ignore);
/* aggregate input already sorted */
bool aggpresorted pg_node_attr(equal_ignore, query_jumble_ignore);
/* > 0 if agg belongs to outer query */
Index agglevelsup pg_node_attr(query_jumble_ignore);
/* expected agg-splitting mode of parent Agg */
AggSplit aggsplit pg_node_attr(query_jumble_ignore);
/* unique ID within the Agg node */
int aggno pg_node_attr(query_jumble_ignore);
/* unique ID of transition state in the Agg */
int aggtransno pg_node_attr(query_jumble_ignore);
/* token location, or -1 if unknown */
ParseLoc location;
} Aggref;
/*
* GroupingFunc
*
* A GroupingFunc is a GROUPING(...) expression, which behaves in many ways
* like an aggregate function (e.g. it "belongs" to a specific query level,
* which might not be the one immediately containing it), but also differs in
* an important respect: it never evaluates its arguments, they merely
* designate expressions from the GROUP BY clause of the query level to which
* it belongs.
*
* The spec defines the evaluation of GROUPING() purely by syntactic
* replacement, but we make it a real expression for optimization purposes so
* that one Agg node can handle multiple grouping sets at once. Evaluating the
* result only needs the column positions to check against the grouping set
* being projected. However, for EXPLAIN to produce meaningful output, we have
* to keep the original expressions around, since expression deparse does not
* give us any feasible way to get at the GROUP BY clause.
*
* Also, we treat two GroupingFunc nodes as equal if they have equal arguments
* lists and agglevelsup, without comparing the refs and cols annotations.
*
* In raw parse output we have only the args list; parse analysis fills in the
* refs list, and the planner fills in the cols list.
*
* All the fields used as information for an internal state are irrelevant
* for the query jumbling.
*/
typedef struct GroupingFunc
{
Expr xpr;
/* arguments, not evaluated but kept for benefit of EXPLAIN etc. */
List *args pg_node_attr(query_jumble_ignore);
/* ressortgrouprefs of arguments */
List *refs pg_node_attr(equal_ignore);
/* actual column positions set by planner */
List *cols pg_node_attr(equal_ignore, query_jumble_ignore);
/* same as Aggref.agglevelsup */
Index agglevelsup;
/* token location */
ParseLoc location;
} GroupingFunc;
/*
* WindowFunc
*
* Collation information is irrelevant for the query jumbling, as is the
* internal state information of the node like "winstar" and "winagg".
*/
typedef struct WindowFunc
{
Expr xpr;
/* pg_proc Oid of the function */
Oid winfnoid;
/* type Oid of result of the window function */
Oid wintype pg_node_attr(query_jumble_ignore);
/* OID of collation of result */
Oid wincollid pg_node_attr(query_jumble_ignore);
/* OID of collation that function should use */
Oid inputcollid pg_node_attr(query_jumble_ignore);
/* arguments to the window function */
List *args;
/* FILTER expression, if any */
Expr *aggfilter;
/* List of WindowFuncRunConditions to help short-circuit execution */
List *runCondition pg_node_attr(query_jumble_ignore);
/* index of associated WindowClause */
Index winref;
/* true if argument list was really '*' */
bool winstar pg_node_attr(query_jumble_ignore);
/* is function a simple aggregate? */
bool winagg pg_node_attr(query_jumble_ignore);
/* token location, or -1 if unknown */
ParseLoc location;
} WindowFunc;
/*
* WindowFuncRunCondition
*
* Represents intermediate OpExprs which will be used by WindowAgg to
* short-circuit execution.
*/
typedef struct WindowFuncRunCondition
{
Expr xpr;
/* PG_OPERATOR OID of the operator */
Oid opno;
/* OID of collation that operator should use */
Oid inputcollid pg_node_attr(query_jumble_ignore);
/*
* true of WindowFunc belongs on the left of the resulting OpExpr or false
* if the WindowFunc is on the right.
*/
bool wfunc_left;
/*
* The Expr being compared to the WindowFunc to use in the OpExpr in the
* WindowAgg's runCondition
*/
Expr *arg;
} WindowFuncRunCondition;
/*
* MergeSupportFunc
*
* A MergeSupportFunc is a merge support function expression that can only
* appear in the RETURNING list of a MERGE command. It returns information
* about the currently executing merge action.
*
* Currently, the only supported function is MERGE_ACTION(), which returns the
* command executed ("INSERT", "UPDATE", or "DELETE").
*/
typedef struct MergeSupportFunc
{
Expr xpr;
/* type Oid of result */
Oid msftype;
/* OID of collation, or InvalidOid if none */
Oid msfcollid;
/* token location, or -1 if unknown */
ParseLoc location;
} MergeSupportFunc;
/*
* SubscriptingRef: describes a subscripting operation over a container
* (array, etc).
*
* A SubscriptingRef can describe fetching a single element from a container,
* fetching a part of a container (e.g. an array slice), storing a single
* element into a container, or storing a slice. The "store" cases work with
* an initial container value and a source value that is inserted into the
* appropriate part of the container; the result of the operation is an
* entire new modified container value.
*
* If reflowerindexpr = NIL, then we are fetching or storing a single container
* element at the subscripts given by refupperindexpr. Otherwise we are
* fetching or storing a container slice, that is a rectangular subcontainer
* with lower and upper bounds given by the index expressions.
* reflowerindexpr must be the same length as refupperindexpr when it
* is not NIL.
*
* In the slice case, individual expressions in the subscript lists can be
* NULL, meaning "substitute the array's current lower or upper bound".
* (Non-array containers may or may not support this.)
*
* refcontainertype is the actual container type that determines the
* subscripting semantics. (This will generally be either the exposed type of
* refexpr, or the base type if that is a domain.) refelemtype is the type of
* the container's elements; this is saved for the use of the subscripting
* functions, but is not used by the core code. refrestype, reftypmod, and
* refcollid describe the type of the SubscriptingRef's result. In a store
* expression, refrestype will always match refcontainertype; in a fetch,
* it could be refelemtype for an element fetch, or refcontainertype for a
* slice fetch, or possibly something else as determined by type-specific
* subscripting logic. Likewise, reftypmod and refcollid will match the
* container's properties in a store, but could be different in a fetch.
*
* Any internal state data is ignored for the query jumbling.
*
* Note: for the cases where a container is returned, if refexpr yields a R/W
* expanded container, then the implementation is allowed to modify that
* object in-place and return the same object.
*/
typedef struct SubscriptingRef
{
Expr xpr;
/* type of the container proper */
Oid refcontainertype pg_node_attr(query_jumble_ignore);
/* the container type's pg_type.typelem */
Oid refelemtype pg_node_attr(query_jumble_ignore);
/* type of the SubscriptingRef's result */
Oid refrestype pg_node_attr(query_jumble_ignore);
/* typmod of the result */
int32 reftypmod pg_node_attr(query_jumble_ignore);
/* collation of result, or InvalidOid if none */
Oid refcollid pg_node_attr(query_jumble_ignore);
/* expressions that evaluate to upper container indexes */
List *refupperindexpr;
/*
* expressions that evaluate to lower container indexes, or NIL for single
* container element.
*/
List *reflowerindexpr;
/* the expression that evaluates to a container value */
Expr *refexpr;
/* expression for the source value, or NULL if fetch */
Expr *refassgnexpr;
} SubscriptingRef;
/*
* CoercionContext - distinguishes the allowed set of type casts
*
* NB: ordering of the alternatives is significant; later (larger) values
* allow more casts than earlier ones.
*/
typedef enum CoercionContext
{
COERCION_IMPLICIT, /* coercion in context of expression */
COERCION_ASSIGNMENT, /* coercion in context of assignment */
COERCION_PLPGSQL, /* if no assignment cast, use CoerceViaIO */
COERCION_EXPLICIT, /* explicit cast operation */
} CoercionContext;
/*
* CoercionForm - how to display a FuncExpr or related node
*
* "Coercion" is a bit of a misnomer, since this value records other
* special syntaxes besides casts, but for now we'll keep this naming.
*
* NB: equal() ignores CoercionForm fields, therefore this *must* not carry
* any semantically significant information. We need that behavior so that
* the planner will consider equivalent implicit and explicit casts to be
* equivalent. In cases where those actually behave differently, the coercion
* function's arguments will be different.
*/
typedef enum CoercionForm
{
COERCE_EXPLICIT_CALL, /* display as a function call */
COERCE_EXPLICIT_CAST, /* display as an explicit cast */
COERCE_IMPLICIT_CAST, /* implicit cast, so hide it */
COERCE_SQL_SYNTAX, /* display with SQL-mandated special syntax */
} CoercionForm;
/*
* FuncExpr - expression node for a function call
*
* Collation information is irrelevant for the query jumbling, only the
* arguments and the function OID matter.
*/
typedef struct FuncExpr
{
Expr xpr;
/* PG_PROC OID of the function */
Oid funcid;
/* PG_TYPE OID of result value */
Oid funcresulttype pg_node_attr(query_jumble_ignore);
/* true if function returns set */
bool funcretset pg_node_attr(query_jumble_ignore);
/*
* true if variadic arguments have been combined into an array last
* argument
*/
bool funcvariadic pg_node_attr(query_jumble_ignore);
/* how to display this function call */
CoercionForm funcformat pg_node_attr(query_jumble_ignore);
/* OID of collation of result */
Oid funccollid pg_node_attr(query_jumble_ignore);
/* OID of collation that function should use */
Oid inputcollid pg_node_attr(query_jumble_ignore);
/* arguments to the function */
List *args;
/* token location, or -1 if unknown */
ParseLoc location;
} FuncExpr;
/*
* NamedArgExpr - a named argument of a function
*
* This node type can only appear in the args list of a FuncCall or FuncExpr
* node. We support pure positional call notation (no named arguments),
* named notation (all arguments are named), and mixed notation (unnamed
* arguments followed by named ones).
*
* Parse analysis sets argnumber to the positional index of the argument,
* but doesn't rearrange the argument list.
*
* The planner will convert argument lists to pure positional notation
* during expression preprocessing, so execution never sees a NamedArgExpr.
*/
typedef struct NamedArgExpr
{
Expr xpr;
/* the argument expression */
Expr *arg;
/* the name */
char *name pg_node_attr(query_jumble_ignore);
/* argument's number in positional notation */
int argnumber;
/* argument name location, or -1 if unknown */
ParseLoc location;
} NamedArgExpr;
/*
* OpExpr - expression node for an operator invocation
*
* Semantically, this is essentially the same as a function call.
*
* Note that opfuncid is not necessarily filled in immediately on creation
* of the node. The planner makes sure it is valid before passing the node
* tree to the executor, but during parsing/planning opfuncid can be 0.
* Therefore, equal() will accept a zero value as being equal to other values.
*
* Internal state information and collation data is irrelevant for the query
* jumbling.
*/
typedef struct OpExpr
{
Expr xpr;
/* PG_OPERATOR OID of the operator */
Oid opno;
/* PG_PROC OID of underlying function */
Oid opfuncid pg_node_attr(equal_ignore_if_zero, query_jumble_ignore);
/* PG_TYPE OID of result value */
Oid opresulttype pg_node_attr(query_jumble_ignore);
/* true if operator returns set */
bool opretset pg_node_attr(query_jumble_ignore);
/* OID of collation of result */
Oid opcollid pg_node_attr(query_jumble_ignore);
/* OID of collation that operator should use */
Oid inputcollid pg_node_attr(query_jumble_ignore);
/* arguments to the operator (1 or 2) */
List *args;
/* token location, or -1 if unknown */
ParseLoc location;
} OpExpr;
/*
* DistinctExpr - expression node for "x IS DISTINCT FROM y"
*
* Except for the nodetag, this is represented identically to an OpExpr
* referencing the "=" operator for x and y.
* We use "=", not the more obvious "<>", because more datatypes have "="
* than "<>". This means the executor must invert the operator result.
* Note that the operator function won't be called at all if either input
* is NULL, since then the result can be determined directly.
*/
typedef OpExpr DistinctExpr;
/*
* NullIfExpr - a NULLIF expression
*
* Like DistinctExpr, this is represented the same as an OpExpr referencing
* the "=" operator for x and y.
*/
typedef OpExpr NullIfExpr;
/*
* ScalarArrayOpExpr - expression node for "scalar op ANY/ALL (array)"
*
* The operator must yield boolean. It is applied to the left operand
* and each element of the righthand array, and the results are combined
* with OR or AND (for ANY or ALL respectively). The node representation
* is almost the same as for the underlying operator, but we need a useOr
* flag to remember whether it's ANY or ALL, and we don't have to store
* the result type (or the collation) because it must be boolean.
*
* A ScalarArrayOpExpr with a valid hashfuncid is evaluated during execution
* by building a hash table containing the Const values from the RHS arg.
* This table is probed during expression evaluation. The planner will set
* hashfuncid to the hash function which must be used to build and probe the
* hash table. The executor determines if it should use hash-based checks or
* the more traditional means based on if the hashfuncid is set or not.
*
* When performing hashed NOT IN, the negfuncid will also be set to the
* equality function which the hash table must use to build and probe the hash
* table. opno and opfuncid will remain set to the <> operator and its
* corresponding function and won't be used during execution. For
* non-hashtable based NOT INs, negfuncid will be set to InvalidOid. See
* convert_saop_to_hashed_saop().
*
* Similar to OpExpr, opfuncid, hashfuncid, and negfuncid are not necessarily
* filled in right away, so will be ignored for equality if they are not set
* yet.
*
* OID entries of the internal function types are irrelevant for the query
* jumbling, but the operator OID and the arguments are.
*/
typedef struct ScalarArrayOpExpr
{
Expr xpr;
/* PG_OPERATOR OID of the operator */
Oid opno;
/* PG_PROC OID of comparison function */
Oid opfuncid pg_node_attr(equal_ignore_if_zero, query_jumble_ignore);
/* PG_PROC OID of hash func or InvalidOid */
Oid hashfuncid pg_node_attr(equal_ignore_if_zero, query_jumble_ignore);
/* PG_PROC OID of negator of opfuncid function or InvalidOid. See above */
Oid negfuncid pg_node_attr(equal_ignore_if_zero, query_jumble_ignore);
/* true for ANY, false for ALL */
bool useOr;
/* OID of collation that operator should use */
Oid inputcollid pg_node_attr(query_jumble_ignore);
/* the scalar and array operands */
List *args;
/* token location, or -1 if unknown */
ParseLoc location;
} ScalarArrayOpExpr;
/*
* BoolExpr - expression node for the basic Boolean operators AND, OR, NOT
*
* Notice the arguments are given as a List. For NOT, of course the list
* must always have exactly one element. For AND and OR, there can be two
* or more arguments.
*/
typedef enum BoolExprType
{
AND_EXPR, OR_EXPR, NOT_EXPR
} BoolExprType;
typedef struct BoolExpr
{
pg_node_attr(custom_read_write)
Expr xpr;
BoolExprType boolop;
List *args; /* arguments to this expression */
ParseLoc location; /* token location, or -1 if unknown */
} BoolExpr;
/*
* SubLink
*
* A SubLink represents a subselect appearing in an expression, and in some
* cases also the combining operator(s) just above it. The subLinkType
* indicates the form of the expression represented:
* EXISTS_SUBLINK EXISTS(SELECT ...)
* ALL_SUBLINK (lefthand) op ALL (SELECT ...)
* ANY_SUBLINK (lefthand) op ANY (SELECT ...)
* ROWCOMPARE_SUBLINK (lefthand) op (SELECT ...)
* EXPR_SUBLINK (SELECT with single targetlist item ...)
* MULTIEXPR_SUBLINK (SELECT with multiple targetlist items ...)
* ARRAY_SUBLINK ARRAY(SELECT with single targetlist item ...)
* CTE_SUBLINK WITH query (never actually part of an expression)
* For ALL, ANY, and ROWCOMPARE, the lefthand is a list of expressions of the
* same length as the subselect's targetlist. ROWCOMPARE will *always* have
* a list with more than one entry; if the subselect has just one target
* then the parser will create an EXPR_SUBLINK instead (and any operator
* above the subselect will be represented separately).
* ROWCOMPARE, EXPR, and MULTIEXPR require the subselect to deliver at most
* one row (if it returns no rows, the result is NULL).
* ALL, ANY, and ROWCOMPARE require the combining operators to deliver boolean
* results. ALL and ANY combine the per-row results using AND and OR
* semantics respectively.
* ARRAY requires just one target column, and creates an array of the target
* column's type using any number of rows resulting from the subselect.
*
* SubLink is classed as an Expr node, but it is not actually executable;
* it must be replaced in the expression tree by a SubPlan node during
* planning.
*
* NOTE: in the raw output of gram.y, testexpr contains just the raw form
* of the lefthand expression (if any), and operName is the String name of
* the combining operator. Also, subselect is a raw parsetree. During parse
* analysis, the parser transforms testexpr into a complete boolean expression
* that compares the lefthand value(s) to PARAM_SUBLINK nodes representing the
* output columns of the subselect. And subselect is transformed to a Query.
* This is the representation seen in saved rules and in the rewriter.
*
* In EXISTS, EXPR, MULTIEXPR, and ARRAY SubLinks, testexpr and operName
* are unused and are always null.
*
* subLinkId is currently used only for MULTIEXPR SubLinks, and is zero in
* other SubLinks. This number identifies different multiple-assignment
* subqueries within an UPDATE statement's SET list. It is unique only
* within a particular targetlist. The output column(s) of the MULTIEXPR
* are referenced by PARAM_MULTIEXPR Params appearing elsewhere in the tlist.
*
* The CTE_SUBLINK case never occurs in actual SubLink nodes, but it is used
* in SubPlans generated for WITH subqueries.
*/
typedef enum SubLinkType
{
EXISTS_SUBLINK,
ALL_SUBLINK,
ANY_SUBLINK,
ROWCOMPARE_SUBLINK,