Data skipping indexes and projections are two mechanisms to optimize queries that do not use the primary key. Both reduce the number of rows read for a given query, but they do it in different ways, and they come with different tradeoffs. Understanding how they work and when to use them helps you choose the right tool for each problem.
The problem: queries that don’t use the primary key
Every table has exactly one sort order. If a query filters on a column that is not in that sort order, it cannot use the primary key to skip data, and must read more rows than necessary. This is often visible in query logs as an unexpectedly high number of rows_read. Data skipping indexes and projections both address this problem.
Projections
A projection is a physically separate copy of your data, stored in the same part directory but sorted by a different key. It can also store pre-aggregated data. If the query planner decides that the projection is appropriate for a query, it will use it instead of the main data.
There are different types of projections. One is a projection on all columns, with a different sort order. This is effectively a second table, and it provides query latency comparable to the primary key. Another type is a _part_offset projection, which stores the sorting key and the position of the data in the table (_part_offset), but not the data itself. This is closer in storage requirements to a data skipping index, but on selective queries it can provide query latency closer to a projection with a full copy of the data.
Pre-aggregation projections store the results of a GROUP BY query. This can speed up aggregate queries that run often.
The tradeoff for projections is that they must be maintained. Every time you insert data, it must be written into and indexed for all projections, and it must be maintained during merges.
Data skipping indexes
Data skipping indexes store information for each granule of rows. This could be min/max values, a bloom filter, a token bloom filter, etc. During a query, the engine can skip any granule where it knows there is no data that matches the query.
A data skipping index does not change the sort order of the data, and does not store a copy of the data. Instead, it adds a small amount of information on top of the existing data.
There are two main types of data skipping indexes to be aware of: minmax and bloom filter (bloom_filter, tokenbf_v1, ngrambf_v1). A minmax index is good for range queries on numeric or date columns, while bloom filter indexes are good for equality or substring queries.
For example, in a trace table, sorting by trace_id would not allow for good pruning of aggregate queries over time ranges. However, you can add a bloom filter data skipping index on trace_id to get fast queries for a single trace.
Tradeoffs
Projections can be expensive to maintain, as noted above. If you have a table that sees a lot of writes, projections can make merges even more expensive.
A projection is not used by queries with the FINAL modifier. This is because applying the projection before the FINAL merge would change the order of deduplication and filtering, and could change the results of the query. If most of your queries use FINAL, projections will not help you.
A data skipping index can fail to skip any data. If you choose an index on a column that does not allow the engine to rule out an entire granule of data, you will add storage overhead and query overhead, but you will not see a reduction in rows read. For example, a bloom filter index that is larger than the data it covers and never skips any data is a waste of time and space.
The optimization hierarchy
These different optimization strategies serve different use cases and can be thought of as a hierarchy. First and foremost, you should optimize your primary key. If you see high rows_read on a column that is in the ORDER BY, there may be a way to improve the ordering of the primary key. If you have a recurring query pattern that filters on a column that is not in the ORDER BY, and the queries do not use FINAL, you may benefit from a projection. If you have sporadic queries that filter on a particular column, and the cost of a projection is too high, you may benefit from a bloom filter data skipping index. If you have queries with a range condition on a numeric column that is not in the ORDER BY, you may benefit from a minmax data skipping index.
Projections provide much larger speedups than data skipping indexes for queries that would otherwise need to scan most granules. But if you see that a data skipping index is not skipping any granules for your queries, you are not getting the benefit of the index, and it may be better to remove it.
You can use rows_read to determine if an index or projection is helping with a query. You can use EXPLAIN PLAN (with indexes=1 and projections=1) to see if a projection was used and how many granules were skipped by a data skipping index. You can see which projections and data skipping indexes were used for a query in the query log system tables, but you cannot see directly how many granules were dropped by an index.
The use_skip_indexes_for_top_k setting can be used to optimize LIMIT N queries. When this is enabled, min/max data from a data skipping index can be used to determine which granules may contain values that qualify for the top N, allowing the other granules to be skipped. If dynamic filtering is also enabled, a running threshold can be compared against the min/max values for each granule. In ClickStack, use_skip_indexes_for_top_k = 1 is enabled by default where supported, and a query_plan_max_limit_for_top_k_optimization setting is available.
Use of data skipping indexes and projections in ClickStack
Observability workloads often have query patterns that do not match the primary key of the table. For example, you may want to run aggregate queries over time ranges, but you may also want to quickly find a particular trace by its trace_id. You can use data skipping indexes and projections to optimize both types of queries.
In 25.12, we added support for data skipping indexes to be used on disjunctive predicates, allowing for more queries to benefit from pruning. The Top-N optimization described above is another example of a new use of data skipping index information, for LIMIT queries. This includes static Top-N queries (without filter predicates) and, with other settings, dynamic Top-N queries (with filter predicates).