summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorTom Lane2017-11-25 19:15:48 +0000
committerTom Lane2017-11-25 19:15:48 +0000
commit9b63c13f0a213bfb38bb70a3df3f28cc1f496b30 (patch)
treee56c3528b7c96510dcb3bb05de81e0b350aee552 /src/test
parentab97aaac8f058f2e16ef08655d185db20bc241d3 (diff)
Repair failure with SubPlans in multi-row VALUES lists.
When nodeValuesscan.c was written, it was impossible to have a SubPlan in VALUES --- any sub-SELECT there would have to be uncorrelated and thereby would produce an InitPlan instead. We therefore took a shortcut in the logic that throws away a ValuesScan's per-row expression evaluation data structures. This was broken by the introduction of LATERAL however; a sub-SELECT containing a lateral reference produces a correlated SubPlan. The cleanest fix for this would be to give up the optimization of discarding the expression eval state. But that still seems pretty unappetizing for long VALUES lists. It seems to work to just prevent the subexpressions from hooking into the ValuesScan node's subPlan list, so let's do that and see how well it works. (If this breaks, due to additional connections between the subexpressions and the outer query structures, we might consider compromises like throwing away data only for VALUES rows not containing SubPlans.) Per bug #14924 from Christian Duta. Back-patch to 9.3 where LATERAL was introduced. Discussion: https://postgr.es/m/20171124120836.1463.5310@wrigleys.postgresql.org
Diffstat (limited to 'src/test')
-rw-r--r--src/test/regress/expected/subselect.out30
-rw-r--r--src/test/regress/sql/subselect.sql10
2 files changed, 40 insertions, 0 deletions
diff --git a/src/test/regress/expected/subselect.out b/src/test/regress/expected/subselect.out
index 992d29bb860..4b893856cfc 100644
--- a/src/test/regress/expected/subselect.out
+++ b/src/test/regress/expected/subselect.out
@@ -841,6 +841,36 @@ select exists(select * from nocolumns);
(1 row)
--
+-- Check behavior with a SubPlan in VALUES (bug #14924)
+--
+select val.x
+ from generate_series(1,10) as s(i),
+ lateral (
+ values ((select s.i + 1)), (s.i + 101)
+ ) as val(x)
+where s.i < 10 and (select val.x) < 110;
+ x
+-----
+ 2
+ 102
+ 3
+ 103
+ 4
+ 104
+ 5
+ 105
+ 6
+ 106
+ 7
+ 107
+ 8
+ 108
+ 9
+ 109
+ 10
+(17 rows)
+
+--
-- Check sane behavior with nested IN SubLinks
--
explain (verbose, costs off)
diff --git a/src/test/regress/sql/subselect.sql b/src/test/regress/sql/subselect.sql
index 0d2dd2f1d81..0100367b8d7 100644
--- a/src/test/regress/sql/subselect.sql
+++ b/src/test/regress/sql/subselect.sql
@@ -473,6 +473,16 @@ create temp table nocolumns();
select exists(select * from nocolumns);
--
+-- Check behavior with a SubPlan in VALUES (bug #14924)
+--
+select val.x
+ from generate_series(1,10) as s(i),
+ lateral (
+ values ((select s.i + 1)), (s.i + 101)
+ ) as val(x)
+where s.i < 10 and (select val.x) < 110;
+
+--
-- Check sane behavior with nested IN SubLinks
--
explain (verbose, costs off)