复合索引如何工作? [英] How do composite indexes work?
问题描述
我已经在表格上为表格创建了复合索引( indices ),然后假设它们是如何工作的。我只是好奇我的假设是否正确。
I've created composite indexes (indices for you mathematical folk) on tables before with an assumption of how they worked. I was just curious if my assumption is correct or not.
我假设当你列出索引的列顺序时,你还要指定索引的编写方式分组。例如,如果列 a
, b
, c
,并以相同的顺序指定索引 a ASC
, b ASC
和 c ASC
然后结果索引基本上是 a
中每个组的许多索引。
I assume that when you list the order of columns for the index, you are also specifying how the indexes will be grouped. For instance, if you have columns a
, b
, and c
, and you specify the index in that same order a ASC
, b ASC
, and c ASC
then the resultant index will essentially be many indexes for each "group" in a
.
这是对的吗?如果不是,结果索引实际上会是什么样的?
Is this correct? If not, what will the resultant index actually look like?
推荐答案
复合索引就像常规索引一样工作,除非它们具有多个索引值键。
Composite indexes work just like regular indexes, except they have multi-values keys.
如果在字段(a,b,c)上定义索引,则记录首先在a上排序,然后是b,然后是c。
If you define an index on the fields (a,b,c) , the records are sorted first on a, then b, then c.
示例:
| A | B | C |
-------------
| 1 | 2 | 3 |
| 1 | 4 | 2 |
| 1 | 4 | 4 |
| 2 | 3 | 5 |
| 2 | 4 | 4 |
| 2 | 4 | 5 |
这篇关于复合索引如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!