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

  • Home
  • SEARCH
  • 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 6474223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:33:44+00:00 2026-05-25T06:33:44+00:00

I am using EntityFramework 4 to access a SQL Server 2008 database. One of

  • 0

I am using EntityFramework 4 to access a SQL Server 2008 database.

One of the SQL queries that the EF generates is having a behavior that I cannot explain.
The query is like this:

SELECT tableA.field1, tableA.field2, ...
FROM tableA join tableB on tableA.field1 = tableB.field1
WHERE
    tableA.field2 > '20110825'
    and tableA.field3 in ('a', 'b', 'c,')
    and tableB.field4 = 'xxx'

Where tableA.field2 is datetime not null, and the other fields are varchars.
tableA contains circa 1.5 million records, tableB contains circa 2 million records, and the query returns 1877 rows.

The problem is, it returns them in 86 seconds, and that time changes dramatically when I change the ‘20110825’ literal to older values.

For instance if I put ‘20110725’ the query returns 3483 rows in 35 milliseconds.

I found out in the execution plan that the difference between the two lies in the indexes SQL Server chooses to use depending on the date used to compare.

When it is taking time, the execution plan shows:

  • 50%: index seek on tableA.field2 (it’s a clustered index on this field alone)
  • 50%: index seek on tableB.field1 (non-unique, non-clustered index on this field alone)
  • 0%: join

When it is almost instantaneous, the execution plan shows:

  • 98%: index seek on tableA.field1 (non-unique, non-clustered index on this field alone)
  • 2%: index seek on tableB.field1 (non-unique, non-clustered index on this field alone)
  • 0%: join

So it seems to me that the decision of the optimizer to use the clustered index on tableA.field2 is not optimal.

Is there a flaw in the database design? In the SQL query?

Can I force in any way the database to use the correct execution plan?

  • 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-05-25T06:33:44+00:00Added an answer on May 25, 2026 at 6:33 am

    Given that you are using literal values and are only encountering the issue with recent date strings I would suspect you are hitting the issue described here and need to schedule a job to update your statistics.

    Presumably when they were last updated there were few or no rows meeting the '20110825' criteria and SQL Server is using a join strategy predicated on that assumption.

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

Sidebar

Related Questions

I'm trying to setup the Entity Framework with SQL Server 2008. I'm using Guids
So, I have an app that uses a SQL Server express db. I have
We been having some discussions on approaches to using the entity framework at work
I am working with VS 2010, Entity framework, SQl-Server 2005, ASP.Net web forms .
Here's my problem: I am creating a Blackberry application that access's my data via
I'm using Entity Framework O/R mapper from Microsoft and using entity classes (generated classes
I am using Entity Framework with my website. To improve performance, I have started
I have a problem with the following Linq query using Entity Framework: from o
When using the Entity Framework, does ESQL perform better than Linq to Entities? I'd
So, I am using the Linq entity framework. I have 2 entities: Content and

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.