ClickHouse

Primary Key Index Mismatch

warning
latencyUpdated Jan 21, 2026

Queries filtering on columns not in ORDER BY key prefix perform full granule scans instead of using primary index, reading far more data than necessary. This manifests as high read_bytes relative to result size.

How to detect:

Use EXPLAIN indexes=1 to verify primary key usage. Monitor ratio of read_bytes to result_bytes in system.query_log. Alert when queries read >100x more data than they return, especially on tables with composite ORDER BY keys.

Recommended action:

Reorder ORDER BY key to place most selective filter columns first. For queries on non-key columns, add skip indexes (bloom filters for strings, set indexes for low-cardinality). Consider projections for common query patterns with different sort orders. Use PREWHERE for selective filters.