--- { "title": "ALTER-TABLE-ROLLUP", "language": "en" } --- ## ALTER-TABLE-ROLLUP ### Name ALTER TABLE ROLLUP ### Description This statement is used to perform a rollup modification operation on an existing table. The rollup is an asynchronous operation, and the task is returned when the task is submitted successfully. After that, you can use the [SHOW ALTER](../../Show-Statements/SHOW-ALTER.md) command to view the progress. grammar: ```sql ALTER TABLE [database.]table alter_clause; ``` The alter_clause of rollup supports the following creation methods 1. Create a rollup index grammar: ```sql ADD ROLLUP rollup_name (column_name1, column_name2, ...) [FROM from_index_name] [PROPERTIES ("key"="value", ...)] ``` 2. Create rollup indexes in batches grammar: ```sql ADD ROLLUP [rollup_name (column_name1, column_name2, ...) [FROM from_index_name] [PROPERTIES ("key"="value", ...)],...] ``` Notice: - If from_index_name is not specified, it will be created from base index by default - Columns in rollup table must be columns already in from_index - In properties, the storage format can be specified. For details, see [CREATE TABLE](../Create/CREATE-TABLE.html#create-table) 3. Delete rollup index grammar: ```sql DROP ROLLUP rollup_name [PROPERTIES ("key"="value", ...)] ``` 4. Batch delete rollup index grammar: ```sql DROP ROLLUP [rollup_name [PROPERTIES ("key"="value", ...)],...] ``` Notice: - cannot delete base index ### Example 1. Create index: example_rollup_index, based on base index (k1,k2,k3,v1,v2). Columnar storage. ```sql ALTER TABLE example_db.my_table ADD ROLLUP example_rollup_index(k1, k3, v1, v2); ``` 2. Create index: example_rollup_index2, based on example_rollup_index (k1,k3,v1,v2) ```sql ALTER TABLE example_db.my_table ADD ROLLUP example_rollup_index2 (k1, v1) FROM example_rollup_index; ``` 3. Create index: example_rollup_index3, based on base index (k1,k2,k3,v1), with a custom rollup timeout of one hour. ```sql ALTER TABLE example_db.my_table ADD ROLLUP example_rollup_index(k1, k3, v1) PROPERTIES("timeout" = "3600"); ``` 4. Delete index: example_rollup_index2 ```sql ALTER TABLE example_db.my_table DROP ROLLUP example_rollup_index2; ``` ### Keywords ```text ALTER, TABLE, ROLLUP ``` ### Best Practice