fix: incorrect assignment of previous_row_chunk leads to logical errors

This commit is contained in:
wxybear 2024-11-14 00:05:11 +08:00
parent aaca3b6156
commit 2d85df2748
3 changed files with 25 additions and 2 deletions

View File

@ -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 WITH TIES is enabled and rows read is less than 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);

View File

@ -53,3 +53,5 @@
100
100
100
12
12

View File

@ -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;