我最近致力于 MySQL 表的索引优化,我注意到
FORCE INDEX
和 USE INDEX
几乎提供相同的功能,我想问问他们有什么不同?
最佳答案
发表我以上评论作为答案:
如果您使用 USE INDEX,那么您建议优化器使用此索引,但如果优化器认为它会更快,它可以使用表扫描。如果您使用 FORCE INDEX,那么即使优化器认为表扫描更有效,您也可以使用该索引。仅当无法使用索引查找行时,优化器才会使用表扫描。
You can also use FORCE INDEX, which acts like USE INDEX (index_list) but 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 given indexes to find rows in the table.
关于MySQL : FORCE INDEX vs USE INDEX,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20797475/