何时使用多重索引?什么时候用力指数?

When multiple index is used? And when to use Force Index?

我想要根据性能在 table 秒以下的确切差异。

我有这样的虚拟 table。

CREATE TABLE multinindx1 ( id int not null auto_increment primary key, i int(11) NOT NULL, j int(11) NOT NULL, val char(10) NOT NULL, KEY i (i), KEY j (j) ) ENGINE=InnoDB;

CREATE TABLE multinindx2( id int not null auto_increment primary key, i int(11) NOT NULL, j int(11) NOT NULL, val char(10) NOT NULL, KEY ij (i,j) ) ENGINE=InnoDB;

如果我想要 select 上面 table 的 1M 行,table 获取数据的效率非常高。

注意:- 这只是虚拟 table 实际 table 包含 16 列。

When are multiple indexes is used?

简答:"Almost never"。它在在线文档中被称为 "index merge" 。使用复合索引几乎总是更好。

And when to use Force Index?

简答:"Almost never"。如果您将 FORCE INDEX 用于 今天的 版本的查询,您可能会搞砸 明天的 版本的性能。

一个完整的答案是一篇硕士论文的大小。或者完整阅读 MySQL 的源代码。进一步注意,不同的版本会给出不同的答案。

部分答案在 Intro to compund indexing and Cookbook for devising the best index for a given SELECT 中。尽管从不同的角度来看,这两个博客都针对您的一对表。

由于您没有提供任何 SELECTs,我将对您的广泛问题进行广泛的答复。