SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Why would the same query use 2 different indexes based on date?


Why would the same query use 2 different indexes based on date?

Author
Message
RICHTER-311234
RICHTER-311234
SSC Rookie
SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)

Group: General Forum Members
Points: 41 Visits: 55
SO a client calls in with a problem that has started happening recently and as it turns out the problem seems to be date related. I have a SQL database obviously, and a table with several indexes on the table. I have 2 queries that are setup exactly the same, except the date range specified does vary.

When the date range is older then it will use one index, which is super fast. When the date range is newer, it will use a different index which is much slower.

The query is hitting 2 seperate tables, however the date is only found in one table.

So the question for me is what would make the query switch which index it was going to use?

I have rebuilt the index and ran a updatestats full on the index I am wanting both queries to use, Just a bit at a loss as to what to look at?

Any help is appreciated!!!

Thanks,

Richtoss
Brandie Tarvin
Brandie Tarvin
SSC-Dedicated
SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)

Group: General Forum Members
Points: 39418 Visits: 9291
RICHTER-311234 (10/20/2010)
I have rebuilt the index and ran a updatestats full on the index I am wanting both queries to use, Just a bit at a loss as to what to look at?


And did it help or is it still doing the same thing?

If the later, please post table & index creation statements in addition to the two queries being used. (EDIT: And tell us, please, which index is being used for which query). Also, have you looked at the execution plan for both queries? I bet that would tell us the answer to your question.

Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search