From b11123b675d9317f771d2bc44f72594de329098d Mon Sep 17 00:00:00 2001
From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Thu, 17 May 2007 19:35:08 +0000
Subject: Fix parameter recalculation for Limit nodes: during a ReScan call we
 must recompute the limit/offset immediately, so that the updated values are
 available when the child's ReScan function is invoked.  Add a regression test
 for this, too.  Bug is new in HEAD (due to the bounded-sorting patch) so no
 need for back-patch.

I did not do anything about merging this signaling with chgParam processing,
but if we were to do that we'd still need to compute the updated values
at this point rather than during the first ProcNode call.

Per observation and test case from Greg Stark, though I didn't use his patch.
---
 src/test/regress/sql/limit.sql | 9 +++++++++
 1 file changed, 9 insertions(+)

(limited to 'src/test/regress/sql/limit.sql')

diff --git a/src/test/regress/sql/limit.sql b/src/test/regress/sql/limit.sql
index c15a486aff..3004550b65 100644
--- a/src/test/regress/sql/limit.sql
+++ b/src/test/regress/sql/limit.sql
@@ -30,3 +30,12 @@ SELECT ''::text AS five, unique1, unique2, stringu1
 SELECT ''::text AS five, unique1, unique2, stringu1 
 		FROM onek
 		ORDER BY unique1 LIMIT 5 OFFSET 900;
+
+-- Stress test for variable LIMIT in conjunction with bounded-heap sorting
+
+SELECT
+  (SELECT n
+     FROM (VALUES (1)) AS x,
+          (SELECT n FROM generate_series(1,10) AS n
+             ORDER BY n LIMIT 1 OFFSET s-1) AS y) AS z
+  FROM generate_series(1,10) AS s;
-- 
cgit v1.2.1

