- Learn T-SQL Querying
- Pedro Lopes Pam Lahoud
- 263字
- 2021-06-24 14:38:15
To cache or not to cache
In general, caching and reusing query plans is a good thing, and writing T-SQL code that encourages plan reuse is recommended.
In some cases, such as with a reporting or Online Analytic Processing (OLAP) workloads, caching queries might make less sense. These types of systems tend to have a heavy ad hoc workload. The queries that run are typically long-running and, while they may consume a large quantity of resources in a single execution, they typically run with less frequency than OLTP systems. Since these queries tend to be long-running, saving a few hundred milliseconds by reusing a cached plan doesn't make as much sense as creating a new plan that is designed specifically to execute that query. Spending that time compiling a new plan may even result in saving more time in the long run, since a fresh plan will likely perform better than a plan that was generated based on a different set of parameter values.
In summary, for most workloads in SQL Server, leveraging stored procedures and/or parameterized queries is recommended to encourage plan reuse. For workloads that have heavy ad hoc queries and/or long-running reporting-style queries, consider enabling the Optimize for Ad hoc Workloads server setting and leveraging the RECOMPILE hint to guarantee a new plan for each execution (provided that the queries are run with a low frequency). Also, be sure to review Chapter 8, Building Diagnostic Queries Using DMVs and DMFs, for techniques to identify single-use plans, monitor for excessive recompilation, and identify plan variability and potential parameter-sniffing issues.
- Big Data Analytics with Hadoop 3
- 繪制進程圖:可視化D++語言(第1冊)
- 21小時學(xué)通AutoCAD
- 西門子PLC與InTouch綜合應(yīng)用
- 實時流計算系統(tǒng)設(shè)計與實現(xiàn)
- Visual C# 2008開發(fā)技術(shù)實例詳解
- Apache Hive Essentials
- 自動化控制工程設(shè)計
- Flink原理與實踐
- 基于敏捷開發(fā)的數(shù)據(jù)結(jié)構(gòu)研究
- 單片機技術(shù)項目化原理與實訓(xùn)
- FANUC工業(yè)機器人配置與編程技術(shù)
- 機器人剛?cè)狁詈蟿恿W(xué)
- 伺服與運動控制系統(tǒng)設(shè)計
- Keras Reinforcement Learning Projects