免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2421 | 回复: 0
打印 上一主题 下一主题

Autore-plan cached queries when table definitions change or stats updated [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-02-22 18:27 |只看该作者 |倒序浏览
最近从一位朋友那里得知在PG中使用绑定变量查询非常慢,不使用绑定变量的查询正常。
  在GreenPlum中:当WHERE条件中使用变量时间如now()时和静态时间如'2010-12-24'时执行计划不一致的情况(特指时间分区的分区表),不过这个已经在GreenPlum的release中有说明。
  PostgreSQL中到目前为止没有类似案例,因此怀疑是执行计划的问题,(postgresql 8.4以后可以跟踪到SQL的执行计划信息,需修改参数)

Automatically re-plan cached queries when table definitions change or statistics are updated
  这句话来自PostgreSQL 8.3 Release Notes
当表的定义或统计信息改变时,cached queries将重新生成执行计划。
届时影响绑定变量的SQL。此时可能改变执行计划,出现和以前执行计划不一致的情况,严重的影响数据库性能。
如果绑定变量的SQL出现执行计划不正常,建议重新生成统计信息。

另外可以通过discard命令释放CACHE资源(仅仅针对当前SESSION)

DISCARD { ALL | PLANS | TEMPORARY | TEMP }

Description

DISCARD releases internal resources associated with a database session. These resources are normally released at the end of the session.

DISCARD TEMP drops all temporary tables created in the current session. DISCARD PLANS releases all internally cached query plans. DISCARD ALL resets a session to its original state, discarding temporary resources and resetting session-local configuration changes.

例如

Releases all temporary resources associated with the current session and resets the session to its initial state. Currently, this has the same effect as executing the following sequence of statements:

SET SESSION AUTHORIZATION DEFAULT;
RESET ALL;
DEALLOCATE ALL;
CLOSE ALL;
UNLISTEN *;
SELECT pg_advisory_unlock_all();
DISCARD PLANS;
DISCARD TEMP;
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP