SQL Server查询执行过程
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
1.4.query execution phase
本文作者:KiGiBoy
本文链接:https://www.cnblogs.com/ls11736/p/13628096.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
分类:
MSSQL
, SQL Server
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步