HestonJames
Programmer
Hello Guys,
I thought I'd ask your advice on this one, quite commonly within my applications I'll have a query which has optional WHERE clauses in it, so sometimes the query is executed looking like this:
This is not the real query, I'm using it simply for demonstration purposes to give us a nice generic scenario. Other times the query will be run like this:
And thirdly it might be run with both clauses, like so:
Now, suppose I want to place an index on this table to increase the performance of these queries. Will a single index on both the FirstName and LastName Columns suffice? or should I create 3 separate indexes, one for FirstName, one for LastName and one for Both?
My initial gut feeling is that it'll need all three indexes, just wanted to come on an clarify it.
Thanks for any advice on how to tackle this kind of scenario.
Heston
I thought I'd ask your advice on this one, quite commonly within my applications I'll have a query which has optional WHERE clauses in it, so sometimes the query is executed looking like this:
Code:
Select Username
From Users
Where FirstName = 'Dave'
This is not the real query, I'm using it simply for demonstration purposes to give us a nice generic scenario. Other times the query will be run like this:
Code:
Select Username
From Users
Where LastName = 'Smith'
And thirdly it might be run with both clauses, like so:
Code:
Select Username
From Users
Where FirstName = 'Dave'
And LastName = 'Smith'
Now, suppose I want to place an index on this table to increase the performance of these queries. Will a single index on both the FirstName and LastName Columns suffice? or should I create 3 separate indexes, one for FirstName, one for LastName and one for Both?
My initial gut feeling is that it'll need all three indexes, just wanted to come on an clarify it.
Thanks for any advice on how to tackle this kind of scenario.
Heston