Cluster a table according to an index.
CLUSTER instructs GaussDB(DWS) to cluster the table specified by table_name based on the index specified by index_name. The index specified by index_name must have been defined in the specified table.
When a table is clustered, it is physically reordered based on the index information. Clustering is a one-time operation: when the table is subsequently updated, the changes are not clustered. That is, no attempt is made to store new or updated rows according to their index order.
When a table is clustered, GaussDB(DWS) records which index the table was clustered by. The form CLUSTER table_name reclusters the table using the same index used previously. You can also use the CLUSTER or SET WITHOUT CLUSTER forms of ALTER TABLE to set the index to be used for future cluster operations, or to clear any previous setting.
CLUSTER without any parameter reclusters all the previously-clustered tables in the current database that the calling user owns, or all such tables if called by an administrator.
When a table is being clustered, an ACCESS EXCLUSIVE lock is acquired on it. This prevents any other database operations (both reads and writes) from operating on the table until the CLUSTER is finished.
1 | CLUSTER [ VERBOSE ] table_name [ USING index_name ]; |
1 | CLUSTER [ VERBOSE ] table_name PARTITION ( partition_name ) [ USING index_name ]; |
1 | CLUSTER [ VERBOSE ]; |
Enables the display of progress messages.
Specifies the name of the table.
Value range: an existing table name
Name of this index
Value range: An existing index name.
Specifies the partition name.
Value range: An existing partition name.
Create a partitioned table.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | CREATE TABLE inventory_p1 ( INV_DATE_SK INTEGER NOT NULL, INV_ITEM_SK INTEGER NOT NULL, INV_WAREHOUSE_SK INTEGER NOT NULL, INV_QUANTITY_ON_HAND INTEGER ) DISTRIBUTE BY HASH(INV_ITEM_SK) PARTITION BY RANGE(INV_DATE_SK) ( PARTITION P1 VALUES LESS THAN(2451179), PARTITION P2 VALUES LESS THAN(2451544), PARTITION P3 VALUES LESS THAN(2451910), PARTITION P4 VALUES LESS THAN(2452275), PARTITION P5 VALUES LESS THAN(2452640), PARTITION P6 VALUES LESS THAN(2453005), PARTITION P7 VALUES LESS THAN(MAXVALUE) ); |
Create an index named ds_inventory_p1_index1.
1 | CREATE INDEX ds_inventory_p1_index1 ON inventory_p1 (INV_ITEM_SK) LOCAL; |
Cluster the inventory_p1 table.
1 | CLUSTER inventory_p1 USING ds_inventory_p1_index1; |
Cluster the p3 partition.
1 | CLUSTER inventory_p1 PARTITION (p3) USING ds_inventory_p1_index1; |
Cluster the tables that can be clustered in the database.
1 | CLUSTER; |