Indexing The Other Way
A table is sharded by its primary key, but queries often filter by a different column. A global secondary index is a separate sharded structure keyed by the indexed column, mapping its values back to base table keys.
How Lookups Work
- A query on the indexed column reads the index shards for matching values.
- The index entry points to the base row key.
- The engine then fetches the full row from the base table shard.
This lets a filter on a non primary column find rows without scanning every shard of the base table.
The Write Cost
Because the index lives on different shards than the base row, inserting or updating an indexed column must change two shards that may sit on different nodes. To stay consistent the write becomes a distributed transaction spanning the base and index, adding latency. Designers add indexes deliberately, since each one taxes writes.
Key idea
A global secondary index is independently sharded by the indexed column, enabling efficient lookups but forcing writes into distributed transactions across base and index shards.