SQL运行引擎会从pg_stats、pg_class等相关系统字典表、视图获取生成最佳运行计划的数据,假设相关字典视图的数据不准确就没有办法生成良好的运行计划。

发现下面Bug一枚。

0. 插入数据之后,新创建的索引不会自己主动更新收集索引的pg_class.relpages\pg_class.reltuples信息。

1. 对一个表,当运行UPDATE\DELETE之后,对表运行VACUUM FULL(首次)操作之后,pg_class.relpages\pg_class.reltuples两个字段的信息是不对的。得到的结果为运行DDL之前的数据;

2. 对一个索引运行REINDEX INDEX之后,pg_class.relpages\pg_class.reltuples信息会被清空;



第1个问题在新版本号得到修复;对于第0、2个问题没有不论什么改进,貌似默认情况就是这样。

[gpadmin@wx60 ~]$ psql gtlions
psql (8.2.15)
Type "help" for help. gtlions=# select version();
version
------------------------------------------------------------------------------------------------------------------------------------------------------
PostgreSQL 8.2.15 (Greenplum Database 4.2.7.2 build 1) on x86_64-unknown-linux-gnu, compiled by GCC gcc (GCC) 4.4.2 compiled on Feb 25 2014 18:05:04
(1 row)
gtlions=# create table test(id int,name varchar(200));
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'id' as the Greenplum Database data distribution key for this table.
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
CREATE TABLE
gtlions=# insert into test select generate_series(1,10000),generate_series(1,10000)||'-asfd';
INSERT 0 10000
gtlions=# create index idxtestid on test(id);
CREATE INDEX
gtlions=# select relname,relpages,reltuples from pg_class where relname like '%test%';
relname | relpages | reltuples
-----------+----------+-----------
test | 14 | 10000
idxtestid | 0 | 0
(2 rows) gtlions=# vacuum full test;
NOTICE: 'VACUUM FULL' is not safe for large tables and has been known to yield unpredictable runtimes.
HINT: Use 'VACUUM' instead.
VACUUM
gtlions=# select relname,relpages,reltuples from pg_class where relname like '%test%';
relname | relpages | reltuples
-----------+----------+-----------
test | 14 | 10000
idxtestid | 12 | 10000
(2 rows) gtlions=# select relname,relpages,reltuples from pg_class where relname like '%test%';
relname | relpages | reltuples
-----------+----------+-----------
test | 14 | 10000
idxtestid | 12 | 10000
(2 rows) gtlions=# update test set name='asdfasfdf';
UPDATE 10000
gtlions=# select relname,relpages,reltuples from pg_class where relname like '%test%';
relname | relpages | reltuples
-------------+----------+-----------
test | 14 | 10000
idxtestid | 12 | 10000
idxtestname | 14 | 10000
(3 rows) gtlions=# vacuum full test;
NOTICE: 'VACUUM FULL' is not safe for large tables and has been known to yield unpredictable runtimes.
HINT: Use 'VACUUM' instead.
VACUUM
gtlions=# select relname,relpages,reltuples from pg_class where relname like '%test%';
relname | relpages | reltuples
-------------+----------+-----------
test | 14 | 10000
idxtestid | 36 | 20000
idxtestname | 61 | 20000
(3 rows) gtlions=# analyze test
gtlions-# ;
ANALYZE
gtlions=# select relname,relpages,reltuples from pg_class where relname like '%test%'; relname | relpages | reltuples
-------------+----------+-----------
test | 14 | 10000
idxtestid | 18 | 10000
idxtestname | 32 | 10000
(3 rows) gtlions=# delete from test where id<=10000;
DELETE 10001
gtlions=# vacuum full test;
NOTICE: 'VACUUM FULL' is not safe for large tables and has been known to yield unpredictable runtimes.
HINT: Use 'VACUUM' instead.
VACUUM
gtlions=# select relname,relpages,reltuples from pg_class where relname like '%test%';
relname | relpages | reltuples
-------------+----------+-----------
test | 14 | 10000
idxtestid | 56 | 20000
idxtestname | 92 | 20000
(3 rows) gtlions=# vacuum full test;
NOTICE: 'VACUUM FULL' is not safe for large tables and has been known to yield unpredictable runtimes.
HINT: Use 'VACUUM' instead.
VACUUM
gtlions=# select relname,relpages,reltuples from pg_class where relname like '%test%';
relname | relpages | reltuples
-------------+----------+-----------
test | 14 | 10000
idxtestid | 28 | 10000
idxtestname | 46 | 10000
(3 rows) gtlions=# reindex index idxtestid;
REINDEX
gtlions=# reindex index idxtestname;
REINDEX
gtlions=# select relname,relpages,reltuples from pg_class where relname like '%test%';
relname | relpages | reltuples
-------------+----------+-----------
test | 14 | 10000
idxtestid | 0 | 0
idxtestname | 0 | 0
(3 rows) gtlions=# analyze test;
ANALYZE
gtlions=# select relname,relpages,reltuples from pg_class where relname like '%test%';
relname | relpages | reltuples
-------------+----------+-----------
test | 14 | 10000
idxtestid | 12 | 10000
idxtestname | 14 | 10000
(3 rows)

-EOF-

Index statistics collected bug的更多相关文章

  1. 译:Missing index DMV的 bug可能会使你失去理智---慎重看待缺失索引DMV中的信息

    注: 本文译自https://www.sqlskills.com/blogs/paul/missing-index-dmvs-bug-that-could-cost-your-sanity/ 原文作者 ...

  2. 译:SQL Server的Missing index DMV的 bug可能会使你失去理智---慎重看待缺失索引DMV中的信息

    注: 本文译自https://www.sqlskills.com/blogs/paul/missing-index-dmvs-bug-that-could-cost-your-sanity/ 原文作者 ...

  3. Index & Statistics ->> Rebuild Index会不会覆盖原先Index的WITH选项设置

    昨天因为工作中遇到要对某个数据库的表通通启用data_compression,突然有个念头,就是如果我当初用"ALTER INDEX XXX ON YYY REBUILD WITH (DAT ...

  4. Oracle 11.1.0.6 导入导出bug

    实验环境: 11.1.0.6.0   对ANONYMOUSUSER_ALL表中分区进行备份 SQL> select TABLE_NAME,PARTITION_NAME,HIGH_VALUE,PA ...

  5. 记录一次bug解决过程:git深入学习和JDK8新特性

    一 总结 熟悉廖雪峰git基础; 由于git跟踪的是修改,而不是版本号:因此对于修改撤销的操作,文件在eclipse中依旧有>修改标记,这点不同于svn. 二 BUG描述:熟悉Git基础 在Gi ...

  6. FAQ: Automatic Statistics Collection (文档 ID 1233203.1)

    In this Document   Purpose   Questions and Answers   What kind of statistics do the Automated tasks ...

  7. 【技巧性(+递归运用)】UVa 1596 - Bug Hunt

    In this problem, we consider a simple programming language that has only declarations of onedimensio ...

  8. 一个疑难bug的解决过程

    一个crontab脚本,下载一个文件并把内容入mysql数据库.具体流程如下: 1, wget一个文件. 2,处理文件生成一个中间文件. 3,将中间文件load入库. 05 10 * * * /hom ...

  9. 转:MySQL InnoDB Add Index实现调研

    MySQL InnoDB Add Index实现调研 MySQL Add Index实现 MySQL各版本,对于add Index的处理方式是不同的,主要有三种: Copy Table方式 这是Inn ...

随机推荐

  1. HTML <section> 标签

    实例 文档中的区段,解释了 PRC: <section>   <h1>PRC</h1>   <p>The People's Republic of Ch ...

  2. RocketMQ学习笔记(15)----RocketMQ的消息模式

    在前面学习ActiveMQ时,看到ActiveMQ可以是队列消息模式,也可以是订阅发布模式. 同样,在RocketMQ中,也存在两种消息模式,即是集群消费模式和广播消费模式. 1. 集群消费模式 跟A ...

  3. C++算法库学习__std::sort__对 vector进行排序_排序后就可以进行使用std::lower_bound进行二分查找(查找第一个大于等于指定值的迭代器的位置)__std::unique

    std::sort      对vector成员进行排序; std::sort(v.begin(),v.end(),compare);   std::lower_bound 在排序的vector中进行 ...

  4. JS中的let和var的区别

    最近很多前端的朋友去面试被问到let和var的区别,其实阮一峰老师的ES6中已经很详细介绍了let的用法和var的区别.我简单总结一下,以便各位以后面试中使用. ES6 新增了let命令,用来声明局部 ...

  5. Appium 的xpath定位

    Appium 的xpath定位 1.如果元素text是唯一的,可以通过text文本定位 //*[@text=’text文本属性’] # 定位text driver.find_element_by_xp ...

  6. 剑指offer---最小的K个数

    题目:最小的K个数 要求:输入n个整数,找出其中最小的K个数.例如输入4,5,1,6,2,7,3,8这8个数字,则最小的4个数字是1,2,3,4,. class Solution { public: ...

  7. Object类型转换为String类型

    1. Object.toString() 1 obj.toString() 注意:必须保证Object不是null值,否则将抛出NullPointerException异常. 2. (String)O ...

  8. Oracle 回滚(ROLLBACK)和撤销(UNDO)

    一.回滚(ROLLBACK)和撤销(UNDO) 回滚和前滚是保证Oracle数据库中的数据处于一致性状态的重要手段. 在9i版本以前 Oracle使用数据库中的回滚段来实现未提交数据或因系统故障导致实 ...

  9. dock helloworld

    Docker Hello World Docker 允许你在容器内运行应用程序, 使用 docker run 命令来在容器内运行一个应用程序. 输出Hello world runoob@runoob: ...

  10. Python字符串(Python学习笔记02)

    字符串 Python 3 中的字符串可以使用双引号或单引号标示,如果字符串出现引号,则可以使用 \ 来去除引号标示字符串的作用. 几种字符串的表示方法: str1 = "hello" ...