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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:21:38+00:00 2026-05-17T23:21:38+00:00

I was having a horrible time today trying to get a query to perform

  • 0

I was having a horrible time today trying to get a query to perform the way I would expect. I had to make a slight change to a table valued function that lives in the query yesterday and that change created a huge performance impact on the query. After evaluating the execution plan and looking at statistics IO and Time I found that because I changed the function to return a table variable instead of just a result set it was doing a full scan on one of the tables being queried.

My question is why would having it return the table (TableVariable) instead of just a Select / Result set cause such a big change to the plan?

Stumped….

  • 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-17T23:21:39+00:00Added an answer on May 17, 2026 at 11:21 pm

    Returning a Table Variable will make it a multi-statement table valued function and can be bad for performance due to the fact that it’s treated like a table except there are no statistics available for SQL Server to base a good execution plan on – so it will estimate the function as returning a very small number of rows. If it returns a larger number of rows, then therefore the plan generated could be a lot less than optimal.

    Whereas, returning just a SELECT makes it an inline table valued function – think of it more as a view. In this case, the actual underlying tables get brought into the main query and a better execution plan can be generated based on proper statistics. You’ll notice that in this case, the execution plan will NOT have a mention of the function at all as it’s basically just merged the function into the main query.

    There’s a great reference on it on MSDN by CSS SQL Server Engineers including (quote):

    But if you use multi-statement TVF,
    it’s treated as just like another
    table. Because there is no
    statistics available, SQL Server has
    to make some assumptions and in
    general provide low estimate. If your
    TVF returns only a few rows, it will
    be fine. But if you intend to
    populate the TVF with thousands of
    rows and if this TVF is joined with
    other tables, inefficient plan can
    result from low cardinality estimate.

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

Sidebar

Related Questions

So I'm trying to make the horrible leap from VB.NET to objective-C. My only
I've just suffered a horrible time of having my application freezing after a few
Having a heckuva time with this one, though I feel I'm missing something obvious.
This seems like such a simple task, but I'm having a hard time finding
I'm having a lot of trouble with a query. I don't really know how
Having problems figuring this out. trying to do a rescue_from NoMethodError, :with => :try_some_options
I'm having some trouble with a jquery script I'm writing, as I cannot get
Having been a PHP developer on LAMP servers for quite a while, is there
Having worked with Classic ASP for about 2 years now by creating a few
Having read the threads Is SqlCommand.Dispose enough? and Closing and Disposing a WCF Service

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.