Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

sql server 2008 - query cost (relative to the batch)

Posted on 2012-08-21
7
Medium Priority
?
901 Views
Last Modified: 2012-08-26
hi experts, can you explain me
query cost (relative to the batch)
i attached image

this query is better
select *
from dbo.Data
where ADate > DATEADD(day, -1, GetDate())
go

but i do not understand:
query cost (relative to the batch)
queryCOSTrelativeBATCH.jpg
0
Comment
Question by:enrique_aeo
  • 3
  • 3
7 Comments
 
LVL 66

Assisted Solution

by:Jim Horn
Jim Horn earned 500 total points
ID: 38318938
Batch = the entire script that you're running
Query cost relative to the batch = the %age of time a single T-SQL statement runs vs. the time the entire script runs.

So ...  in your two-statement batch, the first query runs 34% of the total time, the second 66%
0
 
LVL 8

Assisted Solution

by:Crashman
Crashman earned 1500 total points
ID: 38318951
you must see the entire plan, if you put the mause pointer in front you will see more information, but in this case


If your batch (what you are executing within a given call) has one query then relative to that batch that query takes up 100% as it is the only query within that batch.

BEGIN
  SELECT * FROM table -- Will be 100% of batch
END

BEGIN
  SELECT * FROM table -- Will be 50% of batch
  SELECT * FROM table -- Will be 50% of batch
END

SELECT * FROM table -- Will be 100% of batch (implicit begin/end around it)

Open in new window


http://stackoverflow.com/questions/3191356/query-cost-relative-to-batch-is-100
0
 

Author Comment

by:enrique_aeo
ID: 38319978
I enable set statistics IO on
--query 1
Table 'Data'. Scan count 1, logical reads 1141,

--query 2
Table 'Data'. Scan count 1, logical reads 838

query2 is better, but i do not understand
Query cost relative to the batch = 66%
should not be less?
0
[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

 

Author Comment

by:enrique_aeo
ID: 38323235
please experts,
as I interpret the difference in percentages and the results of the statistics?
0
 
LVL 8

Assisted Solution

by:Crashman
Crashman earned 1500 total points
ID: 38323336
0
 

Author Comment

by:enrique_aeo
ID: 38323375
but in this case
0
 
LVL 8

Accepted Solution

by:
Crashman earned 1500 total points
ID: 38323453
As you read (suppous) one query take a more percent of 100% thats because this qiery read the entire table and the other use the index to read
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Integration Management Part 2

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question