You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ji...@apache.org on 2022/12/29 02:45:31 UTC
[shardingsphere] branch master updated: Add IF NOT EXISTS to all CREATE statements in DistSQL documents (#23134)
This is an automated email from the ASF dual-hosted git repository.
jianglongtao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new f2307320908 Add IF NOT EXISTS to all CREATE statements in DistSQL documents (#23134)
f2307320908 is described below
commit f2307320908bd679cdb77b07a5e3240d2794accd
Author: Zichao <57...@users.noreply.github.com>
AuthorDate: Thu Dec 29 15:45:24 2022 +1300
Add IF NOT EXISTS to all CREATE statements in DistSQL documents (#23134)
* Add IF NOT EXISTS to all CREATE statements in DistSQL documents
* Add IF NOT EXISTS to all CREATE statements in DistSQL documents
* Add IF NOT EXISTS to all CREATE statements in DistSQL documents
---
.../db-discovery/create-db-discovery-rule.cn.md | 18 +++++++++--
.../db-discovery/create-db-discovery-rule.en.md | 21 ++++++++++---
.../encrypt/create-encrypt-rule.cn.md | 23 ++++++++++++--
.../encrypt/create-encrypt-rule.en.md | 27 ++++++++++++++---
.../alter-readwrite-splitting-rule.cn.md | 2 +-
.../alter-readwrite-splitting-rule.en.md | 2 +-
.../create-readwrite-splitting-rule.cn.md | 32 ++++++++++++++++++--
.../create-readwrite-splitting-rule.en.md | 32 ++++++++++++++++++--
.../shadow/create-default-shadow-algorithm.cn.md | 14 +++++++--
.../shadow/create-default-shadow-algorithm.en.md | 14 +++++++--
.../shadow/create-shadow-rule.cn.md | 19 ++++++++++--
.../shadow/create-shadow-rule.en.md | 19 ++++++++++--
.../sharding/create-broadcast-table-rule.cn.md | 12 +++++++-
.../sharding/create-broadcast-table-rule.en.md | 14 +++++++--
.../create-default-sharding-strategy.cn.md | 16 ++++++++--
.../create-default-sharding-strategy.en.md | 16 ++++++++--
.../create-sharding-table-reference-rule.cn.md | 12 +++++++-
.../create-sharding-table-reference-rule.en.md | 12 +++++++-
.../sharding/create-sharding-table-rule.cn.md | 35 ++++++++++++++++++++--
.../sharding/create-sharding-table-rule.en.md | 34 +++++++++++++++++++--
.../register-storage-unit.cn.md | 20 +++++++++++--
.../register-storage-unit.en.md | 20 +++++++++++--
.../syntax/rdl/rule-definition/db-discovery.cn.md | 7 +++--
.../syntax/rdl/rule-definition/db-discovery.en.md | 7 +++--
.../syntax/rdl/rule-definition/encrypt.cn.md | 7 +++--
.../syntax/rdl/rule-definition/encrypt.en.md | 7 +++--
.../rdl/rule-definition/readwrite-splitting.cn.md | 9 ++++--
.../rdl/rule-definition/readwrite-splitting.en.md | 9 ++++--
.../syntax/rdl/rule-definition/shadow.cn.md | 11 ++++---
.../syntax/rdl/rule-definition/shadow.en.md | 11 ++++---
.../syntax/rdl/rule-definition/sharding.cn.md | 25 +++++++++++-----
.../syntax/rdl/rule-definition/sharding.en.md | 25 +++++++++++-----
.../syntax/rdl/storage-unit-definition.cn.md | 7 +++--
.../syntax/rdl/storage-unit-definition.en.md | 7 +++--
34 files changed, 457 insertions(+), 89 deletions(-)
diff --git a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/db-discovery/create-db-discovery-rule.cn.md b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/db-discovery/create-db-discovery-rule.cn.md
index 477c3f400a1..aeee7a8b001 100644
--- a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/db-discovery/create-db-discovery-rule.cn.md
+++ b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/db-discovery/create-db-discovery-rule.cn.md
@@ -11,7 +11,10 @@ weight = 2
```sql
CreateDatabaseDiscoveryRule ::=
- 'CREATE' 'DB_DISCOVERY' 'RULE' databaseDiscoveryDefinition (',' databaseDiscoveryDefinition)*
+ 'CREATE' 'DB_DISCOVERY' 'RULE' ifNotExists? databaseDiscoveryDefinition (',' databaseDiscoveryDefinition)*
+
+ifNotExists ::=
+ 'IF' 'NOT' 'EXISTS'
databaseDiscoveryDefinition ::=
ruleName '(' 'STORAGE_UNITS' '(' storageUnitName (',' storageUnitName)* ')' ',' 'TYPE' '(' 'NAME' '=' typeName (',' propertiesDefinition)? ')' ',' 'HEARTBEAT' '(' propertiesDefinition ')' ')'
@@ -41,7 +44,8 @@ value ::=
### 补充说明
- `discoveryType` 指定数据库发现服务类型,`ShardingSphere` 内置支持 `MySQL.MGR`;
-- 重复的 `ruleName` 将无法被创建。
+- 重复的 `ruleName` 将无法被创建;
+- `ifNotExists` 子句用于避免出现 `Duplicate db_discovery rule` 错误。
### 示例
@@ -55,6 +59,16 @@ CREATE DB_DISCOVERY RULE db_discovery_group_0 (
);
```
+- 使用 `ifNotExists` 子句创建数据库发现规则
+
+```sql
+CREATE DB_DISCOVERY RULE IF NOT EXISTS db_discovery_group_0 (
+ STORAGE_UNITS(su_0, su_1, su_2),
+ TYPE(NAME='MySQL.MGR',PROPERTIES('group-name'='92504d5b-6dec')),
+ HEARTBEAT(PROPERTIES('keep-alive-cron'='0/5 * * * * ?'))
+);
+```
+
### 保留字
`CREATE`、`DB_DISCOVERY`、`RULE`、`STORAGE_UNITS`、`TYPE`、`NAME`、`PROPERTIES`、`HEARTBEAT`
diff --git a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/db-discovery/create-db-discovery-rule.en.md b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/db-discovery/create-db-discovery-rule.en.md
index 6aa0a48c7ae..3388dee1536 100644
--- a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/db-discovery/create-db-discovery-rule.en.md
+++ b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/db-discovery/create-db-discovery-rule.en.md
@@ -11,7 +11,10 @@ The `CREATE DB_DISCOVERY RULE` syntax is used to create a database discovery rul
```sql
CreateDatabaseDiscoveryRule ::=
- 'CREATE' 'DB_DISCOVERY' 'RULE' databaseDiscoveryDefinition (',' databaseDiscoveryDefinition)*
+ 'CREATE' 'DB_DISCOVERY' 'RULE' ifNotExists? databaseDiscoveryDefinition (',' databaseDiscoveryDefinition)*
+
+ifNotExists ::=
+ 'IF' 'NOT' 'EXISTS'
databaseDiscoveryDefinition ::=
ruleName '(' 'STORAGE_UNITS' '(' storageUnitName (',' storageUnitName)* ')' ',' 'TYPE' '(' 'NAME' '=' typeName (',' propertiesDefinition)? ')' ',' 'HEARTBEAT' '(' propertiesDefinition ')' ')'
@@ -41,15 +44,25 @@ value ::=
### Supplement
- `discoveryType` specifies the database discovery service type, `ShardingSphere` has built-in support for `MySQL.MGR`;
-- Duplicate `ruleName` will not be created.
+- Duplicate `ruleName` will not be created;
+- `ifNotExists` clause used for avoid `Duplicate db_discovery rule` error.
### Example
- Create database discovery rule
```sql
-CREATE
-DB_DISCOVERY RULE db_discovery_group_0 (
+CREATE DB_DISCOVERY RULE db_discovery_group_0 (
+ STORAGE_UNITS(su_0, su_1, su_2),
+ TYPE(NAME='MySQL.MGR',PROPERTIES('group-name'='92504d5b-6dec')),
+ HEARTBEAT(PROPERTIES('keep-alive-cron'='0/5 * * * * ?'))
+);
+```
+
+- Create database discovery rule with `ifNotExists` clause
+
+```sql
+CREATE DB_DISCOVERY RULE IF NOT EXISTS db_discovery_group_0 (
STORAGE_UNITS(su_0, su_1, su_2),
TYPE(NAME='MySQL.MGR',PROPERTIES('group-name'='92504d5b-6dec')),
HEARTBEAT(PROPERTIES('keep-alive-cron'='0/5 * * * * ?'))
diff --git a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/encrypt/create-encrypt-rule.cn.md b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/encrypt/create-encrypt-rule.cn.md
index 0187bfa4d6a..b7c41019b92 100644
--- a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/encrypt/create-encrypt-rule.cn.md
+++ b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/encrypt/create-encrypt-rule.cn.md
@@ -11,7 +11,10 @@ weight = 2
```sql
CreateEncryptRule ::=
- 'CREATE' 'ENCRYPT' 'RULE' encryptDefinition (',' encryptDefinition)*
+ 'CREATE' 'ENCRYPT' 'RULE' ifNotExists? encryptDefinition (',' encryptDefinition)*
+
+ifNotExists ::=
+ 'IF' 'NOT' 'EXISTS'
encryptDefinition ::=
ruleName '(' 'COLUMNS' '(' columnDefinition (',' columnDefinition)* ')' (',' 'QUERY_WITH_CIPHER_COLUMN' '=' ('TRUE' | 'FALSE'))? ')'
@@ -63,7 +66,8 @@ value ::=
- `PLAIN` 指定明文数据列,`CIPHER` 指定密文数据列,`ASSISTED_QUERY_COLUMN` 指定辅助查询列,`LIKE_QUERY_COLUMN` 指定模糊查询列;
- `encryptAlgorithmType` 指定加密算法类型,请参考 [加密算法](/cn/user-manual/common-config/builtin-algorithm/encrypt/);
-- 重复的 `ruleName` 将无法被创建。
+- 重复的 `ruleName` 将无法被创建;
+- `ifNotExists` 子句用于避免出现 `Duplicate encrypt rule` 错误。
### 示例
@@ -82,6 +86,21 @@ COLUMNS(
), QUERY_WITH_CIPHER_COLUMN=FALSE);
```
+#### 使用 `ifNotExists` 子句创建数据加密规则
+
+```sql
+CREATE ENCRYPT RULE IF NOT EXISTS t_encrypt (
+COLUMNS(
+(NAME=user_id,PLAIN=user_plain,CIPHER=user_cipher,ENCRYPT_ALGORITHM(TYPE(NAME='AES',PROPERTIES('aes-key-value'='123456abc')))),
+(NAME=order_id, CIPHER =order_cipher,ENCRYPT_ALGORITHM(TYPE(NAME='MD5')))
+),QUERY_WITH_CIPHER_COLUMN=true),
+t_encrypt_2 (
+COLUMNS(
+(NAME=user_id,PLAIN=user_plain,CIPHER=user_cipher,ENCRYPT_ALGORITHM(TYPE(NAME='AES',PROPERTIES('aes-key-value'='123456abc')))),
+(NAME=order_id, CIPHER=order_cipher,ENCRYPT_ALGORITHM(TYPE(NAME='MD5')))
+), QUERY_WITH_CIPHER_COLUMN=FALSE);
+```
+
### 保留字
`CREATE`、`ENCRYPT`、`RULE`、`COLUMNS`、`NAME`、`CIPHER`、`PLAIN`、`QUERY_WITH_CIPHER_COLUMN`、`TYPE`、`TRUE`、`FALSE`
diff --git a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/encrypt/create-encrypt-rule.en.md b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/encrypt/create-encrypt-rule.en.md
index 8f91604b940..054e602b810 100644
--- a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/encrypt/create-encrypt-rule.en.md
+++ b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/encrypt/create-encrypt-rule.en.md
@@ -11,7 +11,10 @@ The `CREATE READWRITE_SPLITTING RULE` syntax is used to create a readwrite split
```sql
CreateEncryptRule ::=
- 'CREATE' 'ENCRYPT' 'RULE' encryptDefinition (',' encryptDefinition)*
+ 'CREATE' 'ENCRYPT' 'RULE' ifNotExists? encryptDefinition (',' encryptDefinition)*
+
+ifNotExists ::=
+ 'IF' 'NOT' 'EXISTS'
encryptDefinition ::=
ruleName '(' 'COLUMNS' '(' columnDefinition (',' columnDefinition)* ')' (',' 'QUERY_WITH_CIPHER_COLUMN' '=' ('TRUE' | 'FALSE'))? ')'
@@ -61,9 +64,10 @@ value ::=
### Supplement
-- `PLAIN` specifies the plain column, `CIPHER` specifies the cipher column, `ASSISTED_QUERY_COLUMN` specifies the assisted query column,`LIKE_QUERY_COLUMN` specifies the like query column
-- `encryptAlgorithmType` specifies the encryption algorithm type, please refer to [Encryption Algorithm](/en/user-manual/common-config/builtin-algorithm/encrypt/)
-- Duplicate `ruleName` will not be created
+- `PLAIN` specifies the plain column, `CIPHER` specifies the cipher column, `ASSISTED_QUERY_COLUMN` specifies the assisted query column,`LIKE_QUERY_COLUMN` specifies the like query column;
+- `encryptAlgorithmType` specifies the encryption algorithm type, please refer to [Encryption Algorithm](/en/user-manual/common-config/builtin-algorithm/encrypt/);
+- Duplicate `ruleName` will not be created;
+- `ifNotExists` clause used for avoid `Duplicate encrypt rule` error.
### Example
@@ -82,6 +86,21 @@ COLUMNS(
), QUERY_WITH_CIPHER_COLUMN=FALSE);
```
+#### Create a encrypt rule with `ifNotExists` clause
+
+```sql
+CREATE ENCRYPT RULE t_encrypt IF NOT EXISTS (
+COLUMNS(
+(NAME=user_id,PLAIN=user_plain,CIPHER=user_cipher,ENCRYPT_ALGORITHM(TYPE(NAME='AES',PROPERTIES('aes-key-value'='123456abc')))),
+(NAME=order_id, CIPHER =order_cipher,ENCRYPT_ALGORITHM(TYPE(NAME='MD5')))
+),QUERY_WITH_CIPHER_COLUMN=true),
+t_encrypt_2 (
+COLUMNS(
+(NAME=user_id,PLAIN=user_plain,CIPHER=user_cipher,ENCRYPT_ALGORITHM(TYPE(NAME='AES',PROPERTIES('aes-key-value'='123456abc')))),
+(NAME=order_id, CIPHER=order_cipher,ENCRYPT_ALGORITHM(TYPE(NAME='MD5')))
+), QUERY_WITH_CIPHER_COLUMN=FALSE);
+```
+
### Reserved word
`CREATE`, `ENCRYPT`, `RULE`, `COLUMNS`, `NAME`, `CIPHER`, `PLAIN`, `QUERY_WITH_CIPHER_COLUMN`, `TYPE`, `TRUE`, `FALSE`
diff --git a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/readwrite-splitting/alter-readwrite-splitting-rule.cn.md b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/readwrite-splitting/alter-readwrite-splitting-rule.cn.md
index ec889f98ed0..8e4f9581f8e 100644
--- a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/readwrite-splitting/alter-readwrite-splitting-rule.cn.md
+++ b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/readwrite-splitting/alter-readwrite-splitting-rule.cn.md
@@ -73,7 +73,7 @@ ALTER READWRITE_SPLITTING RULE ms_group_0 (
ALTER READWRITE_SPLITTING RULE ms_group_1 (
AUTO_AWARE_RESOURCE=group_0,
WRITE_DATA_SOURCE_QUERY_ENABLED=false,
- TYPE(NAME="random",PROPERTIES("read_weight"="2:1"))
+ TYPE(NAME="random")
);
```
diff --git a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/readwrite-splitting/alter-readwrite-splitting-rule.en.md b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/readwrite-splitting/alter-readwrite-splitting-rule.en.md
index d7587527125..7d083817959 100644
--- a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/readwrite-splitting/alter-readwrite-splitting-rule.en.md
+++ b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/readwrite-splitting/alter-readwrite-splitting-rule.en.md
@@ -73,7 +73,7 @@ ALTER READWRITE_SPLITTING RULE ms_group_0 (
ALTER READWRITE_SPLITTING RULE ms_group_1 (
AUTO_AWARE_RESOURCE=group_0,
WRITE_DATA_SOURCE_QUERY_ENABLED=false,
- TYPE(NAME="random",PROPERTIES("read_weight"="2:1"))
+ TYPE(NAME="random")
);
```
diff --git a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/readwrite-splitting/create-readwrite-splitting-rule.cn.md b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/readwrite-splitting/create-readwrite-splitting-rule.cn.md
index cd12bbd44ab..53eb14061ed 100644
--- a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/readwrite-splitting/create-readwrite-splitting-rule.cn.md
+++ b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/readwrite-splitting/create-readwrite-splitting-rule.cn.md
@@ -11,7 +11,10 @@ weight = 2
```sql
CreateReadwriteSplittingRule ::=
- 'CREATE' 'READWRITE_SPLITTING' 'RULE' readwriteSplittingDefinition (',' readwriteSplittingDefinition)*
+ 'CREATE' 'READWRITE_SPLITTING' 'RULE' ifNotExists? readwriteSplittingDefinition (',' readwriteSplittingDefinition)*
+
+ifNotExists ::=
+ 'IF' 'NOT' 'EXISTS'
readwriteSplittingDefinition ::=
ruleName '(' (staticReadwriteSplittingDefinition | dynamicReadwriteSplittingDefinition) (',' loadBalancerDefinition)? ')'
@@ -55,7 +58,8 @@ value ::=
- 支持创建静态读写分离规则和动态读写分离规则;
- 动态读写分离规则依赖于数据库发现规则;
- `loadBalancerType` 指定负载均衡算法类型,请参考负载均衡算法;
-- 重复的 `ruleName` 将无法被创建。
+- 重复的 `ruleName` 将无法被创建;
+- `ifNotExists` 子句用于避免出现 `Duplicate readwrite_splitting rule` 错误。
### 示例
@@ -75,7 +79,29 @@ CREATE READWRITE_SPLITTING RULE ms_group_0 (
CREATE READWRITE_SPLITTING RULE ms_group_1 (
AUTO_AWARE_RESOURCE=group_0,
WRITE_DATA_SOURCE_QUERY_ENABLED=false,
- TYPE(NAME="random",PROPERTIES("read_weight"="2:1"))
+ TYPE(NAME="random")
+);
+```
+
+#### 使用 `ifNotExists` 子句创建读写分离规则
+
+- 静态读写分离规则
+
+```sql
+CREATE READWRITE_SPLITTING RULE IF NOT EXISTS ms_group_0 (
+ WRITE_STORAGE_UNIT=write_ds,
+ READ_STORAGE_UNITS(read_ds_0,read_ds_1),
+ TYPE(NAME="random")
+);
+```
+
+- 动态读写分离规则
+
+```sql
+CREATE READWRITE_SPLITTING RULE IF NOT EXISTS ms_group_1 (
+ AUTO_AWARE_RESOURCE=group_0,
+ WRITE_DATA_SOURCE_QUERY_ENABLED=false,
+ TYPE(NAME="random")
);
```
diff --git a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/readwrite-splitting/create-readwrite-splitting-rule.en.md b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/readwrite-splitting/create-readwrite-splitting-rule.en.md
index d2d1ffbc095..b1454695a72 100644
--- a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/readwrite-splitting/create-readwrite-splitting-rule.en.md
+++ b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/readwrite-splitting/create-readwrite-splitting-rule.en.md
@@ -11,7 +11,10 @@ The `CREATE READWRITE_SPLITTING RULE` syntax is used to create a readwrite split
```sql
CreateReadwriteSplittingRule ::=
- 'CREATE' 'READWRITE_SPLITTING' 'RULE' readwriteSplittingDefinition (',' readwriteSplittingDefinition)*
+ 'CREATE' 'READWRITE_SPLITTING' 'RULE' ifNotExists? readwriteSplittingDefinition (',' readwriteSplittingDefinition)*
+
+ifNotExists ::=
+ 'IF' 'NOT' 'EXISTS'
readwriteSplittingDefinition ::=
ruleName '(' (staticReadwriteSplittingDefinition | dynamicReadwriteSplittingDefinition) (',' loadBalancerDefinition)? ')'
@@ -55,7 +58,8 @@ value ::=
- Support the creation of static readwrite-splitting rules and dynamic readwrite-splitting rules;
- Dynamic readwrite-splitting rules rely on database discovery rules;
- `loadBalancerType` specifies the load balancing algorithm type, please refer to Load Balance Algorithm;
-- Duplicate `ruleName` will not be created.
+- Duplicate `ruleName` will not be created;
+- `ifNotExists` clause used for avoid `Duplicate readwrite_splitting rule` error.
### Example
@@ -75,7 +79,29 @@ CREATE READWRITE_SPLITTING RULE ms_group_0 (
CREATE READWRITE_SPLITTING RULE ms_group_1 (
AUTO_AWARE_RESOURCE=group_0,
WRITE_DATA_SOURCE_QUERY_ENABLED=false,
- TYPE(NAME="random",PROPERTIES("read_weight"="2:1"))
+ TYPE(NAME="random")
+);
+```
+
+#### Create readwrite splitting rule with `ifNotExists` clause
+
+- Statics readwrite splitting rule
+
+```sql
+CREATE READWRITE_SPLITTING RULE IF NOT EXISTS ms_group_0 (
+ WRITE_STORAGE_UNIT=write_ds,
+ READ_STORAGE_UNITS(read_ds_0,read_ds_1),
+ TYPE(NAME="random")
+);
+```
+
+- Dynamic readwrite splitting rule
+
+```sql
+CREATE READWRITE_SPLITTING RULE IF NOT EXISTS ms_group_1 (
+ AUTO_AWARE_RESOURCE=group_0,
+ WRITE_DATA_SOURCE_QUERY_ENABLED=false,
+ TYPE(NAME="random")
);
```
diff --git a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/shadow/create-default-shadow-algorithm.cn.md b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/shadow/create-default-shadow-algorithm.cn.md
index b0e3bd94d09..dbca638ae5a 100644
--- a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/shadow/create-default-shadow-algorithm.cn.md
+++ b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/shadow/create-default-shadow-algorithm.cn.md
@@ -11,7 +11,10 @@ weight = 5
```sql
CreateDefaultShadowAlgorithm ::=
- 'CREATE' 'DEFAULT' 'SHADOW' 'ALGORITHM' shadowAlgorithm
+ 'CREATE' 'DEFAULT' 'SHADOW' 'ALGORITHM' ifNotExists? shadowAlgorithm
+
+ifNotExists ::=
+ 'IF' 'NOT' 'EXISTS'
shadowAlgorithm ::=
'TYPE' '(' 'NAME' '=' shadowAlgorithmType ',' propertiesDefiinition ')'
@@ -31,7 +34,8 @@ value ::=
### 补充说明
-- `shadowAlgorithmType` 目前支持 `VALUE_MATCH`、`REGEX_MATCH` 和 `SIMPLE_HINT`。
+- `shadowAlgorithmType` 目前支持 `VALUE_MATCH`、`REGEX_MATCH` 和 `SIMPLE_HINT`;
+- `ifNotExists` 子句用于避免出现 `Duplicate default shadow algorithm` 错误。
### 示例
@@ -41,6 +45,12 @@ value ::=
CREATE DEFAULT SHADOW ALGORITHM TYPE(NAME="SIMPLE_HINT", PROPERTIES("shadow"="true", "foo"="bar"));
```
+- 使用 `ifNotExists` 子句创建默认影子库压测算法
+
+```sql
+CREATE DEFAULT SHADOW ALGORITHM IF NOT EXISTS TYPE(NAME="SIMPLE_HINT", PROPERTIES("shadow"="true", "foo"="bar"));
+```
+
### 保留字
`CREATE`、`DEFAULT`、`SHADOW`、`ALGORITHM`、`TYPE`、`NAME`、`PROPERTIES`
diff --git a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/shadow/create-default-shadow-algorithm.en.md b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/shadow/create-default-shadow-algorithm.en.md
index 8be029ed9cf..2a863a26a88 100644
--- a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/shadow/create-default-shadow-algorithm.en.md
+++ b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/shadow/create-default-shadow-algorithm.en.md
@@ -11,7 +11,10 @@ The `CREATE DEFAULT SHADOW ALGORITHM` syntax is used to create a default shadow
```sql
CreateDefaultShadowAlgorithm ::=
- 'CREATE' 'DEFAULT' 'SHADOW' 'ALGORITHM' shadowAlgorithm
+ 'CREATE' 'DEFAULT' 'SHADOW' 'ALGORITHM' ifNotExists? shadowAlgorithm
+
+ifNotExists ::=
+ 'IF' 'NOT' 'EXISTS'
shadowAlgorithm ::=
'TYPE' '(' 'NAME' '=' shadowAlgorithmType ',' propertiesDefiinition ')'
@@ -31,7 +34,8 @@ value ::=
### Supplement
-- `shadowAlgorithmType` currently supports `VALUE_MATCH`, `REGEX_MATCH` and `SIMPLE_HINT`.
+- `shadowAlgorithmType` currently supports `VALUE_MATCH`, `REGEX_MATCH` and `SIMPLE_HINT`;
+- `ifNotExists` clause is used for avoid `Duplicate default shadow algorithm` error.
### Example
@@ -41,6 +45,12 @@ value ::=
CREATE DEFAULT SHADOW ALGORITHM TYPE(NAME="SIMPLE_HINT", PROPERTIES("shadow"="true", "foo"="bar"));
```
+- Create default shadow algorithm with `ifNotExist` clause
+
+```sql
+CREATE DEFAULT SHADOW ALGORITHM IF NOT EXISTS TYPE(NAME="SIMPLE_HINT", PROPERTIES("shadow"="true", "foo"="bar"));
+```
+
### Reserved word
`CREATE`, `DEFAULT`, `SHADOW`, `ALGORITHM`, `TYPE`, `NAME`, `PROPERTIES`
diff --git a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/shadow/create-shadow-rule.cn.md b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/shadow/create-shadow-rule.cn.md
index 55f9ee7636e..90100087790 100644
--- a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/shadow/create-shadow-rule.cn.md
+++ b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/shadow/create-shadow-rule.cn.md
@@ -11,7 +11,10 @@ weight = 2
```sql
CreateShadowRule ::=
- 'CREATE' 'SHADOW' 'RULE' shadowRuleDefinition (',' shadowRuleDefinition)*
+ 'CREATE' 'SHADOW' 'RULE' ifNotExists? shadowRuleDefinition (',' shadowRuleDefinition)*
+
+ifNotExists ::=
+ 'IF' 'NOT' 'EXISTS'
shadowRuleDefinition ::=
ruleName '(' storageUnitMapping shadowTableRule (',' shadowTableRule)* ')'
@@ -57,7 +60,8 @@ value ::=
,请参考 [存储单元](https://shardingsphere.apache.org/document/current/cn/reference/distsql/syntax/rdl/storage-unit-definition/);
- `shadowAlgorithm` 可同时作用于多个 `shadowTableRule`;
- `algorithmName` 会根据 `ruleName`、`tableName` 和 `shadowAlgorithmType` 自动生成;
-- `shadowAlgorithmType` 目前支持 `VALUE_MATCH`、`REGEX_MATCH` 和 `SIMPLE_HINT`。
+- `shadowAlgorithmType` 目前支持 `VALUE_MATCH`、`REGEX_MATCH` 和 `SIMPLE_HINT`;
+- `ifNotExists` 子句用于避免出现 `Duplicate shadow rule` 错误。
### 示例
@@ -72,6 +76,17 @@ CREATE SHADOW RULE shadow_rule(
);
```
+- 使用 `ifNotExists` 子句创建影子库压测规则
+
+```sql
+CREATE SHADOW RULE IF NOT EXISTS shadow_rule(
+ SOURCE=demo_su,
+ SHADOW=demo_su_shadow,
+ t_order(TYPE(NAME="SIMPLE_HINT", PROPERTIES("shadow"="true", "foo"="bar"))),
+ t_order_item(TYPE(NAME="VALUE_MATCH", PROPERTIES("operation"="insert","column"="user_id", "value"='1')))
+);
+```
+
### 保留字
`CREATE`、`SHADOW`、`RULE`、`SOURCE`、`SHADOW`、`TYPE`、`NAME`、`PROPERTIES`
diff --git a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/shadow/create-shadow-rule.en.md b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/shadow/create-shadow-rule.en.md
index a31b0cb4d2d..963e7c6e3f4 100644
--- a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/shadow/create-shadow-rule.en.md
+++ b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/shadow/create-shadow-rule.en.md
@@ -11,7 +11,10 @@ The `CREATE SHADOW RULE` syntax is used to create a shadow rule.
```sql
CreateShadowRule ::=
- 'CREATE' 'SHADOW' 'RULE' shadowRuleDefinition (',' shadowRuleDefinition)*
+ 'CREATE' 'SHADOW' 'RULE' ifNotExists? shadowRuleDefinition (',' shadowRuleDefinition)*
+
+ifNotExists ::=
+ 'IF' 'NOT' 'EXISTS'
shadowRuleDefinition ::=
ruleName '(' storageUnitMapping shadowTableRule (',' shadowTableRule)* ')'
@@ -59,7 +62,8 @@ value ::=
- `shadowAlgorithm` can act on multiple `shadowTableRule` at the same time;
- If `algorithmName` is not specified, it will be automatically generated according to `ruleName`, `tableName`
and `shadowAlgorithmType`;
-- `shadowAlgorithmType` currently supports `VALUE_MATCH`, `REGEX_MATCH` and `SIMPLE_HINT`.
+- `shadowAlgorithmType` currently supports `VALUE_MATCH`, `REGEX_MATCH` and `SIMPLE_HINT`;
+- `ifNotExists` caluse is used for avoid `Duplicate shadow rule` error.
### Example
@@ -74,6 +78,17 @@ CREATE SHADOW RULE shadow_rule(
);
```
+- Create a shadow rule with `ifNotExists` clause
+
+```sql
+CREATE SHADOW RULE IF NOT EXISTS shadow_rule(
+ SOURCE=demo_su,
+ SHADOW=demo_su_shadow,
+ t_order(TYPE(NAME="SIMPLE_HINT", PROPERTIES("shadow"="true", "foo"="bar"))),
+ t_order_item(TYPE(NAME="VALUE_MATCH", PROPERTIES("operation"="insert","column"="user_id", "value"='1')))
+);
+```
+
### Reserved word
`CREATE`, `SHADOW`, `RULE`, `SOURCE`, `SHADOW`, `TYPE`, `NAME`, `PROPERTIES`
diff --git a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/sharding/create-broadcast-table-rule.cn.md b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/sharding/create-broadcast-table-rule.cn.md
index e4f4cc4d1c7..1cd430acf58 100644
--- a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/sharding/create-broadcast-table-rule.cn.md
+++ b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/sharding/create-broadcast-table-rule.cn.md
@@ -11,7 +11,10 @@ weight = 16
```sql
CreateBroadcastTableRule ::=
- 'CREATE' 'BROADCAST' 'TABLE' 'RULE' tableName (',' tableName)*
+ 'CREATE' 'BROADCAST' 'TABLE' 'RULE' ifNotExists? tableName (',' tableName)*
+
+ifNotExists ::=
+ 'IF' 'NOT' 'EXISTS'
tableName ::=
identifier
@@ -20,6 +23,7 @@ tableName ::=
### 补充说明
- `tableName` 可使用已经存在的表或者将要创建的表;
+- `ifNotExists` 子句用于避免 `Duplicate Broadcast rule` 错误。
### 示例
@@ -30,6 +34,12 @@ tableName ::=
CREATE BROADCAST TABLE RULE t_province, t_city;
```
+#### 使用 `ifNotExists` 子句创建广播规则
+
+```sql
+CREATE BROADCAST TABLE RULE IF NOT EXISTS t_province, t_city;
+```
+
### 保留字
`CREATE`、`BROADCAST`、`TABLE`、`RULE`
diff --git a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/sharding/create-broadcast-table-rule.en.md b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/sharding/create-broadcast-table-rule.en.md
index 14e468f9637..6268aa2a7ce 100644
--- a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/sharding/create-broadcast-table-rule.en.md
+++ b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/sharding/create-broadcast-table-rule.en.md
@@ -12,7 +12,10 @@ broadcast (broadcast tables)
```sql
CreateBroadcastTableRule ::=
- 'CREATE' 'BROADCAST' 'TABLE' 'RULE' tableName (',' tableName)*
+ 'CREATE' 'BROADCAST' 'TABLE' 'RULE' ifNotExists? tableName (',' tableName)*
+
+ifNotExists ::=
+ 'IF' 'NOT' 'EXISTS'
tableName ::=
identifier
@@ -20,7 +23,8 @@ tableName ::=
### Supplement
-- `tableName` can use an existing table or a table that will be created.
+- `tableName` can use an existing table or a table that will be created;
+- `ifNotExists` clause is used for avoid `Duplicate Broadcast rule` error.
### Example
@@ -31,6 +35,12 @@ tableName ::=
CREATE BROADCAST TABLE RULE t_province, t_city;
```
+#### Create broadcast table rule with `ifNotExists` clause
+
+```sql
+CREATE BROADCAST TABLE RULE IF NOT EXISTS t_province, t_city;
+```
+
### Reserved word
`CREATE`, `BROADCAST`, `TABLE`, `RULE`
diff --git a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/sharding/create-default-sharding-strategy.cn.md b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/sharding/create-default-sharding-strategy.cn.md
index 0dfc9a47e0e..fab830c408c 100644
--- a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/sharding/create-default-sharding-strategy.cn.md
+++ b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/sharding/create-default-sharding-strategy.cn.md
@@ -11,7 +11,10 @@ weight = 5
```sql
CreateDefaultShardingStrategy ::=
- 'CREATE' 'DEFAULT' 'SHARDING' ('DATABASE' | 'TABLE') 'STRATEGY' '(' shardingStrategy ')'
+ 'CREATE' 'DEFAULT' 'SHARDING' ('DATABASE' | 'TABLE') 'STRATEGY' ifNotExists? '(' shardingStrategy ')'
+
+ifNotExists ::=
+ 'IF' 'NOT' 'EXISTS'
shardingStrategy ::=
'TYPE' '=' strategyType ',' ('SHARDING_COLUMN' '=' columnName | 'SHARDING_COLUMNS' '=' columnNames) ',' 'SHARDING_ALGORITHM' '=' algorithmDefinition
@@ -44,7 +47,8 @@ value ::=
### 补充说明
- 当使用复合分片算法时,需要通过 `SHARDING_COLUMNS` 指定多个分片键;
-- `algorithmType` 为分片算法类型,详细的分片算法类型信息请参考[分片算法](/cn/user-manual/common-config/builtin-algorithm/sharding/)。
+- `algorithmType` 为分片算法类型,详细的分片算法类型信息请参考[分片算法](/cn/user-manual/common-config/builtin-algorithm/sharding/);
+- `ifNotExists` 子句用于避免出现 `Duplicate default sharding strategy` 错误。
### 示例
@@ -56,6 +60,14 @@ CREATE DEFAULT SHARDING TABLE STRATEGY (
);
```
+- 使用 `ifNotExists` 创建默认分表策略
+
+```sql
+CREATE DEFAULT SHARDING TABLE STRATEGY IF NOT EXISTS (
+ TYPE="standard", SHARDING_COLUMN=user_id, SHARDING_ALGORITHM(TYPE(NAME=inline, PROPERTIES("algorithm-expression"="t_order_${user_id % 2}")))
+);
+```
+
### 保留字
`CREATE`、`DEFAULT`、`SHARDING`、`DATABASE`、`TABLE`、`STRATEGY`、`TYPE`、`SHARDING_COLUMN`、`SHARDING_COLUMNS`、`SHARDING_ALGORITHM`、`NAME`、`PROPERTIES`
diff --git a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/sharding/create-default-sharding-strategy.en.md b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/sharding/create-default-sharding-strategy.en.md
index 19b57b1bbbf..c04484944ce 100644
--- a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/sharding/create-default-sharding-strategy.en.md
+++ b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/sharding/create-default-sharding-strategy.en.md
@@ -11,7 +11,10 @@ The `CREATE DEFAULT SHARDING STRATEGY` syntax is used to create a default shardi
```sql
CreateDefaultShardingStrategy ::=
- 'CREATE' 'DEFAULT' 'SHARDING' ('DATABASE' | 'TABLE') 'STRATEGY' '(' shardingStrategy ')'
+ 'CREATE' 'DEFAULT' 'SHARDING' ('DATABASE' | 'TABLE') 'STRATEGY' ifNotExists? '(' shardingStrategy ')'
+
+ifNotExists ::=
+ 'IF' 'NOT' 'EXISTS'
shardingStrategy ::=
'TYPE' '=' strategyType ',' ('SHARDING_COLUMN' '=' columnName | 'SHARDING_COLUMNS' '=' columnNames) ',' 'SHARDING_ALGORITHM' '=' algorithmDefinition
@@ -45,7 +48,8 @@ value ::=
- When using the complex sharding algorithm, multiple sharding columns need to be specified using `SHARDING_COLUMNS`;
- `algorithmType` is the sharding algorithm type. For detailed sharding algorithm type information, please refer
- to [Sharding Algorithm](/en/user-manual/common-config/builtin-algorithm/sharding/).
+ to [Sharding Algorithm](/en/user-manual/common-config/builtin-algorithm/sharding/);
+- `ifNotExists` clause is used for avoid `Duplicate default sharding strategy` error.
### Example
@@ -58,6 +62,14 @@ CREATE DEFAULT SHARDING TABLE STRATEGY (
);
```
+- create a default sharding table strategy with `ifNotExists` clause
+
+```sql
+CREATE DEFAULT SHARDING TABLE STRATEGY IF NOT EXISTS (
+ TYPE="standard", SHARDING_COLUMN=user_id, SHARDING_ALGORITHM(TYPE(NAME="inline", PROPERTIES("algorithm-expression"="t_order_${user_id % 2}")))
+);
+```
+
### Reserved word
`CREATE`, `DEFAULT`, `SHARDING`, `DATABASE`, `TABLE`, `STRATEGY`, `TYPE`, `SHARDING_COLUMN`, `SHARDING_COLUMNS`, `SHARDING_ALGORITHM`, `NAME`, `PROPERTIES`
diff --git a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/sharding/create-sharding-table-reference-rule.cn.md b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/sharding/create-sharding-table-reference-rule.cn.md
index c579e8e6abb..bcde7ae859d 100644
--- a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/sharding/create-sharding-table-reference-rule.cn.md
+++ b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/sharding/create-sharding-table-reference-rule.cn.md
@@ -11,7 +11,10 @@ weight = 13
```sql
CreateShardingTableReferenceRule ::=
- 'CREATE' 'SHARDING' 'TABLE' 'REFERENCE' 'RULE' referenceRelationshipDefinition (',' referenceRelationshipDefinition)*
+ 'CREATE' 'SHARDING' 'TABLE' 'REFERENCE' 'RULE' ifNotExists? referenceRelationshipDefinition (',' referenceRelationshipDefinition)*
+
+ifNotExists ::=
+ 'IF' 'NOT' 'EXISTS'
referenceRelationshipDefinition ::=
ruleName '(' tableName (',' tableName)* ')'
@@ -26,6 +29,7 @@ tableName ::=
- 一张分片表只能具有一个关联关系;
- 关联的分片表应分布在相同的存储单元,并且分片个数相同。例如 `ds_${0..1}.t_order_${0..1}` 与 `ds_${0..1}.t_order_item_${0..1}`;
- 关联的分片表应使用一致的分片算法。例如 `t_order_${order_id % 2}` 与 `t_order_item_${order_item_id % 2}`;
+- `ifNotExists` 子句用于避免 `Duplicate sharding table reference rule` 错误。
### 示例
@@ -43,6 +47,12 @@ CREATE SHARDING TABLE REFERENCE RULE ref_0 (t_order,t_order_item);
CREATE SHARDING TABLE REFERENCE RULE ref_0 (t_order,t_order_item), ref_1 (t_product,t_product_item);
```
+#### 3.使用 `ifNotExists` 子句创建关联关系
+
+```sql
+CREATE SHARDING TABLE REFERENCE RULE IF NOT EXISTS ref_0 (t_order,t_order_item);
+```
+
### 保留字
`CREATE`、`SHARDING`、`TABLE`、`REFERENCE`、`RULE`
diff --git a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/sharding/create-sharding-table-reference-rule.en.md b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/sharding/create-sharding-table-reference-rule.en.md
index 0e7c1e27ae4..20cb901d805 100644
--- a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/sharding/create-sharding-table-reference-rule.en.md
+++ b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/sharding/create-sharding-table-reference-rule.en.md
@@ -11,7 +11,10 @@ The `CREATE SHARDING TABLE REFERENCE RULE` syntax is used to create reference ru
```sql
CreateShardingTableReferenceRule ::=
- 'CREATE' 'SHARDING' 'TABLE' 'REFERENCE' 'RULE' referenceRelationshipDefinition (',' referenceRelationshipDefinition)*
+ 'CREATE' 'SHARDING' 'TABLE' 'REFERENCE' 'RULE' ifNotExists? referenceRelationshipDefinition (',' referenceRelationshipDefinition)*
+
+ifNotExists ::=
+ 'IF' 'NOT' 'EXISTS'
referenceRelationshipDefinition ::=
ruleName '(' tableName (',' tableName)* ')'
@@ -27,6 +30,7 @@ tableName ::=
- The referenced sharding tables should be sharded in the same storage units and have the same number of sharding nodes. For
example `ds_${0..1}.t_order_${0..1}` and `ds_${0..1}.t_order_item_${0..1}`;
- The referenced sharding tables should use consistent sharding algorithms. For example `t_order_{order_id % 2}` and `t_order_item_{order_item_id % 2}`;
+- `ifNotExists` clause used for avoid `Duplicate sharding table reference rule` error.
### Example
@@ -44,6 +48,12 @@ CREATE SHARDING TABLE REFERENCE RULE ref_0 (t_order,t_order_item);
CREATE SHARDING TABLE REFERENCE RULE ref_0 (t_order,t_order_item), ref_1 (t_product,t_product_item);
```
+#### 3.Create a sharding table reference rule with `ifNotExists` clause
+
+```sql
+CREATE SHARDING TABLE REFERENCE RULE IF NOT EXISTS ref_0 (t_order,t_order_item);
+```
+
### Reserved word
`CREATE`, `SHARDING`, `TABLE`, `REFERENCE`, `RULE`
diff --git a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/sharding/create-sharding-table-rule.cn.md b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/sharding/create-sharding-table-rule.cn.md
index 81b6cddb76f..dcd6ae72452 100644
--- a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/sharding/create-sharding-table-rule.cn.md
+++ b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/sharding/create-sharding-table-rule.cn.md
@@ -11,7 +11,10 @@ weight = 2
```sql
CreateShardingTableRule ::=
- 'CREATE' 'SHARDING' 'TABLE' 'RULE' (tableDefinition | autoTableDefinition) (',' (tableDefinition | autoTableDefinition))*
+ 'CREATE' 'SHARDING' 'TABLE' 'RULE' ifNotExists? (tableDefinition | autoTableDefinition) (',' (tableDefinition | autoTableDefinition))*
+
+ifNotExists ::=
+ 'IF' 'NOT' 'EXISTS'
tableDefinition ::=
tableName '(' 'DATANODES' '(' dataNode (',' dataNode)* ')' (',' 'DATABASE_STRATEGY' '(' strategyDefinition ')')? (',' 'TABLE_STRATEGY' '(' strategyDefinition ')')? (',' 'KEY_GENERATE_STRATEGY' '(' keyGenerateStrategyDefinition ')')? (',' 'AUDIT_STRATEGY' '(' auditStrategyDefinition ')')? ')'
@@ -75,9 +78,10 @@ strategyType ::=
- 自动生成的算法命名规则为 `tableName` _ `strategyType` _ `algorithmType`;
- 自动生成的主键策略命名规则为 `tableName` _ `strategyType;
- `KEY_GENERATE_STRATEGY`
- 用于指定主键生成策略,为可选项,关于主键生成策略可参考[分布式主键](/cn/user-manual/common-config/builtin-algorithm/keygen/)。
+ 用于指定主键生成策略,为可选项,关于主键生成策略可参考[分布式主键](/cn/user-manual/common-config/builtin-algorithm/keygen/);
- `AUDIT_STRATEGY`
- 用于指定分配审计生成策略,为可选项,关于分片审计生成策略可参考[分片审计](/cn/user-manual/common-config/builtin-algorithm/audit/)。
+ 用于指定分配审计生成策略,为可选项,关于分片审计生成策略可参考[分片审计](/cn/user-manual/common-config/builtin-algorithm/audit/);
+- `ifNotExists` 子句用于避免出现 `Duplicate sharding rule` 错误。
### 示例
@@ -104,6 +108,31 @@ AUDIT_STRATEGY (TYPE(NAME="DML_SHARDING_CONDITIONS"),ALLOW_HINT_DISABLE=true)
);
```
+#### 3.使用 `ifNotExists` 子句创建分片规则
+
+- 标准分片规则
+
+```sql
+CREATE SHARDING TABLE RULE IF NOT EXISTS t_order_item (
+DATANODES("ds_${0..1}.t_order_item_${0..1}"),
+DATABASE_STRATEGY(TYPE="standard",SHARDING_COLUMN=user_id,SHARDING_ALGORITHM(TYPE(NAME="inline",PROPERTIES("algorithm-expression"="ds_${user_id % 2}")))),
+TABLE_STRATEGY(TYPE="standard",SHARDING_COLUMN=order_id,SHARDING_ALGORITHM(TYPE(NAME="inline",PROPERTIES("algorithm-expression"="t_order_item_${order_id % 2}")))),
+KEY_GENERATE_STRATEGY(COLUMN=another_id,TYPE(NAME="snowflake")),
+AUDIT_STRATEGY (TYPE(NAME="DML_SHARDING_CONDITIONS"),ALLOW_HINT_DISABLE=true)
+);
+```
+
+- 自动分片规则
+
+```sql
+CREATE SHARDING TABLE RULE IF NOT EXISTS t_order (
+STORAGE_UNITS(ds_0,ds_1),
+SHARDING_COLUMN=order_id,TYPE(NAME="hash_mod",PROPERTIES("sharding-count"="4")),
+KEY_GENERATE_STRATEGY(COLUMN=another_id,TYPE(NAME="snowflake")),
+AUDIT_STRATEGY (TYPE(NAME="DML_SHARDING_CONDITIONS"),ALLOW_HINT_DISABLE=true)
+);
+```
+
### 保留字
`CREATE`、`SHARDING`、`TABLE`、`RULE`、`DATANODES`、`DATABASE_STRATEGY`、`TABLE_STRATEGY`、`KEY_GENERATE_STRATEGY`、`STORAGE_UNITS`、`SHARDING_COLUMN`、`TYPE`、`SHARDING_COLUMN`、`KEY_GENERATOR`、`SHARDING_ALGORITHM`、`COLUMN`、`NAME`、`PROPERTIES`、`AUDIT_STRATEGY`、`AUDITORS`、`ALLOW_HINT_DISABLE`
diff --git a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/sharding/create-sharding-table-rule.en.md b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/sharding/create-sharding-table-rule.en.md
index 57c40102c80..c00b900d3d9 100644
--- a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/sharding/create-sharding-table-rule.en.md
+++ b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/sharding/create-sharding-table-rule.en.md
@@ -11,7 +11,10 @@ The `CREATE SHARDING TABLE RULE` syntax is used to add sharding table rule for t
```sql
CreateShardingTableRule ::=
- 'CREATE' 'SHARDING' 'TABLE' 'RULE' (tableDefinition | autoTableDefinition) (',' (tableDefinition | autoTableDefinition))*
+ 'CREATE' 'SHARDING' 'TABLE' 'RULE' ifNotExists? (tableDefinition | autoTableDefinition) (',' (tableDefinition | autoTableDefinition))*
+
+ifNotExists ::=
+ 'IF' 'NOT' 'EXISTS'
tableDefinition ::=
tableName '(' 'DATANODES' '(' dataNode (',' dataNode)* ')' (',' 'DATABASE_STRATEGY' '(' strategyDefinition ')')? (',' 'TABLE_STRATEGY' '(' strategyDefinition ')')? (',' 'KEY_GENERATE_STRATEGY' '(' keyGenerateStrategyDefinition ')')? (',' 'AUDIT_STRATEGY' '(' auditStrategyDefinition ')')? ')'
@@ -84,10 +87,11 @@ strategyType ::=
- The auto-generated primary key strategy naming rule is `tableName` _ `strategyType`;
- `KEY_GENERATE_STRATEGY` is used to specify the primary key generation strategy, which is optional. For the primary key
generation strategy, please refer
- to [Distributed Primary Key](/en/user-manual/common-config/builtin-algorithm/keygen/).
+ to [Distributed Primary Key](/en/user-manual/common-config/builtin-algorithm/keygen/);
- `AUDIT_STRATEGY` is used to specify the sharding audit strategy, which is optional. For the sharding audit
generation strategy, please refer
- to [Sharding Audit](/en/user-manual/common-config/builtin-algorithm/audit/).
+ to [Sharding Audit](/en/user-manual/common-config/builtin-algorithm/audit/);
+- `ifNotExists` clause is used for avoid `Duplicate sharding rule` error.
### Example
@@ -114,6 +118,30 @@ AUDIT_STRATEGY (TYPE(NAME="DML_SHARDING_CONDITIONS"),ALLOW_HINT_DISABLE=true)
);
```
+#### 3.Create sharding rule with `ifNotExists` clause
+
+- Standard sharding table rule
+
+```sql
+CREATE SHARDING TABLE RULE IF NOT EXISTS t_order_item (
+DATANODES("ds_${0..1}.t_order_item_${0..1}"),
+DATABASE_STRATEGY(TYPE="standard",SHARDING_COLUMN=user_id,SHARDING_ALGORITHM(TYPE(NAME="inline",PROPERTIES("algorithm-expression"="ds_${user_id % 2}")))),
+TABLE_STRATEGY(TYPE="standard",SHARDING_COLUMN=order_id,SHARDING_ALGORITHM(TYPE(NAME="inline",PROPERTIES("algorithm-expression"="t_order_item_${order_id % 2}")))),
+KEY_GENERATE_STRATEGY(COLUMN=another_id,TYPE(NAME="snowflake")),
+AUDIT_STRATEGY (TYPE(NAME="DML_SHARDING_CONDITIONS"),ALLOW_HINT_DISABLE=true)
+);
+```
+- Auto sharding table rule
+
+```sql
+CREATE SHARDING TABLE RULE IF NOT EXISTS t_order (
+STORAGE_UNITS(ds_0,ds_1),
+SHARDING_COLUMN=order_id,TYPE(NAME="hash_mod",PROPERTIES("sharding-count"="4")),
+KEY_GENERATE_STRATEGY(COLUMN=another_id,TYPE(NAME="snowflake")),
+AUDIT_STRATEGY (TYPE(NAME="DML_SHARDING_CONDITIONS"),ALLOW_HINT_DISABLE=true)
+);
+```
+
### Reserved word
`CREATE`, `SHARDING`, `TABLE`, `RULE`, `DATANODES`, `DATABASE_STRATEGY`, `TABLE_STRATEGY`, `KEY_GENERATE_STRATEGY`, `STORAGE_UNITS`, `SHARDING_COLUMN`, `TYPE`, `SHARDING_COLUMN`, `KEY_GENERATOR`, `SHARDING_ALGORITHM`, `COLUMN`, `NAME`, `PROPERTIES`, `AUDIT_STRATEGY`, `AUDITORS`, `ALLOW_HINT_DISABLE`
diff --git a/docs/document/content/reference/distsql/syntax/rdl/storage-unit-definition/register-storage-unit.cn.md b/docs/document/content/reference/distsql/syntax/rdl/storage-unit-definition/register-storage-unit.cn.md
index e3d313a41b7..2813906c054 100644
--- a/docs/document/content/reference/distsql/syntax/rdl/storage-unit-definition/register-storage-unit.cn.md
+++ b/docs/document/content/reference/distsql/syntax/rdl/storage-unit-definition/register-storage-unit.cn.md
@@ -11,11 +11,14 @@ weight = 2
```sql
RegisterStorageUnit ::=
- 'REGISTER' 'STORAGE' 'UNIT' storageUnitDefinition (',' storageUnitDefinition)*
+ 'REGISTER' 'STORAGE' 'UNIT' ifNotExists? storageUnitDefinition (',' storageUnitDefinition)*
storageUnitDefinition ::=
storageUnitName '(' ('HOST' '=' hostName ',' 'PORT' '=' port ',' 'DB' '=' dbName | 'URL' '=' url) ',' 'USER' '=' user (',' 'PASSWORD' '=' password)? (',' propertiesDefinition)?')'
+ifNotExists ::=
+ 'IF' 'NOT' 'EXISTS'
+
storageUnitName ::=
identifier
@@ -54,7 +57,8 @@ value ::=
- `storageUnitName` 区分大小写;
- `storageUnitName` 在当前逻辑库中需要唯一;
- `storageUnitName` 命名只允许使用字母、数字以及 `_` ,且必须以字母开头;
-- `poolProperty` 用于自定义连接池参数,`key` 必须和连接池参数名一致。
+- `poolProperty` 用于自定义连接池参数,`key` 必须和连接池参数名一致;
+- `ifNotExists` 子句用于避免出现 `Duplicate storage unit` 的错误。
### 示例
@@ -94,6 +98,18 @@ REGISTER STORAGE UNIT su_2 (
);
```
+- 使用 `ifNotExists` 子句注册存储单元
+
+```sql
+REGISTER STORAGE UNIT IF NOT EXISTS su_0 (
+ HOST="127.0.0.1",
+ PORT=3306,
+ DB="db_0",
+ USER="root",
+ PASSWORD="root"
+);
+```
+
### 保留字
`REGISTER`、`STORAGE`、`UNIT`、`HOST`、`PORT`、`DB`、`USER`、`PASSWORD`、`PROPERTIES`、`URL`
diff --git a/docs/document/content/reference/distsql/syntax/rdl/storage-unit-definition/register-storage-unit.en.md b/docs/document/content/reference/distsql/syntax/rdl/storage-unit-definition/register-storage-unit.en.md
index c612a8280a3..534dd1b3eac 100644
--- a/docs/document/content/reference/distsql/syntax/rdl/storage-unit-definition/register-storage-unit.en.md
+++ b/docs/document/content/reference/distsql/syntax/rdl/storage-unit-definition/register-storage-unit.en.md
@@ -11,11 +11,14 @@ The `REGISTER STORAGE UNIT` syntax is used to register storage unit for the curr
```sql
RegisterStorageUnit ::=
- 'REGISTER' 'STORAGE' 'UNIT' storageUnitDefinition (',' storageUnitDefinition)*
+ 'REGISTER' 'STORAGE' 'UNIT' ifNotExists? storageUnitDefinition (',' storageUnitDefinition)*
storageUnitDefinition ::=
storageUnitName '(' ('HOST' '=' hostName ',' 'PORT' '=' port ',' 'DB' '=' dbName | 'URL' '=' url) ',' 'USER' '=' user (',' 'PASSWORD' '=' password)? (',' propertiesDefinition)?')'
+ifNotExists ::=
+ 'IF' 'NOT' 'EXISTS'
+
storageUnitName ::=
identifier
@@ -56,7 +59,8 @@ value ::=
- `storageUnitName` needs to be unique within the current database;
- `storageUnitName` name only allows letters, numbers and `_`, and must start with a letter;
- `poolProperty` is used to customize connection pool parameters, `key` must be the same as the connection pool
- parameter name.
+ parameter name;
+- `ifNotExists` clause is used for avoid `Duplicate storage unit` error.
### Example
@@ -96,6 +100,18 @@ REGISTER STORAGE UNIT su_2 (
);
```
+- Register storage unit with `ifNotExists` clause
+
+```sql
+REGISTER STORAGE UNIT IF NOT EXISTS su_0 (
+ HOST="127.0.0.1",
+ PORT=3306,
+ DB="db_0",
+ USER="root",
+ PASSWORD="root"
+);
+```
+
### Reserved word
`REGISTER`, `STORAGE`, `UNIT`, `HOST`, `PORT`, `DB`, `USER`, `PASSWORD`, `PROPERTIES`, `URL`
diff --git a/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/rule-definition/db-discovery.cn.md b/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/rule-definition/db-discovery.cn.md
index c73447044c2..366ddff421c 100644
--- a/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/rule-definition/db-discovery.cn.md
+++ b/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/rule-definition/db-discovery.cn.md
@@ -6,7 +6,7 @@ weight = 4
## 语法说明
```sql
-CREATE DB_DISCOVERY RULE ruleDefinition [, ruleDefinition] ...
+CREATE DB_DISCOVERY RULE ifNotExistsClause? ruleDefinition [, ruleDefinition] ...
ALTER DB_DISCOVERY RULE ruleDefinition [, ruleDefinition] ...
@@ -16,6 +16,9 @@ DROP DB_DISCOVERY TYPE discoveryTypeName [, discoveryTypeName] ...
DROP DB_DISCOVERY HEARTBEAT discoveryHeartbeatName [, discoveryHeartbeatName] ...
+ifNotExistsClause:
+ IF NOT EXISTS
+
ruleDefinition:
ruleName (storageUnits, typeDefinition, heartbeatDefinition)
@@ -57,7 +60,7 @@ property:
### 创建 `discoveryRule` 时同时创建 `discoveryType` 和 `discoveryHeartbeat`
```sql
-CREATE DB_DISCOVERY RULE db_discovery_group_0 (
+CREATE DB_DISCOVERY RULE IF NOT EXISTS db_discovery_group_0 (
STORAGE_UNITS(ds_0, ds_1, ds_2),
TYPE(NAME='MySQL.MGR',PROPERTIES('group-name'='92504d5b-6dec')),
HEARTBEAT(PROPERTIES('keep-alive-cron'='0/5 * * * * ?'))
diff --git a/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/rule-definition/db-discovery.en.md b/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/rule-definition/db-discovery.en.md
index a72c374166e..6c73140a8c3 100644
--- a/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/rule-definition/db-discovery.en.md
+++ b/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/rule-definition/db-discovery.en.md
@@ -6,7 +6,7 @@ weight = 4
## Syntax
```sql
-CREATE DB_DISCOVERY RULE ruleDefinition [, ruleDefinition] ...
+CREATE DB_DISCOVERY RULE ifNotExistsClause? ruleDefinition [, ruleDefinition] ...
ALTER DB_DISCOVERY RULE ruleDefinition [, ruleDefinition] ...
@@ -16,6 +16,9 @@ DROP DB_DISCOVERY TYPE discoveryTypeName [, discoveryTypeName] ...
DROP DB_DISCOVERY HEARTBEAT discoveryHeartbeatName [, discoveryHeartbeatName] ...
+ifNotExistsClause:
+ IF NOT EXISTS
+
ruleDefinition:
ruleName (storageUnits, typeDefinition, heartbeatDefinition)
@@ -57,7 +60,7 @@ property:
### When creating a `discoveryRule`, create both `discoveryType` and `discoveryHeartbeat`
```sql
-CREATE DB_DISCOVERY RULE db_discovery_group_0 (
+CREATE DB_DISCOVERY RULE IF NOT EXISTS db_discovery_group_0 (
STORAGE_UNITS(ds_0, ds_1, ds_2),
TYPE(NAME='MySQL.MGR',PROPERTIES('group-name'='92504d5b-6dec')),
HEARTBEAT(PROPERTIES('keep-alive-cron'='0/5 * * * * ?'))
diff --git a/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/rule-definition/encrypt.cn.md b/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/rule-definition/encrypt.cn.md
index d2a5826f408..2b23739014d 100644
--- a/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/rule-definition/encrypt.cn.md
+++ b/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/rule-definition/encrypt.cn.md
@@ -6,12 +6,15 @@ weight = 5
## 语法说明
```sql
-CREATE ENCRYPT RULE encryptRuleDefinition [, encryptRuleDefinition] ...
+CREATE ENCRYPT RULE ifNotExistsClause? encryptRuleDefinition [, encryptRuleDefinition] ...
ALTER ENCRYPT RULE encryptRuleDefinition [, encryptRuleDefinition] ...
DROP ENCRYPT RULE tableName [, tableName] ...
+ifNotExistsClause:
+ IF NOT EXISTS
+
encryptRuleDefinition:
tableName(COLUMNS(columnDefinition [, columnDefinition] ...), QUERY_WITH_CIPHER_COLUMN=queryWithCipherColumn)
@@ -55,7 +58,7 @@ algorithmProperty:
## 示例
```sql
-CREATE ENCRYPT RULE t_encrypt (
+CREATE ENCRYPT RULE IF NOT EXISTS t_encrypt (
COLUMNS(
(NAME=user_id,PLAIN=user_plain,CIPHER=user_cipher,ASSISTED_QUERY_COLUMN=user_assisted,LIKE_QUERY_COLUMN=user_like,ENCRYPT_ALGORITHM(TYPE(NAME='AES',PROPERTIES('aes-key-value'='123456abc'))),ASSISTED_QUERY_ALGORITHM(TYPE(NAME='MD5')), LIKE_QUERY_ALGORITHM(TYPE(NAME='CHAR_DIGEST_LIKE'))),
(NAME=order_id, CIPHER =order_cipher, ENCRYPT_ALGORITHM(TYPE(NAME='MD5')), QUERY_WITH_CIPHER_COLUMN=FALSE)
diff --git a/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/rule-definition/encrypt.en.md b/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/rule-definition/encrypt.en.md
index 80edc7ae037..8a77307d146 100644
--- a/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/rule-definition/encrypt.en.md
+++ b/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/rule-definition/encrypt.en.md
@@ -6,12 +6,15 @@ weight = 5
## Syntax
```sql
-CREATE ENCRYPT RULE encryptRuleDefinition [, encryptRuleDefinition] ...
+CREATE ENCRYPT RULE ifNotExistsClause? encryptRuleDefinition [, encryptRuleDefinition] ...
ALTER ENCRYPT RULE encryptRuleDefinition [, encryptRuleDefinition] ...
DROP ENCRYPT RULE tableName [, tableName] ...
+ifNotExistsClause:
+ IF NOT EXISTS
+
encryptRuleDefinition:
tableName(COLUMNS(columnDefinition [, columnDefinition] ...), QUERY_WITH_CIPHER_COLUMN=queryWithCipherColumn)
@@ -55,7 +58,7 @@ algorithmProperty:
## Example
```sql
-CREATE ENCRYPT RULE t_encrypt (
+CREATE ENCRYPT RULE IF NOT EXISTS t_encrypt (
COLUMNS(
(NAME=user_id,PLAIN=user_plain,CIPHER=user_cipher,ASSISTED_QUERY_COLUMN=user_assisted,LIKE_QUERY_COLUMN=user_like,ENCRYPT_ALGORITHM(TYPE(NAME='AES',PROPERTIES('aes-key-value'='123456abc'))),ASSISTED_QUERY_ALGORITHM(TYPE(NAME='MD5')), LIKE_QUERY_ALGORITHM(TYPE(NAME='CHAR_DIGEST_LIKE'))),
(NAME=order_id, CIPHER =order_cipher, ENCRYPT_ALGORITHM(TYPE(NAME='MD5')), QUERY_WITH_CIPHER_COLUMN=FALSE)
diff --git a/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/rule-definition/readwrite-splitting.cn.md b/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/rule-definition/readwrite-splitting.cn.md
index 6ccb66c06fb..82b82963397 100644
--- a/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/rule-definition/readwrite-splitting.cn.md
+++ b/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/rule-definition/readwrite-splitting.cn.md
@@ -6,12 +6,15 @@ weight = 3
## 语法说明
```sql
-CREATE READWRITE_SPLITTING RULE readwriteSplittingRuleDefinition [, readwriteSplittingRuleDefinition] ...
+CREATE READWRITE_SPLITTING RULE ifNotExistsClause? readwriteSplittingRuleDefinition [, readwriteSplittingRuleDefinition] ...
ALTER READWRITE_SPLITTING RULE readwriteSplittingRuleDefinition [, readwriteSplittingRuleDefinition] ...
DROP READWRITE_SPLITTING RULE ruleName [, ruleName] ...
+ifNotExistsClause:
+ IF NOT EXISTS
+
readwriteSplittingRuleDefinition:
ruleName ([staticReadwriteSplittingRuleDefinition | dynamicReadwriteSplittingRuleDefinition]
[, loadBalancerDefinition])
@@ -55,14 +58,14 @@ writeDataSourceQueryEnabled:
```sql
// Static
-CREATE READWRITE_SPLITTING RULE ms_group_0 (
+CREATE READWRITE_SPLITTING RULE IF NOT EXISTS ms_group_0 (
WRITE_STORAGE_UNIT=write_ds,
READ_STORAGE_UNITS(read_ds_0,read_ds_1),
TYPE(NAME="random")
);
// Dynamic
-CREATE READWRITE_SPLITTING RULE ms_group_1 (
+CREATE READWRITE_SPLITTING RULE IF NOT EXISTS ms_group_1 (
AUTO_AWARE_RESOURCE=group_0,
WRITE_DATA_SOURCE_QUERY_ENABLED=false,
TYPE(NAME="random")
diff --git a/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/rule-definition/readwrite-splitting.en.md b/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/rule-definition/readwrite-splitting.en.md
index 46107ff26de..1c391732343 100644
--- a/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/rule-definition/readwrite-splitting.en.md
+++ b/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/rule-definition/readwrite-splitting.en.md
@@ -6,12 +6,15 @@ weight = 3
## Syntax
```sql
-CREATE READWRITE_SPLITTING RULE readwriteSplittingRuleDefinition [, readwriteSplittingRuleDefinition] ...
+CREATE READWRITE_SPLITTING RULE ifNotExistsClause? readwriteSplittingRuleDefinition [, readwriteSplittingRuleDefinition] ...
ALTER READWRITE_SPLITTING RULE readwriteSplittingRuleDefinition [, readwriteSplittingRuleDefinition] ...
DROP READWRITE_SPLITTING RULE ruleName [, ruleName] ...
+ifNotExistsClause:
+ IF NOT EXISTS
+
readwriteSplittingRuleDefinition:
ruleName ([staticReadwriteSplittingRuleDefinition | dynamicReadwriteSplittingRuleDefinition]
[, loadBalancerDefinition])
@@ -55,14 +58,14 @@ writeDataSourceQueryEnabled:
```sql
// Static
-CREATE READWRITE_SPLITTING RULE ms_group_0 (
+CREATE READWRITE_SPLITTING RULE IF NOT EXISTS ms_group_0 (
WRITE_STORAGE_UNIT=write_ds,
READ_STORAGE_UNITS(read_ds_0,read_ds_1),
TYPE(NAME="random")
);
// Dynamic
-CREATE READWRITE_SPLITTING RULE ms_group_1 (
+CREATE READWRITE_SPLITTING RULE IF NOT EXISTS ms_group_1 (
AUTO_AWARE_RESOURCE=group_0,
WRITE_DATA_SOURCE_QUERY_ENABLED=false,
TYPE(NAME="random")
diff --git a/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/rule-definition/shadow.cn.md b/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/rule-definition/shadow.cn.md
index 540b7314eca..c4783d8ab0b 100644
--- a/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/rule-definition/shadow.cn.md
+++ b/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/rule-definition/shadow.cn.md
@@ -6,7 +6,7 @@ weight = 6
## 语法说明
```sql
-CREATE SHADOW RULE shadowRuleDefinition [, shadowRuleDefinition] ...
+CREATE SHADOW RULE ifNotExistsClause? shadowRuleDefinition [, shadowRuleDefinition] ...
ALTER SHADOW RULE shadowRuleDefinition [, shadowRuleDefinition] ...
@@ -14,7 +14,7 @@ DROP SHADOW RULE ruleName [, ruleName] ...
DROP SHADOW ALGORITHM algorithmName [, algorithmName] ...
-CREATE DEFAULT SHADOW ALGORITHM shadowAlgorithm
+CREATE DEFAULT SHADOW ALGORITHM ifNotExistsClause? shadowAlgorithm
ALTER DEFAULT SHADOW ALGORITHM shadowAlgorithm
@@ -24,6 +24,9 @@ SHOW DEFAULT SHADOW ALGORITHM
SHOW SHADOW ALGORITHMS
+ifNotExistsClause:
+ IF NOT EXISTS
+
shadowRuleDefinition: ruleName(storageUnitMapping, shadowTableRule [, shadowTableRule] ...)
storageUnitMapping: SOURCE=storageUnitName, SHADOW=storageUnitName
@@ -58,7 +61,7 @@ algorithmProperty: key=value
## 示例
```sql
-CREATE SHADOW RULE shadow_rule(
+CREATE SHADOW RULE IF NOT EXISTS shadow_rule(
SOURCE=demo_ds,
SHADOW=demo_ds_shadow,
t_order(TYPE(NAME="SIMPLE_HINT", PROPERTIES("shadow"=true, "foo"="bar")),TYPE(NAME="REGEX_MATCH", PROPERTIES("operation"="insert","column"="user_id", "regex"='[1]'))),
@@ -74,7 +77,7 @@ DROP SHADOW RULE shadow_rule;
DROP SHADOW ALGORITHM simple_hint_algorithm;
-CREATE DEFAULT SHADOW ALGORITHM TYPE(NAME="SIMPLE_HINT", PROPERTIES("shadow"=true, "foo"="bar"));
+CREATE DEFAULT SHADOW ALGORITHM IF NOT EXISTS TYPE(NAME="SIMPLE_HINT", PROPERTIES("shadow"=true, "foo"="bar"));
ALTER DEFAULT SHADOW ALGORITHM TYPE(NAME="SIMPLE_HINT", PROPERTIES("shadow"=false, "foo"="bar"));
diff --git a/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/rule-definition/shadow.en.md b/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/rule-definition/shadow.en.md
index 3064375bf37..30c5ec2ca0d 100644
--- a/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/rule-definition/shadow.en.md
+++ b/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/rule-definition/shadow.en.md
@@ -6,7 +6,7 @@ weight = 6
## Syntax
```sql
-CREATE SHADOW RULE shadowRuleDefinition [, shadowRuleDefinition] ...
+CREATE SHADOW RULE ifNotExistsClause? shadowRuleDefinition [, shadowRuleDefinition] ...
ALTER SHADOW RULE shadowRuleDefinition [, shadowRuleDefinition] ...
@@ -14,7 +14,7 @@ DROP SHADOW RULE ruleName [, ruleName] ...
DROP SHADOW ALGORITHM algorithmName [, algorithmName] ...
-CREATE DEFAULT SHADOW ALGORITHM shadowAlgorithm
+CREATE DEFAULT SHADOW ALGORITHM ifNotExistsClause? shadowAlgorithm
ALTER DEFAULT SHADOW ALGORITHM shadowAlgorithm
@@ -24,6 +24,9 @@ SHOW DEFAULT SHADOW ALGORITHM
SHOW SHADOW ALGORITHMS
+ifNotExistsClause:
+ IF NOT EXISTS
+
shadowRuleDefinition: ruleName(storageUnitMapping, shadowTableRule [, shadowTableRule] ...)
storageUnitMapping: SOURCE=storageUnitName, SHADOW=storageUnitName
@@ -58,7 +61,7 @@ algorithmProperty: key=value
## Example
```sql
-CREATE SHADOW RULE shadow_rule(
+CREATE SHADOW RULE IF NOT EXISTS shadow_rule(
SOURCE=demo_ds,
SHADOW=demo_ds_shadow,
t_order(TYPE(NAME="SIMPLE_HINT", PROPERTIES("shadow"=true, "foo"="bar")),TYPE(NAME="REGEX_MATCH", PROPERTIES("operation"="insert","column"="user_id", "regex"='[1]'))),
@@ -74,7 +77,7 @@ DROP SHADOW RULE shadow_rule;
DROP SHADOW ALGORITHM simple_hint_algorithm;
-CREATE DEFAULT SHADOW ALGORITHM TYPE(NAME="SIMPLE_HINT", PROPERTIES("shadow"=true, "foo"="bar"));
+CREATE DEFAULT SHADOW ALGORITHM IF NOT EXISTS TYPE(NAME="SIMPLE_HINT", PROPERTIES("shadow"=true, "foo"="bar"));
ALTER DEFAULT SHADOW ALGORITHM TYPE(NAME="SIMPLE_HINT", PROPERTIES("shadow"=false, "foo"="bar"));
diff --git a/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/rule-definition/sharding.cn.md b/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/rule-definition/sharding.cn.md
index 9fa6f8ccdf2..f10dbba4ade 100644
--- a/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/rule-definition/sharding.cn.md
+++ b/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/rule-definition/sharding.cn.md
@@ -8,13 +8,13 @@ weight = 1
### Sharding Table Rule
```sql
-CREATE SHARDING TABLE RULE shardingTableRuleDefinition [, shardingTableRuleDefinition] ...
+CREATE SHARDING TABLE RULE ifNotExistsClause? shardingTableRuleDefinition [, shardingTableRuleDefinition] ...
ALTER SHARDING TABLE RULE shardingTableRuleDefinition [, shardingTableRuleDefinition] ...
DROP SHARDING TABLE RULE tableName [, tableName] ...
-CREATE DEFAULT SHARDING shardingScope STRATEGY (shardingStrategy)
+CREATE DEFAULT SHARDING shardingScope STRATEGY ifNotExistsClause? (shardingStrategy)
ALTER DEFAULT SHARDING shardingScope STRATEGY (shardingStrategy)
@@ -26,6 +26,9 @@ DROP SHARDING KEY GENERATOR [IF EXISTS] keyGeneratorName [, keyGeneratorName] ..
DROP SHARDING AUDITOR [IF EXISTS] auditorName [, auditorName] ...
+ifNotExistsClause:
+ IF NOT EXISTS
+
shardingTableRuleDefinition:
shardingAutoTableRule | shardingTableRule
@@ -100,12 +103,15 @@ algorithmProperty:
### Sharding Table Reference Rule
```sql
-CREATE SHARDING TABLE REFERENCE RULE tableReferenceRuleDefinition [, tableReferenceRuleDefinition] ...
+CREATE SHARDING TABLE REFERENCE RULE ifNotExistsClause? tableReferenceRuleDefinition [, tableReferenceRuleDefinition] ...
ALTER SHARDING TABLE REFERENCE RULE tableReferenceRuleDefinition [, tableReferenceRuleDefinition] ...
DROP SHARDING TABLE REFERENCE RULE ifExists? ruleName [, ruleName] ...
+ifNotExistsClause:
+ IF NOT EXISTS
+
tableReferenceRuleDefinition:
ruleName (tableName [, tableName] ... )
```
@@ -114,9 +120,12 @@ tableReferenceRuleDefinition:
### Broadcast Table Rule
```sql
-CREATE BROADCAST TABLE RULE tableName [, tableName] ...
+CREATE BROADCAST TABLE RULE ifNotExistsClause? tableName [, tableName] ...
DROP BROADCAST TABLE RULE tableName [, tableName] ...
+
+ifNotExistsClause:
+ IF NOT EXISTS
```
## 示例
@@ -137,7 +146,7 @@ DROP SHARDING AUDITOR IF EXISTS sharding_key_required_auditor;
*Auto Table*
```sql
-CREATE SHARDING TABLE RULE t_order (
+CREATE SHARDING TABLE RULE IF NOT EXISTS t_order (
STORAGE_UNITS(ds_0,ds_1),
SHARDING_COLUMN=order_id,TYPE(NAME="hash_mod",PROPERTIES("sharding-count"="4")),
KEY_GENERATE_STRATEGY(COLUMN=another_id,TYPE(NAME="snowflake")),
@@ -159,7 +168,7 @@ DROP SHARDING ALGORITHM t_order_hash_mod;
*Table*
```sql
-CREATE SHARDING TABLE RULE t_order_item (
+CREATE SHARDING TABLE RULE IF NOT EXISTS t_order_item (
DATANODES("ds_${0..1}.t_order_item_${0..1}"),
DATABASE_STRATEGY(TYPE="standard",SHARDING_COLUMN=user_id,SHARDING_ALGORITHM(TYPE(NAME="inline",PROPERTIES("algorithm-expression"="ds_${user_id % 2}")))),
TABLE_STRATEGY(TYPE="standard",SHARDING_COLUMN=order_id,SHARDING_ALGORITHM(TYPE(NAME="inline",PROPERTIES("algorithm-expression"="t_order_item_${order_id % 2}")))),
@@ -193,7 +202,7 @@ DROP DEFAULT SHARDING DATABASE STRATEGY;
### Sharding Table Reference Rule
```sql
-CREATE SHARDING TABLE REFERENCE RULE ref_0 (t_order,t_order_item), ref_1 (t_1,t_2);
+CREATE SHARDING TABLE REFERENCE RULE IF NOT EXISTS ref_0 (t_order,t_order_item), ref_1 (t_1,t_2);
ALTER SHARDING TABLE REFERENCE RULE ref_0 (t_order,t_order_item,t_user);
@@ -203,7 +212,7 @@ DROP SHARDING TABLE REFERENCE RULE ref_0, ref_1;
### Broadcast Table Rule
```sql
-CREATE BROADCAST TABLE RULE t_a,t_b;
+CREATE BROADCAST TABLE RULE IF NOT EXISTS t_a,t_b;
DROP BROADCAST TABLE RULE t_a;
```
diff --git a/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/rule-definition/sharding.en.md b/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/rule-definition/sharding.en.md
index 9e64bc6c45a..17f558ef3bd 100644
--- a/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/rule-definition/sharding.en.md
+++ b/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/rule-definition/sharding.en.md
@@ -8,13 +8,13 @@ weight = 1
### Sharding Table Rule
```sql
-CREATE SHARDING TABLE RULE shardingTableRuleDefinition [, shardingTableRuleDefinition] ...
+CREATE SHARDING TABLE RULE ifNotExistsClause? shardingTableRuleDefinition [, shardingTableRuleDefinition] ...
ALTER SHARDING TABLE RULE shardingTableRuleDefinition [, shardingTableRuleDefinition] ...
DROP SHARDING TABLE RULE tableName [, tableName] ...
-CREATE DEFAULT SHARDING shardingScope STRATEGY (shardingStrategy)
+CREATE DEFAULT SHARDING shardingScope STRATEGY ifNotExistsClause? (shardingStrategy)
ALTER DEFAULT SHARDING shardingScope STRATEGY (shardingStrategy)
@@ -26,6 +26,9 @@ DROP SHARDING KEY GENERATOR [IF EXISTS] keyGeneratorName [, keyGeneratorName] ..
DROP SHARDING AUDITOR [IF EXISTS] auditorName [, auditorName] ...
+ifNotExistsClause:
+ IF NOT EXISTS
+
shardingTableRuleDefinition:
shardingAutoTableRule | shardingTableRule
@@ -100,12 +103,15 @@ algorithmProperty:
### Sharding Table Reference Rule
```sql
-CREATE SHARDING TABLE REFERENCE RULE tableReferenceRuleDefinition [, tableReferenceRuleDefinition] ...
+CREATE SHARDING TABLE REFERENCE RULE ifNotExistsClause? tableReferenceRuleDefinition [, tableReferenceRuleDefinition] ...
ALTER SHARDING TABLE REFERENCE RULE tableReferenceRuleDefinition [, tableReferenceRuleDefinition] ...
DROP SHARDING TABLE REFERENCE RULE ifExists? ruleName [, ruleName] ...
+ifNotExistsClause:
+ IF NOT EXISTS
+
tableReferenceRuleDefinition:
ruleName (tableName [, tableName] ... )
```
@@ -114,9 +120,12 @@ tableReferenceRuleDefinition:
### Broadcast Table Rule
```sql
-CREATE BROADCAST TABLE RULE tableName [, tableName] ...
+CREATE BROADCAST TABLE RULE ifNotExistsClause? tableName [, tableName] ...
DROP BROADCAST TABLE RULE tableName [, tableName] ...
+
+ifNotExistsClause:
+ IF NOT EXISTS
```
## Example
@@ -137,7 +146,7 @@ DROP SHARDING AUDITOR IF EXISTS sharding_key_required_auditor;
*Auto Table*
```sql
-CREATE SHARDING TABLE RULE t_order (
+CREATE SHARDING TABLE RULE IF NOT EXISTS t_order (
STORAGE_UNITS(ds_0,ds_1),
SHARDING_COLUMN=order_id,TYPE(NAME="hash_mod",PROPERTIES("sharding-count"="4")),
KEY_GENERATE_STRATEGY(COLUMN=another_id,TYPE(NAME="snowflake")),
@@ -159,7 +168,7 @@ DROP SHARDING ALGORITHM t_order_hash_mod;
*Table*
```sql
-CREATE SHARDING TABLE RULE t_order_item (
+CREATE SHARDING TABLE RULE IF NOT EXISTS t_order_item (
DATANODES("ds_${0..1}.t_order_item_${0..1}"),
DATABASE_STRATEGY(TYPE="standard",SHARDING_COLUMN=user_id,SHARDING_ALGORITHM(TYPE(NAME="inline",PROPERTIES("algorithm-expression"="ds_${user_id % 2}")))),
TABLE_STRATEGY(TYPE="standard",SHARDING_COLUMN=order_id,SHARDING_ALGORITHM(TYPE(NAME="inline",PROPERTIES("algorithm-expression"="t_order_item_${order_id % 2}")))),
@@ -193,7 +202,7 @@ DROP DEFAULT SHARDING DATABASE STRATEGY;
### Sharding Table Reference Rule
```sql
-CREATE SHARDING TABLE REFERENCE RULE ref_0 (t_order,t_order_item), ref_1 (t_1,t_2);
+CREATE SHARDING TABLE REFERENCE RULE IF NOT EXISTS ref_0 (t_order,t_order_item), ref_1 (t_1,t_2);
ALTER SHARDING TABLE REFERENCE RULE ref_0 (t_order,t_order_item,t_user);
@@ -203,7 +212,7 @@ DROP SHARDING TABLE REFERENCE RULE ref_0, ref_1;
### Broadcast Table Rule
```sql
-CREATE BROADCAST TABLE RULE t_a,t_b;
+CREATE BROADCAST TABLE RULE IF NOT EXISTS t_a,t_b;
DROP BROADCAST TABLE RULE t_a;
```
diff --git a/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/storage-unit-definition.cn.md b/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/storage-unit-definition.cn.md
index cad84ab42b6..1428fda8920 100644
--- a/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/storage-unit-definition.cn.md
+++ b/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/storage-unit-definition.cn.md
@@ -6,12 +6,15 @@ weight = 1
## 语法说明
```sql
-REGISTER STORAGE UNIT storageUnitDefinition [, storageUnitDefinition] ...
+REGISTER STORAGE UNIT ifNotExistsClause? storageUnitDefinition [, storageUnitDefinition] ...
ALTER STORAGE UNIT storageUnitDefinition [, storageUnitDefinition] ...
UNREGISTER STORAGE UNIT storageUnitName [, storageUnitName] ... [ignore single tables]
+ifNotExistsClause:
+ IF NOT EXISTS
+
storageUnitDefinition:
simpleSource | urlSource
@@ -52,7 +55,7 @@ property:
## 示例
```sql
-REGISTER STORAGE UNIT ds_0 (
+REGISTER STORAGE UNIT IF NOT EXISTS ds_0 (
HOST="127.0.0.1",
PORT=3306,
DB="db0",
diff --git a/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/storage-unit-definition.en.md b/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/storage-unit-definition.en.md
index c7fa4aff598..00ceb39990f 100644
--- a/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/storage-unit-definition.en.md
+++ b/docs/document/content/user-manual/shardingsphere-proxy/distsql/syntax/rdl/storage-unit-definition.en.md
@@ -6,12 +6,15 @@ weight = 1
## Syntax
```sql
-REGISTER STORAGE UNIT storageUnitDefinition [, storageUnitDefinition] ...
+REGISTER STORAGE UNIT ifNotExistsClause? storageUnitDefinition [, storageUnitDefinition] ...
ALTER STORAGE UNIT storageUnitDefinition [, storageUnitDefinition] ...
UNREGISTER STORAGE UNIT storageUnitName [, storageUnitName] ... [ignore single tables]
+ifNotExistsClause:
+ IF NOT EXISTS
+
storageUnitDefinition:
simpleSource | urlSource
@@ -52,7 +55,7 @@ property:
## Example
```sql
-REGISTER STORAGE UNIT ds_0 (
+REGISTER STORAGE UNIT IF NOT EXISTS ds_0 (
HOST="127.0.0.1",
PORT=3306,
DB="db0",