Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query cost relative to batch is 100%

I'm not sure sure how to interpret this, but all the queries I run in sql server 2005 have a "query cost (relative to batch)" of 100%. Is there any way to reduce the cost?

like image 462
chobo Avatar asked Jul 07 '10 01:07

chobo


People also ask

What does query cost relative to the batch mean?

The cost relative to the batch is just comparing the cost estimates of each statement within the batch. That's all. It's not itself a measure as much as it's a comparison of other measures. As a comparison, it's useful.

How is query cost calculated?

To estimate the cost of a query evaluation plan, we use the number of blocks transferred from the disk, and the number of disks seeks. Suppose the disk has an average block access time of ts seconds and takes an average of tT seconds to transfer x data blocks.

What is query cost in execution plan?

Every query has a cost, which SQL Server records in the Execution Plan. This is the cost assigned to the query by the optimizer. While troubleshooting query performance in SQL Server, it is crucial to be are aware of this cost. In many cases, queries are sorting and hashing as a result of internal operations.

What is cost of a query?

Query Cost is a cost in which the enhancer considers what amount of time your query will require (comparative with absolute clump time).


2 Answers

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.

I.e.:

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)
like image 163
Matt Mitchell Avatar answered Sep 27 '22 22:09

Matt Mitchell


As long as there is only one query in your batch, it's cost relative to the batch will always be 100%. If you have more than one query in the batch, they will add up to 100%.

The percentage only shows how queries in the batch relate to each other, it's not an absolute measure of the cost. Even if the cost is minimal, it's still always 100%.

like image 24
Guffa Avatar answered Sep 27 '22 22:09

Guffa