Quantcast
Channel: Forum SQL Server Database Engine
Viewing all articles
Browse latest Browse all 15889

different "estimated rows" in execution plan with "same" query

$
0
0

Hi all,

currently it's snowing outside and I wanted to optimize one of my databases. Within these optimizations I found a quite currious behaviour which I don't really understand. I have a relation which i query two times - basically - the same time. The query is as follows:

-- First query with usage of parameter
SELECT	SId, SName1
FROM	dbo.tbl_Stammdaten
WHERE	Category = @condition

-- Second query with usage of fixed value
SELECT	SId, SName1
FROM	dbo.tbl_Stammdaten
WHERE	Category = 'FRM'

SET STATISTICS XML OFF;
SET STATISTICS IO OFF;

When I have a look to the execution plan I'm wondering about ONE difference I can not really understand.

As you can see the plan is using - as expected - the created index. But... If i compare the estimated record both queris differ from each other.
The first query which is using the variable as filter has a higher value (app. 72 records) instead of 23 records which will be the estimated (and retrieved) records from the second query.

Please note: It is not a problem - I want to understand WHY the usage of the variable has a higher estimated record count.
That's the reason why i've marked this thread as a discussion thread instead of a problem.

To replay the problem you can download the t-sql script as ZIP from the following location:

http://www.db-berater.de/Files/executionplan_demo.zip


Uwe Ricken

MCITP Database Administrator 2005
MCITP Database Administrator 2008
MCITP Microsoft SQL Server 2008, Database Development

db Berater GmbH
http://www-db-berater.de
SQL Server Blog (german only)


Viewing all articles
Browse latest Browse all 15889

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>