Skip to content

Commit 70a3c1d

Browse files
authored
Added REMOVE PARTITIONING and ALTER TABLE t PARTITION BY (#13167)
1 parent ba18862 commit 70a3c1d

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

partitioned-table.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,46 @@ ALTER TABLE example TRUNCATE PARTITION p0;
11311131
Query OK, 0 rows affected (0.03 sec)
11321132
```
11331133

1134+
### Convert a partitioned table to a non-partitioned table
1135+
1136+
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:
1137+
1138+
```sql
1139+
ALTER TABLE <table_name> REMOVE PARTITIONING
1140+
```
1141+
1142+
For example, to convert the `members` partitioned table to the non-partitioned table, you can execute the following statement:
1143+
1144+
```sql
1145+
ALTER TABLE members REMOVE PARTITIONING
1146+
```
1147+
1148+
### Partition an existing table
1149+
1150+
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:
1151+
1152+
```sql
1153+
ALTER TABLE <table_name> PARTITION BY <new partition type and definitions>
1154+
```
1155+
1156+
Examples:
1157+
1158+
To convert the existing `members` table to a HASH partitioned table with 10 partitions, you can execute the following statement:
1159+
1160+
```sql
1161+
ALTER TABLE members PARTITION BY HASH(id) PARTITIONS 10;
1162+
```
1163+
1164+
To convert the existing `member_level` table to a RANGE partitioned table, you can execute the following statement:
1165+
1166+
```sql
1167+
ALTER TABLE member_level PARTITION BY RANGE(level)
1168+
(PARTITION pLow VALUES LESS THAN (1),
1169+
PARTITION pMid VALUES LESS THAN (3),
1170+
PARTITION pHigh VALUES LESS THAN (7)
1171+
PARTITION pMax VALUES LESS THAN (MAXVALUE));
1172+
```
1173+
11341174
## Partition pruning
11351175

11361176
[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.

0 commit comments

Comments
 (0)