QuestionQ378

Integrating applications with Google Cloud services

You are designing a schema for a Cloud Spanner customer database. You need to store an array field of phone numbers in a customer table, while also allowing users to search for customers by phone number.

How should this schema be designed?

  • 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.
Explanation

Cloud Spanner ARRAY columns cannot be index key columns, and arrays are not intended for access to individual elements. Storing each phone number as a scalar value in a Phones child table allows a secondary index on that value for customer lookups. Interleaving the child table under Customers is an appropriate parent-child data model that colocates each customer’s phone records with the customer row.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!