Fix nulls direction check.

This commit is contained in:
Nikolai Kochetov 2024-11-15 16:02:07 +00:00
parent 5f02dc546f
commit 6dbe20839a
3 changed files with 25 additions and 14 deletions

View File

@ -426,7 +426,7 @@ SortingInputOrder buildInputOrderFromSortDescription(
/// Since sorting key columns are always sorted with NULLS LAST, reading in order
/// supported only for ASC NULLS LAST ("in order"), and DESC NULLS FIRST ("reverse")
const auto column_is_nullable = sorting_key.data_types[next_sort_key]->isNullable();
if (column_is_nullable && sort_column_description.nulls_direction != 1)
if (column_is_nullable && sort_column_description.nulls_direction != sort_column_description.direction)
break;
/// Direction for current sort key.

View File

@ -1,22 +1,25 @@
3
8
Sorting (Sorting for ORDER BY)
Prefix sort description: __table1.i DESC
Result sort description: __table1.i DESC
(Expression)
ExpressionTransform
(Limit)
Limit
(Sorting)
MergeSortingTransform
LimitsCheckingTransform
PartialSortingTransform
(Expression)
ExpressionTransform
(ReadFromMergeTree)
MergeTreeSelect(pool: ReadPoolInOrder, algorithm: InOrder) 0 → 1
(Expression)
ExpressionTransform
(ReadFromMergeTree)
MergeTreeSelect(pool: ReadPoolInOrder, algorithm: InOrder) 0 → 1
99
98
97
96
95
Sorting (Sorting for ORDER BY)
Prefix sort description: __table1.i ASC
Result sort description: __table1.i ASC
(Expression)
ExpressionTransform
(Limit)
@ -34,22 +37,26 @@ ExpressionTransform
4
3 1003
6
Sorting (Sorting for ORDER BY)
Prefix sort description: __table1.i ASC, __table1.j DESC
Result sort description: __table1.i ASC, __table1.j DESC
(Expression)
ExpressionTransform
(Limit)
Limit
(Sorting)
FinishSortingTransform
PartialSortingTransform
(Expression)
ExpressionTransform
(ReadFromMergeTree)
MergeTreeSelect(pool: ReadPoolInOrder, algorithm: InOrder) 0 → 1
(Expression)
ExpressionTransform
(ReadFromMergeTree)
MergeTreeSelect(pool: ReadPoolInOrder, algorithm: InOrder) 0 → 1
0 1090
0 1080
0 1070
0 1060
0 1050
Sorting (Sorting for ORDER BY)
Prefix sort description: __table1.i ASC
Result sort description: __table1.i ASC, __table1.j ASC
(Expression)
ExpressionTransform
(Limit)

View File

@ -17,10 +17,12 @@ select * from x1 where i = 3;
select count() from x1 where i between 3 and 10;
select trimLeft(explain) from (explain actions=1 select * from x1 order by i desc limit 5 settings max_threads=1, enable_analyzer=1) where explain ilike '%sort%';
explain pipeline select * from x1 order by i desc limit 5 settings max_threads=1;
select * from x1 order by i desc limit 5;
select trimLeft(explain) from (explain actions=1 select * from x1 order by i limit 5 settings max_threads=1, enable_analyzer=1) where explain ilike '%sort%';
explain pipeline select * from x1 order by i limit 5 settings max_threads=1;
select * from x1 order by i limit 5;
@ -35,10 +37,12 @@ select * from x2 where j = 1003;
select count() from x2 where i between 3 and 10 and j between 1003 and 1008;
select trimLeft(explain) from (explain actions=1 select * from x2 order by i, j desc limit 5 settings max_threads=1, enable_analyzer=1) where explain ilike '%sort%';
explain pipeline select * from x2 order by i, j desc limit 5 settings max_threads=1;
select * from x2 order by i, j desc limit 5;
select trimLeft(explain) from (explain actions=1 select * from x2 order by i, j limit 5 settings max_threads=1, enable_analyzer=1) where explain ilike '%sort%';
explain pipeline select * from x2 order by i, j limit 5 settings max_threads=1;
select * from x2 order by i, j limit 5;