简体   繁体   English

Sql Server是否缓存了跨事务的编译查询和执行计划?

[英]Does Sql Server cached compiled queries and execution plan across transactions?

Folks, 伙计们,

I'm using the best-practice of prepared sql statements to execute many Inserts/Updates that vary by the same parameters. 我正在使用准备好的sql语句的最佳实践来执行许多因相同参数而异的插入/更新。 I have two choices in my design: 1. all of the work gets done in a single transaction. 我的设计有两个选择:1。所有工作都在一次交易中完成。 2. break-up the work into a number of transactions (not one per statement, but something that suits the concurrency of my environment). 2.将工作分解为多个事务(不是每个语句一个,而是适合我的环境的并发性)。 If I opt for #2, will SQL take advantage of the cached compiled query/execution plan across transactions? 如果我选择#2,SQL是否会利用跨事务的缓存编译查询/执行计划? Or, because the query was made within a transaction, the life of the cache will be limited to the transaction? 或者,因为查询是在事务中进行的,所以缓存的生命周期将仅限于事务?

Plans are unrelated to transactions. 计划与交易无关。 Or connections for that matter 或者就此而言的联系

That is, a plan can be shared by many txns and/or users and/or connections. 也就是说,许多txns和/或用户和/或连接可以共享计划。 And at different times if the plan is valid and still in cache 如果计划有效且仍在缓存中,则在不同时间

查询缓存独立于事务,因此无论您选择哪个选项,您的查询都将被缓存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM