本文介绍Cluster的语法并给出相关示例。

背景说明

Oracle中的 Cluster是一种共享公共列,在相同块中存储相关数据的表。当使用Cluster表时,单个数据块可以包含来自多个表的行,对于经常发生连接的表可以减少磁盘IO。

在PolarDB O引擎中不支持共享列的表,但PolarDB O引擎提供按某一个特定索引重新组织堆表数据的能力。

解决方案

Cluster语法
CLUSTER [VERBOSE] table_name [ USING index_name ]

Cluster会对数据的物理存储顺序进行调整,重新按照指定索引进行排序。注意Cluster是一次性操作,后续对于表的更改不会自动调整。

示例

#Cluster the table employees on the basis of its index employees_ind:
CLUSTER employees USING employees_ind;

#Cluster the employees table using the same index that was used before:
CLUSTER employees;

#Cluster all tables in the database that have previously been clustered:
CLUSTER;