I study indexes and try to understand how they work, and how I can use them to improve performance, but I'm missing something.
I have the following table:
Person
| Id | Name | Email | Phone |
| 1 | John | E1 | P1 |
| 2 | Max | E2 | P2 |
I am trying to find a better way to index columns Emailand Phoneconsidering that the queries will (most of the time) look like
[1] SELECT * FROM Person WHERE Email = '...' OR Phone = '...'
[2] SELECT * FROM Person WHERE Email = ...
[3] SELECT * FROM Person WHERE Phone = ...
I thought the best approach is to create a single index using both columns:
CREATE NONCLUSTERED INDEX [IX_EmailPhone]
ON [dbo].[Person]([Email], [PhoneNumber]);
However, with the above index, only the query [2] benefits from the index search, while others use index scanning.
I also tried to create several indexes: one with both columns, one for email and one for email. In this case, [2] and [3] use the search, but [1] continues to use the scan.
? ?