Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 93236b5

Browse files
committed
Add defenses against trying to attach qual conditions to a setOperation
query node, since that won't work unless the planner is upgraded. Someday we should try to support at least some cases of this, but for now just plug the hole in the dike. Per discussion with Dmitry Tkach.
1 parent 96be4b2 commit 93236b5

File tree

4 files changed

+64
-7
lines changed

4 files changed

+64
-7
lines changed

src/backend/optimizer/prep/prepunion.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*
1515
*
1616
* IDENTIFICATION
17-
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.97 2003/06/29 23:05:04 tgl Exp $
17+
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.98 2003/07/16 17:25:48 tgl Exp $
1818
*
1919
*-------------------------------------------------------------------------
2020
*/
@@ -85,6 +85,14 @@ plan_set_operations(Query *parse)
8585

8686
Assert(topop && IsA(topop, SetOperationStmt));
8787

88+
/* check for unsupported stuff */
89+
Assert(parse->utilityStmt == NULL);
90+
Assert(parse->jointree->fromlist == NIL);
91+
Assert(parse->jointree->quals == NULL);
92+
Assert(parse->groupClause == NIL);
93+
Assert(parse->havingQual == NULL);
94+
Assert(parse->distinctClause == NIL);
95+
8896
/*
8997
* Find the leftmost component Query. We need to use its column names
9098
* for all generated tlists (else SELECT INTO won't work right).

src/backend/parser/analyze.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.278 2003/07/03 19:07:30 tgl Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.279 2003/07/16 17:25:48 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -1787,6 +1787,15 @@ transformRuleStmt(ParseState *pstate, RuleStmt *stmt,
17871787
*/
17881788
sub_qry = getInsertSelectQuery(top_subqry, NULL);
17891789

1790+
/*
1791+
* If the sub_qry is a setop, we cannot attach any qualifications
1792+
* to it, because the planner won't notice them. This could
1793+
* perhaps be relaxed someday, but for now, we may as well reject
1794+
* such a rule immediately.
1795+
*/
1796+
if (sub_qry->setOperations != NULL && stmt->whereClause != NULL)
1797+
elog(ERROR, "Conditional UNION/INTERSECT/EXCEPT statements are not implemented");
1798+
17901799
/*
17911800
* Validate action's use of OLD/NEW, qual too
17921801
*/
@@ -1841,6 +1850,13 @@ transformRuleStmt(ParseState *pstate, RuleStmt *stmt,
18411850
*/
18421851
if (has_old || (has_new && stmt->event == CMD_UPDATE))
18431852
{
1853+
/*
1854+
* If sub_qry is a setop, manipulating its jointree will do
1855+
* no good at all, because the jointree is dummy. (This
1856+
* should be a can't-happen case because of prior tests.)
1857+
*/
1858+
if (sub_qry->setOperations != NULL)
1859+
elog(ERROR, "Conditional UNION/INTERSECT/EXCEPT statements are not implemented");
18441860
/* hack so we can use addRTEtoQuery() */
18451861
sub_pstate->p_rtable = sub_qry->rtable;
18461862
sub_pstate->p_joinlist = sub_qry->jointree->fromlist;

src/backend/rewrite/rewriteHandler.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteHandler.c,v 1.122 2003/07/03 16:34:25 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteHandler.c,v 1.123 2003/07/16 17:25:48 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -148,18 +148,31 @@ rewriteRuleAction(Query *parsetree,
148148
* As above, the action's jointree must not share substructure with the
149149
* main parsetree's.
150150
*/
151-
if (sub_action->jointree != NULL)
151+
if (sub_action->commandType != CMD_UTILITY)
152152
{
153153
bool keeporig;
154154
List *newjointree;
155155

156+
Assert(sub_action->jointree != NULL);
156157
keeporig = (!rangeTableEntry_used((Node *) sub_action->jointree,
157158
rt_index, 0)) &&
158159
(rangeTableEntry_used(rule_qual, rt_index, 0) ||
159160
rangeTableEntry_used(parsetree->jointree->quals, rt_index, 0));
160161
newjointree = adjustJoinTreeList(parsetree, !keeporig, rt_index);
161-
sub_action->jointree->fromlist =
162-
nconc(newjointree, sub_action->jointree->fromlist);
162+
if (newjointree != NIL)
163+
{
164+
/*
165+
* If sub_action is a setop, manipulating its jointree will do
166+
* no good at all, because the jointree is dummy. (Perhaps
167+
* someday we could push the joining and quals down to the
168+
* member statements of the setop?)
169+
*/
170+
if (sub_action->setOperations != NULL)
171+
elog(ERROR, "Conditional UNION/INTERSECT/EXCEPT statements are not implemented");
172+
173+
sub_action->jointree->fromlist =
174+
nconc(newjointree, sub_action->jointree->fromlist);
175+
}
163176
}
164177

165178
/*

src/backend/rewrite/rewriteManip.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteManip.c,v 1.72 2003/06/06 15:04:02 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteManip.c,v 1.73 2003/07/16 17:25:48 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -733,6 +733,16 @@ AddQual(Query *parsetree, Node *qual)
733733
elog(ERROR, "Conditional utility statements are not implemented");
734734
}
735735

736+
if (parsetree->setOperations != NULL)
737+
{
738+
/*
739+
* There's noplace to put the qual on a setop statement, either.
740+
* (This could be fixed, but right now the planner simply ignores
741+
* any qual condition on a setop query.)
742+
*/
743+
elog(ERROR, "Conditional UNION/INTERSECT/EXCEPT statements are not implemented");
744+
}
745+
736746
/* INTERSECT want's the original, but we need to copy - Jan */
737747
copy = copyObject(qual);
738748

@@ -773,6 +783,16 @@ AddHavingQual(Query *parsetree, Node *havingQual)
773783
elog(ERROR, "Conditional utility statements are not implemented");
774784
}
775785

786+
if (parsetree->setOperations != NULL)
787+
{
788+
/*
789+
* There's noplace to put the qual on a setop statement, either.
790+
* (This could be fixed, but right now the planner simply ignores
791+
* any qual condition on a setop query.)
792+
*/
793+
elog(ERROR, "Conditional UNION/INTERSECT/EXCEPT statements are not implemented");
794+
}
795+
776796
/* INTERSECT want's the original, but we need to copy - Jan */
777797
copy = copyObject(havingQual);
778798

0 commit comments

Comments
 (0)