Skip to content

Commit b762fed

Browse files
committed
Fix LATERAL join test in test memoize.sql
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 Backpatch-through: 14, where Memoize was added.
1 parent 8dd4389 commit b762fed

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/test/regress/expected/memoize.out

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ WHERE t2.unique1 < 1000;
6363
-- Try with LATERAL joins
6464
SELECT explain_memoize('
6565
SELECT COUNT(*),AVG(t2.unique1) FROM tenk1 t1,
66-
LATERAL (SELECT t2.unique1 FROM tenk1 t2 WHERE t1.twenty = t2.unique1) t2
66+
LATERAL (SELECT t2.unique1 FROM tenk1 t2
67+
WHERE t1.twenty = t2.unique1 ORDER BY 1) t2
6768
WHERE t1.unique1 < 1000;', false);
6869
explain_memoize
6970
-------------------------------------------------------------------------------------------
@@ -74,7 +75,7 @@ WHERE t1.unique1 < 1000;', false);
7475
Rows Removed by Filter: 9000
7576
-> Memoize (actual rows=1 loops=N)
7677
Cache Key: t1.twenty
77-
Cache Mode: logical
78+
Cache Mode: binary
7879
Hits: 980 Misses: 20 Evictions: Zero Overflows: 0 Memory Usage: NkB
7980
-> Index Only Scan using tenk1_unique1 on tenk1 t2 (actual rows=1 loops=N)
8081
Index Cond: (unique1 = t1.twenty)
@@ -83,7 +84,8 @@ WHERE t1.unique1 < 1000;', false);
8384

8485
-- And check we get the expected results.
8586
SELECT COUNT(*),AVG(t2.unique1) FROM tenk1 t1,
86-
LATERAL (SELECT t2.unique1 FROM tenk1 t2 WHERE t1.twenty = t2.unique1) t2
87+
LATERAL (SELECT t2.unique1 FROM tenk1 t2
88+
WHERE t1.twenty = t2.unique1 ORDER BY 1) t2
8789
WHERE t1.unique1 < 1000;
8890
count | avg
8991
-------+--------------------

src/test/regress/sql/memoize.sql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,14 @@ WHERE t2.unique1 < 1000;
4747
-- Try with LATERAL joins
4848
SELECT explain_memoize('
4949
SELECT COUNT(*),AVG(t2.unique1) FROM tenk1 t1,
50-
LATERAL (SELECT t2.unique1 FROM tenk1 t2 WHERE t1.twenty = t2.unique1) t2
50+
LATERAL (SELECT t2.unique1 FROM tenk1 t2
51+
WHERE t1.twenty = t2.unique1 ORDER BY 1) t2
5152
WHERE t1.unique1 < 1000;', false);
5253

5354
-- And check we get the expected results.
5455
SELECT COUNT(*),AVG(t2.unique1) FROM tenk1 t1,
55-
LATERAL (SELECT t2.unique1 FROM tenk1 t2 WHERE t1.twenty = t2.unique1) t2
56+
LATERAL (SELECT t2.unique1 FROM tenk1 t2
57+
WHERE t1.twenty = t2.unique1 ORDER BY 1) t2
5658
WHERE t1.unique1 < 1000;
5759

5860
-- Reduce work_mem and hash_mem_multiplier so that we see some cache evictions

0 commit comments

Comments
 (0)