Improve test.

This commit is contained in:
Nikolai Kochetov 2022-11-07 13:31:07 +00:00
parent 9043df56a8
commit 7ac258c2a7
2 changed files with 243 additions and 0 deletions

View File

@ -183,6 +183,49 @@ select * from (explain plan actions = 1 select * from tab order by (a + b) * c d
select * from (explain plan actions = 1 select * from tab order by (a + b) * c, intDiv(intDiv(sin(a / b), -2), -3)) where explain like '%sort description%';
Prefix sort description: multiply(plus(a, b), c) ASC, intDiv(intDiv(sin(divide(a, b)), -2), -3) ASC
Result sort description: multiply(plus(a, b), c) ASC, intDiv(intDiv(sin(divide(a, b)), -2), -3) ASC
-- Aliases
select * from (select *, a + b as x from tab) order by x * c;
0 0 0 0 0
0 0 0 0 0
1 1 1 1 2
1 1 1 1 2
2 2 2 2 4
2 2 2 2 4
3 3 3 3 6
3 3 3 3 6
4 4 4 4 8
4 4 4 4 8
select * from (explain plan actions = 1 select * from (select *, a + b as x from tab) order by x * c) where explain like '%sort description%';
Prefix sort description: multiply(x, c) ASC
Result sort description: multiply(x, c) ASC
select * from (select *, a + b as x, a / b as y from tab) order by x * c, sin(y);
0 0 0 0 0 nan
0 0 0 0 0 nan
1 1 1 1 2 1
1 1 1 1 2 1
2 2 2 2 4 1
2 2 2 2 4 1
3 3 3 3 6 1
3 3 3 3 6 1
4 4 4 4 8 1
4 4 4 4 8 1
select * from (explain plan actions = 1 select * from (select *, a + b as x, a / b as y from tab) order by x * c, sin(y)) where explain like '%sort description%';
Prefix sort description: multiply(x, c) ASC, sin(y) ASC
Result sort description: multiply(x, c) ASC, sin(y) ASC
select * from (select *, a / b as y from (select *, a + b as x from tab)) order by x * c, sin(y);
0 0 0 0 0 nan
0 0 0 0 0 nan
1 1 1 1 2 1
1 1 1 1 2 1
2 2 2 2 4 1
2 2 2 2 4 1
3 3 3 3 6 1
3 3 3 3 6 1
4 4 4 4 8 1
4 4 4 4 8 1
select * from (explain plan actions = 1 select * from (select *, a / b as y from (select *, a + b as x from tab)) order by x * c, sin(y)) where explain like '%sort description%';
Prefix sort description: multiply(x, c) ASC, sin(y) ASC
Result sort description: multiply(x, c) ASC, sin(y) ASC
-- { echoOn }
select * from tab2 order by toTimeZone(toTimezone(x, 'UTC'), 'CET'), intDiv(intDiv(y, -2), -3);
@ -213,3 +256,150 @@ select * from (explain plan actions = 1 select * from tab2 order by toStartOfDay
select * from (explain plan actions = 1 select * from tab2 where toTimezone(x, 'CET') = '2020-02-03 01:00:00' order by intDiv(intDiv(y, -2), -3)) where explain like '%sort description%';
Prefix sort description: intDiv(intDiv(y, -2), -3) ASC
Result sort description: intDiv(intDiv(y, -2), -3) ASC
-- { echoOn }
-- Union (not fully supported)
select * from (select * from tab union all select * from tab3) order by (a + b) * c, sin(a / b);
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
2 2 2 2
2 2 2 2
2 2 2 2
2 2 2 2
3 3 3 3
3 3 3 3
3 3 3 3
3 3 3 3
4 4 4 4
4 4 4 4
4 4 4 4
4 4 4 4
select * from (explain plan actions = 1 select * from (select * from tab union all select * from tab3) order by (a + b) * c, sin(a / b)) where explain like '%sort description%' or explain like '%ReadType%';
Prefix sort description: multiply(plus(a, b), c) ASC, sin(divide(a, b)) ASC
Result sort description: multiply(plus(a, b), c) ASC, sin(divide(a, b)) ASC
ReadType: InOrder
ReadType: InOrder
select * from (select * from tab where (a + b) * c = 8 union all select * from tab3 where (a + b) * c = 18) order by sin(a / b);
2 2 2 2
2 2 2 2
3 3 3 3
3 3 3 3
select * from (explain plan actions = 1 select * from (select * from tab where (a + b) * c = 8 union all select * from tab3 where (a + b) * c = 18) order by sin(a / b)) where explain like '%sort description%' or explain like '%ReadType%';
Prefix sort description: sin(divide(a, b)) ASC
Result sort description: sin(divide(a, b)) ASC
ReadType: InOrder
ReadType: InOrder
select * from (select * from tab where (a + b) * c = 8 union all select * from tab4) order by sin(a / b);
2 2 2 2
2 2 2 2
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
0 0 0 0
0 0 0 0
select * from (explain plan actions = 1 select * from (select * from tab where (a + b) * c = 8 union all select * from tab4) order by sin(a / b)) where explain like '%sort description%' or explain like '%ReadType%';
Prefix sort description: sin(divide(a, b)) ASC
Result sort description: sin(divide(a, b)) ASC
ReadType: InOrder
ReadType: InOrder
select * from (select * from tab union all select * from tab5) order by (a + b) * c;
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
2 2 2 2
2 2 2 2
2 2 2 2
2 2 2 2
3 3 3 3
3 3 3 3
3 3 3 3
3 3 3 3
4 4 4 4
4 4 4 4
4 4 4 4
4 4 4 4
select * from (explain plan actions = 1 select * from (select * from tab union all select * from tab5) order by (a + b) * c) where explain like '%sort description%' or explain like '%ReadType%';
Prefix sort description: multiply(plus(a, b), c) ASC
Result sort description: multiply(plus(a, b), c) ASC
ReadType: InOrder
ReadType: InOrder
select * from (select * from tab union all select * from tab5) order by (a + b) * c, sin(a / b);
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
2 2 2 2
2 2 2 2
2 2 2 2
2 2 2 2
3 3 3 3
3 3 3 3
3 3 3 3
3 3 3 3
4 4 4 4
4 4 4 4
4 4 4 4
4 4 4 4
select * from (explain plan actions = 1 select * from (select * from tab union all select * from tab5) order by (a + b) * c, sin(a / b)) where explain like '%sort description%' or explain like '%ReadType%';
Prefix sort description: multiply(plus(a, b), c) ASC, sin(divide(a, b)) ASC
Result sort description: multiply(plus(a, b), c) ASC, sin(divide(a, b)) ASC
ReadType: InOrder
Prefix sort description: multiply(plus(a, b), c) ASC
Result sort description: multiply(plus(a, b), c) ASC, sin(divide(a, b)) ASC
ReadType: InOrder
-- Union with limit
select * from (select * from tab union all select * from tab5) order by (a + b) * c, sin(a / b) limit 3;
0 0 0 0
0 0 0 0
0 0 0 0
select * from (explain plan actions = 1 select * from (select * from tab union all select * from tab5) order by (a + b) * c, sin(a / b) limit 3) where explain ilike '%sort description%' or explain like '%ReadType%' or explain like '%Limit%';
Limit (preliminary LIMIT (without OFFSET))
Limit 3
Prefix sort description: multiply(plus(a, b), c) ASC, sin(divide(a, b)) ASC
Result sort description: multiply(plus(a, b), c) ASC, sin(divide(a, b)) ASC
Limit 3
ReadType: InOrder
Prefix sort description: multiply(plus(a, b), c) ASC
Result sort description: multiply(plus(a, b), c) ASC, sin(divide(a, b)) ASC
ReadType: InOrder
-- In this example, we read-in-order from tab up to ((a + b) * c, sin(a / b)) and from tab5 up to ((a + b) * c).
-- In case of tab5, there would be two finish sorting transforms: ((a + b) * c) -> ((a + b) * c, sin(a / b)) -> ((a + b) * c, sin(a / b), d).
-- It's important that ((a + b) * c) -> ((a + b) * c does not have LIMIT. We can add LIMIT WITH TIES later, when sorting alog support it.
-- In case of tab4, we do full sorting by ((a + b) * c, sin(a / b), d) with LIMIT. We can replace it to sorting by ((a + b) * c, sin(a / b)) and LIMIT WITH TIES, when sorting alog support it.
select * from (select * from tab union all select * from tab5 union all select * from tab4) order by (a + b) * c, sin(a / b), d limit 3;
0 0 0 0
0 0 0 0
0 0 0 0
select * from (explain plan actions = 1 select * from (select * from tab union all select * from tab5 union all select * from tab4) order by (a + b) * c, sin(a / b), d limit 3) where explain ilike '%sort description%' or explain like '%ReadType%' or explain like '%Limit%';
Limit (preliminary LIMIT (without OFFSET))
Limit 3
Prefix sort description: multiply(plus(a, b), c) ASC, sin(divide(a, b)) ASC
Result sort description: multiply(plus(a, b), c) ASC, sin(divide(a, b)) ASC, d ASC
Limit 3
ReadType: InOrder
Prefix sort description: multiply(plus(a, b), c) ASC
Result sort description: multiply(plus(a, b), c) ASC, sin(divide(a, b)) ASC
ReadType: InOrder
Sort description: multiply(plus(a, b), c) ASC, sin(divide(a, b)) ASC, d ASC
Limit 3
ReadType: Default

View File

@ -73,6 +73,16 @@ select * from (explain plan actions = 1 select * from tab order by (a + b) * c d
-- select * from tab order by (a + b) * c, intDiv(intDiv(sin(a / b), -2), -3);
select * from (explain plan actions = 1 select * from tab order by (a + b) * c, intDiv(intDiv(sin(a / b), -2), -3)) where explain like '%sort description%';
-- Aliases
select * from (select *, a + b as x from tab) order by x * c;
select * from (explain plan actions = 1 select * from (select *, a + b as x from tab) order by x * c) where explain like '%sort description%';
select * from (select *, a + b as x, a / b as y from tab) order by x * c, sin(y);
select * from (explain plan actions = 1 select * from (select *, a + b as x, a / b as y from tab) order by x * c, sin(y)) where explain like '%sort description%';
select * from (select *, a / b as y from (select *, a + b as x from tab)) order by x * c, sin(y);
select * from (explain plan actions = 1 select * from (select *, a / b as y from (select *, a + b as x from tab)) order by x * c, sin(y)) where explain like '%sort description%';
-- { echoOff }
create table tab2 (x DateTime, y UInt32, z UInt32) engine = MergeTree order by (x, y);
@ -89,3 +99,46 @@ select * from (explain plan actions = 1 select * from tab2 order by toStartOfDay
-- select * from tab2 where toTimezone(x, 'CET') = '2020-02-03 01:00:00' order by intDiv(intDiv(y, -2), -3);
select * from (explain plan actions = 1 select * from tab2 where toTimezone(x, 'CET') = '2020-02-03 01:00:00' order by intDiv(intDiv(y, -2), -3)) where explain like '%sort description%';
-- { echoOff }
create table tab3 (a UInt32, b UInt32, c UInt32, d UInt32) engine = MergeTree order by ((a + b) * c, sin(a / b));
insert into tab3 select number, number, number, number from numbers(5);
insert into tab3 select number, number, number, number from numbers(5);
create table tab4 (a UInt32, b UInt32, c UInt32, d UInt32) engine = MergeTree order by sin(a / b);
insert into tab4 select number, number, number, number from numbers(5);
insert into tab4 select number, number, number, number from numbers(5);
create table tab5 (a UInt32, b UInt32, c UInt32, d UInt32) engine = MergeTree order by (a + b) * c;
insert into tab5 select number, number, number, number from numbers(5);
insert into tab5 select number, number, number, number from numbers(5);
-- { echoOn }
-- Union (not fully supported)
select * from (select * from tab union all select * from tab3) order by (a + b) * c, sin(a / b);
select * from (explain plan actions = 1 select * from (select * from tab union all select * from tab3) order by (a + b) * c, sin(a / b)) where explain like '%sort description%' or explain like '%ReadType%';
select * from (select * from tab where (a + b) * c = 8 union all select * from tab3 where (a + b) * c = 18) order by sin(a / b);
select * from (explain plan actions = 1 select * from (select * from tab where (a + b) * c = 8 union all select * from tab3 where (a + b) * c = 18) order by sin(a / b)) where explain like '%sort description%' or explain like '%ReadType%';
select * from (select * from tab where (a + b) * c = 8 union all select * from tab4) order by sin(a / b);
select * from (explain plan actions = 1 select * from (select * from tab where (a + b) * c = 8 union all select * from tab4) order by sin(a / b)) where explain like '%sort description%' or explain like '%ReadType%';
select * from (select * from tab union all select * from tab5) order by (a + b) * c;
select * from (explain plan actions = 1 select * from (select * from tab union all select * from tab5) order by (a + b) * c) where explain like '%sort description%' or explain like '%ReadType%';
select * from (select * from tab union all select * from tab5) order by (a + b) * c, sin(a / b);
select * from (explain plan actions = 1 select * from (select * from tab union all select * from tab5) order by (a + b) * c, sin(a / b)) where explain like '%sort description%' or explain like '%ReadType%';
-- Union with limit
select * from (select * from tab union all select * from tab5) order by (a + b) * c, sin(a / b) limit 3;
select * from (explain plan actions = 1 select * from (select * from tab union all select * from tab5) order by (a + b) * c, sin(a / b) limit 3) where explain ilike '%sort description%' or explain like '%ReadType%' or explain like '%Limit%';
-- In this example, we read-in-order from tab up to ((a + b) * c, sin(a / b)) and from tab5 up to ((a + b) * c).
-- In case of tab5, there would be two finish sorting transforms: ((a + b) * c) -> ((a + b) * c, sin(a / b)) -> ((a + b) * c, sin(a / b), d).
-- It's important that ((a + b) * c) -> ((a + b) * c does not have LIMIT. We can add LIMIT WITH TIES later, when sorting alog support it.
-- In case of tab4, we do full sorting by ((a + b) * c, sin(a / b), d) with LIMIT. We can replace it to sorting by ((a + b) * c, sin(a / b)) and LIMIT WITH TIES, when sorting alog support it.
select * from (select * from tab union all select * from tab5 union all select * from tab4) order by (a + b) * c, sin(a / b), d limit 3;
select * from (explain plan actions = 1 select * from (select * from tab union all select * from tab5 union all select * from tab4) order by (a + b) * c, sin(a / b), d limit 3) where explain ilike '%sort description%' or explain like '%ReadType%' or explain like '%Limit%';