PostgreSQL Source Code  git master
nodeNamedtuplestorescan.c File Reference
Include dependency graph for nodeNamedtuplestorescan.c:

Go to the source code of this file.

Functions

static TupleTableSlotNamedTuplestoreScanNext (NamedTuplestoreScanState *node)
 
static bool NamedTuplestoreScanRecheck (NamedTuplestoreScanState *node, TupleTableSlot *slot)
 
static TupleTableSlotExecNamedTuplestoreScan (PlanState *pstate)
 
NamedTuplestoreScanStateExecInitNamedTuplestoreScan (NamedTuplestoreScan *node, EState *estate, int eflags)
 
void ExecReScanNamedTuplestoreScan (NamedTuplestoreScanState *node)
 

Function Documentation

◆ ExecInitNamedTuplestoreScan()

NamedTuplestoreScanState* ExecInitNamedTuplestoreScan ( NamedTuplestoreScan node,
EState estate,
int  eflags 
)

Definition at line 82 of file nodeNamedtuplestorescan.c.

83 {
84  NamedTuplestoreScanState *scanstate;
86 
87  /* check for unsupported flags */
88  Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
89 
90  /*
91  * NamedTuplestoreScan should not have any children.
92  */
93  Assert(outerPlan(node) == NULL);
94  Assert(innerPlan(node) == NULL);
95 
96  /*
97  * create new NamedTuplestoreScanState for node
98  */
100  scanstate->ss.ps.plan = (Plan *) node;
101  scanstate->ss.ps.state = estate;
103 
104  enr = get_ENR(estate->es_queryEnv, node->enrname);
105  if (!enr)
106  elog(ERROR, "executor could not find named tuplestore \"%s\"",
107  node->enrname);
108 
109  Assert(enr->reldata);
110  scanstate->relation = (Tuplestorestate *) enr->reldata;
111  scanstate->tupdesc = ENRMetadataGetTupDesc(&(enr->md));
112  scanstate->readptr =
114 
115  /*
116  * The new read pointer copies its position from read pointer 0, which
117  * could be anywhere, so explicitly rewind it.
118  */
119  tuplestore_select_read_pointer(scanstate->relation, scanstate->readptr);
120  tuplestore_rescan(scanstate->relation);
121 
122  /*
123  * XXX: Should we add a function to free that read pointer when done?
124  *
125  * This was attempted, but it did not improve performance or memory usage
126  * in any tested cases.
127  */
128 
129  /*
130  * Miscellaneous initialization
131  *
132  * create expression context for node
133  */
134  ExecAssignExprContext(estate, &scanstate->ss.ps);
135 
136  /*
137  * The scan tuple type is specified for the tuplestore.
138  */
139  ExecInitScanTupleSlot(estate, &scanstate->ss, scanstate->tupdesc,
141 
142  /*
143  * Initialize result type and projection.
144  */
145  ExecInitResultTypeTL(&scanstate->ss.ps);
146  ExecAssignScanProjectionInfo(&scanstate->ss);
147 
148  /*
149  * initialize child expressions
150  */
151  scanstate->ss.ps.qual =
152  ExecInitQual(node->scan.plan.qual, (PlanState *) scanstate);
153 
154  return scanstate;
155 }
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:224
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:213
void ExecAssignScanProjectionInfo(ScanState *node)
Definition: execScan.c:270
void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1810
void ExecInitResultTypeTL(PlanState *planstate)
Definition: execTuples.c:1754
const TupleTableSlotOps TTSOpsMinimalTuple
Definition: execTuples.c:85
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:483
#define EXEC_FLAG_BACKWARD
Definition: executor.h:68
#define EXEC_FLAG_REWIND
Definition: executor.h:67
#define EXEC_FLAG_MARK
Definition: executor.h:69
Assert(fmt[strlen(fmt) - 1] !='\n')
static TupleTableSlot * ExecNamedTuplestoreScan(PlanState *pstate)
#define makeNode(_type_)
Definition: nodes.h:155
#define innerPlan(node)
Definition: plannodes.h:181
#define outerPlan(node)
Definition: plannodes.h:182
TupleDesc ENRMetadataGetTupDesc(EphemeralNamedRelationMetadata enrmd)
EphemeralNamedRelation get_ENR(QueryEnvironment *queryEnv, const char *name)
QueryEnvironment * es_queryEnv
Definition: execnodes.h:662
EphemeralNamedRelationMetadataData md
Tuplestorestate * relation
Definition: execnodes.h:1935
ExprState * qual
Definition: execnodes.h:1064
Plan * plan
Definition: execnodes.h:1043
EState * state
Definition: execnodes.h:1045
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:1049
PlanState ps
Definition: execnodes.h:1480
void tuplestore_select_read_pointer(Tuplestorestate *state, int ptr)
Definition: tuplestore.c:473
void tuplestore_rescan(Tuplestorestate *state)
Definition: tuplestore.c:1233
int tuplestore_alloc_read_pointer(Tuplestorestate *state, int eflags)
Definition: tuplestore.c:383

References Assert(), elog, ENRMetadataGetTupDesc(), NamedTuplestoreScan::enrname, ERROR, EState::es_queryEnv, EXEC_FLAG_BACKWARD, EXEC_FLAG_MARK, EXEC_FLAG_REWIND, ExecAssignExprContext(), ExecAssignScanProjectionInfo(), ExecInitQual(), ExecInitResultTypeTL(), ExecInitScanTupleSlot(), ExecNamedTuplestoreScan(), PlanState::ExecProcNode, get_ENR(), innerPlan, makeNode, EphemeralNamedRelationData::md, outerPlan, PlanState::plan, ScanState::ps, PlanState::qual, NamedTuplestoreScanState::readptr, NamedTuplestoreScanState::relation, EphemeralNamedRelationData::reldata, NamedTuplestoreScan::scan, NamedTuplestoreScanState::ss, PlanState::state, TTSOpsMinimalTuple, NamedTuplestoreScanState::tupdesc, tuplestore_alloc_read_pointer(), tuplestore_rescan(), and tuplestore_select_read_pointer().

Referenced by ExecInitNode().

◆ ExecNamedTuplestoreScan()

static TupleTableSlot* ExecNamedTuplestoreScan ( PlanState pstate)
static

Definition at line 67 of file nodeNamedtuplestorescan.c.

68 {
70 
71  return ExecScan(&node->ss,
74 }
TupleTableSlot * ExecScan(ScanState *node, ExecScanAccessMtd accessMtd, ExecScanRecheckMtd recheckMtd)
Definition: execScan.c:156
TupleTableSlot *(* ExecScanAccessMtd)(ScanState *node)
Definition: executor.h:473
bool(* ExecScanRecheckMtd)(ScanState *node, TupleTableSlot *slot)
Definition: executor.h:474
static TupleTableSlot * NamedTuplestoreScanNext(NamedTuplestoreScanState *node)
static bool NamedTuplestoreScanRecheck(NamedTuplestoreScanState *node, TupleTableSlot *slot)
#define castNode(_type_, nodeptr)
Definition: nodes.h:176

References castNode, ExecScan(), NamedTuplestoreScanNext(), NamedTuplestoreScanRecheck(), and NamedTuplestoreScanState::ss.

Referenced by ExecInitNamedTuplestoreScan().

◆ ExecReScanNamedTuplestoreScan()

void ExecReScanNamedTuplestoreScan ( NamedTuplestoreScanState node)

Definition at line 164 of file nodeNamedtuplestorescan.c.

165 {
166  Tuplestorestate *tuplestorestate = node->relation;
167 
168  if (node->ss.ps.ps_ResultTupleSlot)
170 
171  ExecScanReScan(&node->ss);
172 
173  /*
174  * Rewind my own pointer.
175  */
176  tuplestore_select_read_pointer(tuplestorestate, node->readptr);
177  tuplestore_rescan(tuplestorestate);
178 }
void ExecScanReScan(ScanState *node)
Definition: execScan.c:297
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:1081
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:433

References ExecClearTuple(), ExecScanReScan(), ScanState::ps, PlanState::ps_ResultTupleSlot, NamedTuplestoreScanState::readptr, NamedTuplestoreScanState::relation, NamedTuplestoreScanState::ss, tuplestore_rescan(), and tuplestore_select_read_pointer().

Referenced by ExecReScan().

◆ NamedTuplestoreScanNext()

static TupleTableSlot * NamedTuplestoreScanNext ( NamedTuplestoreScanState node)
static

Definition at line 31 of file nodeNamedtuplestorescan.c.

32 {
33  TupleTableSlot *slot;
34 
35  /* We intentionally do not support backward scan. */
37 
38  /*
39  * Get the next tuple from tuplestore. Return NULL if no more tuples.
40  */
41  slot = node->ss.ss_ScanTupleSlot;
43  (void) tuplestore_gettupleslot(node->relation, true, false, slot);
44  return slot;
45 }
#define ScanDirectionIsForward(direction)
Definition: sdir.h:64
ScanDirection es_direction
Definition: execnodes.h:621
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1483
bool tuplestore_gettupleslot(Tuplestorestate *state, bool forward, bool copy, TupleTableSlot *slot)
Definition: tuplestore.c:1078

References Assert(), EState::es_direction, ScanState::ps, NamedTuplestoreScanState::readptr, NamedTuplestoreScanState::relation, ScanDirectionIsForward, NamedTuplestoreScanState::ss, ScanState::ss_ScanTupleSlot, PlanState::state, tuplestore_gettupleslot(), and tuplestore_select_read_pointer().

Referenced by ExecNamedTuplestoreScan().

◆ NamedTuplestoreScanRecheck()

static bool NamedTuplestoreScanRecheck ( NamedTuplestoreScanState node,
TupleTableSlot slot 
)
static

Definition at line 52 of file nodeNamedtuplestorescan.c.

53 {
54  /* nothing to check */
55  return true;
56 }

Referenced by ExecNamedTuplestoreScan().