Skip to content

Commit 31a697b

Browse files
committed
Yohoo UNIONS of VIEWS.
1 parent 8f12541 commit 31a697b

File tree

3 files changed

+38
-17
lines changed

3 files changed

+38
-17
lines changed

src/backend/nodes/copyfuncs.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.27 1998/01/04 04:31:02 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.28 1998/01/09 05:48:10 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -1520,6 +1520,16 @@ _copyQuery(Query *from)
15201520
int i;
15211521

15221522
newnode->commandType = from->commandType;
1523+
if (from->utilityStmt && nodeTag(from->utilityStmt) == T_NotifyStmt)
1524+
{
1525+
NotifyStmt *from_notify = (NotifyStmt *) from->utilityStmt;
1526+
NotifyStmt *n = makeNode(NotifyStmt);
1527+
int length = strlen(from_notify->relname);
1528+
1529+
n->relname = palloc(length + 1);
1530+
strcpy(n->relname, from_notify->relname);
1531+
newnode->utilityStmt = (Node *) n;
1532+
}
15231533
newnode->resultRelation = from->resultRelation;
15241534
/* probably should dup this string instead of just pointing */
15251535
/* to the old one --djm */
@@ -1532,17 +1542,8 @@ _copyQuery(Query *from)
15321542
newnode->into = (char *) 0;
15331543
}
15341544
newnode->isPortal = from->isPortal;
1535-
Node_Copy(from, newnode, rtable);
1536-
if (from->utilityStmt && nodeTag(from->utilityStmt) == T_NotifyStmt)
1537-
{
1538-
NotifyStmt *from_notify = (NotifyStmt *) from->utilityStmt;
1539-
NotifyStmt *n = makeNode(NotifyStmt);
1540-
int length = strlen(from_notify->relname);
1541-
1542-
n->relname = palloc(length + 1);
1543-
strcpy(n->relname, from_notify->relname);
1544-
newnode->utilityStmt = (Node *) n;
1545-
}
1545+
newnode->isBinary = from->isBinary;
1546+
newnode->unionall = from->unionall;
15461547
if (from->uniqueFlag)
15471548
{
15481549
newnode->uniqueFlag = (char *) palloc(strlen(from->uniqueFlag) + 1);
@@ -1551,6 +1552,7 @@ _copyQuery(Query *from)
15511552
else
15521553
newnode->uniqueFlag = NULL;
15531554
Node_Copy(from, newnode, sortClause);
1555+
Node_Copy(from, newnode, rtable);
15541556
Node_Copy(from, newnode, targetList);
15551557
Node_Copy(from, newnode, qual);
15561558

src/backend/rewrite/rewriteHandler.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
*
88
* IDENTIFICATION
9-
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteHandler.c,v 1.9 1998/01/07 21:04:37 momjian Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteHandler.c,v 1.10 1998/01/09 05:48:17 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -598,8 +598,12 @@ RewriteQuery(Query *parsetree, bool *instead_flag, List **qual_products)
598598
*/
599599
Query *other;
600600

601-
other = copyObject(parsetree); /* ApplyRetrieveRule changes the
602-
* range table */
601+
/*
602+
* ApplyRetrieveRule changes the range table
603+
* XXX Unions are copied again.
604+
*/
605+
other = copyObject(parsetree);
606+
603607
return
604608
ProcessRetrieveQuery(other, parsetree->rtable,
605609
instead_flag, FALSE);

src/backend/tcop/postgres.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.59 1998/01/07 21:06:00 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.60 1998/01/09 05:48:22 momjian Exp $
1111
*
1212
* NOTES
1313
* this is the "main" module of the postgres backend and
@@ -439,6 +439,8 @@ pg_parse_and_plan(char *query_string, /* string to execute */
439439
* rewrites */
440440
for (i = 0; i < querytree_list->len; i++)
441441
{
442+
List *union_result, *union_list, *rewritten_list;
443+
442444
querytree = querytree_list->qtrees[i];
443445

444446

@@ -465,6 +467,19 @@ pg_parse_and_plan(char *query_string, /* string to execute */
465467

466468
/* rewrite queries (retrieve, append, delete, replace) */
467469
rewritten = QueryRewrite(querytree);
470+
471+
/*
472+
* Rewrite the UNIONS.
473+
*/
474+
foreach(rewritten_list, rewritten)
475+
{
476+
Query *qry = (Query *)lfirst(rewritten_list);
477+
union_result = NIL;
478+
foreach(union_list, qry->unionClause)
479+
union_result = nconc(union_result, QueryRewrite((Query *)lfirst(union_list)));
480+
qry->unionClause = union_result;
481+
}
482+
468483
if (rewritten != NULL)
469484
{
470485
int len,
@@ -1372,7 +1387,7 @@ PostgresMain(int argc, char *argv[])
13721387
if (IsUnderPostmaster == false)
13731388
{
13741389
puts("\nPOSTGRES backend interactive interface");
1375-
puts("$Revision: 1.59 $ $Date: 1998/01/07 21:06:00 $");
1390+
puts("$Revision: 1.60 $ $Date: 1998/01/09 05:48:22 $");
13761391
}
13771392

13781393
/* ----------------

0 commit comments

Comments
 (0)