Skip to content

Allow index pruning and filter pushdown when an integral column is compared with a float literal in a predicate - #98516

Merged
nihalzp merged 7 commits into
ClickHouse:masterfrom
nihalzp:allow-integral-col-float-comparison
Mar 5, 2026
Merged

nihalzp merged 7 commits into
ClickHouse:masterfrom
nihalzp:allow-integral-col-float-comparison

Conversation

@nihalzp

@nihalzp nihalzp commented Mar 2, 2026 •

Copy link
Copy Markdown
Member

The following query will not cause infinite loop anymore:

SELECT count() FROM primes() WHERE prime < 1e9;

Additionally, given,

CREATE TABLE users (uid Int64) ENGINE=MergeTree ORDER BY uid;
INSERT INTO users SELECT number FROM numbers(200000);

This prunes:

EXPLAIN indexes = 1
SELECT count() FROM users WHERE uid < 100000;

This did not prune. But after this PR, this will also prune:

EXPLAIN indexes = 1
SELECT count() FROM users WHERE uid < 100000.5;

Changelog category (leave one):

  • Performance Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Allow index pruning and filter pushdown when an integral column is compared with a float literal; for example, predicates like WHERE x < 10.5 can now use the primary key for pruning, and filters such as prime < 1e9 or number < 1e5 are now pushed down for the primes() and numbers() table functions instead of causing unbounded execution. Closes #85167.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.3.1.446

@clickhouse-gh

clickhouse-gh Bot commented Mar 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [bdd92e8]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_binary, ParallelReplicas, s3 storage, parallel) failure
04003_cast_nullable_read_in_order_explain FAIL cidb, issue ISSUE EXISTS
AST fuzzer (amd_ubsan) failure
Logical error: Replica A decided to read in B mode, not in C. This is a bug (STID: 7334-66bb) FAIL cidb IGNORED

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Mar 2, 2026

@amosbird amosbird left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Nice PR!

@nihalzp
nihalzp added this pull request to the merge queue Mar 5, 2026
@nihalzp

nihalzp commented Mar 5, 2026

Copy link
Copy Markdown
Member Author

AST fuzzer (amd_ubsan) - Logical error: Replica A decided to read in B mode, not in C. - #95524

Merged via the queue into ClickHouse:master with commit 56b3d6b Mar 5, 2026
285 of 290 checks passed
@nihalzp
nihalzp deleted the allow-integral-col-float-comparison branch March 5, 2026 18:34
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Mar 5, 2026
@zlareb1

zlareb1 commented Mar 9, 2026

Copy link
Copy Markdown
Member

@nihalzp why the below query used to run infinitely?
SELECT count() FROM primes() WHERE prime < 1e9;

@nihalzp

nihalzp commented Mar 9, 2026

Copy link
Copy Markdown
Member Author

@zlareb1 primes() and numbers() are unbounded generators. Both use KeyCondition's filter (WHERE) analysis to understand if they can bound prime/number generation. Previously, KeyCondition was not smart enough to analyze when key column is integral and literal is float (e.g. integral_col < 10.5); as a result, primes() and numbers() stayed unbounded, kept generating forever and query ran indefinitely.

To solve the issue, this PR adds the analysis capability of such scenario to KeyCondition. Thus, as a consequence, primes() and numbers() can now understand filter such as WHERE prime < 1e9 and only generate primes/numbers up to 1e9.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-performance Pull request with some performance improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WHERE int_index_column > float64 disable partition and primary key index search

4 participants