当前位置:Gxlcms > 数据库问题 > Mysql延迟关联和索引覆盖

Mysql延迟关联和索引覆盖

时间:2021-07-01 10:21:17 帮助过:24人阅读

  

自己写了一个灌入数据的web demo,通过http请求来进行数据灌入。github地址:https://github.com/Mingo-xoto/IndexTestDemo ,接口类名:com.yhq.web.controller.TestController

记录数为:13586901

技术分享图片

建立的索引如下:

技术分享图片

1、索引覆盖

 

select id,city from human where city=‘广州市‘ limit 10000,10;

或者

select id,city,town, village from human where city=‘广州市‘ limit 10000,10;

基本都是0.00几秒的级别

由于我建立了一个 city, town, village 的复合索引,索引mysql查询索引就可以直接返回结果而不需要进行回表查询具体列,但假如需要查询不在该复合索引的列的时候,就需要回表操作了。

select id,city,town, village,province from human where city=‘广州市‘ limit 10000,10;

需要46.637秒才能得到结果。

2、延迟关联

传统写法查询10000页后的10条记录:select * from human where city=‘广州市‘ limit 10000,10;耗时将近1分钟技术分享图片

使用延迟关联之后:0.004s, 质的提升!

select * from human h INNER JOIN
(
select id,city from human where city=‘广州市‘ limit 10000,10
) as a on a.id=h.id;

或者

select * from human h INNER JOIN
(
select id,city from human where city=‘广州市‘ limit 10000,10
) as a using(id);

两种都行,测试了好像也没什么区别。

技术分享图片

 

至于为什么提升这么快,在《高性能MySQL》有提到(图片是直接引用别人博客的 :http://blog.csdn.net/u012817635/article/details/52277490):技术分享图片

 

 

 

第一次在博客园写博客,梳理的知识可能也不是很准确,只是作为个人的一个学习记录。

Mysql延迟关联和索引覆盖

标签:延迟   个人   bsp   mysql   mysql查询   min   记录   0.00   tde   

人气教程排行