Skip to content

Commit

Permalink
Remove copyable code snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
lilin90 authored and ti-chi-bot committed May 8, 2024
1 parent 9c24108 commit 9a434dd
Showing 1 changed file with 0 additions and 48 deletions.
48 changes: 0 additions & 48 deletions sql-statements/sql-statement-split-region.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,12 @@ t22_r11

例如,对于表 t,如果想要从 `minInt64`~`maxInt64` 之间均匀切割出 16 个 Region,可以用以下语句:

{{< copyable "sql" >}}

```sql
SPLIT TABLE t BETWEEN (-9223372036854775808) AND (9223372036854775807) REGIONS 16;
```

该语句会把表 t 从 minInt64 到 maxInt64 之间均匀切割出 16 个 Region。如果已知主键的范围没有这么大,比如只会在 0~1000000000 之间,那可以用 01000000000 分别代替上面的 minInt64 和 maxInt64 来切分 Region。

{{< copyable "sql" >}}

```sql
SPLIT TABLE t BETWEEN (0) AND (1000000000) REGIONS 16;
```
Expand All @@ -113,8 +109,6 @@ SPLIT TABLE t BETWEEN (0) AND (1000000000) REGIONS 16;

如果已知数据不是均匀分布的,比如想要 -inf ~ 10000 切一个 Region,10000 ~ 90000 切一个 Region,90000 ~ +inf 切一个 Region,可以通过手动指定点来切分 Region,示例如下:

{{< copyable "sql" >}}

```sql
SPLIT TABLE t BY (10000), (90000);
```
Expand Down Expand Up @@ -143,8 +137,6 @@ t22_i5abc

如果索引 idx 的列也是整数类型,可以用如下 SQL 语句切分索引数据:

{{< copyable "sql" >}}

```sql
SPLIT TABLE t INDEX idx BETWEEN (-9223372036854775808) AND (9223372036854775807) REGIONS 16;
```
Expand All @@ -153,8 +145,6 @@ SPLIT TABLE t INDEX idx BETWEEN (-9223372036854775808) AND (9223372036854775807)

如果索引 idx1 的列是 varchar 类型,希望根据前缀字母来切分索引数据:

{{< copyable "sql" >}}

```sql
SPLIT TABLE t INDEX idx1 BETWEEN ("a") AND ("z") REGIONS 25;
```
Expand All @@ -163,8 +153,6 @@ SPLIT TABLE t INDEX idx1 BETWEEN ("a") AND ("z") REGIONS 25;

上面的切分方法,以 y 和 z 前缀的索引数据都会写到 region 25,因为 `z` 并不是一个上界,真正的上界是 `z` 在 ASCII 码中的下一位 `{`,所以更准确的切分方法如下:

{{< copyable "sql" >}}

```sql
SPLIT TABLE t INDEX idx1 BETWEEN ("a") AND ("{") REGIONS 26;
```
Expand All @@ -173,8 +161,6 @@ SPLIT TABLE t INDEX idx1 BETWEEN ("a") AND ("{") REGIONS 26;

如果索引 idx2 的列是 timestamp/datetime 等时间类型,希望根据时间区间,按年为间隔切分索引数据,示例如下:

{{< copyable "sql" >}}

```sql
SPLIT TABLE t INDEX idx2 BETWEEN ("2010-01-01 00:00:00") AND ("2020-01-01 00:00:00") REGIONS 10;
```
Expand All @@ -183,8 +169,6 @@ SPLIT TABLE t INDEX idx2 BETWEEN ("2010-01-01 00:00:00") AND ("2020-01-01 00:00:

如果希望按照天为间隔切分索引,示例如下:

{{< copyable "sql" >}}

```sql
SPLIT TABLE t INDEX idx2 BETWEEN ("2020-06-01 00:00:00") AND ("2020-07-01 00:00:00") REGIONS 30;
```
Expand All @@ -197,16 +181,12 @@ SPLIT TABLE t INDEX idx2 BETWEEN ("2020-06-01 00:00:00") AND ("2020-07-01 00:00:

比如索引 `idx3 (a, b)` 包含 2 列,a 是 timestamp,b 是 int。如果只想根据 a 列做时间范围的切分,可以用切分单列时间索引的 SQL 语句来切分,`lower_value``upper_velue` 中不指定 b 列的值即可。

{{< copyable "sql" >}}

```sql
SPLIT TABLE t INDEX idx3 BETWEEN ("2010-01-01 00:00:00") AND ("2020-01-01 00:00:00") REGIONS 10;
```

如果想在时间相同的情况下,根据 b 列再做一次切分,在切分时指定 b 列的值即可。

{{< copyable "sql" >}}

```sql
SPLIT TABLE t INDEX idx3 BETWEEN ("2010-01-01 00:00:00", "a") AND ("2010-01-01 00:00:00", "z") REGIONS 10;
```
Expand All @@ -225,8 +205,6 @@ SPLIT TABLE t INDEX `PRIMARY` BETWEEN (-9223372036854775808) AND (92233720368547

假如有 idx4 (a,b),其中 a 列是 varchar 类型,b 列是 timestamp 类型。

{{< copyable "sql" >}}

```sql
SPLIT TABLE t1 INDEX idx4 BY ("a", "2000-01-01 00:00:01"), ("b", "2019-04-17 14:26:19"), ("c", "");
```
Expand All @@ -246,16 +224,12 @@ region4 [("c", "") , maxIndexValue )

- 均匀切分的语法如下:

{{< copyable "sql" >}}

```sql
SPLIT [PARTITION] TABLE t [PARTITION] [(partition_name_list...)] [INDEX index_name] BETWEEN (lower_value) AND (upper_value) REGIONS region_num
```

- 不均匀切分的语法如下:

{{< copyable "sql" >}}

```sql
SPLIT [PARTITION] TABLE table_name [PARTITION (partition_name_list...)] [INDEX index_name] BY (value_list) [, (value_list)] ...
```
Expand All @@ -264,16 +238,12 @@ region4 [("c", "") , maxIndexValue )

1. 首先创建一个分区表。如果你要建一个 Hash 分区表,分成 2 个 partition,示例语句如下:

{{< copyable "sql" >}}

```sql
CREATE TABLE t (a INT, b INT, INDEX idx(a)) PARTITION BY HASH(a) PARTITIONS 2;
```

此时建完表后会为每个 partition 都单独 split 一个 Region,用 [`SHOW TABLE REGIONS`](/sql-statements/sql-statement-show-table-regions.md) 语法查看该表的 Region 如下:

{{< copyable "sql" >}}

```sql
SHOW TABLE t REGIONS;
```
Expand All @@ -289,8 +259,6 @@ region4 [("c", "") , maxIndexValue )

2. 用 `SPLIT` 语法为每个 partition 切分 Region。如果你要将各个 partition 的 [0,10000] 范围内的数据切分成 4 个 Region,示例语句如下:

{{< copyable "sql" >}}

```sql
SPLIT PARTITION TABLE t BETWEEN (0) AND (10000) REGIONS 4;
```
Expand All @@ -303,8 +271,6 @@ region4 [("c", "") , maxIndexValue )

3. 用 `SHOW TABLE REGIONS` 语法查看该表的 Region。如下会发现该表现在一共有 10 个 Region,每个 partition 分别有 5 个 Region,其中 4 个 Region 是表的行数据,1 个 Region 是表的索引数据。

{{< copyable "sql" >}}

```sql
SHOW TABLE t REGIONS;
```
Expand All @@ -328,8 +294,6 @@ region4 [("c", "") , maxIndexValue )

4. 如果你要给每个分区的索引切分 Region,如将索引 `idx` 的 [1000,10000] 范围切分成 2 个 Region,示例语句如下:

{{< copyable "sql" >}}

```sql
SPLIT PARTITION TABLE t INDEX idx BETWEEN (1000) AND (10000) REGIONS 2;
```
Expand All @@ -340,8 +304,6 @@ region4 [("c", "") , maxIndexValue )

1. 首先创建一个分区表。如果你要建一个 Range 分区表,分成 3 个 partition,示例语句如下:

{{< copyable "sql" >}}

```sql
CREATE TABLE t ( a INT, b INT, INDEX idx(b)) PARTITION BY RANGE( a ) (
PARTITION p1 VALUES LESS THAN (10000),
Expand All @@ -351,24 +313,18 @@ region4 [("c", "") , maxIndexValue )

2. 如果你要将 `p1` 分区的 [0,10000] 范围内的数据预切分 2 个 Region,示例语句如下:

{{< copyable "sql" >}}

```sql
SPLIT PARTITION TABLE t PARTITION (p1) BETWEEN (0) AND (10000) REGIONS 2;
```

3. 如果你要将 `p2` 分区的 [10000,20000] 范围内的数据预切分 2 个 Region,示例语句如下:

{{< copyable "sql" >}}

```sql
SPLIT PARTITION TABLE t PARTITION (p2) BETWEEN (10000) AND (20000) REGIONS 2;
```

4. 用 `SHOW TABLE REGIONS` 语法查看该表的 Region 如下:

{{< copyable "sql" >}}

```sql
SHOW TABLE t REGIONS;
```
Expand All @@ -387,8 +343,6 @@ region4 [("c", "") , maxIndexValue )

5. 如果你要将 `p1``p2` 分区的索引 `idx` 的 [0,20000] 范围预切分 2 个 Region,示例语句如下:

{{< copyable "sql" >}}

```sql
SPLIT PARTITION TABLE t PARTITION (p1,p2) INDEX idx BETWEEN (0) AND (20000) REGIONS 2;
```
Expand All @@ -407,8 +361,6 @@ region4 [("c", "") , maxIndexValue )

### pre_split_regions 示例

{{< copyable "sql" >}}

```sql
CREATE TABLE t (a INT, b INT, INDEX idx1(a)) SHARD_ROW_ID_BITS = 4 PRE_SPLIT_REGIONS=2;
```
Expand Down

0 comments on commit 9a434dd

Please sign in to comment.