Why prepared statements are managed by each session?

为什么准备好的语句由每个会话管理?

I am not sure all of databases handle prepared statements per session. but postgresql and mysql(maybe) do.

我不确定每个会话中所有的数据库都要处理准备好的语句。但是postgresql和mysql(也许)可以。

Why they are not shared between session? Is there any reason?

为什么它们不在会话之间共享?有什么原因吗?

For example, There are many connections in connection pool and connections share same queries and also generate same prepared statements. Why database does not let connections share prepared statement?

例如,连接池中有许多连接,连接共享相同的查询并生成相同的准备语句。为什么数据库不允许连接共享准备好的语句?

1 个解决方案

#1


2

Maintaining any shared cache is expensive - you should to protect cache against race condition, you should to clean cache, ... This is first argument. Second argument is more important - prepared statement is cached execution plan - but this plan is optimized for one vector of parameters. When you are using different parameter's vector, then plan can be suboptimal again this vector. There is a philosophy, so any user can uses different vectors and then needs different plans. Using session shared plan cache doesn't eliminate overhead from generating plans (although this overhead is for fast simple queries minimal), but eliminates overhead and race conditions related to management of shared data, and partially reduce risk of using suboptimal prepared plans.

维护任何共享缓存都是昂贵的——您应该保护缓存不受竞争条件的影响,您应该清理缓存,……这是第一个参数。第二个参数更重要——准备好的语句是缓存的执行计划——但是这个计划是针对一个参数向量进行优化的。当你使用不同参数的向量时,那么这个向量也可以是次优的。有一种哲学,所以任何用户都可以使用不同的向量,然后需要不同的计划。使用会话共享计划缓存并不会消除生成计划的开销(尽管这种开销对于快速简单查询来说是最小的),但是会消除与共享数据管理相关的开销和竞争条件,并在一定程度上降低使用次优准备计划的风险。

更多相关文章

  1. 获取项目列表的更好方法:缓存序列化数据与数据库查询或其他?
  2. 如何在Safari浏览器中禁用Ajax缓存?
  3. 是否可以知道文件是否在用户的浏览器缓存中?
  4. 每次部署站点时,如何使用Google App Engine清除内存缓存?
  5. 在需要缓存的时候,谨慎使用python的负下标
  6. MEMCACHED缓存及状态查看
  7. 从QQ浏览器缓存文件中提取出完整的视频
  8. Linux缓存相关知识整理(史上最全!!)
  9. repcached与mysql缓存測试

随机推荐

  1. 关于android在Service中弹出Dialog对话框
  2. Professional Android 2 Development - 6
  3. Android 异步任务加载图片代码
  4. Android USB挂载
  5. Android中Log信息的输出方法
  6. sqlite数据库默认自增标号RecNo与integer
  7. 安卓Android大量项目源码实例
  8. 在4.0以上系统中应用出现2.3版本的系统UI
  9. 2013.07.11——— android MediaRecorder
  10. Android编码规范