You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/04/11 11:09:22 UTC

[GitHub] [shardingsphere] lanchengx opened a new pull request, #16737: Refactor `CREATE SHARDING TABLE RULE` syntax doc

lanchengx opened a new pull request, #16737:
URL: https://github.com/apache/shardingsphere/pull/16737

   For https://github.com/apache/shardingsphere/issues/16666
   
   Changes proposed in this pull request:
   - Add `CREATE SHARDING TABLE RULE` syntax doc
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] RaigorJiang commented on a diff in pull request #16737: Refactor `CREATE SHARDING TABLE RULE` syntax doc

Posted by GitBox <gi...@apache.org>.
RaigorJiang commented on code in PR #16737:
URL: https://github.com/apache/shardingsphere/pull/16737#discussion_r847896277


##########
docs/document/content/reference/distsql/syntax/rdl/rule-definition/create-sharding-table-rule.cn.md:
##########
@@ -0,0 +1,146 @@
++++
+title = "CREATE SHARDING TABLE RULE"
+weight = 1
++++
+
+## 描述
+
+`CREATE SHARDING TABLE RULE` 语法用于为当前所选逻辑库添加分片规则
+
+### 语法定义
+
+```SQL
+CreateShardingTableRule ::=
+  'CREATE' 'SHARDING' 'TABLE' 'RULE' ( tableDefinition | autoTableDefinition ) ( ',' ( tableDefinition | autoTableDefinition ) )*
+
+tableDefinition ::= 
+   tableName '(' 'DATANODES' '(' dataNode ( ',' dataNode )* ')'  ( ','  'DATABASE_STRATEGY' '(' strategyDefinition ')' )?  ( ','  'TABLE_STRATEGY' '(' strategyDefinition ')' )?  ( ','  'KEY_GENERATE_STRATEGY' '(' keyGenerateStrategyDefinition ')' )? ')'
+
+autoTableDefinition ::=
+    tableName '(' 'RESOURCES' '(' resourceName ( ',' resourceName )*  ')' ',' 'SHARDING_COLUMN' '=' columnName ',' algorithmDefinition ( ','  'KEY_GENERATE_STRATEGY' '(' keyGenerateStrategyDefinition ')' )?')'
+
+strategyDefinition ::=
+  'TYPE' '=' strategyType ',' 'SHARDING_COLUMN' '=' columnName ',' algorithmDefinition

Review Comment:
   'SHARDING_COLUMNS' when define complex strategy.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] RaigorJiang commented on a diff in pull request #16737: Refactor `CREATE SHARDING TABLE RULE` syntax doc

Posted by GitBox <gi...@apache.org>.
RaigorJiang commented on code in PR #16737:
URL: https://github.com/apache/shardingsphere/pull/16737#discussion_r848059543


##########
docs/document/content/reference/distsql/syntax/rdl/rule-definition/create-sharding-table-rule.cn.md:
##########
@@ -0,0 +1,146 @@
++++
+title = "CREATE SHARDING TABLE RULE"
+weight = 1
++++
+
+## 描述
+
+`CREATE SHARDING TABLE RULE` 语法用于为当前所选逻辑库添加分片规则
+
+### 语法定义
+
+```SQL
+CreateShardingTableRule ::=
+  'CREATE' 'SHARDING' 'TABLE' 'RULE' ( tableDefinition | autoTableDefinition ) ( ',' ( tableDefinition | autoTableDefinition ) )*
+
+tableDefinition ::= 
+   tableName '(' 'DATANODES' '(' dataNode ( ',' dataNode )* ')'  ( ','  'DATABASE_STRATEGY' '(' strategyDefinition ')' )?  ( ','  'TABLE_STRATEGY' '(' strategyDefinition ')' )?  ( ','  'KEY_GENERATE_STRATEGY' '(' keyGenerateStrategyDefinition ')' )? ')'
+
+autoTableDefinition ::=
+    tableName '(' 'RESOURCES' '(' resourceName ( ',' resourceName )*  ')' ',' 'SHARDING_COLUMN' '=' columnName ',' algorithmDefinition ( ','  'KEY_GENERATE_STRATEGY' '(' keyGenerateStrategyDefinition ')' )?')'
+
+strategyDefinition ::=
+  'TYPE' '=' strategyType ',' ( 'SHARDING_COLUMN' | 'SHARDING_COLUMNS' ) '=' columnName ',' algorithmDefinition
+
+keyGenerateStrategyDefinition ::= 
+  'KEY_GENERATE_STRATEGY' '(' 'COLUMN' '=' columnName ',' ( 'KEY_GENERATOR' '=' algorihtmName | algorithmDefinition ) ')' 
+
+algorithmDefinition ::=
+  ('SHARDING_ALGORITHM' '=' algorithmName | 'TYPE' '(' 'NAME' '=' algorithmType ( ',' 'PROPERTIES'  '(' propretyDefinition  ')' )?')'  )
+
+propretyDefinition ::=
+    ( key  '=' value ) ( ',' key  '=' value )* 
+```
+
+### 补充说明
+
+- `tableDefinition` 为标准分片规则定义;`autoTableDefinition` 为自动分片规则定义。标准分片规则和自动分片规则可参考[数据分片](/cn/user-manual/shardingsphere-jdbc/yaml-config/rules/sharding/)。
+- 当使用标准分片时:
+    - `DATANODES` 只能使用已经添加到当前逻辑库的资源,且只能使用 INLINE 表达式指定需要的资源
+    - `DATABASE_STRATEGY`、`TABLE_STRATEGY` 表示分库和分表策略,均为可选项,未配置时使用默认策略
+    - `strategyDefinition` 中属性 `TYPE` 用于指定[分片算法](/cn/features/sharding/concept/sharding/#自定义分片算法)的类型,目前仅支持 `STANDARD` 、`COMPLEX`。使用 `COMPLEX` 时需要用 `SHARDING_COLUMNS` 指定多个分片键。 
+- 当使用自动分片时:
+    - `RESOURCES` 只能使用已经添加到当前逻辑库的资源,可通过枚举或 INLINE 表达式指定需要的资源
+    - 只能使用自动分片算法,可参考[自动分片算法](/cn/user-manual/shardingsphere-jdbc/builtin-algorithm/sharding/#自动分片算法)
+- 自动生成的算法命名规则为  `tableName` _ `strategyType` _ `shardingAlgorithmType`
+- 自动生成的主键策略命名规则为 `tableName` _ `strategyType`
+- `KEY_GENERATE_STRATEGY` 用于指定主键生成策略,为可选项,关于主键生成策略可参考[分布式主键](/cn/user-manual/shardingsphere-jdbc/builtin-algorithm/keygen/)
+
+### 示例
+
+#### 1.标准分片规则
+
+- ##### 指定分片算法创建标准分片规则
+
+```SQL
+-- 创建分片算法
+CREATE SHARDING ALGORITHM database_inline (
+    TYPE(NAME=inline, PROPERTIES("algorithm-expression"="t_order_${user_id % 2}"))
+), table_inline (
+    TYPE(NAME=inline, PROPERTIES("algorithm-expression"="t_order_${order_id % 2}"))
+); 
+
+-- 指定分片算法创建分片规则
+CREATE SHARDING TABLE RULE t_order (
+    DATANODES("ds_${0..1}.t_order_${0..1}"),
+    DATABASE_STRATEGY(TYPE=standard, SHARDING_COLUMN=user_id, SHARDING_ALGORITHM=database_inline),
+    TABLE_STRATEGY(TYPE=standard, SHARDING_COLUMN=order_id, SHARDING_ALGORITHM=table_inline)
+);
+```
+
+- ##### 在默认分库策略下,通过指定分片算法创建标准分片规则
+
+```SQL
+-- 创建分片算法
+CREATE SHARDING ALGORITHM database_inline (
+    TYPE(NAME=inline, PROPERTIES("algorithm-expression"="t_order_${user_id % 2}"))
+), table_inline (
+    TYPE(NAME=inline, PROPERTIES("algorithm-expression"="t_order_${order_id % 2}"))
+); 
+
+-- 创建默认分库策略
+CREATE DEFAULT SHARDING DATABASE STRATEGY (
+    TYPE = standard, SHARDING_COLUMN=order_id, SHARDING_ALGORITHM=database_inline
+);
+
+-- 指定分片算法创建分片规则
+CREATE SHARDING TABLE RULE t_order (
+    DATANODES("ds_${0..1}.t_order_${0..1}"),
+    TABLE_STRATEGY(TYPE=standard, SHARDING_COLUMN=order_id, SHARDING_ALGORITHM=table_inline)
+);
+```
+
+- ##### 在默认分库分表策略下,通过指定分片算法创建标准分片规则
+
+```SQL
+-- 创建分片算法
+CREATE SHARDING ALGORITHM database_inline (
+    TYPE(NAME=inline, PROPERTIES("algorithm-expression"="t_order_${user_id % 2}"))
+), table_inline (
+    TYPE(NAME=inline, PROPERTIES("algorithm-expression"="t_order_${order_id % 2}"))
+); 
+
+-- 创建默认分库策略
+CREATE DEFAULT SHARDING DATABASE STRATEGY (
+    TYPE = standard, SHARDING_COLUMN=order_id, SHARDING_ALGORITHM=database_inline
+);
+
+

Review Comment:
   Duplicate blank line.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] RaigorJiang merged pull request #16737: Refactor `CREATE SHARDING TABLE RULE` syntax doc

Posted by GitBox <gi...@apache.org>.
RaigorJiang merged PR #16737:
URL: https://github.com/apache/shardingsphere/pull/16737


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] RaigorJiang commented on a diff in pull request #16737: Refactor `CREATE SHARDING TABLE RULE` syntax doc

Posted by GitBox <gi...@apache.org>.
RaigorJiang commented on code in PR #16737:
URL: https://github.com/apache/shardingsphere/pull/16737#discussion_r847894870


##########
docs/document/content/reference/distsql/syntax/rdl/rule-definition/create-sharding-table-rule.en.md:
##########
@@ -0,0 +1,144 @@
++++
+title = "CREATE SHARDING TABLE RULE"
+weight = 1
++++
+
+## 描述

Review Comment:
   English please.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org