diff options
| author | Bruce Momjian | 1998-03-31 04:44:35 +0000 |
|---|---|---|
| committer | Bruce Momjian | 1998-03-31 04:44:35 +0000 |
| commit | d7050cb68cf996dd3c7ffc9bc5984c9b53ed9f77 (patch) | |
| tree | 9ff0e0ea3229eb36d27f287ca59415c542427565 /src/backend | |
| parent | 62943bb76fdb8e2283e2d01e2c81963578a50f62 (diff) | |
Merge rename name page into alter table. Fix UNION with DISTINCT
or ORDER BY bug.
Diffstat (limited to 'src/backend')
| -rw-r--r-- | src/backend/optimizer/prep/prepunion.c | 37 | ||||
| -rw-r--r-- | src/backend/parser/parse_clause.c | 10 |
2 files changed, 31 insertions, 16 deletions
diff --git a/src/backend/optimizer/prep/prepunion.c b/src/backend/optimizer/prep/prepunion.c index e821f20a963..e1c620956a4 100644 --- a/src/backend/optimizer/prep/prepunion.c +++ b/src/backend/optimizer/prep/prepunion.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.21 1998/03/30 19:04:41 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.22 1998/03/31 04:43:49 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -64,12 +64,13 @@ plan_union_queries(Query *parse) { List *union_plans = NIL, *ulist, - *unionall_queries, + *union_all_queries, *union_rts, - *last_union = NIL; + *last_union = NIL, + *hold_sortClause = parse->sortClause; bool union_all_found = false, union_found = false, - last_unionall_flag = false; + last_union_all_flag = false; /*------------------------------------------------------------------ * @@ -120,17 +121,25 @@ plan_union_queries(Query *parse) union_found = true; last_union = ulist; } - last_unionall_flag = union_query->unionall; + last_union_all_flag = union_query->unionall; } /* Is this a simple one */ if (!union_all_found || !union_found || /* A trailing UNION negates the affect of earlier UNION ALLs */ - !last_unionall_flag) + !last_union_all_flag) { List *hold_unionClause = parse->unionClause; + /* we will do this later, so don't do it now */ + if (!union_all_found || + !last_union_all_flag) + { + parse->sortClause = NIL; + parse->uniqueFlag = NULL; + } + parse->unionClause = NIL; /* prevent recursion */ union_plans = lcons(union_planner(parse), NIL); union_rts = lcons(parse->rtable, NIL); @@ -154,7 +163,7 @@ plan_union_queries(Query *parse) */ /* save off everthing past the last UNION */ - unionall_queries = lnext(last_union); + union_all_queries = lnext(last_union); /* clip off the list to remove the trailing UNION ALLs */ lnext(last_union) = NIL; @@ -167,21 +176,21 @@ plan_union_queries(Query *parse) union_rts = lcons(parse->rtable, NIL); /* Append the remainging UNION ALLs */ - foreach(ulist, unionall_queries) + foreach(ulist, union_all_queries) { - Query *unionall_query = lfirst(ulist); + Query *union_all_query = lfirst(ulist); - union_plans = lappend(union_plans, union_planner(unionall_query)); - union_rts = lappend(union_rts, unionall_query->rtable); + union_plans = lappend(union_plans, union_planner(union_all_query)); + union_rts = lappend(union_rts, union_all_query->rtable); } } /* We have already split UNION and UNION ALL and we made it consistent */ - if (!last_unionall_flag) + if (!last_union_all_flag) { parse->uniqueFlag = "*"; parse->sortClause = transformSortClause(NULL, NIL, - parse->sortClause, + hold_sortClause, parse->targetList, "*"); } else @@ -195,7 +204,7 @@ plan_union_queries(Query *parse) union_rts, 0, NULL, - ((Plan *) lfirst(union_plans))->targetlist)); + parse->targetList)); } diff --git a/src/backend/parser/parse_clause.c b/src/backend/parser/parse_clause.c index 9bd664c4ee3..30be8335351 100644 --- a/src/backend/parser/parse_clause.c +++ b/src/backend/parser/parse_clause.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/parser/parse_clause.c,v 1.14 1998/03/18 15:47:51 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/parser/parse_clause.c,v 1.15 1998/03/31 04:43:53 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -313,7 +313,13 @@ transformSortClause(ParseState *pstate, { SortClause *sortcl = lfirst(s); - if (sortcl->resdom == tlelt->resdom) + /* + * We use equal() here because we are called for UNION + * from the optimizer, and at that point, the sort clause + * resdom pointers don't match the target list resdom + * pointers + */ + if (equal(sortcl->resdom, tlelt->resdom)) break; s = lnext(s); } |
