Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added REMOVE PARTITIONING and ALTER TABLE t PARTITION BY #15069

Merged
merged 6 commits into from
Oct 8, 2023
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions partitioned-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,46 @@ ALTER TABLE example TRUNCATE PARTITION p0;
Query OK, 0 rows affected (0.03 sec)
```

## 将分区表转换为非分区表
qiancai marked this conversation as resolved.
Show resolved Hide resolved

要将分区表转换为非分区表,你可以使用以下语句。该语句在执行时将会删除分区,复制表中的所有行,并为表在线重新创建索引。

```sql
ALTER TABLE <table_name> REMOVE PARTITIONING
```

例如,要将分区表 `members` 转换为非分区表,可以执行以下语句:

```sql
ALTER TABLE members REMOVE PARTITIONING
```

## 对现有表进行分区
qiancai marked this conversation as resolved.
Show resolved Hide resolved

要对现有的非分区表进行分区或修改现有分区表的分区类型,你可以使用以下语句。该语句在执行时将根据新的分区定义复制表中的所有行并在线重新创建索引:
qiancai marked this conversation as resolved.
Show resolved Hide resolved

```sql
ALTER TABLE <table_name> PARTITION BY <new partition type and definitions>
```

示例:

要将现有的 `members` 表转换为一个包含 10 个分区的 HASH 分区表,可以执行以下语句:

```sql
ALTER TABLE members PARTITION BY HASH(id) PARTITIONS 10;
```

要将现有的 `member_level` 表转换为 RANGE 分区表,可以执行以下语句:

```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.md),它基于一个非常简单的概念:不需要扫描那些匹配不上的分区。
Expand Down