Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "postgres.h"
00026
00027 #include "access/relscan.h"
00028 #include "executor/execdebug.h"
00029 #include "executor/nodeSeqscan.h"
00030 #include "utils/rel.h"
00031
00032 static void InitScanRelation(SeqScanState *node, EState *estate, int eflags);
00033 static TupleTableSlot *SeqNext(SeqScanState *node);
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 static TupleTableSlot *
00047 SeqNext(SeqScanState *node)
00048 {
00049 HeapTuple tuple;
00050 HeapScanDesc scandesc;
00051 EState *estate;
00052 ScanDirection direction;
00053 TupleTableSlot *slot;
00054
00055
00056
00057
00058 scandesc = node->ss_currentScanDesc;
00059 estate = node->ps.state;
00060 direction = estate->es_direction;
00061 slot = node->ss_ScanTupleSlot;
00062
00063
00064
00065
00066 tuple = heap_getnext(scandesc, direction);
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076 if (tuple)
00077 ExecStoreTuple(tuple,
00078 slot,
00079 scandesc->rs_cbuf,
00080
00081 false);
00082 else
00083 ExecClearTuple(slot);
00084
00085 return slot;
00086 }
00087
00088
00089
00090
00091 static bool
00092 SeqRecheck(SeqScanState *node, TupleTableSlot *slot)
00093 {
00094
00095
00096
00097
00098 return true;
00099 }
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110 TupleTableSlot *
00111 ExecSeqScan(SeqScanState *node)
00112 {
00113 return ExecScan((ScanState *) node,
00114 (ExecScanAccessMtd) SeqNext,
00115 (ExecScanRecheckMtd) SeqRecheck);
00116 }
00117
00118
00119
00120
00121
00122
00123
00124 static void
00125 InitScanRelation(SeqScanState *node, EState *estate, int eflags)
00126 {
00127 Relation currentRelation;
00128 HeapScanDesc currentScanDesc;
00129
00130
00131
00132
00133
00134 currentRelation = ExecOpenScanRelation(estate,
00135 ((SeqScan *) node->ps.plan)->scanrelid,
00136 eflags);
00137
00138
00139 currentScanDesc = heap_beginscan(currentRelation,
00140 estate->es_snapshot,
00141 0,
00142 NULL);
00143
00144 node->ss_currentRelation = currentRelation;
00145 node->ss_currentScanDesc = currentScanDesc;
00146
00147
00148 ExecAssignScanType(node, RelationGetDescr(currentRelation));
00149 }
00150
00151
00152
00153
00154
00155
00156 SeqScanState *
00157 ExecInitSeqScan(SeqScan *node, EState *estate, int eflags)
00158 {
00159 SeqScanState *scanstate;
00160
00161
00162
00163
00164
00165 Assert(outerPlan(node) == NULL);
00166 Assert(innerPlan(node) == NULL);
00167
00168
00169
00170
00171 scanstate = makeNode(SeqScanState);
00172 scanstate->ps.plan = (Plan *) node;
00173 scanstate->ps.state = estate;
00174
00175
00176
00177
00178
00179
00180 ExecAssignExprContext(estate, &scanstate->ps);
00181
00182
00183
00184
00185 scanstate->ps.targetlist = (List *)
00186 ExecInitExpr((Expr *) node->plan.targetlist,
00187 (PlanState *) scanstate);
00188 scanstate->ps.qual = (List *)
00189 ExecInitExpr((Expr *) node->plan.qual,
00190 (PlanState *) scanstate);
00191
00192
00193
00194
00195 ExecInitResultTupleSlot(estate, &scanstate->ps);
00196 ExecInitScanTupleSlot(estate, scanstate);
00197
00198
00199
00200
00201 InitScanRelation(scanstate, estate, eflags);
00202
00203 scanstate->ps.ps_TupFromTlist = false;
00204
00205
00206
00207
00208 ExecAssignResultTypeFromTL(&scanstate->ps);
00209 ExecAssignScanProjectionInfo(scanstate);
00210
00211 return scanstate;
00212 }
00213
00214
00215
00216
00217
00218
00219
00220 void
00221 ExecEndSeqScan(SeqScanState *node)
00222 {
00223 Relation relation;
00224 HeapScanDesc scanDesc;
00225
00226
00227
00228
00229 relation = node->ss_currentRelation;
00230 scanDesc = node->ss_currentScanDesc;
00231
00232
00233
00234
00235 ExecFreeExprContext(&node->ps);
00236
00237
00238
00239
00240 ExecClearTuple(node->ps.ps_ResultTupleSlot);
00241 ExecClearTuple(node->ss_ScanTupleSlot);
00242
00243
00244
00245
00246 heap_endscan(scanDesc);
00247
00248
00249
00250
00251 ExecCloseScanRelation(relation);
00252 }
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265 void
00266 ExecReScanSeqScan(SeqScanState *node)
00267 {
00268 HeapScanDesc scan;
00269
00270 scan = node->ss_currentScanDesc;
00271
00272 heap_rescan(scan,
00273 NULL);
00274
00275 ExecScanReScan((ScanState *) node);
00276 }
00277
00278
00279
00280
00281
00282
00283
00284 void
00285 ExecSeqMarkPos(SeqScanState *node)
00286 {
00287 HeapScanDesc scan = node->ss_currentScanDesc;
00288
00289 heap_markpos(scan);
00290 }
00291
00292
00293
00294
00295
00296
00297
00298 void
00299 ExecSeqRestrPos(SeqScanState *node)
00300 {
00301 HeapScanDesc scan = node->ss_currentScanDesc;
00302
00303
00304
00305
00306
00307
00308
00309 ExecClearTuple(node->ss_ScanTupleSlot);
00310
00311 heap_restrpos(scan);
00312 }