Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2918156
  • 博文数量: 199
  • 博客积分: 1400
  • 博客等级: 上尉
  • 技术积分: 4126
  • 用 户 组: 普通用户
  • 注册时间: 2008-07-06 19:06
个人简介

半个PostgreSQL DBA,热衷于数据库相关的技术。我的ppt分享https://pan.baidu.com/s/1eRQsdAa https://github.com/chenhuajun https://chenhuajun.github.io

文章分类

全部博文(199)

文章存档

2020年(5)

2019年(1)

2018年(12)

2017年(23)

2016年(43)

2015年(51)

2014年(27)

2013年(21)

2011年(1)

2010年(4)

2009年(5)

2008年(6)

分类: Mysql/postgreSQL

2018-08-20 01:01:08


PostgreSQL对空表的行估算逻辑挺奇怪的,固定认为有2000多行

点击(此处)折叠或打开

  1. postgres=# create table tbchj(id int);
  2. CREATE TABLE
  3. postgres=# explain select * from tbchj;
  4.                        QUERY PLAN
  5. ---------------------------------------------------------
  6.  Seq Scan on tbchj (cost=0.00..35.50 rows=2550 width=4)
  7. (1 row)

  8. postgres=# explain select * from tbchj where id =9;
  9.                       QUERY PLAN
  10. -------------------------------------------------------
  11.  Seq Scan on tbchj (cost=0.00..41.88 rows=13 width=4)
  12.    Filter: (id = 9)
  13. (2 rows)

  14. postgres=# analyze tbchj;
  15. ANALYZE
  16. postgres=# explain select * from tbchj;
  17.                        QUERY PLAN
  18. ---------------------------------------------------------
  19.  Seq Scan on tbchj (cost=0.00..35.50 rows=2550 width=4)
  20. (1 row)


插入数据后,行估算才能调整正确

点击(此处)折叠或打开

  1. postgres=# insert into tbchj values(1);
  2. INSERT 0 1
  3. postgres=# explain select * from tbchj;
  4.                        QUERY PLAN
  5. ---------------------------------------------------------
  6.  Seq Scan on tbchj (cost=0.00..35.50 rows=2550 width=4)
  7. (1 row)

  8. postgres=# analyze tbchj;
  9. ANALYZE
  10. postgres=# explain select * from tbchj;
  11.                      QUERY PLAN
  12. -----------------------------------------------------
  13.  Seq Scan on tbchj (cost=0.00..1.01 rows=1 width=4)
  14. (1 row)



阅读(1235) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~