From 70a3c1df57dd2decbda64dbef0fd678062913d15 Mon Sep 17 00:00:00 2001 From: Mattias Jonsson Date: Sat, 7 Oct 2023 22:54:22 -0700 Subject: [PATCH] Added REMOVE PARTITIONING and ALTER TABLE t PARTITION BY (#13167) --- partitioned-table.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/partitioned-table.md b/partitioned-table.md index fa944630b60be..e82952aaf13e4 100644 --- a/partitioned-table.md +++ b/partitioned-table.md @@ -1131,6 +1131,46 @@ ALTER TABLE example TRUNCATE PARTITION p0; Query OK, 0 rows affected (0.03 sec) ``` +### Convert a partitioned table to a non-partitioned table + +To convert a partitioned table to a non-partitioned table, you can use the following statement, which removes the partitioning, copies all rows of the table, and recreates the indexes online for the table: + +```sql +ALTER TABLE REMOVE PARTITIONING +``` + +For example, to convert the `members` partitioned table to the non-partitioned table, you can execute the following statement: + +```sql +ALTER TABLE members REMOVE PARTITIONING +``` + +### Partition an existing table + +To partition an existing non-partitioned table or modify the partition type of an existing partitioned table, you can use the following statement, which copies all rows and recreates the indexes online according to the new partition definitions: + +```sql +ALTER TABLE PARTITION BY +``` + +Examples: + +To convert the existing `members` table to a HASH partitioned table with 10 partitions, you can execute the following statement: + +```sql +ALTER TABLE members PARTITION BY HASH(id) PARTITIONS 10; +``` + +To convert the existing `member_level` table to a RANGE partitioned table, you can execute the following statement: + +```sql +ALTER TABLE member_level PARTITION BY RANGE(level) +(PARTITION pLow VALUES LESS THAN (1), + PARTITION pMid VALUES LESS THAN (3), + PARTITION pHigh VALUES LESS THAN (7) + PARTITION pMax VALUES LESS THAN (MAXVALUE)); +``` + ## Partition pruning [Partition pruning](/partition-pruning.md) is an optimization which is based on a very simple idea - do not scan the partitions that do not match.