-> 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;
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;