Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Why would the same query use 2 different indexes based on date? Expand / Collapse
Author
Message
Posted Wednesday, October 20, 2010 10:53 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, November 12, 2010 3:26 PM
Points: 7, 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
Post #1008169
Posted Thursday, October 21, 2010 4:37 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 10:37 AM
Points: 5,575, Visits: 6,359
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 Administrator

Webpage: http://www.BrandieTarvin.net
LiveJournal Blog: http://brandietarvin.livejournal.com/
On LinkedIn!, Google+, and Twitter.

Freelance Writer: Shadowrun
Latchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.
Post #1008292
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse