官术网_书友最值得收藏!

Parameter sniffing

Given that query plan reuse is so important, why wouldn't SQL Server parameterize every query that comes in by default? One of the reasons is to avoid query performance issues that may result from parameter sniffing. Parameter sniffing is something SQL Server does in order to optimize a parameterized query. The first time a stored procedure or other parameterized query executes, the input parameter values are used to drive the optimization process and produce the execution plan, as discussed in the Query optimization essentials section.

That execution plan will then be cached and reused by subsequent executions of the procedure or query. For most queries, this is a good thing because using a specific value will result in a more accurate cost estimation. In some situations, however, particularly where the data is skewed in some way, the parameters that are sent the first time the query is executed may not represent the typical use case of the query, and the plan that is generated may perform poorly when other parameter values are sent. This is a case where reusing a plan might not be a good thing.

Parameter sniffing is a very common cause of plan variability and performance issues in SQL Server. We will discuss this behavior in more detail in Chapter 6, Easily Identified T-SQL Anti-Patterns, and Chapter 7, Discovering T-SQL Anti-Patterns in Depth.

主站蜘蛛池模板: 高唐县| 方山县| 华蓥市| 城固县| 化隆| 科技| 离岛区| 临夏市| 额敏县| 博客| 龙川县| 军事| 崇仁县| 长海县| 镇远县| 新泰市| 河西区| 冷水江市| 许昌市| 阿瓦提县| 义马市| 手游| 镇原县| 高州市| 梅河口市| 富民县| 方山县| 井研县| 清水县| 西藏| 阿拉善盟| 漳平市| 宾川县| 西乌珠穆沁旗| 双峰县| 丹棱县| 英山县| 金堂县| 来凤县| 枣庄市| 蚌埠市|