我正在测试不同的查询,我很好奇数据库如何决定使用位图堆扫描和索引扫描.
create index customers_email_idx on customers(email
varchar_pattern_ops);
如您所见,有一个customers表(dellstore示例),我向email列添加索引.
select * from customers where email like ‘ITQ%@dell.com’; -> query
with Index Scan
QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------- Index Scan using customers_email_idx on customers (cost=0.00..8.27 rows=2 width=268) (actual time=0.046..0.046 rows=0 loops=1) Index Cond: (((email)::text ~>=~ 'ITQ'::text) AND ((email)::text ~<~ 'ITR'::text)) Filter: ((email)::text ~~ 'ITQ%@dell.com '::text) Total runtime: 0.113 ms
select * from customers where email like ‘IT%@dell.com’; -> query
with Bitmap Heap Scan
QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------ Bitmap Heap Scan on customers (cost=4.54..106.77 rows=2 width=268) (actual time=0.206..0.206 rows=0 loops=1) Filter: ((email)::text ~~ 'IT%@dell.com '::text) -> Bitmap Index Scan on customers_email_idx (cost=0.00..4.54 rows=29 width=0) (actual time=0.084..0.084 rows=28 loops=1) Index Cond: (((email)::text ~>=~ 'IT'::text) AND ((email)::text ~<~ 'IU'::text)) Total runtime: 0.273 ms
你能解释这个例子为什么在这里使用Bitmap和Index Scan吗?
谢谢..
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。