Suppose I have table in my DB schema called TEST with fields (id, name, address, phone, comments). Now, I know that I’m going to perform a large set of different queries for that table, therefore my question is next, when and why I shall create indexes like ID_NAME_INDX (index for id and name) and when it’s more efficient to create separately index for id and index for name field(by when I mean for what type of query)?
Share
The general aim would be to “cover” all columns so the query only has to use the index.
Say you need name and indx but have separate indexes. You’ll end up with a bookmark lookup from the index to the PK to get the other columns (assuming it doesn’t just scan the PK)
Edit, after 1st comment:
For this query, the SELECT * but mitigates against any index so the PK would be used.
If you had:
then an index on ID, name including address would “cover” it.
Using “OR” creates difficulties for any strategy. However,
would still use the “ID, name including address” inex most likely but scan it rather that seek
Read this: Execution Plan Basics