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

关于索引有三种sql提示

https://www.cnblogs.com/huzi007/p/9400297.html

1、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")

 

2、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")

 

3、优先使用这些索引,其它索引不再考虑:use index(索引名或者主键PRI)

例如:

select * from table use index(ziduan1_index)

 

force index 和 use index 的区别:

use index 只是给mysql优化器一种选择的可能,具体的mysql优化器再进行优化选择

但是 force index 是强制mysql优化器使用某个索引

posted @ 2019-11-14 14:27  liuweipcs  阅读(1487)  评论(0)    收藏  举报