← Lessons

quiz vs the machine

Gold1440

Databases

Global Secondary Index In Distributed SQL

Indexing a column sharded differently from the base table.

5 min read · core · beat Gold to climb

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.

Check yourself

Answer to earn rating on the learn ladder.

1. Why is a global secondary index useful?

2. What is the main cost of a global secondary index?