How does PostgreSQL's CLUSTER differ from a clustered index in SQL Server?

♀尐吖头ヾ 提交于 2020-01-03 11:11:49

问题


Many posts like this stackoverflow link claim that there is no concept of a clustered index in PostgreSQL. However, the PostgreSQL documentation contains something similar. A few people claim it is similar to a clustered index in SQL Server.

Do you know what the exact difference between these two is, if there is any?


回答1:


A clustered index or index organized table is a data structure where all the table data are organized in index order, typically by organizing the table in a B-tree structure.

Once a table is organized like this, the order is automatically maintained by all future data modifications.

PostgreSQL does not have such clustering indexes. What the CLUSTER command does is rewrite the table in the order of the index, but the table remains a fundamentally unordered heap of data, so future data modifications will not maintain that index order.

You have to CLUSTER a PostgreSQL table regularly if you want to maintain an approximate index order in the face of data modifications to the table.

Clustering in PostgreSQL can improve performance, because tuples found during an index scan will be close together in the heap table, which can turn random access to the heap to faster sequential access.



来源:https://stackoverflow.com/questions/47669397/how-does-postgresqls-cluster-differ-from-a-clustered-index-in-sql-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!