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

[Doc] fix the behaviour of AUTO NULL PARTITION #481

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
28 changes: 18 additions & 10 deletions docs/advanced/partition/auto-partition.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ mysql> select * from auto_null_list partition(pX);
1 row in set (0.20 sec)
```

2. In Doris, NULL values are included in the minimum value partition, whether they are AUTO PARTITION tables or not. Therefore, if a partition is automatically created for a NULL value, you get a partition starting with the minimum value:
2. For AUTO RANGE PARTITION, the storage of NULL values requires the manual creation of specific partitions.

In Doris' RANGE PARTITION, we do not use a separate NULL PARTITION to contain NULL values, but rather group them in the **minium LESS THAN partition**. For logical clarity, the AUTO RANGE PARTITION does not automatically create such a partition when it encounters a NULL value. If necessary, you can create such a partition yourself to contain NULL values.

```sql
mysql> CREATE TABLE `range_table_nullable` (
Expand All @@ -202,15 +204,21 @@ mysql> CREATE TABLE `range_table_nullable` (
Query OK, 0 rows affected (0.09 sec)

mysql> insert into range_table_nullable values (0, null, null);
Query OK, 1 row affected (0.21 sec)

mysql> show partitions from range_table_nullable;
+-------------+-----------------+----------------+---------------------+--------+--------------+----------------------------------------------------------------------------------------------------------+-----------------+---------+----------------+---------------+---------------------+---------------------+--------------------------+----------+------------+-------------------------+-----------+--------------------+--------------+
| PartitionId | PartitionName | VisibleVersion | VisibleVersionTime | State | PartitionKey | Range | DistributionKey | Buckets | ReplicationNum | StorageMedium | CooldownTime | RemoteStoragePolicy | LastConsistencyCheckTime | DataSize | IsInMemory | ReplicaAllocation | IsMutable | SyncWithBaseTables | UnsyncTables |
+-------------+-----------------+----------------+---------------------+--------+--------------+----------------------------------------------------------------------------------------------------------+-----------------+---------+----------------+---------------+---------------------+---------------------+--------------------------+----------+------------+-------------------------+-----------+--------------------+--------------+
| 457060 | p00000101000000 | 2 | 2024-03-25 03:01:38 | NORMAL | k2 | [types: [DATETIMEV2]; keys: [0000-01-01 00:00:00]; ..types: [DATETIMEV2]; keys: [0000-01-02 00:00:00]; ) | k1 | 16 | 1 | HDD | 9999-12-31 23:59:59 | | NULL | 0.000 | false | tag.location.default: 1 | true | true | NULL |
+-------------+-----------------+----------------+---------------------+--------+--------------+----------------------------------------------------------------------------------------------------------+-----------------+---------+----------------+---------------+---------------------+---------------------+--------------------------+----------+------------+-------------------------+-----------+--------------------+--------------+
1 row in set (0.09 sec)
ERROR 1105 (HY000): errCode = 2, detailMessage = [CANCELLED]TStatus: errCode = 2, detailMessage = Can't create partition for NULL Range

mysql> alter table range_table_nullable add partition pX VALUES LESS THAN ("1970-01-01");
Query OK, 0 rows affected (0.11 sec)

mysql> insert into range_table_nullable values (0, null, null);
Query OK, 1 row affected (0.18 sec)

mysql> select * from range_table_nullable;
+------+------+------+
| k1 | k2 | k3 |
+------+------+------+
| 0 | NULL | NULL |
+------+------+------+
1 row in set (0.18 sec)
```

## Sample Scenarios
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ mysql> select * from auto_null_list partition(pX);
1 row in set (0.20 sec)
```

2. Doris 中,无论是否为 AUTO PARTITION 表,NULL 值都被包含在最小值分区内。因此,如果对 NULL 值自动创建分区,会得到一个最小值起始的分区:
2. 对于 AUTO RANGE PARTITION,NULL 值的存储需要手动创建特定的分区。

在 Doris 的 RANGE PARTITION 中,我们并不使用单独的 NULL PARTITION 来包含 NULL 值,而是将其归属于**最小的 LESS THAN 分区内**。为保持逻辑清晰,AUTO RANGE PARTITION 在遇到 NULL 值时不会自动创建这样的分区。如有需要,可以自行创建这样的分区,以包含 NULL 值。

```sql
mysql> CREATE TABLE `range_table_nullable` (
Expand All @@ -202,15 +204,21 @@ mysql> CREATE TABLE `range_table_nullable` (
Query OK, 0 rows affected (0.09 sec)

mysql> insert into range_table_nullable values (0, null, null);
Query OK, 1 row affected (0.21 sec)

mysql> show partitions from range_table_nullable;
+-------------+-----------------+----------------+---------------------+--------+--------------+----------------------------------------------------------------------------------------------------------+-----------------+---------+----------------+---------------+---------------------+---------------------+--------------------------+----------+------------+-------------------------+-----------+--------------------+--------------+
| PartitionId | PartitionName | VisibleVersion | VisibleVersionTime | State | PartitionKey | Range | DistributionKey | Buckets | ReplicationNum | StorageMedium | CooldownTime | RemoteStoragePolicy | LastConsistencyCheckTime | DataSize | IsInMemory | ReplicaAllocation | IsMutable | SyncWithBaseTables | UnsyncTables |
+-------------+-----------------+----------------+---------------------+--------+--------------+----------------------------------------------------------------------------------------------------------+-----------------+---------+----------------+---------------+---------------------+---------------------+--------------------------+----------+------------+-------------------------+-----------+--------------------+--------------+
| 457060 | p00000101000000 | 2 | 2024-03-25 03:01:38 | NORMAL | k2 | [types: [DATETIMEV2]; keys: [0000-01-01 00:00:00]; ..types: [DATETIMEV2]; keys: [0000-01-02 00:00:00]; ) | k1 | 16 | 1 | HDD | 9999-12-31 23:59:59 | | NULL | 0.000 | false | tag.location.default: 1 | true | true | NULL |
+-------------+-----------------+----------------+---------------------+--------+--------------+----------------------------------------------------------------------------------------------------------+-----------------+---------+----------------+---------------+---------------------+---------------------+--------------------------+----------+------------+-------------------------+-----------+--------------------+--------------+
1 row in set (0.09 sec)
ERROR 1105 (HY000): errCode = 2, detailMessage = [CANCELLED]TStatus: errCode = 2, detailMessage = Can't create partition for NULL Range

mysql> alter table range_table_nullable add partition pX VALUES LESS THAN ("1970-01-01");
Query OK, 0 rows affected (0.11 sec)

mysql> insert into range_table_nullable values (0, null, null);
Query OK, 1 row affected (0.18 sec)

mysql> select * from range_table_nullable;
+------+------+------+
| k1 | k2 | k3 |
+------+------+------+
| 0 | NULL | NULL |
+------+------+------+
1 row in set (0.18 sec)
```

## 场景示例
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ mysql> select * from auto_null_list partition(pX);
1 row in set (0.20 sec)
```

2. Doris 中,无论是否为 AUTO PARTITION 表,NULL 值都被包含在最小值分区内。因此,如果对 NULL 值自动创建分区,会得到一个最小值起始的分区:
2. 对于 AUTO RANGE PARTITION,NULL 值的存储需要手动创建特定的分区。

在 Doris 的 RANGE PARTITION 中,我们并不使用单独的 NULL PARTITION 来包含 NULL 值,而是将其归属于**最小的 LESS THAN 分区内**。为保持逻辑清晰,AUTO RANGE PARTITION 在遇到 NULL 值时不会自动创建这样的分区。如有需要,可以自行创建这样的分区,以包含 NULL 值。

```sql
mysql> CREATE TABLE `range_table_nullable` (
Expand All @@ -204,15 +206,21 @@ mysql> CREATE TABLE `range_table_nullable` (
Query OK, 0 rows affected (0.09 sec)

mysql> insert into range_table_nullable values (0, null, null);
Query OK, 1 row affected (0.21 sec)

mysql> show partitions from range_table_nullable;
+-------------+-----------------+----------------+---------------------+--------+--------------+----------------------------------------------------------------------------------------------------------+-----------------+---------+----------------+---------------+---------------------+---------------------+--------------------------+----------+------------+-------------------------+-----------+--------------------+--------------+
| PartitionId | PartitionName | VisibleVersion | VisibleVersionTime | State | PartitionKey | Range | DistributionKey | Buckets | ReplicationNum | StorageMedium | CooldownTime | RemoteStoragePolicy | LastConsistencyCheckTime | DataSize | IsInMemory | ReplicaAllocation | IsMutable | SyncWithBaseTables | UnsyncTables |
+-------------+-----------------+----------------+---------------------+--------+--------------+----------------------------------------------------------------------------------------------------------+-----------------+---------+----------------+---------------+---------------------+---------------------+--------------------------+----------+------------+-------------------------+-----------+--------------------+--------------+
| 457060 | p00000101000000 | 2 | 2024-03-25 03:01:38 | NORMAL | k2 | [types: [DATETIMEV2]; keys: [0000-01-01 00:00:00]; ..types: [DATETIMEV2]; keys: [0000-01-02 00:00:00]; ) | k1 | 16 | 1 | HDD | 9999-12-31 23:59:59 | | NULL | 0.000 | false | tag.location.default: 1 | true | true | NULL |
+-------------+-----------------+----------------+---------------------+--------+--------------+----------------------------------------------------------------------------------------------------------+-----------------+---------+----------------+---------------+---------------------+---------------------+--------------------------+----------+------------+-------------------------+-----------+--------------------+--------------+
1 row in set (0.09 sec)
ERROR 1105 (HY000): errCode = 2, detailMessage = [CANCELLED]TStatus: errCode = 2, detailMessage = Can't create partition for NULL Range

mysql> alter table range_table_nullable add partition pX VALUES LESS THAN ("1970-01-01");
Query OK, 0 rows affected (0.11 sec)

mysql> insert into range_table_nullable values (0, null, null);
Query OK, 1 row affected (0.18 sec)

mysql> select * from range_table_nullable;
+------+------+------+
| k1 | k2 | k3 |
+------+------+------+
| 0 | NULL | NULL |
+------+------+------+
1 row in set (0.18 sec)
```

## 场景示例
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ PROPERTIES (

#### Overwrite Table Partition

> 该功能自 2.1.2 版本起可用。
> 该功能自 2.1.1 版本起可用。

使用 INSERT OVERWRITE 重写分区时,实际我们是将如下三步操作封装为一个事务并执行,如果中途失败,已进行的操作将会回滚:
1. 假设指定重写分区 p1,首先创建一个与重写的目标分区结构相同的空临时分区 `pTMP`
Expand Down
28 changes: 18 additions & 10 deletions versioned_docs/version-2.1/advanced/partition/auto-partition.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ mysql> select * from auto_null_list partition(pX);
1 row in set (0.20 sec)
```

2. In Doris, NULL values are included in the minimum value partition, whether they are AUTO PARTITION tables or not. Therefore, if a partition is automatically created for a NULL value, you get a partition starting with the minimum value:
2. For AUTO RANGE PARTITION, the storage of NULL values requires the manual creation of specific partitions.

In Doris' RANGE PARTITION, we do not use a separate NULL PARTITION to contain NULL values, but rather group them in the **minium LESS THAN partition**. For logical clarity, the AUTO RANGE PARTITION does not automatically create such a partition when it encounters a NULL value. If necessary, you can create such a partition yourself to contain NULL values.

```sql
mysql> CREATE TABLE `range_table_nullable` (
Expand All @@ -204,15 +206,21 @@ mysql> CREATE TABLE `range_table_nullable` (
Query OK, 0 rows affected (0.09 sec)

mysql> insert into range_table_nullable values (0, null, null);
Query OK, 1 row affected (0.21 sec)

mysql> show partitions from range_table_nullable;
+-------------+-----------------+----------------+---------------------+--------+--------------+----------------------------------------------------------------------------------------------------------+-----------------+---------+----------------+---------------+---------------------+---------------------+--------------------------+----------+------------+-------------------------+-----------+--------------------+--------------+
| PartitionId | PartitionName | VisibleVersion | VisibleVersionTime | State | PartitionKey | Range | DistributionKey | Buckets | ReplicationNum | StorageMedium | CooldownTime | RemoteStoragePolicy | LastConsistencyCheckTime | DataSize | IsInMemory | ReplicaAllocation | IsMutable | SyncWithBaseTables | UnsyncTables |
+-------------+-----------------+----------------+---------------------+--------+--------------+----------------------------------------------------------------------------------------------------------+-----------------+---------+----------------+---------------+---------------------+---------------------+--------------------------+----------+------------+-------------------------+-----------+--------------------+--------------+
| 457060 | p00000101000000 | 2 | 2024-03-25 03:01:38 | NORMAL | k2 | [types: [DATETIMEV2]; keys: [0000-01-01 00:00:00]; ..types: [DATETIMEV2]; keys: [0000-01-02 00:00:00]; ) | k1 | 16 | 1 | HDD | 9999-12-31 23:59:59 | | NULL | 0.000 | false | tag.location.default: 1 | true | true | NULL |
+-------------+-----------------+----------------+---------------------+--------+--------------+----------------------------------------------------------------------------------------------------------+-----------------+---------+----------------+---------------+---------------------+---------------------+--------------------------+----------+------------+-------------------------+-----------+--------------------+--------------+
1 row in set (0.09 sec)
ERROR 1105 (HY000): errCode = 2, detailMessage = [CANCELLED]TStatus: errCode = 2, detailMessage = Can't create partition for NULL Range

mysql> alter table range_table_nullable add partition pX VALUES LESS THAN ("1970-01-01");
Query OK, 0 rows affected (0.11 sec)

mysql> insert into range_table_nullable values (0, null, null);
Query OK, 1 row affected (0.18 sec)

mysql> select * from range_table_nullable;
+------+------+------+
| k1 | k2 | k3 |
+------+------+------+
| 0 | NULL | NULL |
+------+------+------+
1 row in set (0.18 sec)
```

## Sample Scenarios
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ The following is examples:

#### Overwrite Auto Detect Partition

> This feature is available since version 2.1.2.
> This feature is available since version 2.1.1.

When the PARTITION clause specified by the INSERT OVERWRITE command is `PARTITION(*)`, this overwrite will automatically detect the partition where the data is located. Example:

Expand Down