Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Which query to be used if IO Stats are different but actual execution time on production is same.


Which query to be used if IO Stats are different but actual execution time on production is same.

Author
Message
T.Ashish
T.Ashish
Right there with Babe
Right there with Babe (767 reputation)Right there with Babe (767 reputation)Right there with Babe (767 reputation)Right there with Babe (767 reputation)Right there with Babe (767 reputation)Right there with Babe (767 reputation)Right there with Babe (767 reputation)Right there with Babe (767 reputation)

Group: General Forum Members
Points: 767 Visits: 582
Below are the IO Statistics for a query before and after optimization.

IO Stats are different but actual execution time on production is same for both the queries.

Now I want to go with optimized query but my manager want to revert the changes as there is no time gain.

What will be your choice in this case!!!


QUERY 1 I/O STATISTICS after Optimization
(20998 row(s) affected)
Table 'Worktable'. Scan count 0, logical reads 0, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'company'. Scan count 1, logical reads 1027, physical reads 0, read-ahead reads 1, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'person'. Scan count 1, logical reads 646153, physical reads 266, read-ahead reads 430590, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'worker'. Scan count 1, logical reads 24215, physical reads 0, read-ahead reads 50, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'buyer_supplier_contract'. Scan count 1, logical reads 140, physical reads 0, read-ahead reads 47, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.


QUERY 2 I/O STATISTICS before Optimization
(20998 row(s) affected)
Table 'buyer_supplier_contract'. Scan count 20998, logical reads 44642, physical reads 0, read-ahead reads 1, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'Worktable'. Scan count 0, logical reads 0, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'company'. Scan count 1, logical reads 1026, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'person'. Scan count 3, logical reads 1338694, physical reads 399, read-ahead reads 450197, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'worker'. Scan count 1, logical reads 24215, physical reads 0, read-ahead reads 16, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
TheSQLGuru
TheSQLGuru
SSCertifiable
SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)

Group: General Forum Members
Points: 5941 Visits: 8299
There are quite a few different things you can "tune" a query to "optimize/minimize": duration, IO, CPU, Memory, locking, etc. In your case it would seem that you have reduced IO (likely from eliminating nested loop activities) but kept duration roughly the same (likely from an increase in CPU usage to do HASH joins, but that is just an educated guess since you didn't provide the actual query plans).

If the CPU usage is higher on the new query then you can make a secondary decision that you want to minimize that, and thus revert back to the original.

Another consideration is concurrency/locking. One plan could cause many more blocks to occur than another and that could be the thing you need to minimize in a busy environment.

Good tuning takes a LOT of knowledge, experience, some art and even sometimes just plain dumb luck. I have 40000+ hours dealing with just the SQL Server relational engine and sometimes I would still rather be lucky than good!! Cool

Oh, another potential reason for reverting back to the original query: you hopefully have some reasonable certainty that it produces the correct results EVERY time. That may not be a true statement for the refactor - even if it is a "trivial" change. There are bugs and side-effects that present a tiny but non-zero chance of a regression.

Best,

Kevin G. Boles
SQL Server Consultant
SQL MVP 2007-2012
TheSQLGuru at GMail
T.Ashish
T.Ashish
Right there with Babe
Right there with Babe (767 reputation)Right there with Babe (767 reputation)Right there with Babe (767 reputation)Right there with Babe (767 reputation)Right there with Babe (767 reputation)Right there with Babe (767 reputation)Right there with Babe (767 reputation)Right there with Babe (767 reputation)

Group: General Forum Members
Points: 767 Visits: 582
Both queries are tested and giving proper results.
T.Ashish
T.Ashish
Right there with Babe
Right there with Babe (767 reputation)Right there with Babe (767 reputation)Right there with Babe (767 reputation)Right there with Babe (767 reputation)Right there with Babe (767 reputation)Right there with Babe (767 reputation)Right there with Babe (767 reputation)Right there with Babe (767 reputation)

Group: General Forum Members
Points: 767 Visits: 582
I have attached both queries for your reference. Execution plan could not be attached.

Do we have some other way to write these queries?
Attachments
query.doc (8 views, 16.00 KB)
GilaMonster
GilaMonster
SSC-Forever
SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)

Group: General Forum Members
Points: 47196 Visits: 44365
You can start by taking the nolock hints out.
See - http://blogs.msdn.com/b/davidlean/archive/2009/04/06/sql-server-nolock-hint-other-poor-ideas.aspx
Unless, of course, all the users know and accept that the data returned by the query can be wrong and are fine with that.

Will need to see the exec plan to advise any further.


Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


T.Ashish
T.Ashish
Right there with Babe
Right there with Babe (767 reputation)Right there with Babe (767 reputation)Right there with Babe (767 reputation)Right there with Babe (767 reputation)Right there with Babe (767 reputation)Right there with Babe (767 reputation)Right there with Babe (767 reputation)Right there with Babe (767 reputation)

Group: General Forum Members
Points: 767 Visits: 582
Gail,
Just ignore nolock in any of my posts (client policy).
I still need an answer.
GilaMonster
GilaMonster
SSC-Forever
SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)

Group: General Forum Members
Points: 47196 Visits: 44365
GilaMonster (5/16/2013)
Will need to see the exec plan to advise any further.



Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


lgegerton
lgegerton
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 26
Replace

LEFT JOIN (
SELECT
msp_flag,
bc_code
FROM
dbo.bs_contract(nolock)
GROUP BY
msp_flag,
bc_code
) F ON F.bc_code = C.comp_code
AND F.msp_flag = 1

with

LEFT JOIN dbo.bs_contract F (nolock)
ON F.bc_code = C.comp_code AND F.msp_flag = 1


Probably wont make any performance difference
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search