Postgresql 索引分析

索引分析

求出属于test02的所有test01的记录, 下面那种查询速度更快。

表  

create table test01(seq int, test01_id uuid primary key);

create table test02(seq int, test02_id uuid primary key);

create table test01_test02_map(seq int, test01_id uuid, test02_id uuid, primary key(test02_id, test01_id));


test01 -> x records

test01_test02_map 0> y records

test02 -> z records


查询语句一

select * from test01 t1, test01_test02_map tm 
where t1.test01_id = tm.test01_id and tm.test02_id in 
('7bd0ee4d-6303-4d55-b329-8c952ea01fcb','3ac841a9-7840-440c-a7d5-4f2a0403126b','0992a0aa-4e18-4d57-9d5e-b3bd20425546');

执行计划


执行时间分析

索引是B-Tree索引

 所以execute time = mlg(x)   m 是 输入的test02_id的数目。 

假设  x = 10000000, y=10000000,  m = 10

mlg(x*y) = 230


查询语句二

select * from test01 t1  where t1.test01_id in 
('7bd0ee4d-6303-4d55-b329-8c952ea01fcb','3ac841a9-7840-440c-a7d5-4f2a0403126b','0992a0aa-4e18-4d57-9d5e-b3bd20425546');

执行计划




select * from test01_test02_map tm where tm.test02_id in 
('7bd0ee4d-6303-4d55-b329-8c952ea01fcb','3ac841a9-7840-440c-a7d5-4f2a0403126b','0992a0aa-4e18-4d57-9d5e-b3bd20425546');

执行计划



 x = 10000000, y=10000000,  m = 50, n=10

执行时间 = m lgx + nlgz = 50*23 + 10*23 = 1380



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值