PostgreSQL CLUSTER on multi-column index
Say I have an index on (a, b, c) and I perform 开发者_StackOverflow社区CLUSTER on that index. How exactly will the data be stored? I would assume it's something like this (just guessing): first sort by a, then by b, then by c. For example:
(a, b, c)
---------
(1, 1, 1)
(1, 1, 2)
(1, 2, 5)
(2, 1, 4)
(3, 1, 1)
That means, if I want to have it ordered by b first, I can drop the index, re-create it as (b, a, c), then CLUSTER?
Yes, CLUSTER recreates the table in the order of the index.
To get (b,a,c) you could also create a new index, then cluster on that new index, then remove the index.
精彩评论