|
14 | 14 | *
|
15 | 15 | *
|
16 | 16 | * IDENTIFICATION
|
17 |
| - * $PostgreSQL: pgsql/src/backend/optimizer/prep/prepunion.c,v 1.109 2004/04/07 18:17:25 tgl Exp $ |
| 17 | + * $PostgreSQL: pgsql/src/backend/optimizer/prep/prepunion.c,v 1.110 2004/05/11 22:43:55 tgl Exp $ |
18 | 18 | *
|
19 | 19 | *-------------------------------------------------------------------------
|
20 | 20 | */
|
@@ -264,8 +264,11 @@ generate_union_plan(SetOperationStmt *op, Query *parse,
|
264 | 264 | List*sortList;
|
265 | 265 |
|
266 | 266 | sortList=addAllTargetsToSortList(NULL,NIL,tlist, false);
|
267 |
| -plan= (Plan*)make_sort_from_sortclauses(parse,sortList,plan); |
268 |
| -plan= (Plan*)make_unique(plan,sortList); |
| 267 | +if (sortList) |
| 268 | +{ |
| 269 | +plan= (Plan*)make_sort_from_sortclauses(parse,sortList,plan); |
| 270 | +plan= (Plan*)make_unique(plan,sortList); |
| 271 | +} |
269 | 272 | *sortClauses=sortList;
|
270 | 273 | }
|
271 | 274 | else
|
@@ -324,6 +327,13 @@ generate_nonunion_plan(SetOperationStmt *op, Query *parse,
|
324 | 327 | * correct output.
|
325 | 328 | */
|
326 | 329 | sortList=addAllTargetsToSortList(NULL,NIL,tlist, false);
|
| 330 | + |
| 331 | +if (sortList==NIL)/* nothing to sort on? */ |
| 332 | +{ |
| 333 | +*sortClauses=NIL; |
| 334 | +returnplan; |
| 335 | +} |
| 336 | + |
327 | 337 | plan= (Plan*)make_sort_from_sortclauses(parse,sortList,plan);
|
328 | 338 | switch (op->op)
|
329 | 339 | {
|
@@ -519,9 +529,9 @@ generate_append_tlist(List *colTypes, bool flag,
|
519 | 529 | * First extract typmods to use.
|
520 | 530 | *
|
521 | 531 | * If the inputs all agree on type and typmod of a particular column, use
|
522 |
| - * that typmod; else use -1. |
| 532 | + * that typmod; else use -1. (+1 here in case of zero columns.) |
523 | 533 | */
|
524 |
| -colTypmods= (int32*)palloc(length(colTypes)*sizeof(int32)); |
| 534 | +colTypmods= (int32*)palloc(length(colTypes)*sizeof(int32)+1); |
525 | 535 |
|
526 | 536 | foreach(planl,input_plans)
|
527 | 537 | {
|
|