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
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 #include "postgres.h"
00047
00048 #include "executor/executor.h"
00049 #include "executor/nodeResult.h"
00050 #include "utils/memutils.h"
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 TupleTableSlot *
00067 ExecResult(ResultState *node)
00068 {
00069 TupleTableSlot *outerTupleSlot;
00070 TupleTableSlot *resultSlot;
00071 PlanState *outerPlan;
00072 ExprContext *econtext;
00073 ExprDoneCond isDone;
00074
00075 econtext = node->ps.ps_ExprContext;
00076
00077
00078
00079
00080 if (node->rs_checkqual)
00081 {
00082 bool qualResult = ExecQual((List *) node->resconstantqual,
00083 econtext,
00084 false);
00085
00086 node->rs_checkqual = false;
00087 if (!qualResult)
00088 {
00089 node->rs_done = true;
00090 return NULL;
00091 }
00092 }
00093
00094
00095
00096
00097
00098
00099 if (node->ps.ps_TupFromTlist)
00100 {
00101 resultSlot = ExecProject(node->ps.ps_ProjInfo, &isDone);
00102 if (isDone == ExprMultipleResult)
00103 return resultSlot;
00104
00105 node->ps.ps_TupFromTlist = false;
00106 }
00107
00108
00109
00110
00111
00112
00113 ResetExprContext(econtext);
00114
00115
00116
00117
00118
00119
00120
00121 while (!node->rs_done)
00122 {
00123 outerPlan = outerPlanState(node);
00124
00125 if (outerPlan != NULL)
00126 {
00127
00128
00129
00130 outerTupleSlot = ExecProcNode(outerPlan);
00131
00132 if (TupIsNull(outerTupleSlot))
00133 return NULL;
00134
00135
00136
00137
00138
00139 econtext->ecxt_outertuple = outerTupleSlot;
00140 }
00141 else
00142 {
00143
00144
00145
00146
00147 node->rs_done = true;
00148 }
00149
00150
00151
00152
00153
00154
00155 resultSlot = ExecProject(node->ps.ps_ProjInfo, &isDone);
00156
00157 if (isDone != ExprEndResult)
00158 {
00159 node->ps.ps_TupFromTlist = (isDone == ExprMultipleResult);
00160 return resultSlot;
00161 }
00162 }
00163
00164 return NULL;
00165 }
00166
00167
00168
00169
00170
00171 void
00172 ExecResultMarkPos(ResultState *node)
00173 {
00174 PlanState *outerPlan = outerPlanState(node);
00175
00176 if (outerPlan != NULL)
00177 ExecMarkPos(outerPlan);
00178 else
00179 elog(DEBUG2, "Result nodes do not support mark/restore");
00180 }
00181
00182
00183
00184
00185
00186 void
00187 ExecResultRestrPos(ResultState *node)
00188 {
00189 PlanState *outerPlan = outerPlanState(node);
00190
00191 if (outerPlan != NULL)
00192 ExecRestrPos(outerPlan);
00193 else
00194 elog(ERROR, "Result nodes do not support mark/restore");
00195 }
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205 ResultState *
00206 ExecInitResult(Result *node, EState *estate, int eflags)
00207 {
00208 ResultState *resstate;
00209
00210
00211 Assert(!(eflags & (EXEC_FLAG_MARK | EXEC_FLAG_BACKWARD)) ||
00212 outerPlan(node) != NULL);
00213
00214
00215
00216
00217 resstate = makeNode(ResultState);
00218 resstate->ps.plan = (Plan *) node;
00219 resstate->ps.state = estate;
00220
00221 resstate->rs_done = false;
00222 resstate->rs_checkqual = (node->resconstantqual == NULL) ? false : true;
00223
00224
00225
00226
00227
00228
00229 ExecAssignExprContext(estate, &resstate->ps);
00230
00231 resstate->ps.ps_TupFromTlist = false;
00232
00233
00234
00235
00236 ExecInitResultTupleSlot(estate, &resstate->ps);
00237
00238
00239
00240
00241 resstate->ps.targetlist = (List *)
00242 ExecInitExpr((Expr *) node->plan.targetlist,
00243 (PlanState *) resstate);
00244 resstate->ps.qual = (List *)
00245 ExecInitExpr((Expr *) node->plan.qual,
00246 (PlanState *) resstate);
00247 resstate->resconstantqual = ExecInitExpr((Expr *) node->resconstantqual,
00248 (PlanState *) resstate);
00249
00250
00251
00252
00253 outerPlanState(resstate) = ExecInitNode(outerPlan(node), estate, eflags);
00254
00255
00256
00257
00258 Assert(innerPlan(node) == NULL);
00259
00260
00261
00262
00263 ExecAssignResultTypeFromTL(&resstate->ps);
00264 ExecAssignProjectionInfo(&resstate->ps, NULL);
00265
00266 return resstate;
00267 }
00268
00269
00270
00271
00272
00273
00274
00275 void
00276 ExecEndResult(ResultState *node)
00277 {
00278
00279
00280
00281 ExecFreeExprContext(&node->ps);
00282
00283
00284
00285
00286 ExecClearTuple(node->ps.ps_ResultTupleSlot);
00287
00288
00289
00290
00291 ExecEndNode(outerPlanState(node));
00292 }
00293
00294 void
00295 ExecReScanResult(ResultState *node)
00296 {
00297 node->rs_done = false;
00298 node->ps.ps_TupFromTlist = false;
00299 node->rs_checkqual = (node->resconstantqual == NULL) ? false : true;
00300
00301
00302
00303
00304
00305 if (node->ps.lefttree &&
00306 node->ps.lefttree->chgParam == NULL)
00307 ExecReScan(node->ps.lefttree);
00308 }