Skip to content

Commit bdbdfe7

Browse files
committed
Add lazy-materialization arrayJoin nested-subcolumn regression test (#101608)
Pulled in from #101644 (@vdimir / Vladimir Cherkasov) and consolidated here so a single test file covers both lazy-materialization-only repros and the broader `arrayJoin`-below-sort-with-`LIMIT` repros that this PR adds for issue #82279. The second query uses `optimize_read_in_order = 0` and `query_plan_execute_functions_after_sorting = 0` to disable the `liftUpFunctions` guard added in this PR, which isolates the `optimizeLazyMaterialization` guard as the only thing keeping the result correct. This makes the test sensitive to a regression in either the lazy-materialization fix or the lift-up fix.
1 parent c1fb775 commit bdbdfe7

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[('2',2),('2',2)]
2+
[('3',3),('3',3),('3',3)]
3+
----------------------
4+
[('2',2),('2',2)]
5+
[('3',3),('3',3),('3',3)]
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
-- Regression test for the lazy-materialization variant of issue #82279,
2+
-- specifically issue #101608 ("Bad arrayJoin result with optimize_read_in_order
3+
-- and query_plan_execute_functions_after_sorting disabled").
4+
--
5+
-- Pulled in from PR #101644 (Vladimir Cherkasov / @vdimir) and consolidated
6+
-- here so a single test file covers both lazy-materialization-only repros and
7+
-- the broader `arrayJoin`-below-sort-with-`LIMIT` repros that PR #104558
8+
-- adds for issue #82279.
9+
--
10+
-- Without the guard in `optimizeLazyMaterialization2` the `ExpressionStep`
11+
-- containing `arrayJoin` would be split into a main half (run before
12+
-- `JoinLazyColumnsStep`, i.e. before `LIMIT`) and a lazy half (run after
13+
-- `JoinLazyColumnsStep`). The lazy half would then re-expand the already
14+
-- limited rows and produce extra output that the `LIMIT` was supposed to
15+
-- truncate.
16+
17+
SET query_plan_optimize_lazy_materialization = 1;
18+
SET flatten_nested = 0;
19+
20+
DROP TABLE IF EXISTS t0;
21+
CREATE TABLE t0
22+
(
23+
id UInt32,
24+
col1 Nested(a UInt32, n Nested(s String, b UInt32))
25+
)
26+
ENGINE = MergeTree
27+
ORDER BY id;
28+
29+
INSERT INTO t0 SELECT number, arrayMap(x -> (x, arrayMap(y -> (toString(number), number), range(number))), range(number)) FROM numbers(10);
30+
31+
SELECT arrayJoin(col1.n) AS e FROM t0 ORDER BY id LIMIT 2 OFFSET 2;
32+
33+
SELECT '----------------------';
34+
35+
-- This combination disables the `liftUpFunctions` guard added in this PR
36+
-- (via `query_plan_execute_functions_after_sorting = 0`) and forces the
37+
-- non-read-in-order path, isolating the `optimizeLazyMaterialization`
38+
-- guard as the only thing that can keep the result correct.
39+
SELECT arrayJoin(col1.n) AS e FROM t0 ORDER BY id LIMIT 2 OFFSET 2 SETTINGS optimize_read_in_order = 0, query_plan_execute_functions_after_sorting = 0;
40+
41+
DROP TABLE t0;

0 commit comments

Comments
 (0)