Use OFFSET 0 instead of ORDER BY to stop subquery pullup
authorDavid Rowley <drowley@postgresql.org>
Tue, 24 Jan 2023 00:49:10 +0000 (13:49 +1300)
committerDavid Rowley <drowley@postgresql.org>
Tue, 24 Jan 2023 00:49:10 +0000 (13:49 +1300)
b762fed64 recently changed this test to prevent subquery pullup to allow
us to test Memoize with lateral_vars.  As pointed out by Tom Lane, OFFSET
0 is our standard way of preventing subquery pullups, so do it that way
instead.

Discussion: https://postgr.es/m/2144818.1674517061@sss.pgh.pa.us
Backpatch-through: 14, same as b762fed64

src/test/regress/expected/memoize.out
src/test/regress/sql/memoize.sql

index 0871932037634ef4b589ad4f82453a0ca59f2a33..60cbdeec7a8dc87053839e1ea730d7263abc49b4 100644 (file)
@@ -64,7 +64,7 @@ WHERE t2.unique1 < 1000;
 SELECT explain_memoize('
 SELECT COUNT(*),AVG(t2.unique1) FROM tenk1 t1,
 LATERAL (SELECT t2.unique1 FROM tenk1 t2
-         WHERE t1.twenty = t2.unique1 ORDER BY 1) t2
+         WHERE t1.twenty = t2.unique1 OFFSET 0) t2
 WHERE t1.unique1 < 1000;', false);
                                       explain_memoize                                      
 -------------------------------------------------------------------------------------------
@@ -85,7 +85,7 @@ WHERE t1.unique1 < 1000;', false);
 -- And check we get the expected results.
 SELECT COUNT(*),AVG(t2.unique1) FROM tenk1 t1,
 LATERAL (SELECT t2.unique1 FROM tenk1 t2
-         WHERE t1.twenty = t2.unique1 ORDER BY 1) t2
+         WHERE t1.twenty = t2.unique1 OFFSET 0) t2
 WHERE t1.unique1 < 1000;
  count |        avg         
 -------+--------------------
index 623a9d5114f4190617ec88643cfd092c0d76d9af..d66acaed85a406592f33f7edeb4265dce43ecf4d 100644 (file)
@@ -48,13 +48,13 @@ WHERE t2.unique1 < 1000;
 SELECT explain_memoize('
 SELECT COUNT(*),AVG(t2.unique1) FROM tenk1 t1,
 LATERAL (SELECT t2.unique1 FROM tenk1 t2
-         WHERE t1.twenty = t2.unique1 ORDER BY 1) t2
+         WHERE t1.twenty = t2.unique1 OFFSET 0) t2
 WHERE t1.unique1 < 1000;', false);
 
 -- And check we get the expected results.
 SELECT COUNT(*),AVG(t2.unique1) FROM tenk1 t1,
 LATERAL (SELECT t2.unique1 FROM tenk1 t2
-         WHERE t1.twenty = t2.unique1 ORDER BY 1) t2
+         WHERE t1.twenty = t2.unique1 OFFSET 0) t2
 WHERE t1.unique1 < 1000;
 
 -- Reduce work_mem and hash_mem_multiplier so that we see some cache evictions