1

lets say i have a table like this :

a | b | c | d 
______________
1 | 2 | 4 | 5
6 | 2 | 5 | 5
3 | 5 | 2 | 5

[a] column has clustered index

so the physical order which its stored is :

a | b | c | d 
______________
1 | 2 | 4 | 5
3 | 5 | 2 | 5
6 | 2 | 5 | 5

now lets enhance the [a] index to be [a,c] ( still as clustered).

now , I can't udnerstand how it can be stored since [a] column is already sorted and [c] column cant be sorted ( because sorting of [a] hurts the sorting of [c])

so how does sqlServer will store it ?

2'nd question : do I need to open another index for [c] ?

4

2 回答 2

2

我认为你遗漏了一些明显的东西。考虑您对查询的期望

select * from myTable
order by [a], [c]

您在列 [a,c] 上的聚集索引将给出具有相同顺序的物理布局。

于 2012-04-24T10:52:57.833 回答
1

复合索引产生字典顺序c:当值a被认为“相等”时,记录额外排序。

a c
1 2
2 3 -- Within this block, records are sorted on [c]
2 5 --
2 7 --
3 7
4 1
5 6 -- Within this block, records are sorted on [c]
5 8 --

这就是字典的排序方式。

c如果要加快不涉及的查询,则需要附加索引a

SELECT  *
FROM    mytable
WHERE   c = @some_value
于 2012-04-24T11:01:01.003 回答