1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

When testing whether a sub-plan can do projection, use a general-purpose

check instead of hardwiring assumptions that only certain plan node types
can appear at the places where we are testing.  This was always a pretty
fragile assumption, and it turns out to be broken in 7.4 for certain cases
involving IN-subselect tests that need type coercion.
Also, modify code that builds finished Plan tree so that node types that
don't do projection always copy their input node's targetlist, rather than
having the tlist passed in from the caller.  The old method makes it too
easy to write broken code that thinks it can modify the tlist when it
cannot.
This commit is contained in:
Tom Lane
2004-01-18 00:50:03 +00:00
parent de816a03c4
commit 6bdfde9a77
4 changed files with 81 additions and 91 deletions

View File

@ -14,7 +14,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/prep/prepunion.c,v 1.107 2004/01/04 03:51:52 tgl Exp $
* $PostgreSQL: pgsql/src/backend/optimizer/prep/prepunion.c,v 1.108 2004/01/18 00:50:02 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -246,11 +246,9 @@ generate_union_plan(SetOperationStmt *op, Query *parse,
{
List *sortList;
tlist = copyObject(tlist);
sortList = addAllTargetsToSortList(NULL, NIL, tlist, false);
plan = (Plan *) make_sort_from_sortclauses(parse, tlist,
plan, sortList);
plan = (Plan *) make_unique(tlist, plan, sortList);
plan = (Plan *) make_sort_from_sortclauses(parse, sortList, plan);
plan = (Plan *) make_unique(plan, sortList);
}
return plan;
}
@ -300,9 +298,8 @@ generate_nonunion_plan(SetOperationStmt *op, Query *parse,
* Sort the child results, then add a SetOp plan node to generate the
* correct output.
*/
tlist = copyObject(tlist);
sortList = addAllTargetsToSortList(NULL, NIL, tlist, false);
plan = (Plan *) make_sort_from_sortclauses(parse, tlist, plan, sortList);
plan = (Plan *) make_sort_from_sortclauses(parse, sortList, plan);
switch (op->op)
{
case SETOP_INTERSECT:
@ -317,8 +314,7 @@ generate_nonunion_plan(SetOperationStmt *op, Query *parse,
cmd = SETOPCMD_INTERSECT; /* keep compiler quiet */
break;
}
plan = (Plan *) make_setop(cmd, tlist, plan, sortList,
length(op->colTypes) + 1);
plan = (Plan *) make_setop(cmd, plan, sortList, length(op->colTypes) + 1);
return plan;
}