YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/postgres/src/include/nodes/execnodes.h
Line
Count
Source (jump to first uncovered line)
1
/*-------------------------------------------------------------------------
2
 *
3
 * execnodes.h
4
 *    definitions for executor state nodes
5
 *
6
 *
7
 * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
8
 * Portions Copyright (c) 1994, Regents of the University of California
9
 *
10
 * src/include/nodes/execnodes.h
11
 *
12
 *-------------------------------------------------------------------------
13
 */
14
#ifndef EXECNODES_H
15
#define EXECNODES_H
16
17
#include "access/genam.h"
18
#include "access/heapam.h"
19
#include "access/tupconvert.h"
20
#include "executor/instrument.h"
21
#include "lib/pairingheap.h"
22
#include "nodes/params.h"
23
#include "nodes/plannodes.h"
24
#include "utils/hsearch.h"
25
#include "utils/queryenvironment.h"
26
#include "utils/reltrigger.h"
27
#include "utils/sharedtuplestore.h"
28
#include "utils/sortsupport.h"
29
#include "utils/tuplestore.h"
30
#include "utils/tuplesort.h"
31
#include "nodes/tidbitmap.h"
32
#include "storage/condition_variable.h"
33
34
#include "pg_yb_utils.h"
35
36
struct PlanState;       /* forward references in this file */
37
struct ParallelHashJoinState;
38
struct ExprState;
39
struct ExprContext;
40
struct ExprEvalStep;      /* avoid including execExpr.h everywhere */
41
42
43
/* ----------------
44
 *    ExprState node
45
 *
46
 * ExprState is the top-level node for expression evaluation.
47
 * It contains instructions (in ->steps) to evaluate the expression.
48
 * ----------------
49
 */
50
typedef Datum (*ExprStateEvalFunc) (struct ExprState *expression,
51
                  struct ExprContext *econtext,
52
                  bool *isNull);
53
54
/* Bits in ExprState->flags (see also execExpr.h for private flag bits): */
55
/* expression is for use with ExecQual() */
56
186k
#define EEO_FLAG_IS_QUAL          (1 << 0)
57
58
typedef struct ExprState
59
{
60
  Node    tag;
61
62
  uint8   flags;      /* bitmask of EEO_FLAG_* bits, see above */
63
64
  /*
65
   * Storage for result value of a scalar expression, or for individual
66
   * column results within expressions built by ExecBuildProjectionInfo().
67
   */
68
#define FIELDNO_EXPRSTATE_RESNULL 2
69
  bool    resnull;
70
#define FIELDNO_EXPRSTATE_RESVALUE 3
71
  Datum   resvalue;
72
73
  /*
74
   * If projecting a tuple result, this slot holds the result; else NULL.
75
   */
76
#define FIELDNO_EXPRSTATE_RESULTSLOT 4
77
  TupleTableSlot *resultslot;
78
79
  /*
80
   * Instructions to compute expression's return value.
81
   */
82
  struct ExprEvalStep *steps;
83
84
  /*
85
   * Function that actually evaluates the expression.  This can be set to
86
   * different values depending on the complexity of the expression.
87
   */
88
  ExprStateEvalFunc evalfunc;
89
90
  /* original expression tree, for debugging only */
91
  Expr     *expr;
92
93
  /* private state for an evalfunc */
94
  void     *evalfunc_private;
95
96
  /*
97
   * XXX: following fields only needed during "compilation" (ExecInitExpr);
98
   * could be thrown away afterwards.
99
   */
100
101
  int     steps_len;    /* number of steps currently */
102
  int     steps_alloc;  /* allocated length of steps array */
103
104
  struct PlanState *parent; /* parent PlanState node, if any */
105
  ParamListInfo ext_params; /* for compiling PARAM_EXTERN nodes */
106
107
  Datum    *innermost_caseval;
108
  bool     *innermost_casenull;
109
110
  Datum    *innermost_domainval;
111
  bool     *innermost_domainnull;
112
} ExprState;
113
114
115
/* ----------------
116
 *    IndexInfo information
117
 *
118
 *    this struct holds the information needed to construct new index
119
 *    entries for a particular index.  Used for both index_build and
120
 *    retail creation of index entries.
121
 *
122
 *    NumIndexAttrs   total number of columns in this index
123
 *    NumIndexKeyAttrs  number of key columns in index
124
 *    IndexAttrNumbers  underlying-rel attribute numbers used as keys
125
 *              (zeroes indicate expressions). It also contains
126
 *              info about included columns.
127
 *    Expressions     expr trees for expression entries, or NIL if none
128
 *    ExpressionsState  exec state for expressions, or NIL if none
129
 *    Predicate     partial-index predicate, or NIL if none
130
 *    PredicateState    exec state for predicate, or NIL if none
131
 *    ExclusionOps    Per-column exclusion operators, or NULL if none
132
 *    ExclusionProcs    Underlying function OIDs for ExclusionOps
133
 *    ExclusionStrats   Opclass strategy numbers for ExclusionOps
134
 *    UniqueOps     Theses are like Exclusion*, but for unique indexes
135
 *    UniqueProcs
136
 *    UniqueStrats
137
 *    Unique        is it a unique index?
138
 *    ReadyForInserts   is it valid for inserts?
139
 *    Concurrent      are we doing a concurrent index build?
140
 *    BrokenHotChain    did we detect any broken HOT chains?
141
 *    ParallelWorkers   # of workers requested (excludes leader)
142
 *    Am          Oid of index AM
143
 *    AmCache       private cache area for index AM
144
 *    Context       memory context holding this IndexInfo
145
 *    SplitOptions    Options to split index into tablets.
146
 *
147
 * ii_Concurrent, ii_BrokenHotChain, and ii_ParallelWorkers are used only
148
 * during index build; they're conventionally zeroed otherwise.
149
 * ----------------
150
 */
151
typedef struct IndexInfo
152
{
153
  NodeTag   type;
154
  int     ii_NumIndexAttrs; /* total number of columns in index */
155
  int     ii_NumIndexKeyAttrs;  /* number of key columns in index */
156
  AttrNumber  ii_IndexAttrNumbers[INDEX_MAX_KEYS];
157
  List     *ii_Expressions; /* list of Expr */
158
  List     *ii_ExpressionsState;  /* list of ExprState */
159
  List     *ii_Predicate; /* list of Expr */
160
  ExprState  *ii_PredicateState;
161
  Oid      *ii_ExclusionOps;  /* array with one entry per column */
162
  Oid      *ii_ExclusionProcs;  /* array with one entry per column */
163
  uint16     *ii_ExclusionStrats; /* array with one entry per column */
164
  Oid      *ii_UniqueOps; /* array with one entry per column */
165
  Oid      *ii_UniqueProcs; /* array with one entry per column */
166
  uint16     *ii_UniqueStrats;  /* array with one entry per column */
167
  bool    ii_Unique;
168
  bool    ii_ReadyForInserts;
169
  bool    ii_Concurrent;
170
  bool    ii_BrokenHotChain;
171
  int     ii_ParallelWorkers;
172
  Oid     ii_Am;
173
  void     *ii_AmCache;
174
  MemoryContext ii_Context;
175
} IndexInfo;
176
177
/* ----------------
178
 *    ExprContext_CB
179
 *
180
 *    List of callbacks to be called at ExprContext shutdown.
181
 * ----------------
182
 */
183
typedef void (*ExprContextCallbackFunction) (Datum arg);
184
185
typedef struct ExprContext_CB
186
{
187
  struct ExprContext_CB *next;
188
  ExprContextCallbackFunction function;
189
  Datum   arg;
190
} ExprContext_CB;
191
192
/* ----------------
193
 *    ExprContext
194
 *
195
 *    This class holds the "current context" information
196
 *    needed to evaluate expressions for doing tuple qualifications
197
 *    and tuple projections.  For example, if an expression refers
198
 *    to an attribute in the current inner tuple then we need to know
199
 *    what the current inner tuple is and so we look at the expression
200
 *    context.
201
 *
202
 *  There are two memory contexts associated with an ExprContext:
203
 *  * ecxt_per_query_memory is a query-lifespan context, typically the same
204
 *    context the ExprContext node itself is allocated in.  This context
205
 *    can be used for purposes such as storing function call cache info.
206
 *  * ecxt_per_tuple_memory is a short-term context for expression results.
207
 *    As the name suggests, it will typically be reset once per tuple,
208
 *    before we begin to evaluate expressions for that tuple.  Each
209
 *    ExprContext normally has its very own per-tuple memory context.
210
 *
211
 *  GetCurrentMemoryContext() should be set to ecxt_per_tuple_memory before
212
 *  calling ExecEvalExpr() --- see ExecEvalExprSwitchContext().
213
 * ----------------
214
 */
215
typedef struct ExprContext
216
{
217
  NodeTag   type;
218
219
  /* Tuples that Var nodes in expression may refer to */
220
#define FIELDNO_EXPRCONTEXT_SCANTUPLE 1
221
  TupleTableSlot *ecxt_scantuple;
222
#define FIELDNO_EXPRCONTEXT_INNERTUPLE 2
223
  TupleTableSlot *ecxt_innertuple;
224
#define FIELDNO_EXPRCONTEXT_OUTERTUPLE 3
225
  TupleTableSlot *ecxt_outertuple;
226
227
  /* Memory contexts for expression evaluation --- see notes above */
228
  MemoryContext ecxt_per_query_memory;
229
  MemoryContext ecxt_per_tuple_memory;
230
231
  /* Values to substitute for Param nodes in expression */
232
  ParamExecData *ecxt_param_exec_vals;  /* for PARAM_EXEC params */
233
  ParamListInfo ecxt_param_list_info; /* for other param types */
234
235
  /*
236
   * Values to substitute for Aggref nodes in the expressions of an Agg
237
   * node, or for WindowFunc nodes within a WindowAgg node.
238
   */
239
#define FIELDNO_EXPRCONTEXT_AGGVALUES 8
240
  Datum    *ecxt_aggvalues; /* precomputed values for aggs/windowfuncs */
241
#define FIELDNO_EXPRCONTEXT_AGGNULLS 9
242
  bool     *ecxt_aggnulls;  /* null flags for aggs/windowfuncs */
243
244
  /* Value to substitute for CaseTestExpr nodes in expression */
245
#define FIELDNO_EXPRCONTEXT_CASEDATUM 10
246
  Datum   caseValue_datum;
247
#define FIELDNO_EXPRCONTEXT_CASENULL 11
248
  bool    caseValue_isNull;
249
250
  /* Value to substitute for CoerceToDomainValue nodes in expression */
251
#define FIELDNO_EXPRCONTEXT_DOMAINDATUM 12
252
  Datum   domainValue_datum;
253
#define FIELDNO_EXPRCONTEXT_DOMAINNULL 13
254
  bool    domainValue_isNull;
255
256
  /* Link to containing EState (NULL if a standalone ExprContext) */
257
  struct EState *ecxt_estate;
258
259
  /* Functions to call back when ExprContext is shut down or rescanned */
260
  ExprContext_CB *ecxt_callbacks;
261
} ExprContext;
262
263
/*
264
 * Set-result status used when evaluating functions potentially returning a
265
 * set.
266
 */
267
typedef enum
268
{
269
  ExprSingleResult,     /* expression does not return a set */
270
  ExprMultipleResult,     /* this result is an element of a set */
271
  ExprEndResult       /* there are no more elements in the set */
272
} ExprDoneCond;
273
274
/*
275
 * Return modes for functions returning sets.  Note values must be chosen
276
 * as separate bits so that a bitmask can be formed to indicate supported
277
 * modes.  SFRM_Materialize_Random and SFRM_Materialize_Preferred are
278
 * auxiliary flags about SFRM_Materialize mode, rather than separate modes.
279
 */
280
typedef enum
281
{
282
  SFRM_ValuePerCall = 0x01, /* one value returned per call */
283
  SFRM_Materialize = 0x02,  /* result set instantiated in Tuplestore */
284
  SFRM_Materialize_Random = 0x04, /* Tuplestore needs randomAccess */
285
  SFRM_Materialize_Preferred = 0x08 /* caller prefers Tuplestore */
286
} SetFunctionReturnMode;
287
288
/*
289
 * When calling a function that might return a set (multiple rows),
290
 * a node of this type is passed as fcinfo->resultinfo to allow
291
 * return status to be passed back.  A function returning set should
292
 * raise an error if no such resultinfo is provided.
293
 */
294
typedef struct ReturnSetInfo
295
{
296
  NodeTag   type;
297
  /* values set by caller: */
298
  ExprContext *econtext;    /* context function is being called in */
299
  TupleDesc expectedDesc; /* tuple descriptor expected by caller */
300
  int     allowedModes; /* bitmask: return modes caller can handle */
301
  /* result status from function (but pre-initialized by caller): */
302
  SetFunctionReturnMode returnMode; /* actual return mode */
303
  ExprDoneCond isDone;    /* status for ValuePerCall mode */
304
  /* fields filled by function in Materialize return mode: */
305
  Tuplestorestate *setResult; /* holds the complete returned tuple set */
306
  TupleDesc setDesc;    /* actual descriptor for returned tuples */
307
} ReturnSetInfo;
308
309
/* ----------------
310
 *    ProjectionInfo node information
311
 *
312
 *    This is all the information needed to perform projections ---
313
 *    that is, form new tuples by evaluation of targetlist expressions.
314
 *    Nodes which need to do projections create one of these.
315
 *
316
 *    The target tuple slot is kept in ProjectionInfo->pi_state.resultslot.
317
 *    ExecProject() evaluates the tlist, forms a tuple, and stores it
318
 *    in the given slot.  Note that the result will be a "virtual" tuple
319
 *    unless ExecMaterializeSlot() is then called to force it to be
320
 *    converted to a physical tuple.  The slot must have a tupledesc
321
 *    that matches the output of the tlist!
322
 * ----------------
323
 */
324
typedef struct ProjectionInfo
325
{
326
  NodeTag   type;
327
  /* instructions to evaluate projection */
328
  ExprState pi_state;
329
  /* expression context in which to evaluate expression */
330
  ExprContext *pi_exprContext;
331
} ProjectionInfo;
332
333
/* ----------------
334
 *    JunkFilter
335
 *
336
 *    This class is used to store information regarding junk attributes.
337
 *    A junk attribute is an attribute in a tuple that is needed only for
338
 *    storing intermediate information in the executor, and does not belong
339
 *    in emitted tuples.  For example, when we do an UPDATE query,
340
 *    the planner adds a "junk" entry to the targetlist so that the tuples
341
 *    returned to ExecutePlan() contain an extra attribute: the ctid of
342
 *    the tuple to be updated.  This is needed to do the update, but we
343
 *    don't want the ctid to be part of the stored new tuple!  So, we
344
 *    apply a "junk filter" to remove the junk attributes and form the
345
 *    real output tuple.  The junkfilter code also provides routines to
346
 *    extract the values of the junk attribute(s) from the input tuple.
347
 *
348
 *    targetList:   the original target list (including junk attributes).
349
 *    cleanTupType:   the tuple descriptor for the "clean" tuple (with
350
 *            junk attributes removed).
351
 *    cleanMap:     A map with the correspondence between the non-junk
352
 *            attribute numbers of the "original" tuple and the
353
 *            attribute numbers of the "clean" tuple.
354
 *    resultSlot:   tuple slot used to hold cleaned tuple.
355
 *    junkAttNo:    not used by junkfilter code.  Can be used by caller
356
 *            to remember the attno of a specific junk attribute
357
 *            (nodeModifyTable.c keeps the "ctid" or "wholerow"
358
 *            attno here).
359
 * ----------------
360
 */
361
typedef struct JunkFilter
362
{
363
  NodeTag   type;
364
  List     *jf_targetList;
365
  TupleDesc jf_cleanTupType;
366
  AttrNumber *jf_cleanMap;
367
  TupleTableSlot *jf_resultSlot;
368
  AttrNumber  jf_junkAttNo;
369
} JunkFilter;
370
371
/*
372
 * OnConflictSetState
373
 *
374
 * Executor state of an ON CONFLICT DO UPDATE operation.
375
 */
376
typedef struct OnConflictSetState
377
{
378
  NodeTag   type;
379
380
  ProjectionInfo *oc_ProjInfo;  /* for ON CONFLICT DO UPDATE SET */
381
  TupleDesc oc_ProjTupdesc; /* TupleDesc for the above projection */
382
  ExprState  *oc_WhereClause; /* state for the WHERE clause */
383
} OnConflictSetState;
384
385
/*
386
 * ResultRelInfo
387
 *
388
 * Whenever we update an existing relation, we have to update indexes on the
389
 * relation, and perhaps also fire triggers.  ResultRelInfo holds all the
390
 * information needed about a result relation, including indexes.
391
 */
392
typedef struct ResultRelInfo
393
{
394
  NodeTag   type;
395
396
  /* result relation's range table index */
397
  Index   ri_RangeTableIndex;
398
399
  /* relation descriptor for result relation */
400
  Relation  ri_RelationDesc;
401
402
  /* # of indices existing on result relation */
403
  int     ri_NumIndices;
404
405
  /* array of relation descriptors for indices */
406
  RelationPtr ri_IndexRelationDescs;
407
408
  /* array of key/attr info for indices */
409
  IndexInfo **ri_IndexRelationInfo;
410
411
  /* triggers to be fired, if any */
412
  TriggerDesc *ri_TrigDesc;
413
414
  /* cached lookup info for trigger functions */
415
  FmgrInfo   *ri_TrigFunctions;
416
417
  /* array of trigger WHEN expr states */
418
  ExprState **ri_TrigWhenExprs;
419
420
  /* optional runtime measurements for triggers */
421
  Instrumentation *ri_TrigInstrument;
422
423
  /* FDW callback functions, if foreign table */
424
  struct FdwRoutine *ri_FdwRoutine;
425
426
  /* available to save private state of FDW */
427
  void     *ri_FdwState;
428
429
  /* true when modifying foreign table directly */
430
  bool    ri_usesFdwDirectModify;
431
432
  /* list of WithCheckOption's to be checked */
433
  List     *ri_WithCheckOptions;
434
435
  /* list of WithCheckOption expr states */
436
  List     *ri_WithCheckOptionExprs;
437
438
  /* array of constraint-checking expr states */
439
  ExprState **ri_ConstraintExprs;
440
441
  /* for removing junk attributes from tuples */
442
  JunkFilter *ri_junkFilter;
443
444
  /* list of RETURNING expressions */
445
  List     *ri_returningList;
446
447
  /* for computing a RETURNING list */
448
  ProjectionInfo *ri_projectReturning;
449
450
  /* list of arbiter indexes to use to check conflicts */
451
  List     *ri_onConflictArbiterIndexes;
452
453
  /* ON CONFLICT evaluation state */
454
  OnConflictSetState *ri_onConflict;
455
456
  /* partition check expression */
457
  List     *ri_PartitionCheck;
458
459
  /* partition check expression state */
460
  ExprState  *ri_PartitionCheckExpr;
461
462
  /* relation descriptor for root partitioned table */
463
  Relation  ri_PartitionRoot;
464
465
  /* true if ready for tuple routing */
466
  bool    ri_PartitionReadyForRouting;
467
} ResultRelInfo;
468
469
/* ----------------
470
 *    EState information
471
 *
472
 * Master working state for an Executor invocation
473
 * ----------------
474
 */
475
typedef struct EState
476
{
477
  NodeTag   type;
478
479
  /* Basic state for all query types: */
480
  ScanDirection es_direction; /* current scan direction */
481
  Snapshot  es_snapshot;  /* time qual to use */
482
  Snapshot  es_crosscheck_snapshot; /* crosscheck time qual for RI */
483
  List     *es_range_table; /* List of RangeTblEntry */
484
  PlannedStmt *es_plannedstmt;  /* link to top of plan tree */
485
  const char *es_sourceText;  /* Source text from QueryDesc */
486
487
  JunkFilter *es_junkFilter;  /* top-level junk filter, if any */
488
489
  /* If query can insert/delete tuples, the command ID to mark them with */
490
  CommandId es_output_cid;
491
492
  /* Info about target table(s) for insert/update/delete queries: */
493
  ResultRelInfo *es_result_relations; /* array of ResultRelInfos */
494
  int     es_num_result_relations;  /* length of array */
495
  ResultRelInfo *es_result_relation_info; /* currently active array elt */
496
497
  /*
498
   * Info about the target partitioned target table root(s) for
499
   * update/delete queries.  They required only to fire any per-statement
500
   * triggers defined on the table.  It exists separately from
501
   * es_result_relations, because partitioned tables don't appear in the
502
   * plan tree for the update/delete cases.
503
   */
504
  ResultRelInfo *es_root_result_relations;  /* array of ResultRelInfos */
505
  int     es_num_root_result_relations; /* length of the array */
506
507
  /*
508
   * The following list contains ResultRelInfos created by the tuple routing
509
   * code for partitions that don't already have one.
510
   */
511
  List     *es_tuple_routing_result_relations;
512
513
  /* Stuff used for firing triggers: */
514
  List     *es_trig_target_relations; /* trigger-only ResultRelInfos */
515
  TupleTableSlot *es_trig_tuple_slot; /* for trigger output tuples */
516
  TupleTableSlot *es_trig_oldtup_slot;  /* for TriggerEnabled */
517
  TupleTableSlot *es_trig_newtup_slot;  /* for TriggerEnabled */
518
519
  /* Parameter info: */
520
  ParamListInfo es_param_list_info; /* values of external params */
521
  ParamExecData *es_param_exec_vals;  /* values of internal params */
522
523
  QueryEnvironment *es_queryEnv;  /* query environment */
524
525
  /* Other working state: */
526
  MemoryContext es_query_cxt; /* per-query context in which EState lives */
527
528
  List     *es_tupleTable;  /* List of TupleTableSlots */
529
530
  List     *es_rowMarks;  /* List of ExecRowMarks */
531
532
  uint64    es_processed; /* # of tuples processed */
533
  Oid     es_lastoid;   /* last oid processed (by INSERT) */
534
535
  int     es_top_eflags;  /* eflags passed to ExecutorStart */
536
  int     es_instrument;  /* OR of InstrumentOption flags */
537
  bool    es_finished;  /* true when ExecutorFinish is done */
538
539
  List     *es_exprcontexts;  /* List of ExprContexts within EState */
540
541
  List     *es_subplanstates; /* List of PlanState for SubPlans */
542
543
  List     *es_auxmodifytables; /* List of secondary ModifyTableStates */
544
545
  /*
546
   * this ExprContext is for per-output-tuple operations, such as constraint
547
   * checks and index-value computations.  It will be reset for each output
548
   * tuple.  Note that it will be created only if needed.
549
   */
550
  ExprContext *es_per_tuple_exprcontext;
551
552
  /*
553
   * These fields are for re-evaluating plan quals when an updated tuple is
554
   * substituted in READ COMMITTED mode.  es_epqTuple[] contains tuples that
555
   * scan plan nodes should return instead of whatever they'd normally
556
   * return, or NULL if nothing to return; es_epqTupleSet[] is true if a
557
   * particular array entry is valid; and es_epqScanDone[] is state to
558
   * remember if the tuple has been returned already.  Arrays are of size
559
   * list_length(es_range_table) and are indexed by scan node scanrelid - 1.
560
   */
561
  HeapTuple  *es_epqTuple;  /* array of EPQ substitute tuples */
562
  bool     *es_epqTupleSet; /* true if EPQ tuple is provided */
563
  bool     *es_epqScanDone; /* true if EPQ tuple has been fetched */
564
565
  bool    es_use_parallel_mode; /* can we use parallel workers? */
566
567
  /* The per-query shared memory area to use for parallel execution. */
568
  struct dsa_area *es_query_dsa;
569
570
  /*
571
   * JIT information. es_jit_flags indicates whether JIT should be performed
572
   * and with which options.  es_jit is created on-demand when JITing is
573
   * performed.
574
   *
575
   * es_jit_combined_instr is the the combined, on demand allocated,
576
   * instrumentation from all workers. The leader's instrumentation is kept
577
   * separate, and is combined on demand by ExplainPrintJITSummary().
578
   */
579
  int     es_jit_flags;
580
  struct JitContext *es_jit;
581
  struct JitInstrumentation *es_jit_worker_instr;
582
583
  /*
584
   * YugaByte-specific fields
585
   */
586
587
  bool yb_es_is_single_row_modify_txn; /* Is this query a single-row modify
588
                                        * and the only stmt in this txn. */
589
  TupleTableSlot *yb_conflict_slot; /* If a conflict is to be resolved when inserting data,
590
                                     * we cache the conflict tuple here when processing and
591
                                     * then free the slot after the conflict is resolved. */
592
  YBCPgExecParameters yb_exec_params;
593
594
  /*
595
   *  The read hybrid time used for this query. This value is initialized
596
   *  to 0, and later updated by the first read operation initiated for this
597
   *  query. All later read operations are then ensured that they will never
598
   *  read any data written past this time.
599
   */
600
  uint64_t yb_es_read_ht;
601
} EState;
602
603
/*
604
 * ExecRowMark -
605
 *     runtime representation of FOR [KEY] UPDATE/SHARE clauses
606
 *
607
 * When doing UPDATE, DELETE, or SELECT FOR [KEY] UPDATE/SHARE, we will have an
608
 * ExecRowMark for each non-target relation in the query (except inheritance
609
 * parent RTEs, which can be ignored at runtime).  Virtual relations such as
610
 * subqueries-in-FROM will have an ExecRowMark with relation == NULL.  See
611
 * PlanRowMark for details about most of the fields.  In addition to fields
612
 * directly derived from PlanRowMark, we store an activity flag (to denote
613
 * inactive children of inheritance trees), curCtid, which is used by the
614
 * WHERE CURRENT OF code, and ermExtra, which is available for use by the plan
615
 * node that sources the relation (e.g., for a foreign table the FDW can use
616
 * ermExtra to hold information).
617
 *
618
 * EState->es_rowMarks is a list of these structs.
619
 */
620
typedef struct ExecRowMark
621
{
622
  Relation  relation;   /* opened and suitably locked relation */
623
  Oid     relid;      /* its OID (or InvalidOid, if subquery) */
624
  Index   rti;      /* its range table index */
625
  Index   prti;     /* parent range table index, if child */
626
  Index   rowmarkId;    /* unique identifier for resjunk columns */
627
  RowMarkType markType;   /* see enum in nodes/plannodes.h */
628
  LockClauseStrength strength;  /* LockingClause's strength, or LCS_NONE */
629
  LockWaitPolicy waitPolicy;  /* NOWAIT and SKIP LOCKED */
630
  bool    ermActive;    /* is this mark relevant for current tuple? */
631
  ItemPointerData curCtid;  /* ctid of currently locked tuple, if any */
632
  void     *ermExtra;   /* available for use by relation source node */
633
} ExecRowMark;
634
635
/*
636
 * ExecAuxRowMark -
637
 *     additional runtime representation of FOR [KEY] UPDATE/SHARE clauses
638
 *
639
 * Each LockRows and ModifyTable node keeps a list of the rowmarks it needs to
640
 * deal with.  In addition to a pointer to the related entry in es_rowMarks,
641
 * this struct carries the column number(s) of the resjunk columns associated
642
 * with the rowmark (see comments for PlanRowMark for more detail).  In the
643
 * case of ModifyTable, there has to be a separate ExecAuxRowMark list for
644
 * each child plan, because the resjunk columns could be at different physical
645
 * column positions in different subplans.
646
 */
647
typedef struct ExecAuxRowMark
648
{
649
  ExecRowMark *rowmark;   /* related entry in es_rowMarks */
650
  AttrNumber  ctidAttNo;    /* resno of ctid junk attribute, if any */
651
  AttrNumber  toidAttNo;    /* resno of tableoid junk attribute, if any */
652
  AttrNumber  wholeAttNo;   /* resno of whole-row junk attribute, if any */
653
} ExecAuxRowMark;
654
655
/*
656
 * Yugabyte output parameter.
657
 * The following parameters are not yet used.
658
 * - Execution status in text. Currently, details are lost when reporting status. This OUT param
659
 *   value can be used for that purpose.
660
 * - Execution status code in yugabyte (This code might be different from Postgres).
661
 */
662
typedef struct YbPgExecOutParam {
663
  NodeTag type;
664
665
  /* BACKFILL output */
666
  StringInfo bfoutput;
667
668
  /* Not yet used */
669
  StringInfo status;
670
  int64_t status_code;
671
} YbPgExecOutParam;
672
673
typedef struct YbExprParamDesc {
674
  NodeTag type;
675
676
  int32_t attno;
677
  int32_t typid;
678
  int32_t typmod;
679
  int32_t collid;
680
} YbExprParamDesc;
681
682
683
/* ----------------------------------------------------------------
684
 *         Tuple Hash Tables
685
 *
686
 * All-in-memory tuple hash tables are used for a number of purposes.
687
 *
688
 * Note: tab_hash_funcs are for the key datatype(s) stored in the table,
689
 * and tab_eq_funcs are non-cross-type equality operators for those types.
690
 * Normally these are the only functions used, but FindTupleHashEntry()
691
 * supports searching a hashtable using cross-data-type hashing.  For that,
692
 * the caller must supply hash functions for the LHS datatype as well as
693
 * the cross-type equality operators to use.  in_hash_funcs and cur_eq_func
694
 * are set to point to the caller's function arrays while doing such a search.
695
 * During LookupTupleHashEntry(), they point to tab_hash_funcs and
696
 * tab_eq_func respectively.
697
 * ----------------------------------------------------------------
698
 */
699
typedef struct TupleHashEntryData *TupleHashEntry;
700
typedef struct TupleHashTableData *TupleHashTable;
701
702
typedef struct TupleHashEntryData
703
{
704
  MinimalTuple firstTuple;  /* copy of first tuple in this group */
705
  void     *additional;   /* user data */
706
  uint32    status;     /* hash status */
707
  uint32    hash;     /* hash value (cached) */
708
} TupleHashEntryData;
709
710
/* define parameters necessary to generate the tuple hash table interface */
711
#define SH_PREFIX tuplehash
712
#define SH_ELEMENT_TYPE TupleHashEntryData
713
#define SH_KEY_TYPE MinimalTuple
714
#define SH_SCOPE extern
715
#define SH_DECLARE
716
#include "lib/simplehash.h"
717
718
typedef struct TupleHashTableData
719
{
720
  tuplehash_hash *hashtab;  /* underlying hash table */
721
  int     numCols;    /* number of columns in lookup key */
722
  AttrNumber *keyColIdx;    /* attr numbers of key columns */
723
  FmgrInfo   *tab_hash_funcs; /* hash functions for table datatype(s) */
724
  ExprState  *tab_eq_func;  /* comparator for table datatype(s) */
725
  MemoryContext tablecxt;   /* memory context containing table */
726
  MemoryContext tempcxt;    /* context for function evaluations */
727
  Size    entrysize;    /* actual size to make each hash entry */
728
  TupleTableSlot *tableslot;  /* slot for referencing table entries */
729
  /* The following fields are set transiently for each table search: */
730
  TupleTableSlot *inputslot;  /* current input tuple's slot */
731
  FmgrInfo   *in_hash_funcs;  /* hash functions for input datatype(s) */
732
  ExprState  *cur_eq_func;  /* comparator for input vs. table */
733
  uint32    hash_iv;    /* hash-function IV */
734
  ExprContext *exprcontext; /* expression context */
735
}     TupleHashTableData;
736
737
typedef tuplehash_iterator TupleHashIterator;
738
739
/*
740
 * Use InitTupleHashIterator/TermTupleHashIterator for a read/write scan.
741
 * Use ResetTupleHashIterator if the table can be frozen (in this case no
742
 * explicit scan termination is needed).
743
 */
744
#define InitTupleHashIterator(htable, iter) \
745
1.64k
  tuplehash_start_iterate(htable->hashtab, iter)
746
#define TermTupleHashIterator(iter) \
747
0
  ((void) 0)
748
#define ResetTupleHashIterator(htable, iter) \
749
1.64k
  InitTupleHashIterator(htable, iter)
750
#define ScanTupleHashTable(htable, iter) \
751
143k
  tuplehash_iterate(htable->hashtab, iter)
752
753
754
/* ----------------------------------------------------------------
755
 *         Expression State Nodes
756
 *
757
 * Formerly, there was a separate executor expression state node corresponding
758
 * to each node in a planned expression tree.  That's no longer the case; for
759
 * common expression node types, all the execution info is embedded into
760
 * step(s) in a single ExprState node.  But we still have a few executor state
761
 * node types for selected expression node types, mostly those in which info
762
 * has to be shared with other parts of the execution state tree.
763
 * ----------------------------------------------------------------
764
 */
765
766
/* ----------------
767
 *    AggrefExprState node
768
 * ----------------
769
 */
770
typedef struct AggrefExprState
771
{
772
  NodeTag   type;
773
  Aggref     *aggref;     /* expression plan node */
774
  int     aggno;      /* ID number for agg within its plan node */
775
} AggrefExprState;
776
777
/* ----------------
778
 *    WindowFuncExprState node
779
 * ----------------
780
 */
781
typedef struct WindowFuncExprState
782
{
783
  NodeTag   type;
784
  WindowFunc *wfunc;      /* expression plan node */
785
  List     *args;     /* ExprStates for argument expressions */
786
  ExprState  *aggfilter;    /* FILTER expression */
787
  int     wfuncno;    /* ID number for wfunc within its plan node */
788
} WindowFuncExprState;
789
790
791
/* ----------------
792
 *    SetExprState node
793
 *
794
 * State for evaluating a potentially set-returning expression (like FuncExpr
795
 * or OpExpr).  In some cases, like some of the expressions in ROWS FROM(...)
796
 * the expression might not be a SRF, but nonetheless it uses the same
797
 * machinery as SRFs; it will be treated as a SRF returning a single row.
798
 * ----------------
799
 */
800
typedef struct SetExprState
801
{
802
  NodeTag   type;
803
  Expr     *expr;     /* expression plan node */
804
  List     *args;     /* ExprStates for argument expressions */
805
806
  /*
807
   * In ROWS FROM, functions can be inlined, removing the FuncExpr normally
808
   * inside.  In such a case this is the compiled expression (which cannot
809
   * return a set), which'll be evaluated using regular ExecEvalExpr().
810
   */
811
  ExprState  *elidedFuncState;
812
813
  /*
814
   * Function manager's lookup info for the target function.  If func.fn_oid
815
   * is InvalidOid, we haven't initialized it yet (nor any of the following
816
   * fields, except funcReturnsSet).
817
   */
818
  FmgrInfo  func;
819
820
  /*
821
   * For a set-returning function (SRF) that returns a tuplestore, we keep
822
   * the tuplestore here and dole out the result rows one at a time. The
823
   * slot holds the row currently being returned.
824
   */
825
  Tuplestorestate *funcResultStore;
826
  TupleTableSlot *funcResultSlot;
827
828
  /*
829
   * In some cases we need to compute a tuple descriptor for the function's
830
   * output.  If so, it's stored here.
831
   */
832
  TupleDesc funcResultDesc;
833
  bool    funcReturnsTuple; /* valid when funcResultDesc isn't NULL */
834
835
  /*
836
   * Remember whether the function is declared to return a set.  This is set
837
   * by ExecInitExpr, and is valid even before the FmgrInfo is set up.
838
   */
839
  bool    funcReturnsSet;
840
841
  /*
842
   * setArgsValid is true when we are evaluating a set-returning function
843
   * that uses value-per-call mode and we are in the middle of a call
844
   * series; we want to pass the same argument values to the function again
845
   * (and again, until it returns ExprEndResult).  This indicates that
846
   * fcinfo_data already contains valid argument data.
847
   */
848
  bool    setArgsValid;
849
850
  /*
851
   * Flag to remember whether we have registered a shutdown callback for
852
   * this SetExprState.  We do so only if funcResultStore or setArgsValid
853
   * has been set at least once (since all the callback is for is to release
854
   * the tuplestore or clear setArgsValid).
855
   */
856
  bool    shutdown_reg; /* a shutdown callback is registered */
857
858
  /*
859
   * Call parameter structure for the function.  This has been initialized
860
   * (by InitFunctionCallInfoData) if func.fn_oid is valid.  It also saves
861
   * argument values between calls, when setArgsValid is true.
862
   */
863
  FunctionCallInfoData fcinfo_data;
864
} SetExprState;
865
866
/* ----------------
867
 *    SubPlanState node
868
 * ----------------
869
 */
870
typedef struct SubPlanState
871
{
872
  NodeTag   type;
873
  SubPlan    *subplan;    /* expression plan node */
874
  struct PlanState *planstate;  /* subselect plan's state tree */
875
  struct PlanState *parent; /* parent plan node's state tree */
876
  ExprState  *testexpr;   /* state of combining expression */
877
  List     *args;     /* states of argument expression(s) */
878
  HeapTuple curTuple;   /* copy of most recent tuple from subplan */
879
  Datum   curArray;   /* most recent array from ARRAY() subplan */
880
  /* these are used when hashing the subselect's output: */
881
  TupleDesc descRight;    /* subselect desc after projection */
882
  ProjectionInfo *projLeft; /* for projecting lefthand exprs */
883
  ProjectionInfo *projRight;  /* for projecting subselect output */
884
  TupleHashTable hashtable; /* hash table for no-nulls subselect rows */
885
  TupleHashTable hashnulls; /* hash table for rows with null(s) */
886
  bool    havehashrows; /* true if hashtable is not empty */
887
  bool    havenullrows; /* true if hashnulls is not empty */
888
  MemoryContext hashtablecxt; /* memory context containing hash tables */
889
  MemoryContext hashtempcxt;  /* temp memory context for hash tables */
890
  ExprContext *innerecontext; /* econtext for computing inner tuples */
891
  AttrNumber *keyColIdx;    /* control data for hash tables */
892
  Oid      *tab_eq_funcoids;  /* equality func oids for table
893
                   * datatype(s) */
894
  FmgrInfo   *tab_hash_funcs; /* hash functions for table datatype(s) */
895
  FmgrInfo   *tab_eq_funcs; /* equality functions for table datatype(s) */
896
  FmgrInfo   *lhs_hash_funcs; /* hash functions for lefthand datatype(s) */
897
  FmgrInfo   *cur_eq_funcs; /* equality functions for LHS vs. table */
898
  ExprState  *cur_eq_comp;  /* equality comparator for LHS vs. table */
899
} SubPlanState;
900
901
/* ----------------
902
 *    AlternativeSubPlanState node
903
 * ----------------
904
 */
905
typedef struct AlternativeSubPlanState
906
{
907
  NodeTag   type;
908
  AlternativeSubPlan *subplan;  /* expression plan node */
909
  List     *subplans;   /* SubPlanStates of alternative subplans */
910
  int     active;     /* list index of the one we're using */
911
} AlternativeSubPlanState;
912
913
/*
914
 * DomainConstraintState - one item to check during CoerceToDomain
915
 *
916
 * Note: we consider this to be part of an ExprState tree, so we give it
917
 * a name following the xxxState convention.  But there's no directly
918
 * associated plan-tree node.
919
 */
920
typedef enum DomainConstraintType
921
{
922
  DOM_CONSTRAINT_NOTNULL,
923
  DOM_CONSTRAINT_CHECK
924
} DomainConstraintType;
925
926
typedef struct DomainConstraintState
927
{
928
  NodeTag   type;
929
  DomainConstraintType constrainttype;  /* constraint type */
930
  char     *name;     /* name of constraint (for error msgs) */
931
  Expr     *check_expr;   /* for CHECK, a boolean expression */
932
  ExprState  *check_exprstate;  /* check_expr's eval state, or NULL */
933
} DomainConstraintState;
934
935
936
/* ----------------------------------------------------------------
937
 *         Executor State Trees
938
 *
939
 * An executing query has a PlanState tree paralleling the Plan tree
940
 * that describes the plan.
941
 * ----------------------------------------------------------------
942
 */
943
944
/* ----------------
945
 *   ExecProcNodeMtd
946
 *
947
 * This is the method called by ExecProcNode to return the next tuple
948
 * from an executor node.  It returns NULL, or an empty TupleTableSlot,
949
 * if no more tuples are available.
950
 * ----------------
951
 */
952
typedef TupleTableSlot *(*ExecProcNodeMtd) (struct PlanState *pstate);
953
954
/* ----------------
955
 *    PlanState node
956
 *
957
 * We never actually instantiate any PlanState nodes; this is just the common
958
 * abstract superclass for all PlanState-type nodes.
959
 * ----------------
960
 */
961
typedef struct PlanState
962
{
963
  NodeTag   type;
964
965
  Plan     *plan;     /* associated Plan node */
966
967
  EState     *state;      /* at execution time, states of individual
968
                 * nodes point to one EState for the whole
969
                 * top-level plan */
970
971
  ExecProcNodeMtd ExecProcNode; /* function to return next tuple */
972
  ExecProcNodeMtd ExecProcNodeReal; /* actual function, if above is a
973
                     * wrapper */
974
975
  Instrumentation *instrument;  /* Optional runtime stats for this node */
976
  WorkerInstrumentation *worker_instrument; /* per-worker instrumentation */
977
978
  /* Per-worker JIT instrumentation */
979
  struct SharedJitInstrumentation *worker_jit_instrument;
980
981
  /*
982
   * Common structural data for all Plan types.  These links to subsidiary
983
   * state trees parallel links in the associated plan tree (except for the
984
   * subPlan list, which does not exist in the plan tree).
985
   */
986
  ExprState  *qual;     /* boolean qual condition */
987
  struct PlanState *lefttree; /* input plan tree(s) */
988
  struct PlanState *righttree;
989
990
  List     *initPlan;   /* Init SubPlanState nodes (un-correlated expr
991
                 * subselects) */
992
  List     *subPlan;    /* SubPlanState nodes in my expressions */
993
994
  /*
995
   * State for management of parameter-change-driven rescanning
996
   */
997
  Bitmapset  *chgParam;   /* set of IDs of changed Params */
998
999
  /*
1000
   * Other run-time state needed by most if not all node types.
1001
   */
1002
  TupleDesc ps_ResultTupleDesc; /* node's return type */
1003
  TupleTableSlot *ps_ResultTupleSlot; /* slot for my result tuples */
1004
  ExprContext *ps_ExprContext;  /* node's expression-evaluation context */
1005
  ProjectionInfo *ps_ProjInfo;  /* info for doing tuple projection */
1006
1007
  /*
1008
   * Scanslot's descriptor if known. This is a bit of a hack, but otherwise
1009
   * it's hard for expression compilation to optimize based on the
1010
   * descriptor, without encoding knowledge about all executor nodes.
1011
   */
1012
  TupleDesc scandesc;
1013
} PlanState;
1014
1015
/* ----------------
1016
 *  these are defined to avoid confusion problems with "left"
1017
 *  and "right" and "inner" and "outer".  The convention is that
1018
 *  the "left" plan is the "outer" plan and the "right" plan is
1019
 *  the inner plan, but these make the code more readable.
1020
 * ----------------
1021
 */
1022
19.1M
#define innerPlanState(node)    (((PlanState *)(node))->righttree)
1023
38.5M
#define outerPlanState(node)    (((PlanState *)(node))->lefttree)
1024
1025
/* Macros for inline access to certain instrumentation counters */
1026
#define InstrCountTuples2(node, delta) \
1027
6.28k
  do { \
1028
6.28k
    if (((PlanState *)(node))->instrument) \
1029
6.28k
      
((PlanState *)(node))->instrument->ntuples2 += (delta)0
; \
1030
6.28k
  } while (0)
1031
#define InstrCountFiltered1(node, delta) \
1032
6.04M
  do { \
1033
6.04M
    if (((PlanState *)(node))->instrument) \
1034
6.04M
      
((PlanState *)(node))->instrument->nfiltered1 += (delta)62.9k
; \
1035
6.04M
  } while(0)
1036
#define InstrCountFiltered2(node, delta) \
1037
89.5k
  do { \
1038
89.5k
    if (((PlanState *)(node))->instrument) \
1039
89.5k
      
((PlanState *)(node))->instrument->nfiltered2 += (delta)292
; \
1040
89.5k
  } while(0)
1041
1042
/*
1043
 * EPQState is state for executing an EvalPlanQual recheck on a candidate
1044
 * tuple in ModifyTable or LockRows.  The estate and planstate fields are
1045
 * NULL if inactive.
1046
 */
1047
typedef struct EPQState
1048
{
1049
  EState     *estate;     /* subsidiary EState */
1050
  PlanState  *planstate;    /* plan state tree ready to be executed */
1051
  TupleTableSlot *origslot; /* original output tuple to be rechecked */
1052
  Plan     *plan;     /* plan tree to be executed */
1053
  List     *arowMarks;    /* ExecAuxRowMarks (non-locking only) */
1054
  int     epqParam;   /* ID of Param to force scan node re-eval */
1055
} EPQState;
1056
1057
1058
/* ----------------
1059
 *   ResultState information
1060
 * ----------------
1061
 */
1062
typedef struct ResultState
1063
{
1064
  PlanState ps;       /* its first field is NodeTag */
1065
  ExprState  *resconstantqual;
1066
  bool    rs_done;    /* are we done? */
1067
  bool    rs_checkqual; /* do we need to check the qual? */
1068
} ResultState;
1069
1070
/* ----------------
1071
 *   ProjectSetState information
1072
 *
1073
 * Note: at least one of the "elems" will be a SetExprState; the rest are
1074
 * regular ExprStates.
1075
 * ----------------
1076
 */
1077
typedef struct ProjectSetState
1078
{
1079
  PlanState ps;       /* its first field is NodeTag */
1080
  Node    **elems;      /* array of expression states */
1081
  ExprDoneCond *elemdone;   /* array of per-SRF is-done states */
1082
  int     nelems;     /* length of elemdone[] array */
1083
  bool    pending_srf_tuples; /* still evaluating srfs in tlist? */
1084
  MemoryContext argcontext; /* context for SRF arguments */
1085
} ProjectSetState;
1086
1087
/* ----------------
1088
 *   ModifyTableState information
1089
 * ----------------
1090
 */
1091
typedef struct ModifyTableState
1092
{
1093
  PlanState ps;       /* its first field is NodeTag */
1094
  CmdType   operation;    /* INSERT, UPDATE, or DELETE */
1095
  bool    canSetTag;    /* do we set the command tag/es_processed? */
1096
  bool    mt_done;    /* are we done? */
1097
  PlanState **mt_plans;   /* subplans (one per target rel) */
1098
  int     mt_nplans;    /* number of plans in the array */
1099
  int     mt_whichplan; /* which one is being executed (0..n-1) */
1100
  ResultRelInfo *resultRelInfo; /* per-subplan target relations */
1101
  ResultRelInfo *rootResultRelInfo; /* root target relation (partitioned
1102
                     * table root) */
1103
  List    **mt_arowmarks; /* per-subplan ExecAuxRowMark lists */
1104
  EPQState  mt_epqstate;  /* for evaluating EvalPlanQual rechecks */
1105
  bool    fireBSTriggers; /* do we need to fire stmt triggers? */
1106
  TupleTableSlot *mt_existing;  /* slot to store existing target tuple in */
1107
  List     *mt_excludedtlist; /* the excluded pseudo relation's tlist  */
1108
  TupleTableSlot *mt_conflproj; /* CONFLICT ... SET ... projection target */
1109
1110
  /* Tuple-routing support info */
1111
  struct PartitionTupleRouting *mt_partition_tuple_routing;
1112
1113
  /* controls transition table population for specified operation */
1114
  struct TransitionCaptureState *mt_transition_capture;
1115
1116
  /* controls transition table population for INSERT...ON CONFLICT UPDATE */
1117
  struct TransitionCaptureState *mt_oc_transition_capture;
1118
1119
  /* Per plan map for tuple conversion from child to root */
1120
  TupleConversionMap **mt_per_subplan_tupconv_maps;
1121
1122
  /* YB specific attributes. */
1123
  bool yb_mt_is_single_row_update_or_delete;
1124
} ModifyTableState;
1125
1126
/* ----------------
1127
 *   AppendState information
1128
 *
1129
 *    nplans        how many plans are in the array
1130
 *    whichplan     which plan is being executed (0 .. n-1), or a
1131
 *              special negative value. See nodeAppend.c.
1132
 *    prune_state     details required to allow partitions to be
1133
 *              eliminated from the scan, or NULL if not possible.
1134
 *    valid_subplans    for runtime pruning, valid appendplans indexes to
1135
 *              scan.
1136
 * ----------------
1137
 */
1138
1139
struct AppendState;
1140
typedef struct AppendState AppendState;
1141
struct ParallelAppendState;
1142
typedef struct ParallelAppendState ParallelAppendState;
1143
struct PartitionPruneState;
1144
1145
struct AppendState
1146
{
1147
  PlanState ps;       /* its first field is NodeTag */
1148
  PlanState **appendplans;  /* array of PlanStates for my inputs */
1149
  int     as_nplans;
1150
  int     as_whichplan;
1151
  int     as_first_partial_plan;  /* Index of 'appendplans' containing
1152
                     * the first partial plan */
1153
  ParallelAppendState *as_pstate; /* parallel coordination info */
1154
  Size    pstate_len;   /* size of parallel coordination info */
1155
  struct PartitionPruneState *as_prune_state;
1156
  Bitmapset  *as_valid_subplans;
1157
  bool    (*choose_next_subplan) (AppendState *);
1158
};
1159
1160
/* ----------------
1161
 *   MergeAppendState information
1162
 *
1163
 *    nplans      how many plans are in the array
1164
 *    nkeys     number of sort key columns
1165
 *    sortkeys    sort keys in SortSupport representation
1166
 *    slots     current output tuple of each subplan
1167
 *    heap      heap of active tuples
1168
 *    initialized   true if we have fetched first tuple from each subplan
1169
 * ----------------
1170
 */
1171
typedef struct MergeAppendState
1172
{
1173
  PlanState ps;       /* its first field is NodeTag */
1174
  PlanState **mergeplans;   /* array of PlanStates for my inputs */
1175
  int     ms_nplans;
1176
  int     ms_nkeys;
1177
  SortSupport ms_sortkeys;  /* array of length ms_nkeys */
1178
  TupleTableSlot **ms_slots;  /* array of length ms_nplans */
1179
  struct binaryheap *ms_heap; /* binary heap of slot indices */
1180
  bool    ms_initialized; /* are subplans started? */
1181
} MergeAppendState;
1182
1183
/* ----------------
1184
 *   RecursiveUnionState information
1185
 *
1186
 *    RecursiveUnionState is used for performing a recursive union.
1187
 *
1188
 *    recursing     T when we're done scanning the non-recursive term
1189
 *    intermediate_empty  T if intermediate_table is currently empty
1190
 *    working_table   working table (to be scanned by recursive term)
1191
 *    intermediate_table  current recursive output (next generation of WT)
1192
 * ----------------
1193
 */
1194
typedef struct RecursiveUnionState
1195
{
1196
  PlanState ps;       /* its first field is NodeTag */
1197
  bool    recursing;
1198
  bool    intermediate_empty;
1199
  Tuplestorestate *working_table;
1200
  Tuplestorestate *intermediate_table;
1201
  /* Remaining fields are unused in UNION ALL case */
1202
  Oid      *eqfuncoids;   /* per-grouping-field equality fns */
1203
  FmgrInfo   *hashfunctions;  /* per-grouping-field hash fns */
1204
  MemoryContext tempContext;  /* short-term context for comparisons */
1205
  TupleHashTable hashtable; /* hash table for tuples already seen */
1206
  MemoryContext tableContext; /* memory context containing hash table */
1207
} RecursiveUnionState;
1208
1209
/* ----------------
1210
 *   BitmapAndState information
1211
 * ----------------
1212
 */
1213
typedef struct BitmapAndState
1214
{
1215
  PlanState ps;       /* its first field is NodeTag */
1216
  PlanState **bitmapplans;  /* array of PlanStates for my inputs */
1217
  int     nplans;     /* number of input plans */
1218
} BitmapAndState;
1219
1220
/* ----------------
1221
 *   BitmapOrState information
1222
 * ----------------
1223
 */
1224
typedef struct BitmapOrState
1225
{
1226
  PlanState ps;       /* its first field is NodeTag */
1227
  PlanState **bitmapplans;  /* array of PlanStates for my inputs */
1228
  int     nplans;     /* number of input plans */
1229
} BitmapOrState;
1230
1231
/* ----------------------------------------------------------------
1232
 *         Scan State Information
1233
 * ----------------------------------------------------------------
1234
 */
1235
1236
/* ----------------
1237
 *   ScanState information
1238
 *
1239
 *    ScanState extends PlanState for node types that represent
1240
 *    scans of an underlying relation.  It can also be used for nodes
1241
 *    that scan the output of an underlying plan node --- in that case,
1242
 *    only ScanTupleSlot is actually useful, and it refers to the tuple
1243
 *    retrieved from the subplan.
1244
 *
1245
 *    currentRelation    relation being scanned (NULL if none)
1246
 *    currentScanDesc    current scan descriptor for scan (NULL if none)
1247
 *    ScanTupleSlot    pointer to slot in tuple table holding scan tuple
1248
 * ----------------
1249
 */
1250
typedef struct ScanState
1251
{
1252
  PlanState ps;       /* its first field is NodeTag */
1253
  Relation  ss_currentRelation;
1254
  HeapScanDesc ss_currentScanDesc;
1255
  TupleTableSlot *ss_ScanTupleSlot;
1256
} ScanState;
1257
1258
/* ----------------
1259
 *   SeqScanState information
1260
 * ----------------
1261
 */
1262
typedef struct SeqScanState
1263
{
1264
  ScanState ss;       /* its first field is NodeTag */
1265
  Size    pscan_len;    /* size of parallel heap scan descriptor */
1266
} SeqScanState;
1267
1268
/* ----------------
1269
 *   SampleScanState information
1270
 * ----------------
1271
 */
1272
typedef struct SampleScanState
1273
{
1274
  ScanState ss;
1275
  List     *args;     /* expr states for TABLESAMPLE params */
1276
  ExprState  *repeatable;   /* expr state for REPEATABLE expr */
1277
  /* use struct pointer to avoid including tsmapi.h here */
1278
  struct TsmRoutine *tsmroutine;  /* descriptor for tablesample method */
1279
  void     *tsm_state;    /* tablesample method can keep state here */
1280
  bool    use_bulkread; /* use bulkread buffer access strategy? */
1281
  bool    use_pagemode; /* use page-at-a-time visibility checking? */
1282
  bool    begun;      /* false means need to call BeginSampleScan */
1283
  uint32    seed;     /* random seed */
1284
} SampleScanState;
1285
1286
/*
1287
 * These structs store information about index quals that don't have simple
1288
 * constant right-hand sides.  See comments for ExecIndexBuildScanKeys()
1289
 * for discussion.
1290
 */
1291
typedef struct
1292
{
1293
  ScanKey   scan_key;   /* scankey to put value into */
1294
  ExprState  *key_expr;   /* expr to evaluate to get value */
1295
  bool    key_toastable;  /* is expr's result a toastable datatype? */
1296
} IndexRuntimeKeyInfo;
1297
1298
typedef struct
1299
{
1300
  ScanKey   scan_key;   /* scankey to put value into */
1301
  ExprState  *array_expr;   /* expr to evaluate to get array value */
1302
  int     next_elem;    /* next array element to use */
1303
  int     num_elems;    /* number of elems in current array value */
1304
  Datum    *elem_values;  /* array of num_elems Datums */
1305
  bool     *elem_nulls;   /* array of num_elems is-null flags */
1306
} IndexArrayKeyInfo;
1307
1308
/* ----------------
1309
 *   IndexScanState information
1310
 *
1311
 *    indexqualorig    execution state for indexqualorig expressions
1312
 *    indexorderbyorig   execution state for indexorderbyorig expressions
1313
 *    ScanKeys       Skey structures for index quals
1314
 *    NumScanKeys      number of ScanKeys
1315
 *    OrderByKeys      Skey structures for index ordering operators
1316
 *    NumOrderByKeys     number of OrderByKeys
1317
 *    RuntimeKeys      info about Skeys that must be evaluated at runtime
1318
 *    NumRuntimeKeys     number of RuntimeKeys
1319
 *    RuntimeKeysReady   true if runtime Skeys have been computed
1320
 *    RuntimeContext     expr context for evaling runtime Skeys
1321
 *    RelationDesc     index relation descriptor
1322
 *    ScanDesc       index scan descriptor
1323
 *
1324
 *    ReorderQueue     tuples that need reordering due to re-check
1325
 *    ReachedEnd       have we fetched all tuples from index already?
1326
 *    OrderByValues    values of ORDER BY exprs of last fetched tuple
1327
 *    OrderByNulls     null flags for OrderByValues
1328
 *    SortSupport      for reordering ORDER BY exprs
1329
 *    OrderByTypByVals   is the datatype of order by expression pass-by-value?
1330
 *    OrderByTypLens     typlens of the datatypes of order by expressions
1331
 *    pscan_len      size of parallel index scan descriptor
1332
 * ----------------
1333
 */
1334
typedef struct IndexScanState
1335
{
1336
  ScanState ss;       /* its first field is NodeTag */
1337
  ExprState  *indexqualorig;
1338
  List     *indexorderbyorig;
1339
  ScanKey   iss_ScanKeys;
1340
  int     iss_NumScanKeys;
1341
  ScanKey   iss_OrderByKeys;
1342
  int     iss_NumOrderByKeys;
1343
  IndexRuntimeKeyInfo *iss_RuntimeKeys;
1344
  int     iss_NumRuntimeKeys;
1345
  bool    iss_RuntimeKeysReady;
1346
  ExprContext *iss_RuntimeContext;
1347
  Relation  iss_RelationDesc;
1348
  IndexScanDesc iss_ScanDesc;
1349
1350
  /* These are needed for re-checking ORDER BY expr ordering */
1351
  pairingheap *iss_ReorderQueue;
1352
  bool    iss_ReachedEnd;
1353
  Datum    *iss_OrderByValues;
1354
  bool     *iss_OrderByNulls;
1355
  SortSupport iss_SortSupport;
1356
  bool     *iss_OrderByTypByVals;
1357
  int16    *iss_OrderByTypLens;
1358
  Size    iss_PscanLen;
1359
} IndexScanState;
1360
1361
/* ----------------
1362
 *   IndexOnlyScanState information
1363
 *
1364
 *    indexqual      execution state for indexqual expressions
1365
 *    ScanKeys       Skey structures for index quals
1366
 *    NumScanKeys      number of ScanKeys
1367
 *    OrderByKeys      Skey structures for index ordering operators
1368
 *    NumOrderByKeys     number of OrderByKeys
1369
 *    RuntimeKeys      info about Skeys that must be evaluated at runtime
1370
 *    NumRuntimeKeys     number of RuntimeKeys
1371
 *    RuntimeKeysReady   true if runtime Skeys have been computed
1372
 *    RuntimeContext     expr context for evaling runtime Skeys
1373
 *    RelationDesc     index relation descriptor
1374
 *    ScanDesc       index scan descriptor
1375
 *    VMBuffer       buffer in use for visibility map testing, if any
1376
 *    ioss_PscanLen    Size of parallel index-only scan descriptor
1377
 * ----------------
1378
 */
1379
typedef struct IndexOnlyScanState
1380
{
1381
  ScanState ss;       /* its first field is NodeTag */
1382
  ExprState  *indexqual;
1383
  ScanKey   ioss_ScanKeys;
1384
  int     ioss_NumScanKeys;
1385
  ScanKey   ioss_OrderByKeys;
1386
  int     ioss_NumOrderByKeys;
1387
  IndexRuntimeKeyInfo *ioss_RuntimeKeys;
1388
  int     ioss_NumRuntimeKeys;
1389
  bool    ioss_RuntimeKeysReady;
1390
  ExprContext *ioss_RuntimeContext;
1391
  Relation  ioss_RelationDesc;
1392
  IndexScanDesc ioss_ScanDesc;
1393
  Buffer    ioss_VMBuffer;
1394
  Size    ioss_PscanLen;
1395
} IndexOnlyScanState;
1396
1397
/* ----------------
1398
 *   BitmapIndexScanState information
1399
 *
1400
 *    result         bitmap to return output into, or NULL
1401
 *    ScanKeys       Skey structures for index quals
1402
 *    NumScanKeys      number of ScanKeys
1403
 *    RuntimeKeys      info about Skeys that must be evaluated at runtime
1404
 *    NumRuntimeKeys     number of RuntimeKeys
1405
 *    ArrayKeys      info about Skeys that come from ScalarArrayOpExprs
1406
 *    NumArrayKeys     number of ArrayKeys
1407
 *    RuntimeKeysReady   true if runtime Skeys have been computed
1408
 *    RuntimeContext     expr context for evaling runtime Skeys
1409
 *    RelationDesc     index relation descriptor
1410
 *    ScanDesc       index scan descriptor
1411
 * ----------------
1412
 */
1413
typedef struct BitmapIndexScanState
1414
{
1415
  ScanState ss;       /* its first field is NodeTag */
1416
  TIDBitmap  *biss_result;
1417
  ScanKey   biss_ScanKeys;
1418
  int     biss_NumScanKeys;
1419
  IndexRuntimeKeyInfo *biss_RuntimeKeys;
1420
  int     biss_NumRuntimeKeys;
1421
  IndexArrayKeyInfo *biss_ArrayKeys;
1422
  int     biss_NumArrayKeys;
1423
  bool    biss_RuntimeKeysReady;
1424
  ExprContext *biss_RuntimeContext;
1425
  Relation  biss_RelationDesc;
1426
  IndexScanDesc biss_ScanDesc;
1427
} BitmapIndexScanState;
1428
1429
/* ----------------
1430
 *   SharedBitmapState information
1431
 *
1432
 *    BM_INITIAL    TIDBitmap creation is not yet started, so first worker
1433
 *            to see this state will set the state to BM_INPROGRESS
1434
 *            and that process will be responsible for creating
1435
 *            TIDBitmap.
1436
 *    BM_INPROGRESS TIDBitmap creation is in progress; workers need to
1437
 *            sleep until it's finished.
1438
 *    BM_FINISHED   TIDBitmap creation is done, so now all workers can
1439
 *            proceed to iterate over TIDBitmap.
1440
 * ----------------
1441
 */
1442
typedef enum
1443
{
1444
  BM_INITIAL,
1445
  BM_INPROGRESS,
1446
  BM_FINISHED
1447
} SharedBitmapState;
1448
1449
/* ----------------
1450
 *   ParallelBitmapHeapState information
1451
 *    tbmiterator       iterator for scanning current pages
1452
 *    prefetch_iterator   iterator for prefetching ahead of current page
1453
 *    mutex         mutual exclusion for the prefetching variable
1454
 *                and state
1455
 *    prefetch_pages      # pages prefetch iterator is ahead of current
1456
 *    prefetch_target     current target prefetch distance
1457
 *    state         current state of the TIDBitmap
1458
 *    cv            conditional wait variable
1459
 *    phs_snapshot_data   snapshot data shared to workers
1460
 * ----------------
1461
 */
1462
typedef struct ParallelBitmapHeapState
1463
{
1464
  dsa_pointer tbmiterator;
1465
  dsa_pointer prefetch_iterator;
1466
  slock_t   mutex;
1467
  int     prefetch_pages;
1468
  int     prefetch_target;
1469
  SharedBitmapState state;
1470
  ConditionVariable cv;
1471
  char    phs_snapshot_data[FLEXIBLE_ARRAY_MEMBER];
1472
} ParallelBitmapHeapState;
1473
1474
/* ----------------
1475
 *   BitmapHeapScanState information
1476
 *
1477
 *    bitmapqualorig     execution state for bitmapqualorig expressions
1478
 *    tbm          bitmap obtained from child index scan(s)
1479
 *    tbmiterator      iterator for scanning current pages
1480
 *    tbmres         current-page data
1481
 *    can_skip_fetch     can we potentially skip tuple fetches in this scan?
1482
 *    skip_fetch       are we skipping tuple fetches on this page?
1483
 *    vmbuffer       buffer for visibility-map lookups
1484
 *    pvmbuffer      ditto, for prefetched pages
1485
 *    exact_pages      total number of exact pages retrieved
1486
 *    lossy_pages      total number of lossy pages retrieved
1487
 *    prefetch_iterator  iterator for prefetching ahead of current page
1488
 *    prefetch_pages     # pages prefetch iterator is ahead of current
1489
 *    prefetch_target    current target prefetch distance
1490
 *    prefetch_maximum   maximum value for prefetch_target
1491
 *    pscan_len      size of the shared memory for parallel bitmap
1492
 *    initialized      is node is ready to iterate
1493
 *    shared_tbmiterator     shared iterator
1494
 *    shared_prefetch_iterator shared iterator for prefetching
1495
 *    pstate         shared state for parallel bitmap scan
1496
 * ----------------
1497
 */
1498
typedef struct BitmapHeapScanState
1499
{
1500
  ScanState ss;       /* its first field is NodeTag */
1501
  ExprState  *bitmapqualorig;
1502
  TIDBitmap  *tbm;
1503
  TBMIterator *tbmiterator;
1504
  TBMIterateResult *tbmres;
1505
  bool    can_skip_fetch;
1506
  bool    skip_fetch;
1507
  Buffer    vmbuffer;
1508
  Buffer    pvmbuffer;
1509
  long    exact_pages;
1510
  long    lossy_pages;
1511
  TBMIterator *prefetch_iterator;
1512
  int     prefetch_pages;
1513
  int     prefetch_target;
1514
  int     prefetch_maximum;
1515
  Size    pscan_len;
1516
  bool    initialized;
1517
  TBMSharedIterator *shared_tbmiterator;
1518
  TBMSharedIterator *shared_prefetch_iterator;
1519
  ParallelBitmapHeapState *pstate;
1520
} BitmapHeapScanState;
1521
1522
/* ----------------
1523
 *   TidScanState information
1524
 *
1525
 *    tidexprs     list of TidExpr structs (see nodeTidscan.c)
1526
 *    isCurrentOf    scan has a CurrentOfExpr qual
1527
 *    NumTids      number of tids in this scan
1528
 *    TidPtr       index of currently fetched tid
1529
 *    TidList      evaluated item pointers (array of size NumTids)
1530
 *    htup       currently-fetched tuple, if any
1531
 * ----------------
1532
 */
1533
typedef struct TidScanState
1534
{
1535
  ScanState ss;       /* its first field is NodeTag */
1536
  List     *tss_tidexprs;
1537
  bool    tss_isCurrentOf;
1538
  int     tss_NumTids;
1539
  int     tss_TidPtr;
1540
  ItemPointerData *tss_TidList;
1541
  HeapTupleData tss_htup;
1542
} TidScanState;
1543
1544
/* ----------------
1545
 *   SubqueryScanState information
1546
 *
1547
 *    SubqueryScanState is used for scanning a sub-query in the range table.
1548
 *    ScanTupleSlot references the current output tuple of the sub-query.
1549
 * ----------------
1550
 */
1551
typedef struct SubqueryScanState
1552
{
1553
  ScanState ss;       /* its first field is NodeTag */
1554
  PlanState  *subplan;
1555
} SubqueryScanState;
1556
1557
/* ----------------
1558
 *   FunctionScanState information
1559
 *
1560
 *    Function nodes are used to scan the results of a
1561
 *    function appearing in FROM (typically a function returning set).
1562
 *
1563
 *    eflags        node's capability flags
1564
 *    ordinality      is this scan WITH ORDINALITY?
1565
 *    simple        true if we have 1 function and no ordinality
1566
 *    ordinal       current ordinal column value
1567
 *    nfuncs        number of functions being executed
1568
 *    funcstates      per-function execution states (private in
1569
 *              nodeFunctionscan.c)
1570
 *    argcontext      memory context to evaluate function arguments in
1571
 * ----------------
1572
 */
1573
struct FunctionScanPerFuncState;
1574
1575
typedef struct FunctionScanState
1576
{
1577
  ScanState ss;       /* its first field is NodeTag */
1578
  int     eflags;
1579
  bool    ordinality;
1580
  bool    simple;
1581
  int64   ordinal;
1582
  int     nfuncs;
1583
  struct FunctionScanPerFuncState *funcstates;  /* array of length nfuncs */
1584
  MemoryContext argcontext;
1585
} FunctionScanState;
1586
1587
/* ----------------
1588
 *   ValuesScanState information
1589
 *
1590
 *    ValuesScan nodes are used to scan the results of a VALUES list
1591
 *
1592
 *    rowcontext      per-expression-list context
1593
 *    exprlists     array of expression lists being evaluated
1594
 *    array_len     size of array
1595
 *    curr_idx      current array index (0-based)
1596
 *
1597
 *  Note: ss.ps.ps_ExprContext is used to evaluate any qual or projection
1598
 *  expressions attached to the node.  We create a second ExprContext,
1599
 *  rowcontext, in which to build the executor expression state for each
1600
 *  Values sublist.  Resetting this context lets us get rid of expression
1601
 *  state for each row, avoiding major memory leakage over a long values list.
1602
 * ----------------
1603
 */
1604
typedef struct ValuesScanState
1605
{
1606
  ScanState ss;       /* its first field is NodeTag */
1607
  ExprContext *rowcontext;
1608
  List    **exprlists;
1609
  int     array_len;
1610
  int     curr_idx;
1611
} ValuesScanState;
1612
1613
/* ----------------
1614
 *    TableFuncScanState node
1615
 *
1616
 * Used in table-expression functions like XMLTABLE.
1617
 * ----------------
1618
 */
1619
typedef struct TableFuncScanState
1620
{
1621
  ScanState ss;       /* its first field is NodeTag */
1622
  ExprState  *docexpr;    /* state for document expression */
1623
  ExprState  *rowexpr;    /* state for row-generating expression */
1624
  List     *colexprs;   /* state for column-generating expression */
1625
  List     *coldefexprs;  /* state for column default expressions */
1626
  List     *ns_names;   /* same as TableFunc.ns_names */
1627
  List     *ns_uris;    /* list of states of namespace URI exprs */
1628
  Bitmapset  *notnulls;   /* nullability flag for each output column */
1629
  void     *opaque;     /* table builder private space */
1630
  const struct TableFuncRoutine *routine; /* table builder methods */
1631
  FmgrInfo   *in_functions; /* input function for each column */
1632
  Oid      *typioparams;  /* typioparam for each column */
1633
  int64   ordinal;    /* row number to be output next */
1634
  MemoryContext perTableCxt;  /* per-table context */
1635
  Tuplestorestate *tupstore;  /* output tuple store */
1636
} TableFuncScanState;
1637
1638
/* ----------------
1639
 *   CteScanState information
1640
 *
1641
 *    CteScan nodes are used to scan a CommonTableExpr query.
1642
 *
1643
 * Multiple CteScan nodes can read out from the same CTE query.  We use
1644
 * a tuplestore to hold rows that have been read from the CTE query but
1645
 * not yet consumed by all readers.
1646
 * ----------------
1647
 */
1648
typedef struct CteScanState
1649
{
1650
  ScanState ss;       /* its first field is NodeTag */
1651
  int     eflags;     /* capability flags to pass to tuplestore */
1652
  int     readptr;    /* index of my tuplestore read pointer */
1653
  PlanState  *cteplanstate; /* PlanState for the CTE query itself */
1654
  /* Link to the "leader" CteScanState (possibly this same node) */
1655
  struct CteScanState *leader;
1656
  /* The remaining fields are only valid in the "leader" CteScanState */
1657
  Tuplestorestate *cte_table; /* rows already read from the CTE query */
1658
  bool    eof_cte;    /* reached end of CTE query? */
1659
} CteScanState;
1660
1661
/* ----------------
1662
 *   NamedTuplestoreScanState information
1663
 *
1664
 *    NamedTuplestoreScan nodes are used to scan a Tuplestore created and
1665
 *    named prior to execution of the query.  An example is a transition
1666
 *    table for an AFTER trigger.
1667
 *
1668
 * Multiple NamedTuplestoreScan nodes can read out from the same Tuplestore.
1669
 * ----------------
1670
 */
1671
typedef struct NamedTuplestoreScanState
1672
{
1673
  ScanState ss;       /* its first field is NodeTag */
1674
  int     readptr;    /* index of my tuplestore read pointer */
1675
  TupleDesc tupdesc;    /* format of the tuples in the tuplestore */
1676
  Tuplestorestate *relation;  /* the rows */
1677
} NamedTuplestoreScanState;
1678
1679
/* ----------------
1680
 *   WorkTableScanState information
1681
 *
1682
 *    WorkTableScan nodes are used to scan the work table created by
1683
 *    a RecursiveUnion node.  We locate the RecursiveUnion node
1684
 *    during executor startup.
1685
 * ----------------
1686
 */
1687
typedef struct WorkTableScanState
1688
{
1689
  ScanState ss;       /* its first field is NodeTag */
1690
  RecursiveUnionState *rustate;
1691
} WorkTableScanState;
1692
1693
/* ----------------
1694
 *   ForeignScanState information
1695
 *
1696
 *    ForeignScan nodes are used to scan foreign-data tables.
1697
 * ----------------
1698
 */
1699
typedef struct ForeignScanState
1700
{
1701
  ScanState ss;       /* its first field is NodeTag */
1702
  ExprState  *fdw_recheck_quals;  /* original quals not in ss.ps.qual */
1703
  Size    pscan_len;    /* size of parallel coordination information */
1704
  /* use struct pointer to avoid including fdwapi.h here */
1705
  struct FdwRoutine *fdwroutine;
1706
  void     *fdw_state;    /* foreign-data wrapper can keep state here */
1707
1708
  /* YB specific attributes. */
1709
  List     *yb_fdw_aggs;  /* aggregate pushdown information */
1710
} ForeignScanState;
1711
1712
/* ----------------
1713
 *   CustomScanState information
1714
 *
1715
 *    CustomScan nodes are used to execute custom code within executor.
1716
 *
1717
 * Core code must avoid assuming that the CustomScanState is only as large as
1718
 * the structure declared here; providers are allowed to make it the first
1719
 * element in a larger structure, and typically would need to do so.  The
1720
 * struct is actually allocated by the CreateCustomScanState method associated
1721
 * with the plan node.  Any additional fields can be initialized there, or in
1722
 * the BeginCustomScan method.
1723
 * ----------------
1724
 */
1725
struct CustomExecMethods;
1726
1727
typedef struct CustomScanState
1728
{
1729
  ScanState ss;
1730
  uint32    flags;      /* mask of CUSTOMPATH_* flags, see
1731
                 * nodes/extensible.h */
1732
  List     *custom_ps;    /* list of child PlanState nodes, if any */
1733
  Size    pscan_len;    /* size of parallel coordination information */
1734
  const struct CustomExecMethods *methods;
1735
} CustomScanState;
1736
1737
/* ----------------------------------------------------------------
1738
 *         Join State Information
1739
 * ----------------------------------------------------------------
1740
 */
1741
1742
/* ----------------
1743
 *   JoinState information
1744
 *
1745
 *    Superclass for state nodes of join plans.
1746
 * ----------------
1747
 */
1748
typedef struct JoinState
1749
{
1750
  PlanState ps;
1751
  JoinType  jointype;
1752
  bool    single_match; /* True if we should skip to next outer tuple
1753
                 * after finding one inner match */
1754
  ExprState  *joinqual;   /* JOIN quals (in addition to ps.qual) */
1755
} JoinState;
1756
1757
/* ----------------
1758
 *   NestLoopState information
1759
 *
1760
 *    NeedNewOuter     true if need new outer tuple on next call
1761
 *    MatchedOuter     true if found a join match for current outer tuple
1762
 *    NullInnerTupleSlot prepared null tuple for left outer joins
1763
 * ----------------
1764
 */
1765
typedef struct NestLoopState
1766
{
1767
  JoinState js;       /* its first field is NodeTag */
1768
  bool    nl_NeedNewOuter;
1769
  bool    nl_MatchedOuter;
1770
  TupleTableSlot *nl_NullInnerTupleSlot;
1771
} NestLoopState;
1772
1773
/* ----------------
1774
 *   MergeJoinState information
1775
 *
1776
 *    NumClauses       number of mergejoinable join clauses
1777
 *    Clauses        info for each mergejoinable clause
1778
 *    JoinState      current state of ExecMergeJoin state machine
1779
 *    SkipMarkRestore    true if we may skip Mark and Restore operations
1780
 *    ExtraMarks       true to issue extra Mark operations on inner scan
1781
 *    ConstFalseJoin     true if we have a constant-false joinqual
1782
 *    FillOuter      true if should emit unjoined outer tuples anyway
1783
 *    FillInner      true if should emit unjoined inner tuples anyway
1784
 *    MatchedOuter     true if found a join match for current outer tuple
1785
 *    MatchedInner     true if found a join match for current inner tuple
1786
 *    OuterTupleSlot     slot in tuple table for cur outer tuple
1787
 *    InnerTupleSlot     slot in tuple table for cur inner tuple
1788
 *    MarkedTupleSlot    slot in tuple table for marked tuple
1789
 *    NullOuterTupleSlot prepared null tuple for right outer joins
1790
 *    NullInnerTupleSlot prepared null tuple for left outer joins
1791
 *    OuterEContext    workspace for computing outer tuple's join values
1792
 *    InnerEContext    workspace for computing inner tuple's join values
1793
 * ----------------
1794
 */
1795
/* private in nodeMergejoin.c: */
1796
typedef struct MergeJoinClauseData *MergeJoinClause;
1797
1798
typedef struct MergeJoinState
1799
{
1800
  JoinState js;       /* its first field is NodeTag */
1801
  int     mj_NumClauses;
1802
  MergeJoinClause mj_Clauses; /* array of length mj_NumClauses */
1803
  int     mj_JoinState;
1804
  bool    mj_SkipMarkRestore;
1805
  bool    mj_ExtraMarks;
1806
  bool    mj_ConstFalseJoin;
1807
  bool    mj_FillOuter;
1808
  bool    mj_FillInner;
1809
  bool    mj_MatchedOuter;
1810
  bool    mj_MatchedInner;
1811
  TupleTableSlot *mj_OuterTupleSlot;
1812
  TupleTableSlot *mj_InnerTupleSlot;
1813
  TupleTableSlot *mj_MarkedTupleSlot;
1814
  TupleTableSlot *mj_NullOuterTupleSlot;
1815
  TupleTableSlot *mj_NullInnerTupleSlot;
1816
  ExprContext *mj_OuterEContext;
1817
  ExprContext *mj_InnerEContext;
1818
} MergeJoinState;
1819
1820
/* ----------------
1821
 *   HashJoinState information
1822
 *
1823
 *    hashclauses       original form of the hashjoin condition
1824
 *    hj_OuterHashKeys    the outer hash keys in the hashjoin condition
1825
 *    hj_InnerHashKeys    the inner hash keys in the hashjoin condition
1826
 *    hj_HashOperators    the join operators in the hashjoin condition
1827
 *    hj_HashTable      hash table for the hashjoin
1828
 *                (NULL if table not built yet)
1829
 *    hj_CurHashValue     hash value for current outer tuple
1830
 *    hj_CurBucketNo      regular bucket# for current outer tuple
1831
 *    hj_CurSkewBucketNo    skew bucket# for current outer tuple
1832
 *    hj_CurTuple       last inner tuple matched to current outer
1833
 *                tuple, or NULL if starting search
1834
 *                (hj_CurXXX variables are undefined if
1835
 *                OuterTupleSlot is empty!)
1836
 *    hj_OuterTupleSlot   tuple slot for outer tuples
1837
 *    hj_HashTupleSlot    tuple slot for inner (hashed) tuples
1838
 *    hj_NullOuterTupleSlot prepared null tuple for right/full outer joins
1839
 *    hj_NullInnerTupleSlot prepared null tuple for left/full outer joins
1840
 *    hj_FirstOuterTupleSlot  first tuple retrieved from outer plan
1841
 *    hj_JoinState      current state of ExecHashJoin state machine
1842
 *    hj_MatchedOuter     true if found a join match for current outer
1843
 *    hj_OuterNotEmpty    true if outer relation known not empty
1844
 * ----------------
1845
 */
1846
1847
/* these structs are defined in executor/hashjoin.h: */
1848
typedef struct HashJoinTupleData *HashJoinTuple;
1849
typedef struct HashJoinTableData *HashJoinTable;
1850
1851
typedef struct HashJoinState
1852
{
1853
  JoinState js;       /* its first field is NodeTag */
1854
  ExprState  *hashclauses;
1855
  List     *hj_OuterHashKeys; /* list of ExprState nodes */
1856
  List     *hj_InnerHashKeys; /* list of ExprState nodes */
1857
  List     *hj_HashOperators; /* list of operator OIDs */
1858
  HashJoinTable hj_HashTable;
1859
  uint32    hj_CurHashValue;
1860
  int     hj_CurBucketNo;
1861
  int     hj_CurSkewBucketNo;
1862
  HashJoinTuple hj_CurTuple;
1863
  TupleTableSlot *hj_OuterTupleSlot;
1864
  TupleTableSlot *hj_HashTupleSlot;
1865
  TupleTableSlot *hj_NullOuterTupleSlot;
1866
  TupleTableSlot *hj_NullInnerTupleSlot;
1867
  TupleTableSlot *hj_FirstOuterTupleSlot;
1868
  int     hj_JoinState;
1869
  bool    hj_MatchedOuter;
1870
  bool    hj_OuterNotEmpty;
1871
} HashJoinState;
1872
1873
1874
/* ----------------------------------------------------------------
1875
 *         Materialization State Information
1876
 * ----------------------------------------------------------------
1877
 */
1878
1879
/* ----------------
1880
 *   MaterialState information
1881
 *
1882
 *    materialize nodes are used to materialize the results
1883
 *    of a subplan into a temporary file.
1884
 *
1885
 *    ss.ss_ScanTupleSlot refers to output of underlying plan.
1886
 * ----------------
1887
 */
1888
typedef struct MaterialState
1889
{
1890
  ScanState ss;       /* its first field is NodeTag */
1891
  int     eflags;     /* capability flags to pass to tuplestore */
1892
  bool    eof_underlying; /* reached end of underlying plan? */
1893
  Tuplestorestate *tuplestorestate;
1894
} MaterialState;
1895
1896
/* ----------------
1897
 *   Shared memory container for per-worker sort information
1898
 * ----------------
1899
 */
1900
typedef struct SharedSortInfo
1901
{
1902
  int     num_workers;
1903
  TuplesortInstrumentation sinstrument[FLEXIBLE_ARRAY_MEMBER];
1904
} SharedSortInfo;
1905
1906
/* ----------------
1907
 *   SortState information
1908
 * ----------------
1909
 */
1910
typedef struct SortState
1911
{
1912
  ScanState ss;       /* its first field is NodeTag */
1913
  bool    randomAccess; /* need random access to sort output? */
1914
  bool    bounded;    /* is the result set bounded? */
1915
  int64   bound;      /* if bounded, how many tuples are needed */
1916
  bool    sort_Done;    /* sort completed yet? */
1917
  bool    bounded_Done; /* value of bounded we did the sort with */
1918
  int64   bound_Done;   /* value of bound we did the sort with */
1919
  void     *tuplesortstate; /* private state of tuplesort.c */
1920
  bool    am_worker;    /* are we a worker? */
1921
  SharedSortInfo *shared_info;  /* one entry per worker */
1922
} SortState;
1923
1924
/* ---------------------
1925
 *  GroupState information
1926
 * ---------------------
1927
 */
1928
typedef struct GroupState
1929
{
1930
  ScanState ss;       /* its first field is NodeTag */
1931
  ExprState  *eqfunction;   /* equality function */
1932
  bool    grp_done;   /* indicates completion of Group scan */
1933
} GroupState;
1934
1935
/* ---------------------
1936
 *  AggState information
1937
 *
1938
 *  ss.ss_ScanTupleSlot refers to output of underlying plan.
1939
 *
1940
 *  Note: ss.ps.ps_ExprContext contains ecxt_aggvalues and
1941
 *  ecxt_aggnulls arrays, which hold the computed agg values for the current
1942
 *  input group during evaluation of an Agg node's output tuple(s).  We
1943
 *  create a second ExprContext, tmpcontext, in which to evaluate input
1944
 *  expressions and run the aggregate transition functions.
1945
 * ---------------------
1946
 */
1947
/* these structs are private in nodeAgg.c: */
1948
typedef struct AggStatePerAggData *AggStatePerAgg;
1949
typedef struct AggStatePerTransData *AggStatePerTrans;
1950
typedef struct AggStatePerGroupData *AggStatePerGroup;
1951
typedef struct AggStatePerPhaseData *AggStatePerPhase;
1952
typedef struct AggStatePerHashData *AggStatePerHash;
1953
1954
typedef struct AggState
1955
{
1956
  ScanState ss;       /* its first field is NodeTag */
1957
  List     *aggs;     /* all Aggref nodes in targetlist & quals */
1958
  int     numaggs;    /* length of list (could be zero!) */
1959
  int     numtrans;   /* number of pertrans items */
1960
  AggStrategy aggstrategy;  /* strategy mode */
1961
  AggSplit  aggsplit;   /* agg-splitting mode, see nodes.h */
1962
  AggStatePerPhase phase;   /* pointer to current phase data */
1963
  int     numphases;    /* number of phases (including phase 0) */
1964
  int     current_phase;  /* current phase number */
1965
  AggStatePerAgg peragg;    /* per-Aggref information */
1966
  AggStatePerTrans pertrans;  /* per-Trans state information */
1967
  ExprContext *hashcontext; /* econtexts for long-lived data (hashtable) */
1968
  ExprContext **aggcontexts;  /* econtexts for long-lived data (per GS) */
1969
  ExprContext *tmpcontext;  /* econtext for input expressions */
1970
#define FIELDNO_AGGSTATE_CURAGGCONTEXT 14
1971
  ExprContext *curaggcontext; /* currently active aggcontext */
1972
  AggStatePerAgg curperagg; /* currently active aggregate, if any */
1973
#define FIELDNO_AGGSTATE_CURPERTRANS 16
1974
  AggStatePerTrans curpertrans; /* currently active trans state, if any */
1975
  bool    input_done;   /* indicates end of input */
1976
  bool    agg_done;   /* indicates completion of Agg scan */
1977
  int     projected_set;  /* The last projected grouping set */
1978
#define FIELDNO_AGGSTATE_CURRENT_SET 20
1979
  int     current_set;  /* The current grouping set being evaluated */
1980
  Bitmapset  *grouped_cols; /* grouped cols in current projection */
1981
  List     *all_grouped_cols; /* list of all grouped cols in DESC order */
1982
  /* These fields are for grouping set phase data */
1983
  int     maxsets;    /* The max number of sets in any phase */
1984
  AggStatePerPhase phases;  /* array of all phases */
1985
  Tuplesortstate *sort_in;  /* sorted input to phases > 1 */
1986
  Tuplesortstate *sort_out; /* input is copied here for next phase */
1987
  TupleTableSlot *sort_slot;  /* slot for sort results */
1988
  /* these fields are used in AGG_PLAIN and AGG_SORTED modes: */
1989
  AggStatePerGroup *pergroups;  /* grouping set indexed array of per-group
1990
                   * pointers */
1991
  HeapTuple grp_firstTuple; /* copy of first tuple of current group */
1992
  /* these fields are used in AGG_HASHED and AGG_MIXED modes: */
1993
  bool    table_filled; /* hash table filled yet? */
1994
  int     num_hashes;
1995
  AggStatePerHash perhash;  /* array of per-hashtable data */
1996
  AggStatePerGroup *hash_pergroup;  /* grouping set indexed array of
1997
                     * per-group pointers */
1998
1999
  /* support for evaluation of agg input expressions: */
2000
#define FIELDNO_AGGSTATE_ALL_PERGROUPS 34
2001
  AggStatePerGroup *all_pergroups;  /* array of first ->pergroups, than
2002
                     * ->hash_pergroup */
2003
  ProjectionInfo *combinedproj; /* projection machinery */
2004
2005
  /* YB specific attributes. */
2006
  bool    yb_pushdown_supported;  /* YB pushdown supported for agg */
2007
} AggState;
2008
2009
/* ----------------
2010
 *  WindowAggState information
2011
 * ----------------
2012
 */
2013
/* these structs are private in nodeWindowAgg.c: */
2014
typedef struct WindowStatePerFuncData *WindowStatePerFunc;
2015
typedef struct WindowStatePerAggData *WindowStatePerAgg;
2016
2017
typedef struct WindowAggState
2018
{
2019
  ScanState ss;       /* its first field is NodeTag */
2020
2021
  /* these fields are filled in by ExecInitExpr: */
2022
  List     *funcs;      /* all WindowFunc nodes in targetlist */
2023
  int     numfuncs;   /* total number of window functions */
2024
  int     numaggs;    /* number that are plain aggregates */
2025
2026
  WindowStatePerFunc perfunc; /* per-window-function information */
2027
  WindowStatePerAgg peragg; /* per-plain-aggregate information */
2028
  ExprState  *partEqfunction; /* equality funcs for partition columns */
2029
  ExprState  *ordEqfunction;  /* equality funcs for ordering columns */
2030
  Tuplestorestate *buffer;  /* stores rows of current partition */
2031
  int     current_ptr;  /* read pointer # for current row */
2032
  int     framehead_ptr;  /* read pointer # for frame head, if used */
2033
  int     frametail_ptr;  /* read pointer # for frame tail, if used */
2034
  int     grouptail_ptr;  /* read pointer # for group tail, if used */
2035
  int64   spooled_rows; /* total # of rows in buffer */
2036
  int64   currentpos;   /* position of current row in partition */
2037
  int64   frameheadpos; /* current frame head position */
2038
  int64   frametailpos; /* current frame tail position (frame end+1) */
2039
  /* use struct pointer to avoid including windowapi.h here */
2040
  struct WindowObjectData *agg_winobj;  /* winobj for aggregate fetches */
2041
  int64   aggregatedbase; /* start row for current aggregates */
2042
  int64   aggregatedupto; /* rows before this one are aggregated */
2043
2044
  int     frameOptions; /* frame_clause options, see WindowDef */
2045
  ExprState  *startOffset;  /* expression for starting bound offset */
2046
  ExprState  *endOffset;    /* expression for ending bound offset */
2047
  Datum   startOffsetValue; /* result of startOffset evaluation */
2048
  Datum   endOffsetValue; /* result of endOffset evaluation */
2049
2050
  /* these fields are used with RANGE offset PRECEDING/FOLLOWING: */
2051
  FmgrInfo  startInRangeFunc; /* in_range function for startOffset */
2052
  FmgrInfo  endInRangeFunc; /* in_range function for endOffset */
2053
  Oid     inRangeColl;  /* collation for in_range tests */
2054
  bool    inRangeAsc;   /* use ASC sort order for in_range tests? */
2055
  bool    inRangeNullsFirst;  /* nulls sort first for in_range tests? */
2056
2057
  /* these fields are used in GROUPS mode: */
2058
  int64   currentgroup; /* peer group # of current row in partition */
2059
  int64   frameheadgroup; /* peer group # of frame head row */
2060
  int64   frametailgroup; /* peer group # of frame tail row */
2061
  int64   groupheadpos; /* current row's peer group head position */
2062
  int64   grouptailpos; /* " " " " tail position (group end+1) */
2063
2064
  MemoryContext partcontext;  /* context for partition-lifespan data */
2065
  MemoryContext aggcontext; /* shared context for aggregate working data */
2066
  MemoryContext curaggcontext;  /* current aggregate's working data */
2067
  ExprContext *tmpcontext;  /* short-term evaluation context */
2068
2069
  bool    all_first;    /* true if the scan is starting */
2070
  bool    all_done;   /* true if the scan is finished */
2071
  bool    partition_spooled;  /* true if all tuples in current partition
2072
                   * have been spooled into tuplestore */
2073
  bool    more_partitions;  /* true if there's more partitions after
2074
                   * this one */
2075
  bool    framehead_valid;  /* true if frameheadpos is known up to
2076
                   * date for current row */
2077
  bool    frametail_valid;  /* true if frametailpos is known up to
2078
                   * date for current row */
2079
  bool    grouptail_valid;  /* true if grouptailpos is known up to
2080
                   * date for current row */
2081
2082
  TupleTableSlot *first_part_slot;  /* first tuple of current or next
2083
                     * partition */
2084
  TupleTableSlot *framehead_slot; /* first tuple of current frame */
2085
  TupleTableSlot *frametail_slot; /* first tuple after current frame */
2086
2087
  /* temporary slots for tuples fetched back from tuplestore */
2088
  TupleTableSlot *agg_row_slot;
2089
  TupleTableSlot *temp_slot_1;
2090
  TupleTableSlot *temp_slot_2;
2091
} WindowAggState;
2092
2093
/* ----------------
2094
 *   UniqueState information
2095
 *
2096
 *    Unique nodes are used "on top of" sort nodes to discard
2097
 *    duplicate tuples returned from the sort phase.  Basically
2098
 *    all it does is compare the current tuple from the subplan
2099
 *    with the previously fetched tuple (stored in its result slot).
2100
 *    If the two are identical in all interesting fields, then
2101
 *    we just fetch another tuple from the sort and try again.
2102
 * ----------------
2103
 */
2104
typedef struct UniqueState
2105
{
2106
  PlanState ps;       /* its first field is NodeTag */
2107
  ExprState  *eqfunction;   /* tuple equality qual */
2108
} UniqueState;
2109
2110
/* ----------------
2111
 * GatherState information
2112
 *
2113
 *    Gather nodes launch 1 or more parallel workers, run a subplan
2114
 *    in those workers, and collect the results.
2115
 * ----------------
2116
 */
2117
typedef struct GatherState
2118
{
2119
  PlanState ps;       /* its first field is NodeTag */
2120
  bool    initialized;  /* workers launched? */
2121
  bool    need_to_scan_locally; /* need to read from local plan? */
2122
  int64   tuples_needed;  /* tuple bound, see ExecSetTupleBound */
2123
  /* these fields are set up once: */
2124
  TupleTableSlot *funnel_slot;
2125
  struct ParallelExecutorInfo *pei;
2126
  /* all remaining fields are reinitialized during a rescan: */
2127
  int     nworkers_launched;  /* original number of workers */
2128
  int     nreaders;   /* number of still-active workers */
2129
  int     nextreader;   /* next one to try to read from */
2130
  struct TupleQueueReader **reader; /* array with nreaders active entries */
2131
} GatherState;
2132
2133
/* ----------------
2134
 * GatherMergeState information
2135
 *
2136
 *    Gather merge nodes launch 1 or more parallel workers, run a
2137
 *    subplan which produces sorted output in each worker, and then
2138
 *    merge the results into a single sorted stream.
2139
 * ----------------
2140
 */
2141
struct GMReaderTupleBuffer;   /* private in nodeGatherMerge.c */
2142
2143
typedef struct GatherMergeState
2144
{
2145
  PlanState ps;       /* its first field is NodeTag */
2146
  bool    initialized;  /* workers launched? */
2147
  bool    gm_initialized; /* gather_merge_init() done? */
2148
  bool    need_to_scan_locally; /* need to read from local plan? */
2149
  int64   tuples_needed;  /* tuple bound, see ExecSetTupleBound */
2150
  /* these fields are set up once: */
2151
  TupleDesc tupDesc;    /* descriptor for subplan result tuples */
2152
  int     gm_nkeys;   /* number of sort columns */
2153
  SortSupport gm_sortkeys;  /* array of length gm_nkeys */
2154
  struct ParallelExecutorInfo *pei;
2155
  /* all remaining fields are reinitialized during a rescan */
2156
  /* (but the arrays are not reallocated, just cleared) */
2157
  int     nworkers_launched;  /* original number of workers */
2158
  int     nreaders;   /* number of active workers */
2159
  TupleTableSlot **gm_slots;  /* array with nreaders+1 entries */
2160
  struct TupleQueueReader **reader; /* array with nreaders active entries */
2161
  struct GMReaderTupleBuffer *gm_tuple_buffers; /* nreaders tuple buffers */
2162
  struct binaryheap *gm_heap; /* binary heap of slot indices */
2163
} GatherMergeState;
2164
2165
/* ----------------
2166
 *   Values displayed by EXPLAIN ANALYZE
2167
 * ----------------
2168
 */
2169
typedef struct HashInstrumentation
2170
{
2171
  int     nbuckets;   /* number of buckets at end of execution */
2172
  int     nbuckets_original;  /* planned number of buckets */
2173
  int     nbatch;     /* number of batches at end of execution */
2174
  int     nbatch_original;  /* planned number of batches */
2175
  size_t    space_peak;   /* speak memory usage in bytes */
2176
} HashInstrumentation;
2177
2178
/* ----------------
2179
 *   Shared memory container for per-worker hash information
2180
 * ----------------
2181
 */
2182
typedef struct SharedHashInfo
2183
{
2184
  int     num_workers;
2185
  HashInstrumentation hinstrument[FLEXIBLE_ARRAY_MEMBER];
2186
} SharedHashInfo;
2187
2188
/* ----------------
2189
 *   HashState information
2190
 * ----------------
2191
 */
2192
typedef struct HashState
2193
{
2194
  PlanState ps;       /* its first field is NodeTag */
2195
  HashJoinTable hashtable;  /* hash table for the hashjoin */
2196
  List     *hashkeys;   /* list of ExprState nodes */
2197
  /* hashkeys is same as parent's hj_InnerHashKeys */
2198
2199
  SharedHashInfo *shared_info;  /* one entry per worker */
2200
  HashInstrumentation *hinstrument; /* this worker's entry */
2201
2202
  /* Parallel hash state. */
2203
  struct ParallelHashJoinState *parallel_state;
2204
} HashState;
2205
2206
/* ----------------
2207
 *   SetOpState information
2208
 *
2209
 *    Even in "sorted" mode, SetOp nodes are more complex than a simple
2210
 *    Unique, since we have to count how many duplicates to return.  But
2211
 *    we also support hashing, so this is really more like a cut-down
2212
 *    form of Agg.
2213
 * ----------------
2214
 */
2215
/* this struct is private in nodeSetOp.c: */
2216
typedef struct SetOpStatePerGroupData *SetOpStatePerGroup;
2217
2218
typedef struct SetOpState
2219
{
2220
  PlanState ps;       /* its first field is NodeTag */
2221
  ExprState  *eqfunction;   /* equality comparator */
2222
  Oid      *eqfuncoids;   /* per-grouping-field equality fns */
2223
  FmgrInfo   *hashfunctions;  /* per-grouping-field hash fns */
2224
  bool    setop_done;   /* indicates completion of output scan */
2225
  long    numOutput;    /* number of dups left to output */
2226
  /* these fields are used in SETOP_SORTED mode: */
2227
  SetOpStatePerGroup pergroup;  /* per-group working state */
2228
  HeapTuple grp_firstTuple; /* copy of first tuple of current group */
2229
  /* these fields are used in SETOP_HASHED mode: */
2230
  TupleHashTable hashtable; /* hash table with one entry per group */
2231
  MemoryContext tableContext; /* memory context containing hash table */
2232
  bool    table_filled; /* hash table filled yet? */
2233
  TupleHashIterator hashiter; /* for iterating through hash table */
2234
} SetOpState;
2235
2236
/* ----------------
2237
 *   LockRowsState information
2238
 *
2239
 *    LockRows nodes are used to enforce FOR [KEY] UPDATE/SHARE locking.
2240
 * ----------------
2241
 */
2242
typedef struct LockRowsState
2243
{
2244
  PlanState ps;       /* its first field is NodeTag */
2245
  List     *lr_arowMarks; /* List of ExecAuxRowMarks */
2246
  EPQState  lr_epqstate;  /* for evaluating EvalPlanQual rechecks */
2247
  HeapTuple  *lr_curtuples; /* locked tuples (one entry per RT entry) */
2248
  int     lr_ntables;   /* length of lr_curtuples[] array */
2249
} LockRowsState;
2250
2251
/* ----------------
2252
 *   LimitState information
2253
 *
2254
 *    Limit nodes are used to enforce LIMIT/OFFSET clauses.
2255
 *    They just select the desired subrange of their subplan's output.
2256
 *
2257
 * offset is the number of initial tuples to skip (0 does nothing).
2258
 * count is the number of tuples to return after skipping the offset tuples.
2259
 * If no limit count was specified, count is undefined and noCount is true.
2260
 * When lstate == LIMIT_INITIAL, offset/count/noCount haven't been set yet.
2261
 * ----------------
2262
 */
2263
typedef enum
2264
{
2265
  LIMIT_INITIAL,        /* initial state for LIMIT node */
2266
  LIMIT_RESCAN,       /* rescan after recomputing parameters */
2267
  LIMIT_EMPTY,        /* there are no returnable rows */
2268
  LIMIT_INWINDOW,       /* have returned a row in the window */
2269
  LIMIT_SUBPLANEOF,     /* at EOF of subplan (within window) */
2270
  LIMIT_WINDOWEND,      /* stepped off end of window */
2271
  LIMIT_WINDOWSTART     /* stepped off beginning of window */
2272
} LimitStateCond;
2273
2274
typedef struct LimitState
2275
{
2276
  PlanState ps;       /* its first field is NodeTag */
2277
  ExprState  *limitOffset;  /* OFFSET parameter, or NULL if none */
2278
  ExprState  *limitCount;   /* COUNT parameter, or NULL if none */
2279
  int64   offset;     /* current OFFSET value */
2280
  int64   count;      /* current COUNT, if any */
2281
  bool    noCount;    /* if true, ignore count */
2282
  LimitStateCond lstate;    /* state machine status, as above */
2283
  int64   position;   /* 1-based index of last tuple returned */
2284
  TupleTableSlot *subSlot;  /* tuple last obtained from subplan */
2285
} LimitState;
2286
2287
#endif              /* EXECNODES_H */