v.22.8New Feature

Added exact_rows_before_limit setting for precise row statistics in ClickHouse

Added a setting exact_rows_before_limit (0/1). When enabled, ClickHouse will provide exact value for rows_before_limit_at_least statistic, but with the cost that the data before limit will have to be read completely. This closes #6613. #25333 (kevin wan).
Added the exact_rows_before_limit setting to provide an exact value for the rows_before_limit_at_least statistic in query execution.

Why it matters

This feature solves the problem of inaccuracy in the rows_before_limit_at_least statistic by allowing users to get an exact count. It helps users understand the true number of rows processed before applying the LIMIT operation, at the cost of reading all data before the limit, improving query diagnostics and performance analysis.

How to use it

Enable the feature by setting exact_rows_before_limit to 1 in your session or query settings, for example:

sql<br>SET exact_rows_before_limit = 1<br>

When enabled, the statistic rows_before_limit_at_least will report the exact row count processed before the limit.