Fix LATERAL join test in test memoize.sql
authorDavid Rowley <[email protected]>
Mon, 23 Jan 2023 23:30:30 +0000 (12:30 +1300)
committerDavid Rowley <[email protected]>
Mon, 23 Jan 2023 23:30:30 +0000 (12:30 +1300)
The test in question was meant to be testing Memoize to ensure it worked
correctly when the inner side of the join contained lateral vars, however,
nothing in the lateral subquery stopped it from being pulled up into the
main query, so the planner did that, and that meant no more lateral vars.

Here we add a simple ORDER BY to stop the planner from being able to
pullup the lateral subquery.

Author: Richard Guo
Discussion: https://postgr.es/m/CAMbWs4_LHJaN4L-tXpKMiPFnsCJWU1P8Xh59o0W7AA6UN99=cQ@mail.gmail.com
Back-through: 14, where Memoize was added.

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

index de43afa76ed7653a35d5e93510c539068e8a6486..0871932037634ef4b589ad4f82453a0ca59f2a33 100644 (file)
@@ -63,7 +63,8 @@ WHERE t2.unique1 < 1000;
 -- Try with LATERAL joins
 SELECT explain_memoize('
 SELECT COUNT(*),AVG(t2.unique1) FROM tenk1 t1,
-LATERAL (SELECT t2.unique1 FROM tenk1 t2 WHERE t1.twenty = t2.unique1) t2
+LATERAL (SELECT t2.unique1 FROM tenk1 t2
+         WHERE t1.twenty = t2.unique1 ORDER BY 1) t2
 WHERE t1.unique1 < 1000;', false);
                                       explain_memoize                                      
 -------------------------------------------------------------------------------------------
@@ -74,7 +75,7 @@ WHERE t1.unique1 < 1000;', false);
                Rows Removed by Filter: 9000
          ->  Memoize (actual rows=1 loops=N)
                Cache Key: t1.twenty
-               Cache Mode: logical
+               Cache Mode: binary
                Hits: 980  Misses: 20  Evictions: Zero  Overflows: 0  Memory Usage: NkB
                ->  Index Only Scan using tenk1_unique1 on tenk1 t2 (actual rows=1 loops=N)
                      Index Cond: (unique1 = t1.twenty)
@@ -83,7 +84,8 @@ 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) t2
+LATERAL (SELECT t2.unique1 FROM tenk1 t2
+         WHERE t1.twenty = t2.unique1 ORDER BY 1) t2
 WHERE t1.unique1 < 1000;
  count |        avg         
 -------+--------------------
index 17c5b4bfab5ccd737e1117b3c6be921a0c97f825..623a9d5114f4190617ec88643cfd092c0d76d9af 100644 (file)
@@ -47,12 +47,14 @@ WHERE t2.unique1 < 1000;
 -- Try with LATERAL joins
 SELECT explain_memoize('
 SELECT COUNT(*),AVG(t2.unique1) FROM tenk1 t1,
-LATERAL (SELECT t2.unique1 FROM tenk1 t2 WHERE t1.twenty = t2.unique1) t2
+LATERAL (SELECT t2.unique1 FROM tenk1 t2
+         WHERE t1.twenty = t2.unique1 ORDER BY 1) 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) t2
+LATERAL (SELECT t2.unique1 FROM tenk1 t2
+         WHERE t1.twenty = t2.unique1 ORDER BY 1) t2
 WHERE t1.unique1 < 1000;
 
 -- Reduce work_mem and hash_mem_multiplier so that we see some cache evictions