Toggle navigation
PostgreSQL中文社区
首页
(current)
社区新闻
中文文档
加入ACE
相关资料
了解PostgreSQL
PostgreSQL相关文档
PostgreSQL软件下载
PostgreSQL中文图书
社区年会PPT资料
关于中文社区
注册
登录
全部
Bug
使用技巧
内容问题
建议
系统安装
集群复制
其他
首页
有问有答(FAQ)
【Bug】
类主题列表
jianghz
有关PG查询规划的咨询? ...
... 2018-06-26 14:51:23+08...1楼
1,假设有一个表 结构和索引如下: create table test1(ID BIGINT,name varchar(10),age int,addr varchar(128)); 插入测试数据: insert into test1 select i,'name'||i,100,substr(md5(random()::text),1,30) from generate_series(1,1000000) as t(i); -- 创建组合索引,ID + NAME create index idx_test_id_name on test1(id ,name); analyze test1; 2,分页查询语句 -- sql语句: select id,name from test1 where id between 1000 and 10000 and name in ('name1','name2','name3') order by id desc limit 24; -- 执行计划显示 explain (analyze,buffers) select id,name from test1 where id between 1000 and 10000 and name in ('name1','name2','name3') order by id desc limit 24; Limit (cost=0.42..10879 rows=1 width=51) (actual time=35.174..35.174 rows=0 loops=1) Buffers:shared hit = 39 read=93 --> Index Scan using idx_test1_id_name on test1(cost=0.42..10879.37 row=1 width=51)(actual time=35.169..35.169 rows=0 loops=1) Index Cond:((id >=1000 ) and (id <=10000)) Filter:((name)::text = ANY('{name1,name2}'::text[])) Rows Removed by Filter:9001 Buffers:shared hit=39 read = 93 Planning time : 2.183ms Execution time : 35.311ms -- 2个疑问: 第一个问题: Filter:((name)::text = ANY('{name1,name2}'::text[])) 这步为什么不能在索引的块中过滤,Pg走的是回表过滤,这样会造成效率低下。 仅仅是根据idx_test1_id_name的前导列范围扫描id,直接回表读取heap page过滤 而且我只选中了id和name两列都在索引中的,理论上不需要回表嘛, 这点在oracle数据库中确认没有回表过程 第二个问题: postgresql的执行计划很难看出是否真正的回表了。上面的回表过滤我是通过查看 pg_buffercache插件确认的。 请阿里的大牛帮忙看看,是否有好的思路和方法。
我的签名:
xx
回复: ...
... 2018-08-25 19:49:22+08...2楼
test asdfasfdadsf asdf
我的签名:
您还没有登录,请您登录后再发表回复
© 2010 PostgreSQL中文社区