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 334557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:03:54+00:00 2026-05-12T10:03:54+00:00

SQL Server 2008. I have this very large query which has a high cost

  • 0

SQL Server 2008. I have this very large query which has a high cost associated with it. TOAD has Query Tuning functionality in it and the only change made was the following:

Before:

LEFT OUTER JOIN (SELECT RIN_EXT.rejected, 
                               RIN_EXT.scar, 
                               RIN.fcreceiver, 
                               RIN.fcitemno 
                          FROM RCINSP_EXT RIN_EXT 
                               INNER JOIN dbo.rcinsp RIN 
                                  ON RIN_EXT.fkey_id = RIN.identity_column) RIN1 
         ON RCI.freceiver = RIN1.fcreceiver 
            AND RCI.fitemno = RIN1.fcitemno 
 WHERE RED.[YEAR] = '2009'

After:

LEFT OUTER JOIN (SELECT RIN_EXT.rejected, 
                               RIN_EXT.scar, 
                               RIN.fcreceiver, 
                               RIN.fcitemno 
                          FROM dbo.rcinsp RIN 
                               INNER JOIN RCINSP_EXT RIN_EXT 
                                  ON RIN.identity_column = COALESCE (RIN_EXT.fkey_id , RIN_EXT.fkey_id)) RIN1 
         ON RCI.freceiver = RIN1.fcreceiver 
            AND RCI.fitemno >= RIN1.fcitemno  -- ***** RIGHT HERE 
            AND RCI.fitemno <= RIN1.fcitemno
 WHERE RED.[YEAR] = '2009'

The field is a char(3) field and this is SQL Server 2008.

Any idea why theirs is so much faster than mine?

  • 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-12T10:03:55+00:00Added an answer on May 12, 2026 at 10:03 am

    You didn’t show the ON condition in the “Before” query, so I don’t know what TOAD changed. However, I’ll take a guess about what happened.

    The SQL Server query optimizer uses cost estimates to choose the query plan. The cost estimates are based on rowcount estimates. If the rowcount estimates are not accurate, the optimizer might not choose the best plan.

    Some rowcount estimates are typically accurate, like those of the form (column = value) for a column with statistics. However, some rowcount estimates can only be guessed at, like (column = othercolumn) if the columns aren’t related by a foreign key constraint, or (expression = value), where the expression isn’t trivial or involves more than one column.

    When statistics don’t guide a rowcount estimate, SQL Server uses generic estimates. If you compare the rowcount estimates in an estimated plan to the actual rowcounts in an actual plan, you can sometimes see the problem and “trick” the optimizer into changing its rowcount estimate.

    If you add predicates with AND that don’t actually restrict the results, you may lower the rowcount estimate if the optimizer can’t recognize that they are superfluous. Similarly, if you add predicates with OR that don’t actually yield additional results, you may raise the rowcount estimate.

    Perhaps here the rowcount estimate was too high, and the extra predicates are correcting them, resulting in better cost estimates for the plans being considered and a better plan choice in the end.

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

Sidebar

Ask A Question

Stats

  • Questions 230k
  • Answers 230k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer A couple of things to check: Make sure that your… May 13, 2026 at 2:03 am
  • Editorial Team
    Editorial Team added an answer The most direct way to get the data back to… May 13, 2026 at 2:03 am
  • Editorial Team
    Editorial Team added an answer Evgeny has a good idea with the smart_if template tag.… May 13, 2026 at 2:03 am

Related Questions

I've got a very large xml data set that is structured like the following:
Edit: Im running SQL Server 2008 I have about 400,000 rows in my table.
I've seen in Oracle 10g a feature that estimates the remaining time for a
First, from BOL : Queries that modify table variables do not generate parallel query

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.