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 ExecEndNamedTuplestoreScan (NamedTuplestoreScanState *node)
 
void ExecReScanNamedTuplestoreScan (NamedTuplestoreScanState *node)
 

Function Documentation

◆ ExecEndNamedTuplestoreScan()

void ExecEndNamedTuplestoreScan ( NamedTuplestoreScanState node)

Definition at line 165 of file nodeNamedtuplestorescan.c.

References ExecClearTuple(), ExecFreeExprContext(), ScanState::ps, PlanState::ps_ResultTupleSlot, NamedTuplestoreScanState::ss, and ScanState::ss_ScanTupleSlot.

Referenced by ExecEndNode().

166 {
167  /*
168  * Free exprcontext
169  */
170  ExecFreeExprContext(&node->ss.ps);
171 
172  /*
173  * clean out the tuple table
174  */
175  if (node->ss.ps.ps_ResultTupleSlot)
178 }
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:426
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1334
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:614
PlanState ps
Definition: execnodes.h:1331
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:978

◆ ExecInitNamedTuplestoreScan()

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

Definition at line 83 of file nodeNamedtuplestorescan.c.

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, Scan::plan, PlanState::plan, ScanState::ps, Plan::qual, 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().

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

◆ ExecNamedTuplestoreScan()

static TupleTableSlot* ExecNamedTuplestoreScan ( PlanState pstate)
static

Definition at line 68 of file nodeNamedtuplestorescan.c.

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

Referenced by ExecInitNamedTuplestoreScan().

69 {
71 
72  return ExecScan(&node->ss,
75 }
#define castNode(_type_, nodeptr)
Definition: nodes.h:594
TupleTableSlot * ExecScan(ScanState *node, ExecScanAccessMtd accessMtd, ExecScanRecheckMtd recheckMtd)
Definition: execScan.c:158
static TupleTableSlot * NamedTuplestoreScanNext(NamedTuplestoreScanState *node)
bool(* ExecScanRecheckMtd)(ScanState *node, TupleTableSlot *slot)
Definition: executor.h:426
TupleTableSlot *(* ExecScanAccessMtd)(ScanState *node)
Definition: executor.h:425
static bool NamedTuplestoreScanRecheck(NamedTuplestoreScanState *node, TupleTableSlot *slot)

◆ ExecReScanNamedTuplestoreScan()

void ExecReScanNamedTuplestoreScan ( NamedTuplestoreScanState node)

Definition at line 187 of file nodeNamedtuplestorescan.c.

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

Referenced by ExecReScan().

188 {
189  Tuplestorestate *tuplestorestate = node->relation;
190 
191  if (node->ss.ps.ps_ResultTupleSlot)
193 
194  ExecScanReScan(&node->ss);
195 
196  /*
197  * Rewind my own pointer.
198  */
199  tuplestore_select_read_pointer(tuplestorestate, node->readptr);
200  tuplestore_rescan(tuplestorestate);
201 }
void tuplestore_rescan(Tuplestorestate *state)
Definition: tuplestore.c:1233
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:426
PlanState ps
Definition: execnodes.h:1331
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:978
Tuplestorestate * relation
Definition: execnodes.h:1760
void ExecScanReScan(ScanState *node)
Definition: execScan.c:299
void tuplestore_select_read_pointer(Tuplestorestate *state, int ptr)
Definition: tuplestore.c:473

◆ NamedTuplestoreScanNext()

static TupleTableSlot * NamedTuplestoreScanNext ( NamedTuplestoreScanState node)
static

Definition at line 32 of file nodeNamedtuplestorescan.c.

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().

33 {
34  TupleTableSlot *slot;
35 
36  /* We intentionally do not support backward scan. */
38 
39  /*
40  * Get the next tuple from tuplestore. Return NULL if no more tuples.
41  */
42  slot = node->ss.ss_ScanTupleSlot;
44  (void) tuplestore_gettupleslot(node->relation, true, false, slot);
45  return slot;
46 }
#define ScanDirectionIsForward(direction)
Definition: sdir.h:55
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1334
EState * state
Definition: execnodes.h:942
ScanDirection es_direction
Definition: execnodes.h:502
PlanState ps
Definition: execnodes.h:1331
bool tuplestore_gettupleslot(Tuplestorestate *state, bool forward, bool copy, TupleTableSlot *slot)
Definition: tuplestore.c:1078
#define Assert(condition)
Definition: c.h:732
Tuplestorestate * relation
Definition: execnodes.h:1760
void tuplestore_select_read_pointer(Tuplestorestate *state, int ptr)
Definition: tuplestore.c:473

◆ NamedTuplestoreScanRecheck()

static bool NamedTuplestoreScanRecheck ( NamedTuplestoreScanState node,
TupleTableSlot slot 
)
static

Definition at line 53 of file nodeNamedtuplestorescan.c.

Referenced by ExecNamedTuplestoreScan().

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