*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.25 1997/12/23 21:49:03 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.26 1997/12/24 06:05:52 momjian Exp $
*
*-------------------------------------------------------------------------
*/
}
else
newnode->qry_aggs = NULL;
-
+
+ if (from->unionClause)
+ {
+ List *ulist, *temp_list = NIL;
+
+ foreach(ulist, from->unionClause)
+ temp_list = lappend(temp_list,copyObject(lfirst(ulist)));
+ newnode->unionClause = temp_list;
+ }
+ else
+ newnode->unionClause = NULL;
+
return newnode;
}
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
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,
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
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);
/* 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));
}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.55 1997/12/23 19:39:42 thomas Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.56 1997/12/24 06:06:18 momjian Exp $
*
*-------------------------------------------------------------------------
*/
/* fix where clause */
qry->qual = transformWhereClause(pstate, stmt->whereClause);
- /* check subselect clause */
- if (stmt->unionClause)
- {
- elog(NOTICE, "UNION not yet supported; using first SELECT only", NULL);
-
- /* XXX HACK just playing with union clause - thomas 1997-12-19 */
- if ((qry->uniqueFlag == NULL)
- && (! ((SubSelect *)lfirst(stmt->unionClause))->unionall))
- qry->uniqueFlag = "*";
- }
-
- /* check subselect clause */
+ /* check having clause */
if (stmt->havingClause)
elog(NOTICE, "HAVING not yet supported; ignore clause", NULL);
qry->targetList,
qry->uniqueFlag);
- /* fix group by clause */
qry->groupClause = transformGroupClause(pstate,
stmt->groupClause,
qry->targetList);
if (pstate->p_numAgg > 0)
finalizeAggregates(pstate, qry);
+ if (stmt->unionClause)
+ {
+ List *ulist = NIL;
+ QueryTreeList *qlist;
+ int i;
+
+ qlist = parse_analyze(stmt->unionClause);
+ for (i=0; i < qlist->len; i++)
+ ulist = lappend(ulist, qlist->qtrees[i]);
+ qry->unionClause = ulist;
+ }
+ else
+ qry->unionClause = NULL;
+
return (Query *) qry;
}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 1.80 1997/12/23 19:47:32 thomas Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 1.81 1997/12/24 06:06:26 momjian Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
ProcedureStmt, RecipeStmt, RemoveAggrStmt, RemoveOperStmt,
RemoveFuncStmt, RemoveStmt,
RenameStmt, RevokeStmt, RuleStmt, TransactionStmt, ViewStmt, LoadStmt,
- CreatedbStmt, DestroydbStmt, VacuumStmt, RetrieveStmt, CursorStmt,
- ReplaceStmt, AppendStmt, NotifyStmt, DeleteStmt, ClusterStmt,
+ CreatedbStmt, DestroydbStmt, VacuumStmt, CursorStmt, SubSelect,
+ ReplaceStmt, AppendStmt, RetrieveStmt, NotifyStmt, DeleteStmt, ClusterStmt,
ExplainStmt, VariableSetStmt, VariableShowStmt, VariableResetStmt,
CreateUserStmt, AlterUserStmt, DropUserStmt
+%type
+
%type opt_database, location
%type
user_createdb_clause, user_createuser_clause
%type user_valid_clause
%type user_group_list, user_group_clause
-%type SubSelect
%type join_expr, join_outer, join_spec
%type TriggerActionTime, TriggerForSpec, PLangTrusted
CreateAsStmt: CREATE TABLE relation_name OptCreateAs AS SubSelect
{
- RetrieveStmt *n = makeNode(RetrieveStmt);
- SubSelect *s = (SubSelect *)$6;
- n->unique = s->unique;
- n->targetList = s->targetList;
+ RetrieveStmt *n = (RetrieveStmt *)$6;
if ($4 != NIL)
mapTargetColumns($4, n->targetList);
n->into = $3;
- n->fromClause = s->fromClause;
- n->whereClause = s->whereClause;
- n->groupClause = s->groupClause;
- n->havingClause = s->havingClause;
- n->unionClause = NULL;
- n->sortClause = NULL;
$$ = (Node *)n;
}
;
union_clause: UNION opt_union select_list
{
- SubSelect *n = lfirst($3);
+ RetrieveStmt *n = (RetrieveStmt *)lfirst($3);
n->unionall = $2;
$$ = $3;
}
select_list: select_list UNION opt_union SubSelect
{
- SubSelect *n = (SubSelect *)$4;
+ RetrieveStmt *n = (RetrieveStmt *)$4;
n->unionall = $3;
$$ = lappend($1, $4);
}
from_clause where_clause
group_clause having_clause
{
- SubSelect *n = makeNode(SubSelect);
+ RetrieveStmt *n = makeNode(RetrieveStmt);
n->unique = $2;
n->unionall = FALSE;
n->targetList = $3;
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: parsenodes.h,v 1.38 1997/12/23 19:58:12 thomas Exp $
+ * $Id: parsenodes.h,v 1.39 1997/12/24 06:06:53 momjian Exp $
*
*-------------------------------------------------------------------------
*/
int qry_numAgg; /* number of aggregates in the target list */
Aggreg **qry_aggs; /* the aggregates */
+ List *unionClause; /* unions are linked under the previous query */
+
/* internal to planner */
List *base_relation_list_; /* base relation list */
List *join_relation_list_; /* list of relations */
Node *havingClause; /* having conditional-expression */
List *unionClause; /* union subselect parameters */
List *sortClause; /* sort clause (a list of SortGroupBy's) */
+ int unionall; /* union without unique sort */
} RetrieveStmt;
* Supporting data structures for Parse Trees
****************************************************************************/
-/*
- * SubSelect - specifies subselect parameters
- */
-typedef struct SubSelect
-{
- NodeTag type;
- char *unique; /* NULL, '*', or unique attribute name */
- int unionall; /* union without unique sort */
- List *targetList; /* the target list (of ResTarget) */
- List *fromClause; /* the from clause */
- Node *whereClause; /* qualifications */
- List *groupClause; /* group by clause */
- Node *havingClause; /* having conditional-expression */
-} SubSelect;
-
/*
* TypeName - specifies a type in definitions
*/
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: prep.h,v 1.9 1997/12/20 07:59:44 momjian Exp $
+ * $Id: prep.h,v 1.10 1997/12/24 06:06:58 momjian Exp $
*
*-------------------------------------------------------------------------
*/
*/
typedef enum UnionFlag
{
- INHERITS_FLAG, VERSION_FLAG
+ INHERITS_FLAG, UNION_FLAG, VERSION_FLAG
} UnionFlag;
extern List *find_all_inheritors(List *unexamined_relids,