v.22.4Improvement

Proper handling of max_rows_to_read in sorted query limits

Proper support of setting max_rows_to_read in case of reading in order of sorting key and specified limit. Previously the exception Limit for rows or bytes to read exceeded could be thrown even if query actually requires to read less amount of rows. #33230 (Anton Popov).
Improved handling of the max_rows_to_read setting when reading data in the order of the sorting key with a specified LIMIT, preventing unnecessary exceptions.

Why it matters

This feature addresses the issue where an exception (Limit for rows or bytes to read exceeded) could be incorrectly thrown even though the query logically requires reading fewer rows. It ensures that the max_rows_to_read limit accurately reflects the actual number of rows needed, improving query reliability and predictability.

How to use it

Users can rely on the max_rows_to_read setting during query execution involving ordered reads with LIMIT clauses without additional adjustments. The improved logic is applied automatically to avoid premature exceptions.