You are designing a schema for a Cloud Spanner customer database. You want to store a phone number array field in a customer table. You also want to allow users to search customers by phone number. How should you design this schema?
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.
Correct answer is C, as in the question states: "You want to store a phone number array field in a customer table". So... adding the phone number as array field and adding a secondary index should be the best option in this case.
i say B, because if a user has more numbers you are storing the same user multiple times each time changing the phone number.
Having a second table for phone numbers and having a foreign key that points to the user with this phone number avoid this duplication problem.
The best approach is 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.
Here's why:
Interleaved Tables: Interleaved tables in Cloud Spanner are designed for efficient storage and retrieval of related data. By interleaving the Phones table into the Customers table, you ensure that data for a specific customer is stored together, improving query performance.
Indexing for Search: Creating an index on the phone number field in the Phones table allows for efficient searching of customers based on their phone numbers. This is crucial for your requirement to allow users to search customers by phone number.
Scalability: This approach scales well as your customer database grows. Cloud Spanner automatically handles the distribution and scaling of data across multiple nodes.
Let's look at why the other options are less suitable:
A. Create a table named Customers. Add an Array field in a table that will hold phone numbers for the customer. This approach is inefficient for searching. You would need to scan the entire array field for each customer, which can be slow for large datasets.
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. This approach is less efficient than interleaving. You would need to join the Customers and Phones tables for every search, which can be slower than using interleaved tables.
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. Cloud Spanner doesn't support secondary indexes on array fields.
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.
This design will allow you to store multiple phone numbers for each customer and efficiently search for customers by their phone numbers. In Cloud Spanner, tables can be interleaved, which means that the child table's rows are co-located with the parent table's rows. This setup can offer better performance for certain types of queries and data models, especially when there's a strong relational structure.
The correct answer is D. You should create a table named Customers as a parent table and a table named Phones, and interleave this table into the Customer table. You should also create an index on the phone number field in the Phones table. This allows you to store the phone number array field in the Customers table and search for customers by phone number using the index on the Phones table.
D seems quite nice, but what do u thing about statement "You want to store a phone number array field in a customer table.", and interleave in another table, not customer one.
In sql there is array field, and using UNNEST function is possible to filter records based on array, then answer A
https://cloud.google.com/spanner/docs/schema-design#creating-indexes:
"bad idea to create non-interleaved indexes on columns whose values are monotonically increasing or decreasing"
Since phone numbers monotonically increase/decrease, I would take D as the answer
https://cloud.google.com/spanner/docs/data-types -->can't set secondary index in array
so I vote D
upvoted 4 times
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
dendut
Highly Voted 3 years, 10 months agoStelSen
3 years, 9 months agofosky94
Highly Voted 3 years, 7 months agomastodilu
3 years, 6 months agothewalker
Most Recent 4 months, 1 week agothewalker
4 months, 1 week agosantoshchauhan
8 months, 3 weeks ago__rajan__
1 year, 2 months agoomermahgoub
1 year, 10 months agoomermahgoub
1 year, 10 months agotomato123
2 years, 3 months agoakshaychavan7
2 years, 4 months agokeshav1
2 years, 5 months agoKsamilosb
2 years, 9 months agoParagSanyashiv
2 years, 10 months agosyu31svc
3 years, 4 months agoyuchun
3 years, 5 months ago