MySQL index hint
2015-11-10 10:46
706 查看
语法:
官方说明:
The USE INDEX (index_list) hint tells MySQL to use only one of the named indexes to find rows in the table. The alternative syntax IGNORE INDEX
(index_list) tells MySQL to not use some particular index or indexes. These hints are useful if EXPLAIN shows that MySQL is using the wrong
index from the list of possible indexes.
The FORCE INDEX hint acts like USE INDEX (index_list), with the addition that a table scan is assumed to be very expensive. In other words, a table
scan is used only if there is no way to use one of the named indexes to find rows in the table.
Each hint requires the names of indexes, not the names of columns. To refer to a primary key, use the name PRIMARY. To see the index names for
a table, use SHOW INDEX.
An index_name value need not be a full index name. It can be an unambiguous prefix of an index name. If a prefix is ambiguous, an error occurs.
USE INDEX( 这个可以限制索引的使用范围)
有时我们在数据表里建立了很多索引,当MySQL对索引进行选择时,这些索引都在考虑的范围内。但有时我们希望MySQL只考虑几个索引,而不是全部的索引,这就需要用到USE INDEX对查询语句进行设置
IGNORE INDEX(限制不使用索引的范围)
和上面的use index刚好是相反的。
FORCE INDEX(强迫使用某一个索引)
上面的两个例子都是给MySQL提供一个选择范围。而有时我们希望MySQL必须要使用某一个索引(由于 MySQL在查询时只能使用一个索引,因此只能强迫MySQL使用一个索引)。这就需要使用FORCE INDEX来完成这个功能。
更详细的信息可以查看mysql官方文档
tbl_name [[AS] alias] [index_hint_list] index_hint_list: index_hint [, index_hint] ... index_hint: USE {INDEX|KEY} [FOR {JOIN|ORDER BY|GROUP BY}] ([index_list]) | IGNORE {INDEX|KEY} [FOR {JOIN|ORDER BY|GROUP BY}] (index_list) | FORCE {INDEX|KEY} [FOR {JOIN|ORDER BY|GROUP BY}] (index_list) index_list: index_name [, index_name] ...
官方说明:
The USE INDEX (index_list) hint tells MySQL to use only one of the named indexes to find rows in the table. The alternative syntax IGNORE INDEX
(index_list) tells MySQL to not use some particular index or indexes. These hints are useful if EXPLAIN shows that MySQL is using the wrong
index from the list of possible indexes.
The FORCE INDEX hint acts like USE INDEX (index_list), with the addition that a table scan is assumed to be very expensive. In other words, a table
scan is used only if there is no way to use one of the named indexes to find rows in the table.
Each hint requires the names of indexes, not the names of columns. To refer to a primary key, use the name PRIMARY. To see the index names for
a table, use SHOW INDEX.
An index_name value need not be a full index name. It can be an unambiguous prefix of an index name. If a prefix is ambiguous, an error occurs.
USE INDEX( 这个可以限制索引的使用范围)
有时我们在数据表里建立了很多索引,当MySQL对索引进行选择时,这些索引都在考虑的范围内。但有时我们希望MySQL只考虑几个索引,而不是全部的索引,这就需要用到USE INDEX对查询语句进行设置
IGNORE INDEX(限制不使用索引的范围)
和上面的use index刚好是相反的。
FORCE INDEX(强迫使用某一个索引)
上面的两个例子都是给MySQL提供一个选择范围。而有时我们希望MySQL必须要使用某一个索引(由于 MySQL在查询时只能使用一个索引,因此只能强迫MySQL使用一个索引)。这就需要使用FORCE INDEX来完成这个功能。
更详细的信息可以查看mysql官方文档
相关文章推荐
- MYSQL查询今天昨天本周本月等的数据
- mysql乐观锁总结和实践
- MYSQL加锁的测验
- Mysql自动备份失败
- mysql 多表查询
- mysql:表注释和字段注释
- MySql避免重复插入记录
- mysql 锁 for update
- MySql命令实例汇总
- mysql样例数据库employees
- MySQL-5.1.72 安装编译过程及报错解决
- MYSQL 巧用count,sum进行统计数据
- MySQL数据库重启后乱码
- 解决Mysql服务器启动时报错问题的方法
- mysql配置
- 如何安装mysql ----官网下载的mysql5.7 没有data目录
- MySQL的安装(msi和zip格式)
- 解决Mysql服务器启动时报错问题的方法
- MySql命令实例汇总
- 磁盘空间满了之后MySQL会怎样