Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite439fef

Browse files
committed
Fix subquery pullup logic to not be fooled when a view that appears
'simple' references another view that is not simple. Must recheckconditions after performing recursive pullup. Per example fromLaurent Perez, 9-Jan-04.
1 parent6bd3433 commite439fef

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

‎src/backend/optimizer/prep/prepjointree.c

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
*
1818
* IDENTIFICATION
19-
* $PostgreSQL: pgsql/src/backend/optimizer/prep/prepjointree.c,v 1.14 2003/11/29 19:51:51 pgsql Exp $
19+
* $PostgreSQL: pgsql/src/backend/optimizer/prep/prepjointree.c,v 1.15 2004/01/10 00:30:21 tgl Exp $
2020
*
2121
*-------------------------------------------------------------------------
2222
*/
@@ -168,10 +168,11 @@ pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join)
168168
List*rt;
169169

170170
/*
171-
* First make a modifiable copy of the subquery. This avoids
172-
* problems if the same subquery is referenced from multiple
173-
* jointree items (which can't happen normally, but might after
174-
* rule rewriting).
171+
* Need a modifiable copy of the subquery to hack on. Even if
172+
* we didn't sometimes choose not to pull up below, we must do
173+
* this to avoid problems if the same subquery is referenced from
174+
* multiple jointree items (which can't happen normally, but might
175+
* after rule rewriting).
175176
*/
176177
subquery=copyObject(subquery);
177178

@@ -196,6 +197,33 @@ pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join)
196197
pull_up_subqueries(subquery, (Node*)subquery->jointree,
197198
false);
198199

200+
/*
201+
* Now we must recheck whether the subquery is still simple
202+
* enough to pull up. If not, abandon processing it.
203+
*
204+
* We don't really need to recheck all the conditions involved,
205+
* but it's easier just to keep this "if" looking the same as
206+
* the one above.
207+
*/
208+
if (is_simple_subquery(subquery)&&
209+
(!below_outer_join||has_nullable_targetlist(subquery))&&
210+
!contain_whole_tuple_var((Node*)parse,varno,0))
211+
{
212+
/* good to go */
213+
}
214+
else
215+
{
216+
/*
217+
* Give up, return unmodified RangeTblRef.
218+
*
219+
* Note: The work we just did will be redone when the
220+
* subquery gets planned on its own. Perhaps we could avoid
221+
* that by storing the modified subquery back into the
222+
* rangetable, but I'm not gonna risk it now.
223+
*/
224+
returnjtnode;
225+
}
226+
199227
/*
200228
* Adjust level-0 varnos in subquery so that we can append its
201229
* rangetable to upper query's.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp