mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
Merge pull request #71886 from wxybear/fix_with_ties_when_rows_read_less_than_request
Fix: select statements that use 'with ties' might not return enough rows
This commit is contained in:
commit
2ed8e4c8b8
@ -317,8 +317,9 @@ void LimitTransform::splitChunk(PortsData & data)
|
||||
length = offset + limit - (rows_read - num_rows) - start;
|
||||
}
|
||||
|
||||
/// check if other rows in current block equals to last one in limit
|
||||
if (with_ties && length)
|
||||
/// Check if other rows in current block equals to last one in limit
|
||||
/// when rows read >= offset + limit.
|
||||
if (with_ties && offset + limit <= rows_read && length)
|
||||
{
|
||||
UInt64 current_row_num = start + length;
|
||||
previous_row_chunk = makeChunkWithPreviousRow(data.current_chunk, current_row_num - 1);
|
||||
|
@ -53,3 +53,5 @@
|
||||
100
|
||||
100
|
||||
100
|
||||
12
|
||||
12
|
||||
|
@ -35,4 +35,24 @@ select count() from (select number, number < 100 from numbers(2000) order by num
|
||||
SET max_block_size = 5;
|
||||
select count() from (select number < 100, number from numbers(2000) order by number < 100 desc limit 10 with ties);
|
||||
|
||||
SELECT count() FROM (WITH data AS (
|
||||
SELECT * FROM numbers(0, 10)
|
||||
UNION ALL
|
||||
SELECT * FROM numbers(10, 10)
|
||||
)
|
||||
SELECT number div 10 AS ten, number
|
||||
FROM data
|
||||
ORDER BY ten
|
||||
LIMIT 8,6 WITH TIES);
|
||||
|
||||
SELECT count() FROM (WITH data AS (
|
||||
SELECT * FROM numbers(0, 10)
|
||||
UNION ALL
|
||||
SELECT * FROM numbers(10, 10)
|
||||
)
|
||||
SELECT number div 11 AS eleven, number
|
||||
FROM data
|
||||
ORDER BY eleven
|
||||
LIMIT 8,6 WITH TIES);
|
||||
|
||||
DROP TABLE ties;
|
||||
|
Loading…
Reference in New Issue
Block a user