1.查询过程
1.1.query parse
确认语法是否正确
1.2.query binding
确认对象(表,列等)是否正确
1.3.query optimization
生成执行计划,大多数会生成full cost-based plan(完全基于成本的),少部分生成trivial plan()
基于成本的计划需要3个条件
- Query processor tree
- statistics
统计信息影响到基数,选择性,其由以下部分组成
1.the header – general data about a given set of statistics
2.the density graph – the selectivity, uniqueness, of the data, and, most importantly
3.a histogram – a tabulation of counts of the occurrence of a particular value, taken from
up to 200 data points that are chosen to best represent the complete data in the table.
内存压力或执行计划长期未被使用被新的计划挤出plan cache,手动执行下面的命令也会导致释放plan cache
sys.dm_exec_query_stats sql_handle和plan_handle
dbcc freeproccache(<plan_handle>)
DBCC FLUSHPROCINDB(db_id)
- Constraints