Prev Next

Database / Google Spanner Database Interview questions

How does Spanner's query optimizer choose an execution plan?

Spanner's optimizer is cost-based: it evaluates candidate plans using table and index statistics, such as row counts and cardinality estimates, and picks the plan with the lowest estimated cost in terms of data scanned and rows processed.

Key inputs to that decision include which indexes exist and whether they're covering for the query's columns, whether a join can be satisfied by co-located interleaved data instead of a distributed join, and predicate selectivity, which determines whether filtering early via an index beats scanning the base table. Developers can inspect the chosen plan with EXPLAIN or the query plan visualizer in the console, and can nudge the optimizer using index hints (FORCE_INDEX) when it consistently picks a suboptimal plan, though this should be a last resort after confirming statistics and indexes are actually appropriate for the query.

What kind of optimizer does Spanner use?
How can a developer force a specific index when the optimizer picks a poor plan?

Invest now in Acorns!!! 🚀 Join Acorns and get your $5 bonus!
Acorns Logo

Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!

Earn passively and while sleeping

Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.

Robinhood Logo

Invest now!!! Get Free equity stock (US, UK only)!

Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.

The Robinhood app makes it easy to trade stocks, crypto and more.


Webull Logo

Webull! Receive free stock by signing up using the link: Webull signup.

More Related questions...

What is Google Cloud Spanner? What are the main features of Google Spanner? What is the purpose of TrueTime in Spanner? Define interleaved tables in Google Spanner? What is a Spanner instance? What are processing units in Google Spanner? Describe primary keys in Google Spanner schema design? What are the supported database dialects in Spanner? List the data types supported by Google Spanner? How do you create a database in Google Spanner? What is a secondary index in Spanner? Explain the purpose of splits in Spanner? What are mutations in Google Spanner? How do you apply schema changes in Spanner? What is the Spanner emulator? Why does Spanner use TrueTime for consistency? How does Spanner achieve external consistency? What is the difference between read-write and read-only transactions in Spanner? When should you use interleaved tables versus foreign keys? What happens when a hotspot occurs in Spanner? How is data partitioned across nodes in Spanner? Why should you avoid monotonically increasing primary keys? What is the difference between Spanner and Cloud SQL? How does Spanner handle schema changes without downtime? When would you choose bounded staleness over strong reads? How can you optimize query performance in Spanner? What is the difference between Data Boost and standard reads? Why do we use commit timestamps in Spanner tables? How does Spanner's query optimizer choose an execution plan? What is the difference between batch DML and partitioned DML? When should you use change streams in Spanner? How is fine-grained access control implemented in Spanner? Why doesn't Spanner support auto-incrementing primary keys? What is the difference between GoogleSQL and PostgreSQL dialects in Spanner? How do you troubleshoot high latency in Spanner queries? Explain the internal working of Paxos in Spanner replication? Explain the execution flow of a read-write transaction in Spanner? Explain the lifecycle of a split in Spanner? How does Spanner guarantee external consistency across regions? What happens internally when Spanner commits a distributed transaction? How can you optimize a multi-region Spanner configuration for latency? Which is better and why: multi-region or regional Spanner configuration for a global app? How does directed reads improve read latency in multi-region Spanner? Why is clock skew uncertainty critical to Spanner's TrueTime API? How do you troubleshoot transaction aborts in Spanner? Explain the internal working of the Spanner query execution engine? What happens when a leader region becomes unavailable in Spanner? How does Spanner implement point-in-time recovery internally? Explain the execution flow of a partitioned DML statement in Spanner? How can you optimize schema design to avoid hotspotting at scale?
Show more question and Answers...

Integration

Comments & Discussions