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

Commiteda80f0

Browse files
committed
Repair interaction between IN-join processing and subselect pullup that
I inadvertently broke a few days ago (per report from Sean Thomas).Add regression test case to try to catch any similar breakage in future.
1 parentc02036b commiteda80f0

File tree

3 files changed

+63
-6
lines changed

3 files changed

+63
-6
lines changed

‎src/backend/optimizer/plan/subselect.c

Lines changed: 9 additions & 6 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/optimizer/plan/subselect.c,v 1.82 2003/08/08 21:41:51 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/subselect.c,v 1.83 2003/10/18 16:52:15 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -493,8 +493,8 @@ make_subplan(SubLink *slink, List *lefthand, bool isTopQual)
493493
* If rtindex is 0, we build Params to represent the sub-select outputs.
494494
* The paramids of the Params created are returned in the *righthandIds list.
495495
*
496-
* If rtindex is not 0, we build Vars using that rtindex as varno.The
497-
*Vars themselves are returned in *righthandIds (this is a bit of a type
496+
* If rtindex is not 0, we build Vars using that rtindex as varno.Copies
497+
*of the Var nodes are returned in *righthandIds (this is a bit of a type
498498
* cheat, but we can get away with it).
499499
*/
500500
staticList*
@@ -525,8 +525,11 @@ convert_sublink_opers(List *lefthand, List *operOids,
525525
te->resdom->restype,
526526
te->resdom->restypmod,
527527
0);
528-
/* Record it for caller */
529-
*righthandIds=lappend(*righthandIds,rightop);
528+
/*
529+
* Copy it for caller. NB: we need a copy to avoid having
530+
* doubly-linked substructure in the modified parse tree.
531+
*/
532+
*righthandIds=lappend(*righthandIds,copyObject(rightop));
530533
}
531534
else
532535
{
@@ -735,7 +738,7 @@ convert_IN_to_join(Query *parse, SubLink *sublink)
735738

736739
/*
737740
* Build the result qual expressions. As a side effect,
738-
* ininfo->sub_targetlist is filled with a list oftheVars
741+
* ininfo->sub_targetlist is filled with a list of Vars
739742
* representing the subselect outputs.
740743
*/
741744
exprs=convert_sublink_opers(sublink->lefthand,

‎src/test/regress/expected/subselect.out

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,39 @@ from int8_tbl group by q1 order by q1;
165165
4567890123456789 | 0.6
166166
(2 rows)
167167

168+
--
169+
-- Test cases to catch unpleasant interactions between IN-join processing
170+
-- and subquery pullup.
171+
--
172+
select count(*) from
173+
(select 1 from tenk1 a
174+
where unique1 IN (select hundred from tenk1 b)) ss;
175+
count
176+
-------
177+
100
178+
(1 row)
179+
180+
select count(distinct ss.ten) from
181+
(select ten from tenk1 a
182+
where unique1 IN (select hundred from tenk1 b)) ss;
183+
count
184+
-------
185+
10
186+
(1 row)
187+
188+
select count(*) from
189+
(select 1 from tenk1 a
190+
where unique1 IN (select distinct hundred from tenk1 b)) ss;
191+
count
192+
-------
193+
100
194+
(1 row)
195+
196+
select count(distinct ss.ten) from
197+
(select ten from tenk1 a
198+
where unique1 IN (select distinct hundred from tenk1 b)) ss;
199+
count
200+
-------
201+
10
202+
(1 row)
203+

‎src/test/regress/sql/subselect.sql

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,21 @@ SELECT '' AS eight, ss.f1 AS "Correlated Field", ss.f3 AS "Second Field"
7575

7676
select q1, float8(count(*))/ (selectcount(*)from int8_tbl)
7777
from int8_tblgroup by q1order by q1;
78+
79+
--
80+
-- Test cases to catch unpleasant interactions between IN-join processing
81+
-- and subquery pullup.
82+
--
83+
84+
selectcount(*)from
85+
(select1from tenk1 a
86+
where unique1IN (select hundredfrom tenk1 b)) ss;
87+
selectcount(distinctss.ten)from
88+
(select tenfrom tenk1 a
89+
where unique1IN (select hundredfrom tenk1 b)) ss;
90+
selectcount(*)from
91+
(select1from tenk1 a
92+
where unique1IN (select distinct hundredfrom tenk1 b)) ss;
93+
selectcount(distinctss.ten)from
94+
(select tenfrom tenk1 a
95+
where unique1IN (select distinct hundredfrom tenk1 b)) ss;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp