MySql DBMS 是否在执行查询之前将查询更改为使用索引?

Does MySql DBMS change queries to use index before they execute it?

当我查询时,使用 '!=' 或 '<>' 我知道 DBMS 不使用索引。

select * from test where test_id != 1234

所以像底部查询一样,使用索引也可以得到相同的结果。

select * from test where test_id < 1234 or test_id > 1234

但是当我看到解释计划都使用范围(范围扫描)时。 所以我很好奇,如果我使用 '!=' 进行查询,MySql DBMS 是否会将查询更改为 '> 和 <' 以使用索引。

!=(又名 <>)通常表示“我想要除一行以外的所有行”。因此,在该列上建立索引基本上是无用的;扫描 table 会更快,跳过那一行。

WHERE test_id < 1234 OR test_id > 1234 

等同于

WHERE test_id != 1234

但是OR通常不能使用任何索引。