|
14 | 14 | *
|
15 | 15 | *
|
16 | 16 | * IDENTIFICATION
|
17 |
| - * $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.65 2001/06/05 05:26:04 tgl Exp $ |
| 17 | + * $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.66 2001/08/14 17:12:57 tgl Exp $ |
18 | 18 | *
|
19 | 19 | *-------------------------------------------------------------------------
|
20 | 20 | */
|
@@ -275,12 +275,14 @@ generate_nonunion_plan(SetOperationStmt *op, Query *parse,
|
275 | 275 | *
|
276 | 276 | * The tlist for an Append plan isn't important as far as the Append is
|
277 | 277 | * concerned, but we must make it look real anyway for the benefit of
|
278 |
| - * the next plan level up. |
| 278 | + * the next plan level up. In fact, it has to be real enough that the |
| 279 | + * flag column is shown as a variable not a constant, else setrefs.c |
| 280 | + * will get confused. |
279 | 281 | */
|
280 | 282 | plan= (Plan*)
|
281 | 283 | make_append(makeList2(lplan,rplan),
|
282 | 284 | false,
|
283 |
| -generate_setop_tlist(op->colTypes,0, false, |
| 285 | +generate_setop_tlist(op->colTypes,2, false, |
284 | 286 | lplan->targetlist,
|
285 | 287 | refnames_tlist));
|
286 | 288 |
|
@@ -353,6 +355,13 @@ recurse_union_children(Node *setOp, Query *parse,
|
353 | 355 |
|
354 | 356 | /*
|
355 | 357 | * Generate targetlist for a set-operation plan node
|
| 358 | + * |
| 359 | + * colTypes: column datatypes for non-junk columns |
| 360 | + * flag: -1 if no flag column needed, 0 or 1 to create a const flag column, |
| 361 | + * 2 to create a variable flag column |
| 362 | + * hack_constants: true to copy up constants (see comments in code) |
| 363 | + * input_tlist: targetlist of this node's input node |
| 364 | + * refnames_tlist: targetlist to take column names from |
356 | 365 | */
|
357 | 366 | staticList*
|
358 | 367 | generate_setop_tlist(List*colTypes,intflag,
|
@@ -414,19 +423,32 @@ generate_setop_tlist(List *colTypes, int flag,
|
414 | 423 |
|
415 | 424 | if (flag >=0)
|
416 | 425 | {
|
417 |
| -/* Add a resjunkcolumn yielding specifiedflagvalue */ |
| 426 | +/* Add a resjunk flagcolumn */ |
418 | 427 | resdom=makeResdom((AttrNumber)resno++,
|
419 | 428 | INT4OID,
|
420 | 429 | -1,
|
421 | 430 | pstrdup("flag"),
|
422 | 431 | true);
|
423 |
| -expr= (Node*)makeConst(INT4OID, |
424 |
| -sizeof(int4), |
425 |
| -Int32GetDatum(flag), |
426 |
| - false, |
427 |
| - true, |
428 |
| - false, |
429 |
| - false); |
| 432 | +if (flag <=1) |
| 433 | +{ |
| 434 | +/* flag value is the given constant */ |
| 435 | +expr= (Node*)makeConst(INT4OID, |
| 436 | +sizeof(int4), |
| 437 | +Int32GetDatum(flag), |
| 438 | + false, |
| 439 | + true, |
| 440 | + false, |
| 441 | + false); |
| 442 | +} |
| 443 | +else |
| 444 | +{ |
| 445 | +/* flag value is being copied up from subplan */ |
| 446 | +expr= (Node*)makeVar(0, |
| 447 | +resdom->resno, |
| 448 | +INT4OID, |
| 449 | +-1, |
| 450 | +0); |
| 451 | +} |
430 | 452 | tlist=lappend(tlist,makeTargetEntry(resdom,expr));
|
431 | 453 | }
|
432 | 454 |
|
|