Secondary Index (2i) Query Execution
Legacy secondary indexes (2i) maintain per-column index data in hidden tables. Each node indexes only the partitions it owns. Queries on indexed columns that lack a partition key constraint are executed using a scatter-gather pattern across all token ranges.
Scatter-Gather Execution Model
Section titled “Scatter-Gather Execution Model”Scatter Phase
Section titled “Scatter Phase”- The coordinator receives a query containing an indexed column predicate.
- The coordinator identifies target nodes:
- Global query: one replica from each token range (all nodes in the cluster).
- Partition-restricted query: replicas for the specified partition only.
- The query is dispatched to all identified nodes concurrently.
Gather Phase
Section titled “Gather Phase”- Each replica node:
- Executes a local index lookup against the hidden index table.
- Retrieves matching partition keys.
- Performs base table reads for matched keys.
- Serializes and returns partial results.
- The coordinator:
- Collects responses from all contacted nodes.
- Merges and deduplicates result sets.
- Applies post-filtering for non-indexed predicates.
- Returns the final result to the client.
Latency Characteristics
Section titled “Latency Characteristics”Query latency is dominated by the slowest responding node:
T_total = T_network + max(T_node_1, T_node_2, ..., T_node_n) + T_merge
Where T_node_i = T_index_lookup + T_base_read + T_serializationThis tail latency sensitivity is pronounced in heterogeneous clusters where node performance varies. As cluster size grows, the probability of encountering a slow node on any given query increases.
Implementation Characteristics
Section titled “Implementation Characteristics”| Characteristic | Implementation |
|---|---|
| Storage structure | Separate hidden table per indexed column |
| Replication | Inherits base table replication strategy |
| Compaction | Independent from base table compaction |
| Query coordination | Static scatter-gather |
| Consistency | Index and base table may diverge temporarily |
| Index build visibility | No gossip propagation; status requires manual inspection |
The hidden table approach means the index is replicated separately from the data it references. This can result in temporary divergence between index entries and base table rows during compaction or after node failures.
Limitations
Section titled “Limitations”Scatter-gather at cluster scale
Every global 2i query contacts one replica per token range, regardless of how many results match. In a 30-node cluster, every query contacts 30 nodes. Latency degrades as cluster size increases and is always bounded by the slowest node.
| Limitation | Implication |
|---|---|
| All-node contact for global queries | Latency degrades linearly with cluster size |
| Tail latency sensitivity | One slow node delays all results |
| Unbounded coordinator memory | Large result sets accumulate before returning to client |
| No failed index detection | Queries silently skip nodes with failed index state |
Related Documentation
Section titled “Related Documentation”- Secondary Index Queries Overview - Execution model comparison and query design guidelines
- SASI - SSTable-attached scatter-gather index
- SAI - Adaptive range reading index (recommended replacement)
- Index Overview - Index type selection criteria