Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8688207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:18:09+00:00 2026-06-12T23:18:09+00:00

i have a table on SQL Server with about 1 million rows. It has

  • 0

i have a table on SQL Server with about 1 million rows.
It has an ID (PK), a status (int) and a datetime column.
Also I’ve created an Index on the datetime column.

Now I’ve found out an effect, which I don’t understand.

SELECT status
FROM table
WHERE dateTime BETWEEN '2010-01-01T00:00:00' AND '2010-01-02T12:00:00'

This statement returns 3664 rows. It runs about 150ms and the execution plan shows that its doing an index seek with key lookup.

Now, if I change it as following (just change the hour from 12 to 13):

SELECT status
FROM table
WHERE dateTime BETWEEN '2010-01-01T00:00:00' AND '2010-01-02T13:00:00'

This statement returns 3667 rows. It runs about 600ms and the exuction plan shows that its using the primary key!

I just don’t understand it. For 3667 and more rows its always using the primary key, even if the seek is much faster.

Is there an explanation?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T23:18:11+00:00Added an answer on June 12, 2026 at 11:18 pm

    status is not included in the index on datetime so it needs to do key lookups for each matching row to retrieve this value.

    As the range grows (and hence number of lookups required) it estimates that it will be quicker just to scan the whole (covering) clustered index avoiding the lookups. Possibly incorrectly in your case. The point at which it switches from one plan to the other is known as the tipping point.

    You should check if the estimated vs actual number of rows is out of whack (perhaps some rows that would have matched the range have been deleted since the statistics were last updated).

    Or maybe the index scan is more expensive than the costing assumptions assume due to high levels of fragmentation or for some other reason the costing assumptions made do not reflect the actual relative performance in your environment.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edit: Im running SQL Server 2008 I have about 400,000 rows in my table.
I have a table in SQL Server 2005 which has a date time field.
I have a table in SQL Server 2005 with hundreds of rows with HTML
I have a table in SQL Server. This table has an image field and
I also have a very large table in SQL Server (2008 R2 Developer Edition)
My DB is SQL SERVER 2008 I have a large table with 100 million
I am talking about SQL Server 2008. I have table with three nvarchar columns.
I have SQL Server 2008 database with 2 tables: Table A has columns ID
I have a table about 10 million rows. We just imported it from another
I have some performance issues. I have a table with about 2 million rows.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.