Skip to main content
ALTER TABLE Modifies an existing table, including: Tip This operation requires the ALTER privilege on the destination table.

Syntax

alter_clause can held the following operations: rename, comment, partition, bucket, column, rollup, index, table property, swap, and compaction.
  • rename: renames a table, rollup, partition, or column (supported from v3.3.2 onwards).
  • comment: modifies the table comment (supported from v3.1 onwards).
  • partition: modifies partition properties, drops a partition, or adds a partition.
  • bucket: modifies the bucketing method and number of buckets.
  • column: adds, drops, or reorders columns, modifies column type or comment
  • rollup: creates or drops a rollup.
  • index: modifies indexes.
  • swap: atomic exchange of two tables.
  • compaction: performs manual compaction to merge versions of loaded data (supported from v3.1 onwards).
  • drop persistent index: Drop persistent index for Primary Key table in shared-data cluster (supported from v3.3.9 onwards).

Limits and usage notes

  • Operations on partition, column, and rollup index cannot be performed in one ALTER TABLE statement.
  • One table can have only one ongoing schema change operation at a time. You cannot run two schema change commands on a table at the same time.
  • Operations on bucket, column and rollup are asynchronous operations. A success message is return immediately after the task is submitted. You can run the SHOW ALTER TABLE command to check the progress, and run the CANCEL ALTER TABLE command to cancel the operation.
  • Operations on rename, comment, partition, index and swap are synchronous operations, and a command return indicates that the execution is finished.

Rename

Rename supports modification of table name, rollup, and partition name.

Rename a table

Rename a rollup

Rename a partition

Rename a column

From v3.3.2 onwards, the database supports renaming columns.
Note
  • After renaming a column from A to B, adding a new column named A is not supported.
  • Materialized views built on a renamed column will not take effect. You must rebuild them upon the column with the new name.

Alter table comment (from v3.1)

Syntax:

Modify partition

ADD PARTITION(S)

You must strictly follow the respective syntax to add range partitions or list partitions. Note
  • Adding expression partitions is not supported.
  • Please note that PARTITION BY date_trunc(column) and PARTITION BY time_slice(column) are considered range partitioning, despite their format of expression partitioning. Therefore, you can use the following syntax for range partitions to add new partitions to tables use such partitioning strategies.
Syntax:
  • Range partitions
  • List partitions
Parameters:
  • Partition-related parameters:
    • For range partitions, you can add a single range partition (single_range_partition) or multiple range partitions in batch (multi_range_partitions).
    • For list partitions, you can only add a single list partition.
  • distribution_desc: You can set the number of buckets for the new partition separately, but you cannot set the bucketing method separately.
  • "key"="value": You can set properties for the new partition. For details, see CREATE TABLE.
Examples:
  • Range partitions
    • If the partition column is specified as event_day at table creation, for example PARTITION BY RANGE(event_day), and a new partition needs to be added after table creation, you can execute:
    • If the partition column is specified as datekey at table creation, for example PARTITION BY RANGE (datekey), and multiple partitions need to be added in batch after table creation, you can execute:
  • List partitions
    • If a single partition column is specified at table creation, for example PARTITION BY LIST (city), and a new partition needs to be added after table creation, you can execute:
    • If multiple partition columns are specified at table creation, for example PARTITION BY LIST (dt,city), and a new partition needs to be added after table creation, you can execute:

DROP PARTITION(S)

  • Drop a single partition:
  • Drop partitions in batch (Supported from v3.4.0):
Notes for multi_range_partitions:
  • It only applies to Range Partitioning.
  • The parameters involved is consistent with those in ADD PARTITION(S).
  • It only supports partitions with a single Partition Key.
  • Drop partitions with Common Partition Expression (Supported from v3.5.0):
From v3.5.0 onwards, the database supports dropping partitions using Common Partition Expression. You can specify a WHERE clause with an expression to filter the partitions to drop.
  • The expression declares the partitions to be dropped. Partitions that meet the condition in the expression will be dropped in batch. Be cautious when proceeding.
  • The expression can only contain partition columns and constants. Non-partition columns are not supported.
  • Common Partition Expression applies to List partitions and Range partitions differently:
    • For tables with List partitions, the database supports deleting partitions filtered by the Common Partition Expression.
    • For tables with Range partitions, the database can only filter and delete partitions using the partition pruning capability of FE. Partitions correspond to predicates that are not supported by partition pruning cannot be filtered and deleted.
Example:
Note
  • Keep at least one partition for partitioned tables.
  • If FORCE is not specified, you can recover the dropped partitions by using the RECOVER command within a specified period (1 day by default).
  • If FORCE is specified, the partitions will be deleted directly regardless of whether there are any unfinished operations on the partitions, and they cannot be recovered. Thus, generally, this operation is not recommended.

Add a temporary partition

Syntax:

Use a temporary partition to replace the current partition

Syntax:

Drop a temporary partition

Syntax:

Modify partition properties

Syntax
Usages
  • The following properties of a partition can be modified:
    • storage_medium
    • storage_cooldown_ttl or storage_cooldown_time
    • replication_num
  • For the table that has only one partition, the partition name is the same as the table name. If the table is divided into multiple partitions, you can use (*)to modify the properties of all partitions, which is more convenient.
  • Execute SHOW PARTITIONS FROM <tbl_name> to view the partition properties after modification.

Modify the bucketing method and number of buckets (from v3.2)

Syntax:
Example: For example, the original table is a Duplicate Key table where hash bucketing is used and the number of buckets is automatically set by the database.

Modify the bucketing method only

NOTICE
  • The modification is applied to all partitions in the table and cannot be applied to specific partitions only.
  • Although only the bucketing method needs to be modified, the number of buckets still needs to be specified in the command using BUCKETS <num>. If BUCKETS <num> is not specified, it means that the number of buckets is automatically determined by the database.
  • The bucketing method is modified to random bucketing from hash bucketing and the number of buckets remains automatically set by the database.
  • The keys for hash bucketing are modified to user_id, event_time from event_time, event_type. And the number of buckets remains automatically set by the database.

Modify the number of buckets only

NOTICE Although only the number of buckets needs to be modified, the bucketing method still needs to be specified in the command, for example, HASH(user_id).
  • Modify the number of buckets for all partitions to 10 from being automatically set by the database.
  • Modify the default number of buckets of the table to 10 from being automatically set by the database without changing that of existing partitions (supported from v3.5.8 and v4.0.1 onwards).
    NOTICE You cannot specify both partition_names and DEFAULT.
  • Modify the number of buckets for specified partitions to 15 from being automatically set by the database.
    NOTE Partition names can be viewed by executing SHOW PARTITIONS FROM <table_name>;.

Modify both the bucketing method and the number of buckets

NOTICE The modification is applied to all partitions in the table and cannot be applied to specific partitions only.
  • Modify the bucketing method from hash bucketing to random bucketing, and change the number of buckets to 10 from being automatically set by the database.
  • Modify the key for hash bucketing, and change the number of buckets to 10 from being automatically set by the database. The key used for hashing bucketing is modified to user_id, event_time from the original event_time, event_type. The number of buckets is modified to 10 from automatically set by the database.

Modify the tablet size

The database supports splitting and merging tablets from v4.1 onwards, allowing dynamic management of tablet size, thus an adaptive mechanism for handling data skew. Syntax for SPLIT:
Syntax for MERGE:
Parameter:
  • tablet_reshard_target_size: The target size of the tablets after the SPLIT or MERGE operation. Default: the table property tablet_reshard_target_size if the table has it, otherwise the FE configuration tablet_reshard_target_size (Default: 10 GB). Automatic splitting and merging use the same default, referred to as the table’s target size below. You do not need to specify this parameter if you have explicitly specified tablet IDs. For a manual SPLIT without tablet IDs, the target size must be positive. If the FE configuration tablet_reshard_target_size is 0, specify a positive value in PROPERTIES, even if the table has the table property tablet_reshard_target_size; otherwise, the statement fails with Invalid tablet_reshard_target_size: 0. The 1.5-times split threshold below applies only to positive target sizes.
    • A tablet will be split if both the following conditions are met:
      • The size of the tablet is at least 1.5 times tablet_reshard_target_size (that is, ceil(1.5 × tablet_reshard_target_size)). With the 10 GB default, a tablet is split once it reaches 15 GB. Both automatic splitting and a manual ALTER TABLE ... SPLIT use this threshold: automatic splitting measures against the table’s target size, while a manual SPLIT uses the value specified in PROPERTIES, or the table’s target size if none is specified. This also holds when you specify tablet IDs: a specified tablet below the threshold is not split, and if no tablet qualifies, the statement fails with No tablets need to split in table ....
      • The number of tablets that are running tablet SPLIT or MERGE is less than the FE configuration tablet_reshard_max_parallel_tablets (Default: 10240).
    • Tablets are also split before they reach that threshold while the materialized index they belong to has fewer tablets than the number of compute nodes in its warehouse — capped by tablet_reshard_max_split_count, so lowering that configuration lowers the tablet count at which this stops — and holds less data than that many times the table’s target size. The free slots go to the tablets the threshold above does not already split, one more tablet at a time and to the largest pieces first, as long as every resulting tablet is at least tablet_reshard_min_split_size and no tablet is split into more tablets than one split allows. With tablet_reshard_min_split_size at its 2 GB default, a single-tablet index splits once its tablet reaches 4 GB, and on three compute nodes an index that has reached two tablets gets its third once one of them reaches 4 GB. This allows a newly created partition to reach cluster-wide write parallelism sooner. This rule applies to automatic splitting and to a manual SPLIT that specifies neither tablet IDs nor tablet_reshard_target_size. Specifying either one disables it, leaving only the threshold above. Setting tablet_reshard_min_split_size at or above the table’s target size disables it for that table. To disable it for the whole cluster, set tablet_reshard_min_split_size at or above the FE configuration tablet_reshard_target_size and at or above the table property tablet_reshard_target_size of every table that has it.
    • MERGE requires the FE configuration tablet_reshard_enable_tablet_merge to be true (Default: false). Otherwise, tablets are never merged automatically, and ALTER TABLE ... MERGE is rejected. When it is enabled, tablets are merged as follows:
      • Automatic merging is triggered when the total size of any two adjacent tablets in a materialized index is smaller than 80% of tablet_reshard_target_size (that is, ceil(0.8 × tablet_reshard_target_size)), measured against the table’s target size. With the 10 GB default, merging is triggered once two adjacent tablets together are smaller than 8 GB.
      • Automatic merging and a manual MERGE that does not specify tablet IDs select the tablets to merge in the same way. A manual MERGE uses the value specified in PROPERTIES, or the table’s target size if none is specified. Only tablets smaller than ceil(0.8 × tablet_reshard_target_size) are merged. Adjacent tablets of this kind are grouped in range order, the total size of each group does not exceed tablet_reshard_target_size, and any larger tablet between them ends the group. A merge never reduces a materialized index below its parallelism floor, which is the number of compute nodes in its warehouse, capped by tablet_reshard_max_split_count and no less than 2. If no tablet can be merged, the manual statement fails with No tablets need to merge in table ....
      • A manual MERGE that specifies tablet IDs merges each specified group as is, without checking tablet sizes or the parallelism floor. Each group must consist of at least two contiguous tablets in the same partition and materialized index.
      • A tablet is merged, automatically or manually, only when it no longer shares data files with other tablets. The tablets produced by a SPLIT share the data files of the original tablet until compaction rewrites them, so run ALTER TABLE ... COMPACT on their partition before merging them back.
      • In all cases, the number of tablets that are running tablet SPLIT or MERGE must be less than the FE configuration tablet_reshard_max_parallel_tablets (Default: 10240).
Note MERGE is not supported on a range-distributed Primary Key table whose ORDER BY differs from its primary key. Such a table routes rows by a range in primary-key space while its segments are laid out in sort-key order, so a merge cannot decide which source tablet still owns a given row of a segment those sources share. Both ALTER TABLE ... MERGE TABLETS and the automatic size-based merge are refused with Merge tablet is not supported on a range-distributed primary key table whose ORDER BY differs from the primary key. SPLIT is unaffected, and a Primary Key table whose ORDER BY is its primary key can still be merged. For range-distributed tables in shared-data clusters, split and merge jobs on the same table can run concurrently when their target physical partitions do not overlap. Jobs that touch the same physical partition conflict, even if they target different materialized indexes. This also applies to pre-split jobs triggered by concurrent loads into different partitions. A physical partition becomes available for another split or merge when its job finishes or aborts. The table remains in TABLET_RESHARD state while any split or merge job is active. In this state, you can still add, drop, and replace partitions (including temporary partitions), truncate partitions, modify partition properties, rename the table, its partitions, rollups, and columns, change the table comment, and swap the table with another table. A partition (other than a temporary partition) that a job is splitting or merging can be dropped only with DROP PARTITION ... FORCE, which cannot be recovered. Other ALTER TABLE statements, such as schema changes, are rejected until the jobs finish. To check the status of the jobs, query information_schema.tablet_reshard_jobs. The table returns to NORMAL after all active split and merge jobs finish or abort. All participating FEs must support this concurrency policy. Before rolling back to an older FE version, wait for all split and merge jobs to finish or abort. For detailed examples, see Split or merge tablets.

Modify columns (add/delete columns, change column order, modify column comment)

Add a column to the specified location of the specified index

Syntax:
Note:
  1. If you add a value column to an Aggregate table, you need to specify agg_type.
  2. If you add a key column to a non-Aggregate table (such as a Duplicate Key table), you need to specify the KEY keyword. On an Aggregate table, a column that specifies neither agg_type nor KEY is ambiguous and is rejected, because creating a key column would change the table’s aggregation key and rewrite existing data. Set the FE configuration item allow_implicit_key_column_in_agg_add_column to true to restore the earlier behavior, where such a column became a key column.
  3. You cannot add a column that already exists in the base index to the rollup. (You can recreate a rollup if needed.)
  4. On range-distribution tables in shared-data clusters, adding a key column (which joins the range sort key) is supported for Duplicate Key, Aggregate, and Unique Key tables, from v4.2 onwards. The operation triggers an online rewrite, and the added key column must have a constant DEFAULT value. It is not supported for Primary Key tables, or for tables that have a rollup or synchronous materialized view.

Add multiple columns to specified index

Syntax:
  • Add multiple columns
  • Add multiple columns and use AFTER to specify locations of the added columns
Note:
  1. If you add a value column to an Aggregate table, you need to specify agg_type.
  2. If you add a key column to a non-Aggregate table, you need to specify the KEY keyword. On an Aggregate table, a column that specifies neither agg_type nor KEY is ambiguous and is rejected. Set the FE configuration item allow_implicit_key_column_in_agg_add_column to true to restore the earlier behavior.
  3. You cannot add a column that already exists in the base index to the rollup. (You can create another rollup if needed.)
  4. On range-distribution tables in shared-data clusters, adding a key column (which joins the range sort key) is supported for Duplicate Key, Aggregate, and Unique Key tables, from v4.2 onwards. The operation triggers an online rewrite, and the added key column must have a constant DEFAULT value. It is not supported for Primary Key tables, or for tables that have a rollup or synchronous materialized view.

Add a generated column (from v3.1)

Syntax:
You can add a generated column and specify its expression. The generated column can be used to precompute and store the results of expressions, which significantly accelerates queries with the same complex expressions. Since v3.1, the database supports generated columns.

Drop a column from specified index

Syntax:
Note:
  1. You cannot drop partition column.
  2. If the column is dropped from the base index, it will also be dropped if it is included in the rollup.
  3. On range-distribution tables in shared-data clusters, dropping a key column (a range sort-key column) is supported for Duplicate Key and Aggregate tables (Aggregate only when there is no REPLACE or REPLACE_IF_NOT_NULL value column), from v4.2 onwards. The operation triggers an online rewrite that re-sorts the data, and re-aggregates it under the reduced key for Aggregate tables. It is not supported for Primary Key or Unique Key tables, for a column that has an index (drop the index first), or for tables that have a rollup or synchronous materialized view.

Modify the column type, position, comment, and other properties

Syntax:
Note:
  1. If you modify the value column in aggregation models, you need to specify agg_type.
  2. If you modify the key column in non-aggregation models, you need to specify the KEY keyword.
  3. While modifying the type, default value, nullability, and position, you must specify the full definition of the column in the statement.
  4. Modifying only the column comment — whether via MODIFY COLUMN <column_name> COMMENT "<new_column_comment>" or via a full column definition where only the comment differs — changes only the metadata and does not initiate a Schema Change task. This applies to Primary Key columns, key columns, and regular columns. If the full definition also changes any other attribute of the column, the statement initiates a Schema Change task as usual.
  5. The partition column cannot be modified.
  6. The following types of conversions are currently supported (accuracy loss is guaranteed by the user).
    • Convert TINYINT/SMALLINT/INT/BIGINT to TINYINT/SMALLINT/INT/BIGINT/DOUBLE.
    • Convert TINYINT/SMALLINT/INT/BIGINT/LARGEINT/FLOAT/DOUBLE/DECIMAL to VARCHAR. VARCHAR supports modification of maximum length.
    • Convert VARCHAR to TINYINT/SMALLINT/INT/BIGINT/LARGEINT/FLOAT/DOUBLE.
    • Convert VARCHAR to DATE (currently support six formats: “%Y-%m-%d”, “%y-%m-%d”, “%Y%m%d”, “%y%m%d”, “%Y/%m/%d, “%y/%m/%d”)
    • Convert DATETIME to DATE(only year-month-day information is retained, i.e. 2019-12-09 21:47:05 <--> 2019-12-09)
    • Convert DATE to DATETIME (set hour, minute, second to zero, For example: 2019-12-09 <--> 2019-12-09 00:00:00)
    • Convert FLOAT to DOUBLE
    • Convert INT to DATE (If the INT data fails to convert, the original data remains the same)
  7. Conversion from NULL to NOT NULL is not supported.
  8. You can modify several properties in a single MODIFY COLUMN clause. However, some combination of properties are not supported.

Reorder the columns of specified index

Syntax:
Note:
  • All columns in the index must be written.
  • The value column is listed after the key column.

Modify the sort key

Since v3.0, the sort keys for the Primary Key tables can be modified. v3.3 extends this support to Duplicate Key tables, Aggregate tables, and Unique Key tables. The sort keys in Duplicate Key tables and Primary Key tables can be combination of any sort columns. The sort keys in Aggregate tables and Unique Key tables must include all key columns, but the order of the columns does not need to be same as the key columns. Syntax:
Example: modify the sort keys in Primary Key tables. For example, the original table is a Primary Key table where the sort key and the primary key are coupled, which is dt, order_id.
Decouple the sort key from the primary key, and modify the sort key to dt, revenue, state.

Modify a STRUCT column to add or drop a field

Beta feature Advice on use of Beta features From v3.2.10 and v3.3.2 onwards, the database supports modifying a STRUCT column to add or drop a field, which can be nested or within an ARRAY type. Syntax:
Parameters:
  • field_path: The field to be added or removed. This can be a simple field name, indicating a top-dimension field, for example, new_field_name, or a Column Access Path that represents a nested field, for example, lv1_k1.lv2_k2.[*].new_field_name.
  • [*]: When a STRUCT type is nested within an ARRAY type, [*] represents all elements in the ARRAY field. It is used to add or remove a field in all STRUCT elements nested under the ARRAY field.
  • prior_field_name: The field preceding the newly added field. Used in conjunction with the AFTER keyword to specify the order of the new field. You do not need to specify this parameter if the FIRST keyword is used, indicating the new field should be the first field. The dimension of prior_field_name is determined by field_path (specifically, the part preceding new_field_name, that is, level1_k1.level2_k2.[*]) and does not need to be specified explicitly.
Examples of field_path:
  • Add or drop a sub-field in a STRUCT field nested within a STRUCT column. Suppose there is a column fx stuct<c1 int, c2 struct <v1 int, v2 int>>. The syntax to add a v3 field under c2 is:
    After the operation, the column becomes fx stuct<c1 int, c2 struct <v1 int, v2 int, v3 int>>.
  • Add or drop a sub-field in every STRUCT field nested within a ARRAY field. Suppose there is a column fx struct<c1 int, c2 array<struct <v1 int, v2 int>>>. The field c2 is an ARRAY type, which contains a STRUCT with two fields v1 and v2. The syntax to add a v3 field to the nested STRUCT is:
    After the operation, the column becomes fx struct<c1 int, c2 array<struct <v1 int, v2 int, v3 int>>>.
For more usage instructions, see Example - Column -14. Note
  • Currently, this feature is only supported in shared-nothing clusters.
  • The table must have the fast_schema_evolution property enabled.
  • Modifying the Value type of a MAP subfield in a STRUCT type is not supported, regardless of whether the Value type is ARRAY, STRUCT, or MAP.
  • Newly added fields cannot have default values or attributes such as Nullable specified. They default to being Nullable, with a default value of null.
  • After this feature is used, downgrading the cluster directly to a version that does not support this feature is not allowed.

Modify rollup

Create a rollup

Syntax:
PROPERTIES: Support setting timeout time and the default timeout time is one day. ORDER BY: defines an independent sort key for the rollup that can differ from the base table’s sort key. It is supported only for range-distribution tables in shared-data clusters (from v4.2 onwards), and lets queries that filter or aggregate on the rollup’s leading sort-key columns be served by the rollup. The following limitations apply:
  • The table must be a Duplicate Key, Aggregate, or Unique Key table. Primary Key tables are not supported.
  • On a table with colocate_with, the rollup’s ORDER BY must start with the colocated columns, in the same order and with the same types.
  • A column in the rollup’s sort key cannot be dropped, and its type cannot be changed. The only allowed change is increasing the length of a VARCHAR column on its own (without repositioning it or changing another attribute) when it is applied by fast schema evolution. ORDER BY ... FROM <rollup> is not supported for such a rollup.
  • Multiple such rollups are supported. Each ALTER TABLE statement adds one rollup (add several rollups with separate statements). The rollup is always derived from the base index; FROM <another_rollup> is not supported.
Example:
Example: create a rollup with an independent sort key on a range-distribution table in a shared-data cluster.

Create rollups in batches

Syntax:
Example:
Note:
  1. If from_index_name is not specified, then create from base index by default.
  2. The columns in the rollup table must be existing columns in from_index.
  3. In properties, user can specify the storage format. See CREATE TABLE for details.

Drop a rollup

Syntax:
Example:

Batch drop rollups

Syntax:
Example:
Note: You cannot drop the base index.

Modify indexes

You can create or drop the following indexes:

Create an index

Syntax:
For detailed instructions and examples on creating these indexes, see the corresponding tutorials listed above.

Drop an index

Syntax:

Modify table properties

Syntax:
Currently, the database supports modifying the following table properties:
  • replication_num
  • default.replication_num
  • default.storage_medium
  • Dynamic partitioning related properties
  • enable_persistent_index
  • bloom_filter_columns
  • colocate_with
  • bucket_size (supported since 3.2)
  • base_compaction_forbidden_time_ranges (supported since v3.2.13)
  • enable_statistic_auto_collect
  • tablet_reshard_target_size (range-distributed tables only; set it to "" to remove it). See Modify the tablet size.
Note
  • In most cases, you are only allowed to modify one property at a time. You can only modify multiple properties at a time only if these properties have the same prefix. Currently, only dynamic_partition. and binlog. are supported.
  • You can also modify the properties by merging into the above operation on column. See the following examples.

Swap

Swap supports atomic exchange of two tables. Syntax:
Note
  • Unique Key and Foreign Key constraints between OLAP tables will be validated during Swap to ensure that the constraints of the two tables being swapped are consistent. An error will be returned if inconsistencies are detected. If no inconsistencies are detected, Unique Key and Foreign Key constraints will be automatically swapped.
  • Materialized views that are depended on the tables being swapped will be automatically set to inactive, and their Unique Key and Foreign Key constraints will be removed and no longer available.

Manual compaction (from 3.1)

The database uses a compaction mechanism to merge different versions of loaded data. This feature can combine small files into large files, which effectively improves query performance. Before v3.1, compaction is performed in two ways:
  • Automatic compaction by system: Compaction is performed at the BE level in the background. Users cannot specify database or table for compaction.
  • Users can perform compaction by calling an HTTP interface.
Starting from v3.1, the database offers a SQL interface for users to manually perform compaction by running SQL commands. They can choose a specific table or partition for compaction. This provides more flexibility and control over the compaction process. Shared-data clusters support this feature from v3.3.0 onwards. Base Compaction for shared-data Primary Key tables is supported from v4.1.4. Use ALTER TABLE ... COMPACT to request manual compaction; no additional BASE keyword is needed. From v4.1.6, lake_pk_compaction_base_enable_delete_trigger only controls automatic triggering: setting it to false does not affect manual requests. Manual requests also bypass both delete thresholds. Tablets without deleted rows fall back to ordinary compaction selection. Requests are asynchronous, and a single request does not guarantee a full-tablet merge. See Base Compaction for Primary Key tables.
NOTE The v3.2.13 support for base_compaction_forbidden_time_ranges applies to shared-nothing non-Primary Key tables. The 4.1 series does not support setting this property on shared-data tables. Time windows and minimum intervals for automatic shared-data Base Compaction are supported from v4.2; manual ALTER TABLE ... COMPACT requests bypass these restrictions.
Syntax:
That is:
For shared-nothing clusters, query information_schema.be_compactions for compaction results. For shared-data clusters, use SHOW PROC '/compactions' to inspect task status and information_schema.be_cloud_native_compactions for tablet execution details. See View compaction tasks.

Drop Primary Key Persistent Index (From 3.3.9)

Syntax:
NOTE The database only supports deleting persistent indexes for cloud-native Primary Key tables in shared-data clusters.

Examples

Table

  1. Modify the default number of replicas of the table, which is used as the default number of replicas for newly added partitions.
  2. Modify the actual number of replicas of a single-partition table.
  3. Modify data writing and replication mode among replicas.
    This example sets the data writing and replication mode among replicas to “leaderless replication”, which means data is written to multiple replicas at the same time without differentiating primary and secondary replicas. For more information, see the replicated_storage parameter in CREATE TABLE.

Partition

  1. Add a partition and use the default bucketing mode. The existing partition is [MIN, 2013-01-01). The added partition is [2013-01-01, 2014-01-01).
  2. Add a partition and use the new number of buckets.
  3. Add a partition and use the new number of replicas.
  4. Alter the number of replicas for a partition.
  5. Batch alter the number of replicas for specified partitions.
  6. Batch alter the storage medium of all partitions.
  7. Drop a partition.
  8. Add a partition that has upper and lower boundaries.

Rollup

  1. Create a rollup example_rollup_index based on the base index (k1,k2,k3,v1,v2). Column-based storage is used.
  2. Create a rollup example_rollup_index2 based on example_rollup_index(k1,k3,v1,v2).
  3. Create a rollup example_rollup_index3 based on the base index (k1, k2, k3, v1). The rollup timeout time is set to one hour.
  4. Drop the rollup example_rollup_index2.

Column

  1. Add a key column new_col (non-aggregate column) after the col1 column of example_rollup_index.
  2. Add a value column new_col (non-aggregate column) after the col1 column of example_rollup_index.
  3. Add a key column new_col (aggregate column) after the col1 column of example_rollup_index.
  4. Add a value column new_col SUM (aggregate column) after the col1 column of example_rollup_index.
  5. Add multiple columns to example_rollup_index (aggregate).
  6. Add multiple columns to example_rollup_index (aggregate) and specify the locations of the added columns using AFTER.
  7. Drop a column from example_rollup_index.
  8. Modify the column type of col1 of the base index to BIGINT and put it after col2.
  9. Modify the maximum length of the val1 column of the base index to 64. The original length is 32.
  10. Reorder the columns in example_rollup_index. The original column order is k1, k2, k3, v1, v2.
  11. Perform two operations (ADD COLUMN and ORDER BY) at one time.
  12. Alter the bloomfilter columns of the table.
    This operation can also be merged into the above column operation (note that the syntax of multiple clauses is slightly different).
  13. Modify the data type of multiple columns in a single statement.
  14. Add and drop fields in STRUCT-type data. Prerequisites: Create a table and insert a row of data.
    • Add a new field to a STRUCT-type column.
    • Add a new field to a nested STRUCT type.
    • Add a new field to a STRUCT type in an array.
    • Drop a field from a STRUCT-type column.
    • Drop a field from a nested STRUCT type.
    • Drop a field from a STRUCT type in an array.

Table property

  1. Alter the Colocate property of the table.
  2. Alter the dynamic partition property of the table.
    If you need to add dynamic partition properties to a table with no dynamic partition properties configured, you need to specify all the dynamic partition properties.
  3. Alter the storage medium property of the table.

Rename

  1. Rename table1 to table2.
  2. Rename rollup rollup1 of example_table to rollup2.
  3. Rename partition p1 of example_table to p2.

Index

  1. Create a bitmap index for column siteid in table1.
  2. Drop the bitmap index of column siteid in table1.

Swap

Atomic swap between table1 and table2.

Manual compaction

Drop Primary Key Persistent Index

Drop persistent index on tablets 100 and 101 for Primary Key table db1.test_tbl in a shared-data cluster.

SPLIT or MERGE tablets

  • Split all tablets that meet the conditions in the table to the table’s target size (10 GB by default).
  • Split all tablets that meet the conditions in a partition.
  • Split specific tablets by ID.
  • Merge all tablets that meet the conditions in the table to a target size of 2 GB.
  • Merge all tablets that meet the conditions in specific partitions.
  • Merge specific tablets by ID.

References