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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:03:51+00:00 2026-05-13T13:03:51+00:00

In trying to determine what area of a large query i have is causing

  • 0

In trying to determine what area of a large query i have is causing performance problems i took three steps. Including the execution plan, setting time statistics to on and printing immediately before and after sections that i believe might cause a problem. Example:

print '1'
SELECT ID FROM Test
print '2'

When i look at my execution plan it says that a certain section is taking up a large percentage of the “cost”. When I compare this percentage to the elapsed time between my print '1' and print '2' it’s seems like there is no way that percentage is even close.

Is it a safe bet to rely on the printed values and the time statistics over the estimated cost? If it is, would it make sense for me to focus on areas that have a large elapsed time between printed values rather than the estimated costs?

  • 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-13T13:03:51+00:00Added an answer on May 13, 2026 at 1:03 pm

    If you only print ‘1’ and print ‘2’ then measure the time between when you see the message in your SSMS messages pane then you are falling victim of output buffering between the server and the client. The print '1' may not immediately sent back to the client, and SqlClient, ADO.Net and SSMS also do some buffering of their own. So overall you may see the ‘1’ in your SSMS results Messages panel way, way later than it actually occured. Much better is to print the time from getdate(), not just ‘1’. This way you take out the buffering from the equation and you can see in the message itself the time when the server executed the ‘print’, not the time when its output was displayed by SSMS.

    SET STATISTICS TIME ON will always be more accurate, but is sometimes difficult to understant to which statement exactly it reffers to.

    What I usualy do is something like this:

    declare @nowString varchar(100);
    declare @start datetime, @end datetime, @rc int, @elapsed int;
    
    set @start = getdate();
    
    select many, fields 
    from bigtable 
    join manytables on condition = complex 
    where matches = many
    order by wacky sort;
    
    set @rc = @@rowcount;
    set @end = getdate();
    set @elapsed = datediff(ms, @start, @end);
    set @nowString = cast(varchar(100), getdate(), 14);
    raiserror(N'%s: At select No 1. Selected %i rows in %i ms', 10, 1, %nowString, @rc, @elapsed);
    
    set @start = getdate();
    ...next select here...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to determine if a selected range is within a set area...
I'm trying to determine the working area of the desktop even when the taskbar
I'm trying to determine if a set of three columns on a table in
Trying to determine if it is possible to bind the SelectedValue of a ComboBox
I trying to determine display vertical size of my Blackberry Storm 2. I know,
I'm trying to determine if the current system is 32 or 64 bit. And
I am trying to determine if a phone is located in this polygon using
I'm trying to determine the iPhone user's location using a CLLocationManager and CLGeocoder. My
I'm trying to determine a rank for each key in a hash against the
I am trying to determine the correct RegEx syntax to perform the following. I

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.