|
8 | 8 | * |
9 | 9 | * |
10 | 10 | * IDENTIFICATION |
11 | | - * $PostgreSQL: pgsql/src/backend/executor/nodeAppend.c,v 1.63 2005/04/24 11:46:20 neilc Exp $ |
| 11 | + * $PostgreSQL: pgsql/src/backend/executor/nodeAppend.c,v 1.64 2005/05/22 22:30:19 tgl Exp $ |
12 | 12 | * |
13 | 13 | *------------------------------------------------------------------------- |
14 | 14 | */ |
@@ -251,67 +251,52 @@ ExecCountSlotsAppend(Append *node) |
251 | 251 | /* ---------------------------------------------------------------- |
252 | 252 | * ExecAppend |
253 | 253 | * |
254 | | - * Handles the iteration over the multiple scans. |
| 254 | + * Handles iteration over multiple subplans. |
255 | 255 | * ---------------------------------------------------------------- |
256 | 256 | */ |
257 | 257 | TupleTableSlot * |
258 | 258 | ExecAppend(AppendState *node) |
259 | 259 | { |
260 | | - EState *estate; |
261 | | - int whichplan; |
262 | | - PlanState *subnode; |
263 | | - TupleTableSlot *result; |
264 | | - TupleTableSlot *result_slot; |
265 | | - ScanDirection direction; |
266 | | - |
267 | | - /* |
268 | | - * get information from the node |
269 | | - */ |
270 | | - estate = node->ps.state; |
271 | | - direction = estate->es_direction; |
272 | | - whichplan = node->as_whichplan; |
273 | | - result_slot = node->ps.ps_ResultTupleSlot; |
274 | | - |
275 | | - /* |
276 | | - * figure out which subplan we are currently processing |
277 | | - */ |
278 | | - subnode = node->appendplans[whichplan]; |
279 | | - |
280 | | - /* |
281 | | - * get a tuple from the subplan |
282 | | - */ |
283 | | - result = ExecProcNode(subnode); |
284 | | - |
285 | | - if (!TupIsNull(result)) |
| 260 | + for (;;) |
286 | 261 | { |
| 262 | + PlanState *subnode; |
| 263 | + TupleTableSlot *result; |
| 264 | + |
287 | 265 | /* |
288 | | - * if the subplan gave us something then return it as-is. We do |
289 | | - * NOT make use of the result slot that was set up in ExecInitAppend, |
290 | | - * first because there's no reason to and second because it may have |
291 | | - * the wrong tuple descriptor in inherited-UPDATE cases. |
| 266 | + * figure out which subplan we are currently processing |
292 | 267 | */ |
293 | | - return result; |
294 | | - } |
295 | | - else |
296 | | - { |
| 268 | + subnode = node->appendplans[node->as_whichplan]; |
| 269 | + |
297 | 270 | /* |
298 | | - * .. go on to the "next" subplan in the appropriate direction and |
299 | | - * try processing again (recursively) |
| 271 | + * get a tuple from the subplan |
300 | 272 | */ |
301 | | - if (ScanDirectionIsForward(direction)) |
302 | | - node->as_whichplan++; |
303 | | - else |
304 | | - node->as_whichplan--; |
| 273 | + result = ExecProcNode(subnode); |
| 274 | + |
| 275 | + if (!TupIsNull(result)) |
| 276 | + { |
| 277 | + /* |
| 278 | + * If the subplan gave us something then return it as-is. |
| 279 | + * We do NOT make use of the result slot that was set up in |
| 280 | + * ExecInitAppend, first because there's no reason to and |
| 281 | + * second because it may have the wrong tuple descriptor in |
| 282 | + * inherited-UPDATE cases. |
| 283 | + */ |
| 284 | + return result; |
| 285 | + } |
305 | 286 |
|
306 | 287 | /* |
307 | | - * return something from next node or an empty slot if all of our |
308 | | - * subplans have been exhausted. The empty slot is the one set up |
| 288 | + * Go on to the "next" subplan in the appropriate direction. |
| 289 | + * If no more subplans, return the empty slot set up for us |
309 | 290 | * by ExecInitAppend. |
310 | 291 | */ |
311 | | - if (exec_append_initialize_next(node)) |
312 | | - return ExecAppend(node); |
| 292 | + if (ScanDirectionIsForward(node->ps.state->es_direction)) |
| 293 | + node->as_whichplan++; |
313 | 294 | else |
314 | | - return ExecClearTuple(result_slot); |
| 295 | + node->as_whichplan--; |
| 296 | + if (!exec_append_initialize_next(node)) |
| 297 | + return ExecClearTuple(node->ps.ps_ResultTupleSlot); |
| 298 | + |
| 299 | + /* Else loop back and try to get a tuple from the new subplan */ |
315 | 300 | } |
316 | 301 | } |
317 | 302 |
|
|
0 commit comments