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
|
/*-------------------------------------------------------------------------
*
* plannodes.h
* definitions for query plan nodes
*
*
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: plannodes.h,v 1.50 2001/09/18 01:59:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef PLANNODES_H
#define PLANNODES_H
#include "nodes/execnodes.h"
/* ----------------------------------------------------------------
* Executor State types are used in the plannode structures
* so we have to include their definitions too.
*
* Node Type node information used by executor
*
* control nodes
*
* Result ResultState resstate;
* Append AppendState appendstate;
*
* scan nodes
*
* Scan *** CommonScanState scanstate;
* IndexScan IndexScanState indxstate;
* SubqueryScan SubqueryScanState subquerystate;
*
* (*** nodes which inherit Scan also inherit scanstate)
*
* join nodes
*
* NestLoop NestLoopState nlstate;
* MergeJoin MergeJoinState mergestate;
* HashJoin HashJoinState hashjoinstate;
*
* materialize nodes
*
* Material MaterialState matstate;
* Sort SortState sortstate;
* Unique UniqueState uniquestate;
* SetOp SetOpState setopstate;
* Limit LimitState limitstate;
* Hash HashState hashstate;
*
* ----------------------------------------------------------------
*/
/* ----------------------------------------------------------------
* node definitions
* ----------------------------------------------------------------
*/
/* ----------------
* Plan node
* ----------------
*/
typedef struct Plan
{
NodeTag type;
/* estimated execution costs for plan (see costsize.c for more info) */
Cost startup_cost; /* cost expended before fetching any
* tuples */
Cost total_cost; /* total cost (assuming all tuples
* fetched) */
/*
* planner's estimate of result size (note: LIMIT, if any, is not
* considered in setting plan_rows)
*/
double plan_rows; /* number of rows plan is expected to emit */
int plan_width; /* average row width in bytes */
/*
* execution state data. Having Plan point to this, rather than the
* other way round, is 100% bogus.
*/
EState *state; /* at execution time, state's of
* individual nodes point to one EState
* for the whole top-level plan */
struct Instrumentation *instrument; /* Optional runtime stats for this
* plan node */
/*
* Common structural data for all Plan types. XXX chgParam is runtime
* data and should be in the EState, not here.
*/
List *targetlist;
List *qual; /* implicitly-ANDed qual conditions */
struct Plan *lefttree;
struct Plan *righttree;
List *extParam; /* indices of _all_ _external_ PARAM_EXEC
* for this plan in global
* es_param_exec_vals. Params from
* setParam from initPlan-s are not
* included, but their execParam-s are
* here!!! */
List *locParam; /* someones from setParam-s */
List *chgParam; /* list of changed ones from the above */
List *initPlan; /* Init Plan nodes (un-correlated expr
* subselects) */
List *subPlan; /* Other SubPlan nodes */
/*
* We really need in some TopPlan node to store range table and
* resultRelation from Query there and get rid of Query itself from
* Executor. Some other stuff like below could be put there, too.
*/
int nParamExec; /* Number of them in entire query. This is
* to get Executor know about how many
* param_exec there are in query plan. */
} Plan;
/* ----------------
* these are are defined to avoid confusion problems with "left"
* and "right" and "inner" and "outer". The convention is that
* the "left" plan is the "outer" plan and the "right" plan is
* the inner plan, but these make the code more readable.
* ----------------
*/
#define innerPlan(node) (((Plan *)(node))->righttree)
#define outerPlan(node) (((Plan *)(node))->lefttree)
/*
* ===============
* Top-level nodes
* ===============
*/
/* all plan nodes "derive" from the Plan structure by having the
Plan structure as the first field. This ensures that everything works
when nodes are cast to Plan's. (node pointers are frequently cast to Plan*
when passed around generically in the executor */
/* ----------------
* Result node -
* If no outer plan, evaluate a variable-free targetlist.
* If outer plan, return tuples from outer plan that satisfy
* given quals (we can also do a level of projection)
* ----------------
*/
typedef struct Result
{
Plan plan;
Node *resconstantqual;
ResultState *resstate;
} Result;
/* ----------------
* Append node -
* Generate the concatenation of the results of sub-plans.
*
* Append nodes are sometimes used to switch between several result relations
* (when the target of an UPDATE or DELETE is an inheritance set). Such a
* node will have isTarget true. The Append executor is then responsible
* for updating the executor state to point at the correct target relation
* whenever it switches subplans.
* ----------------
*/
typedef struct Append
{
Plan plan;
List *appendplans;
bool isTarget;
AppendState *appendstate;
} Append;
/*
* ==========
* Scan nodes
* ==========
*/
typedef struct Scan
{
Plan plan;
Index scanrelid; /* relid is index into the range table */
CommonScanState *scanstate;
} Scan;
/* ----------------
* sequential scan node
* ----------------
*/
typedef Scan SeqScan;
/* ----------------
* index scan node
* ----------------
*/
typedef struct IndexScan
{
Scan scan;
List *indxid;
List *indxqual;
List *indxqualorig;
ScanDirection indxorderdir;
IndexScanState *indxstate;
} IndexScan;
/* ----------------
* tid scan node
* ----------------
*/
typedef struct TidScan
{
Scan scan;
bool needRescan;
List *tideval;
TidScanState *tidstate;
} TidScan;
/* ----------------
* subquery scan node
*
* SubqueryScan is for scanning the output of a sub-query in the range table.
* We need a special plan node above the sub-query's plan as a place to switch
* execution contexts. Although we are not scanning a physical relation,
* we make this a descendant of Scan anyway for code-sharing purposes.
*
* Note: we store the sub-plan in the type-specific subplan field, not in
* the generic lefttree field as you might expect. This is because we do
* not want plan-tree-traversal routines to recurse into the subplan without
* knowing that they are changing Query contexts.
* ----------------
*/
typedef struct SubqueryScan
{
Scan scan;
Plan *subplan;
} SubqueryScan;
/*
* ==========
* Join nodes
* ==========
*/
/* ----------------
* Join node
*
* jointype: rule for joining tuples from left and right subtrees
* joinqual: qual conditions that came from JOIN/ON or JOIN/USING
* (plan.qual contains conditions that came from WHERE)
*
* When jointype is INNER, joinqual and plan.qual are semantically
* interchangeable. For OUTER jointypes, the two are *not* interchangeable;
* only joinqual is used to determine whether a match has been found for
* the purpose of deciding whether to generate null-extended tuples.
* (But plan.qual is still applied before actually returning a tuple.)
* For an outer join, only joinquals are allowed to be used as the merge
* or hash condition of a merge or hash join.
* ----------------
*/
typedef struct Join
{
Plan plan;
JoinType jointype;
List *joinqual; /* JOIN quals (in addition to plan.qual) */
} Join;
/* ----------------
* nest loop join node
* ----------------
*/
typedef struct NestLoop
{
Join join;
NestLoopState *nlstate;
} NestLoop;
/* ----------------
* merge join node
* ----------------
*/
typedef struct MergeJoin
{
Join join;
List *mergeclauses;
MergeJoinState *mergestate;
} MergeJoin;
/* ----------------
* hash join (probe) node
* ----------------
*/
typedef struct HashJoin
{
Join join;
List *hashclauses;
Oid hashjoinop;
HashJoinState *hashjoinstate;
} HashJoin;
/* ---------------
* aggregate node
* ---------------
*/
typedef struct Agg
{
Plan plan;
AggState *aggstate;
} Agg;
/* ---------------
* group node -
* use for queries with GROUP BY specified.
*
* If tuplePerGroup is true, one tuple (with group columns only) is
* returned for each group and NULL is returned when there are no more
* groups. Otherwise, all the tuples of a group are returned with a
* NULL returned at the end of each group. (see nodeGroup.c for details)
* ---------------
*/
typedef struct Group
{
Plan plan;
bool tuplePerGroup; /* what tuples to return (see above) */
int numCols; /* number of group columns */
AttrNumber *grpColIdx; /* indexes into the target list */
GroupState *grpstate;
} Group;
/* ----------------
* materialization node
* ----------------
*/
typedef struct Material
{
Plan plan;
MaterialState *matstate;
} Material;
/* ----------------
* sort node
* ----------------
*/
typedef struct Sort
{
Plan plan;
int keycount;
SortState *sortstate;
} Sort;
/* ----------------
* unique node
* ----------------
*/
typedef struct Unique
{
Plan plan;
int numCols; /* number of columns to check for
* uniqueness */
AttrNumber *uniqColIdx; /* indexes into the target list */
UniqueState *uniquestate;
} Unique;
/* ----------------
* setop node
* ----------------
*/
typedef enum SetOpCmd
{
SETOPCMD_INTERSECT,
SETOPCMD_INTERSECT_ALL,
SETOPCMD_EXCEPT,
SETOPCMD_EXCEPT_ALL
} SetOpCmd;
typedef struct SetOp
{
Plan plan;
SetOpCmd cmd; /* what to do */
int numCols; /* number of columns to check for
* duplicate-ness */
AttrNumber *dupColIdx; /* indexes into the target list */
AttrNumber flagColIdx;
SetOpState *setopstate;
} SetOp;
/* ----------------
* limit node
* ----------------
*/
typedef struct Limit
{
Plan plan;
Node *limitOffset; /* OFFSET parameter, or NULL if none */
Node *limitCount; /* COUNT parameter, or NULL if none */
LimitState *limitstate;
} Limit;
/* ----------------
* hash build node
* ----------------
*/
typedef struct Hash
{
Plan plan;
Node *hashkey;
HashState *hashstate;
} Hash;
#ifdef NOT_USED
/* -------------------
* Tee node information
*
* leftParent : the left parent of this node
* rightParent: the right parent of this node
* -------------------
*/
typedef struct Tee
{
Plan plan;
Plan *leftParent;
Plan *rightParent;
TeeState *teestate;
char *teeTableName; /* the name of the table to materialize
* the tee into */
List *rtentries; /* the range table for the plan below the
* Tee may be different than the parent
* plans */
} Tee;
#endif
/* ---------------------
* SubPlan node
* ---------------------
*/
typedef struct SubPlan
{
NodeTag type;
Plan *plan; /* subselect plan itself */
int plan_id; /* dummy thing because of we haven't equal
* funcs for plan nodes... actually, we
* could put *plan itself somewhere else
* (TopPlan node ?)... */
List *rtable; /* range table for subselect */
/* setParam and parParam are lists of integers (param IDs) */
List *setParam; /* non-correlated EXPR & EXISTS subqueries
* have to set some Params for paren Plan */
List *parParam; /* indices of corr. Vars from parent plan */
SubLink *sublink; /* SubLink node from parser; holds info
* about what to do with subselect's
* results */
/*
* Remaining fields are working state for executor; not used in
* planning
*/
bool needShutdown; /* TRUE = need to shutdown subplan */
HeapTuple curTuple; /* copy of most recent tuple from subplan */
} SubPlan;
#endif /* PLANNODES_H */
|