MySQL强制索引和禁止某个索引

MySQL强制使用索引:force index(索引名或者主键PRI)

例如:

select * from table force index(PRI) limit 2; -- (强制使用主键)
select * from table force index(ziduan1_index) limit 2; -- (强制使用索引"ziduan1_index")
select * from table force index(PRI,ziduan1_index) limit 2; -- (强制使用索引"PRI和ziduan1_index")

MySQL禁止某个索引:ignore index(索引名或者主键PRI)

例如:

select * from table ignore index(PRI) limit 2; -- (禁止使用主键)
select * from table ignore index(ziduan1_index) limit 2; -- (禁止使用索引"ziduan1_index")
select * from table ignore index(PRI,ziduan1_index) limit 2; -- (禁止使用索引"PRI,ziduan1_index")

 

posted @ 2022-02-19 12:57  残城碎梦  阅读(397)  评论(0)    收藏  举报