From ce58aad2ba13885e2c5fa50e31ee5945e883096b Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 30 Aug 2013 19:27:40 -0400 Subject: [PATCH] Add test case for bug #8410. Per Andres Freund. --- src/test/regress/expected/inherit.out | 41 +++++++++++++++++++++++++++ src/test/regress/sql/inherit.sql | 20 +++++++++++++ 2 files changed, 61 insertions(+) diff --git a/src/test/regress/expected/inherit.out b/src/test/regress/expected/inherit.out index cc3670bd91..8520281f75 100644 --- a/src/test/regress/expected/inherit.out +++ b/src/test/regress/expected/inherit.out @@ -1350,6 +1350,47 @@ ORDER BY x, y; -> Index Only Scan using tenk1_unique2 on tenk1 b (6 rows) +-- exercise rescan code path via a repeatedly-evaluated subquery +explain (costs off) +SELECT + (SELECT g.i FROM ( + (SELECT * FROM generate_series(1, 2) ORDER BY 1) + UNION ALL + (SELECT * FROM generate_series(1, 2) ORDER BY 1) + ) f(i) + ORDER BY f.i LIMIT 1) +FROM generate_series(1, 3) g(i); + QUERY PLAN +------------------------------------------------------------------------------------ + Function Scan on generate_series g + SubPlan 1 + -> Limit + -> Result + -> Merge Append + Sort Key: generate_series.generate_series + -> Sort + Sort Key: generate_series.generate_series + -> Function Scan on generate_series + -> Sort + Sort Key: generate_series_1.generate_series + -> Function Scan on generate_series generate_series_1 +(12 rows) + +SELECT + (SELECT g.i FROM ( + (SELECT * FROM generate_series(1, 2) ORDER BY 1) + UNION ALL + (SELECT * FROM generate_series(1, 2) ORDER BY 1) + ) f(i) + ORDER BY f.i LIMIT 1) +FROM generate_series(1, 3) g(i); + i +--- + 1 + 2 + 3 +(3 rows) + reset enable_seqscan; reset enable_indexscan; reset enable_bitmapscan; diff --git a/src/test/regress/sql/inherit.sql b/src/test/regress/sql/inherit.sql index 29c1e59fd0..e88a5847b9 100644 --- a/src/test/regress/sql/inherit.sql +++ b/src/test/regress/sql/inherit.sql @@ -439,6 +439,26 @@ SELECT x, y FROM SELECT unique2 AS x, unique2 AS y FROM tenk1 b) s ORDER BY x, y; +-- exercise rescan code path via a repeatedly-evaluated subquery +explain (costs off) +SELECT + (SELECT g.i FROM ( + (SELECT * FROM generate_series(1, 2) ORDER BY 1) + UNION ALL + (SELECT * FROM generate_series(1, 2) ORDER BY 1) + ) f(i) + ORDER BY f.i LIMIT 1) +FROM generate_series(1, 3) g(i); + +SELECT + (SELECT g.i FROM ( + (SELECT * FROM generate_series(1, 2) ORDER BY 1) + UNION ALL + (SELECT * FROM generate_series(1, 2) ORDER BY 1) + ) f(i) + ORDER BY f.i LIMIT 1) +FROM generate_series(1, 3) g(i); + reset enable_seqscan; reset enable_indexscan; reset enable_bitmapscan; -- 2.40.0