【发布时间】:2020-02-25 15:16:35
【问题描述】:
我有以下 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” - 是一个非常大的分区表,例如在应用日期索引后,我们将获得大约 420 万行来扫描以进一步进行过滤。
所以这个查询运行得非常快——大约 250 毫秒,这怎么可能?我们没有教过不要在大表上以任何方式使用 like,尤其是在双向应用 % 的方式中?
当然还有“table”——在“first”列上没有任何索引。 Percona 版本相当老了 - 5.5.61-38.13。
如何解释这种行为?
【问题讨论】: