1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-25 01:02:05 +03:00

Implementation of UNIONs.

This commit is contained in:
Bruce Momjian
1997-12-24 06:06:58 +00:00
parent 18adbd9aed
commit 6231e161c9
7 changed files with 95 additions and 91 deletions

View File

@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.15 1997/12/22 05:42:08 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.16 1997/12/24 06:06:01 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -81,11 +81,19 @@ planner(Query *parse)
int rt_index;
/*
* plan inheritance
*/
rt_index = first_matching_rt_entry(rangetable, INHERITS_FLAG);
if (rt_index != -1)
if (parse->unionClause)
{
result_plan = (Plan *) plan_union_queries(0, /* none */
parse,
UNION_FLAG);
/* XXX do we need to do this? bjm 12/19/97 */
tlist = preprocess_targetlist(tlist,
parse->commandType,
parse->resultRelation,
parse->rtable);
}
else if ((rt_index =
first_matching_rt_entry(rangetable, INHERITS_FLAG)) != -1)
{
result_plan = (Plan *) plan_union_queries((Index) rt_index,
parse,

View File

@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.12 1997/12/21 05:18:28 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.13 1997/12/24 06:06:07 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -149,20 +149,51 @@ plan_union_queries(Index rt_index,
find_all_inheritors(lconsi(rt_entry->relid,
NIL),
NIL);
/*
* Remove the flag for this relation, since we're about to handle it
* (do it before recursing!). XXX destructive parse tree change
*/
switch (flag)
{
case INHERITS_FLAG:
rt_fetch(rt_index, rangetable)->inh = false;
break;
default:
break;
}
/*
* XXX - can't find any reason to sort union-relids as paul did, so
* we're leaving it out for now (maybe forever) - jeff & lp
*
* [maybe so. btw, jeff & lp did the lisp conversion, according to Paul.
* -- ay 10/94.]
*/
union_plans = plan_union_query(union_relids, rt_index, rt_entry,
parse, flag, &union_rt_entries);
return (make_append(union_plans,
rt_index,
union_rt_entries,
((Plan *) lfirst(union_plans))->targetlist));
break;
#if 0
case UNION_FLAG:
{
Index rt_index = 0;
List *ulist, *hold_union, *union_plans;
union_plans = handleunion(root, rangetable, tlist, qual);
hold_union = parse->unionClause;
parse->unionClause = NULL; /* prevent looping */
union_plans = lcons(planner(parse), NIL);
foreach(ulist, hold_union)
union_plans = lappend(union_plans, planner(lfirst(ulist)));
return (make_append(union_plans,
rt_index, rangetable,
((Plan *) lfirst(union_plans))->targetlist));
}
break;
#endif
case VERSION_FLAG:
union_relids = VersionGetParents(rt_entry->relid);
@ -172,34 +203,6 @@ plan_union_queries(Index rt_index,
/* do nothing */
break;
}
/*
* Remove the flag for this relation, since we're about to handle it
* (do it before recursing!). XXX destructive parse tree change
*/
switch (flag)
{
case INHERITS_FLAG:
rt_fetch(rt_index, rangetable)->inh = false;
break;
default:
break;
}
/*
* XXX - can't find any reason to sort union-relids as paul did, so
* we're leaving it out for now (maybe forever) - jeff & lp
*
* [maybe so. btw, jeff & lp did the lisp conversion, according to Paul.
* -- ay 10/94.]
*/
union_plans = plan_union_query(union_relids, rt_index, rt_entry,
parse, flag, &union_rt_entries);
return (make_append(union_plans,
rt_index,
union_rt_entries,
((Plan *) lfirst(union_plans))->targetlist));
}