Inside the SQL Server Query Optimizer - part 3 Cardinality estimation
Hi guys! After the simplification phase discussed in the last article, today we will speak about another fundamental step called Cardinality Estimation . During this step the optimizer try to predict the number of rows returned by each node of the execution plan. As you can imagine this is a step of primary importance because a good prediction generate an accurate execution plan with a lower processing cost to execute. The statistics In order to estimate the number of rows returned by a query the Cardinality Estimator use so called statistics . By default for each column and each index created, SQL Server create it's relative statistic. But what is a statistic? A statististic for query optimization is a binary large object called BLOBs that contain statistical information about the distribution of values for one o more columns of a table. We can observe statistics through the T-SQL command: DBCC SHOW_STATISTICS ( <TABLE> , <FIELD_NAME> ...