EXPLAIN ANALYZE select
*
from
billing_detail as billingDetail
where
billingDetail.start_time >= '2022-06-01 00:00:00'
and billingDetail.end_time <= '2022-07-01 00:00:00'
--billing_cycle='2022-06'
--and billingDetail.id is not null
and billingDetail.tenant_id = 0
and billingDetail.billing_type in('OD',null)
EXPLAIN ANALYZE select
*
from
billing_detail as billingDetail
where
--billingDetail.start_time >= '2022-06-01 00:00:00'
--and billingDetail.end_time <= '2022-07-01 00:00:00'
billing_cycle='2022-06'
--and billingDetail.id is not null
and billingDetail.tenant_id = 0
and billingDetail.billing_type in('OD',null)
表中共有126万行数据,表的数据的索引创建:
验证下来的确范围查询更快一些。很奇怪
再次添加104万行数据,时间格式不重复,随机生成的值,区分度很大,之前的126行区分度底
数据如图所示:
再次进行比较:
再次比较:还是发现范围查询比直接走索引还是快一些。
这里postgresql对范围查询做了优化,但是具体怎么做优化的还需要继续学习调研一下,
有已经参透的同学,可以留言回复。