v.19.14Improvement

When Determining Shards of a Distributed Table to Be Covered by a Read Query (for Optimize_skip_unused_shards = 1) Clickhouse Now Checks Conditions from Both Prewhere and Where Clauses of Select Statement

When determining shards of a Distributed table to be covered by a read query (for optimize_skip_unused_shards = 1) ClickHouse now checks conditions from both prewhere and where clauses of select statement. #6521 (Alexander Kazakov)
ClickHouse improves shard pruning for Distributed tables by considering conditions from both prewhere and where clauses when optimize_skip_unused_shards is enabled.

Why it matters

The feature enhances query efficiency by more accurately determining which shards are relevant for a read query. It leverages filtering conditions from both the prewhere and where clauses, reducing unnecessary shard reads and improving overall query performance on distributed tables.

How to use it

Enable the optimization by setting optimize_skip_unused_shards = 1 in your query or session settings. Then, conditions specified in both the prewhere and where clauses will be used to skip irrelevant shards automatically.