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

  • 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

  • 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/[/url]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.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply