A user runs the above command and expects a row to be returned because the user exists. Which index is missing?
Exhibit
gcloud spanner databases execute-sql my-db --sql="SELECT * FROM Users WHERE Email = 'test@example.com'" --- Output: (empty)
Trap 1: Primary key index on Users(Email)
A primary key index on Users(Email) would be useful but is not required; the query would still find the row via a full table scan.
Trap 2: Index on Users(Email)
An index on Users(Email) would speed up the query but its absence does not prevent the row from being returned; a full table scan will find it.
Trap 3: Composite index on Users(Email, UserId)
A composite index on Users(Email, UserId) is overkill for a single equality condition; not needed.
- A
Primary key index on Users(Email)
Why wrong: A primary key index on Users(Email) would be useful but is not required; the query would still find the row via a full table scan.
- B
Index on Users(Email)
Why wrong: An index on Users(Email) would speed up the query but its absence does not prevent the row from being returned; a full table scan will find it.
- C
Composite index on Users(Email, UserId)
Why wrong: A composite index on Users(Email, UserId) is overkill for a single equality condition; not needed.
- D
No index needed, query scans full table.
No index is needed because a full table scan will correctly return the existing row. This is the correct answer.