
Answer-first summary for fast verification
Answer: Create a table named Customers as a parent table. Create a table named Phones, and interleave this table into the Customer table. Create an index on the phone number field in the Phones table.
To allow efficient search by phone number in Cloud Spanner, the recommended approach is to model the one-to-many relationship using a separate table. Option D suggests creating a Phones table interleaved into Customers and adding an index on the phone number. Interleaving improves data locality, and the index enables fast lookups by phone number. While option C (using an array with an index) is technically possible, Cloud Spanner best practices favor separate tables for scalability and flexibility, especially when querying individual elements frequently. Arrays are suitable for small, static data, but a separate table with an index (as in D) is more robust for dynamic or larger datasets.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
How should you design a Cloud Spanner schema for a customer database that includes an array field for phone numbers while enabling phone number-based customer searches?
A
Create a table named Customers. Add an Array field in a table that will hold phone numbers for the customer.
B
Create a table named Customers. Create a table named Phones. Add a CustomerId field in the Phones table to find the CustomerId from a phone number.
C
Create a table named Customers. Add an Array field in a table that will hold phone numbers for the customer. Create a secondary index on the Array field.
D
Create a table named Customers as a parent table. Create a table named Phones, and interleave this table into the Customer table. Create an index on the phone number field in the Phones table.
No comments yet.