快速percona“赞”查询,需要一些解释

问题描述 投票:0回答:1

我有以下SQL查询:

select a,b from table left join table2 on ... 
   where
     table.date > (some date) and 
     table.date < (some date) and
     table.first not like '%condition1%' and
     table.first not like '%condition2%' and
     table.first not like '%condition3%' and
     table.first not like '%condition4%' and
     table.first not like '%condition5%'
limit 500 offset 500

“ table”-是一个很大的分区表,例如,应用日期之后的AFTER索引,我们将获得约4.2M行,以进一步扫描过滤位置。

因此,此查询的运行非常快-在大约250毫秒内,这怎么可能?我们不是教导我们不要在大表上以任何方式使用,尤其是以双向应用%的方式吗?

当然也是“表”-在“第一”列上没有任何索引。 Percona版本相当旧-5.5.61-38.13。

如何解释这种行为?

mysql percona
1个回答
0
投票

好,我明白了。问题是我的查询缺少“排序依据”。在此查询中添加排序依据可将查询时间提高到6秒-现在可以理解。

因此,在以前的情况下,mysql只是在寻找与5类模式匹配的任何数据,而与排序无关,这现在说明了为什么除了500个极限偏移量之外,它还这么快地工作了

© www.soinside.com 2019 - 2024. All rights reserved.