Database / Google Spanner Database Interview questions
How can you optimize query performance in Spanner?
Most Spanner performance problems trace back to either schema design or query shape, so optimization usually targets both.
- Design keys to avoid hotspots - a hot split caps throughput regardless of query tuning.
- Add targeted secondary indexes with
STORINGcolumns so common queries avoid a base-table lookup. - Use interleaving for parent-child access patterns to cut cross-split reads.
- Check query plans via
EXPLAINin the console to catch full table scans hiding behind a missing index. - Prefer parameterized queries so Spanner can reuse cached query plans instead of re-optimizing each call.
- Batch reads using
Reador index range reads instead of issuing many single-row point queries in a loop.
Query tuning without fixing an underlying hot key rarely helps much, so it's worth confirming split-level metrics in Cloud Monitoring before assuming the query itself is the bottleneck.
More Related questions...