Skip to content

Commit

Permalink
Update sql hint force sharding document (#21654)
Browse files Browse the repository at this point in the history
  • Loading branch information
strongduanmu authored Oct 20, 2022
1 parent 8f9e185 commit 06f5dd7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ HintManager hintManager = HintManager.getInstance();
- 使用 `hintManager.addDatabaseShardingValue` 来添加数据源分片键值。
- 使用 `hintManager.addTableShardingValue` 来添加表分片键值。

> 分库不分表情况下,强制路由至某一个分库时,可使用 `hintManager.setDatabaseShardingValue` 方式添加分片
> 分库不分表情况下,强制路由至某一个分库时,可使用 `hintManager.setDatabaseShardingValue` 方式设置分片值
#### 清除分片键值

Expand Down Expand Up @@ -106,15 +106,17 @@ try (HintManager hintManager = HintManager.getInstance();

##### 使用规范

SQL Hint 功能需要用户提前开启解析注释的配置,设置 `sqlCommentParseEnabled``true`。 注释格式暂时只支持 `/* */`,内容需要以 `SHARDINGSPHERE_HINT:` 开始,属性名为 `SHARDING_DATABASE_VALUE``SHARDING_TABLE_VALUE`
SQL Hint 功能需要用户提前开启解析注释的配置,设置 `sqlCommentParseEnabled``true`。 注释格式暂时只支持 `/* */`,内容需要以 `SHARDINGSPHERE_HINT:` 开始,可选的属性包括:

- 使用 `SHARDING_DATABASE_VALUE` 来指定数据源分片键值。
- 使用 `SHARDING_TABLE_VALUE` 来指定表分片键值。
- `{table}.SHARDING_DATABASE_VALUE`:用于添加 `{table}` 表对应的数据源分片键值,多个属性使用逗号分隔;
- `{table}.SHARDING_TABLE_VALUE`:用于添加 `{table}` 表对应的表分片键值,多个属性使用逗号分隔。

> 分库不分表情况下,强制路由至某一个分库时,可使用 `SHARDING_DATABASE_VALUE` 方式设置分片,无需指定 `{table}`
##### 完整示例

```java
/* SHARDINGSPHERE_HINT: SHARDING_DATABASE_VALUE=1, SHARDING_TABLE_VALUE=1 */
```sql
/* SHARDINGSPHERE_HINT: t_order.SHARDING_DATABASE_VALUE=1, t_order.SHARDING_TABLE_VALUE=1 */
SELECT * FROM t_order;
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ HintManager hintManager = HintManager.getInstance();
- Use `hintManager.addDatabaseShardingValue` to add sharding key value of data source.
- Use `hintManager.addTableShardingValue` to add sharding key value of table.

> Users can use `hintManager.setDatabaseShardingValue` to add sharding in hint route to some certain sharding database without sharding tables.
> Users can use `hintManager.setDatabaseShardingValue` to set sharding value in hint route to some certain sharding database without sharding tables.
#### Clean Hint Values

Expand Down Expand Up @@ -107,14 +107,17 @@ try (HintManager hintManager = HintManager.getInstance();
##### Terms of Use

To use SQL Hint function, users need to set `sqlCommentParseEnabled` to `true`.
The comment format only supports `/* */` for now. The content needs to start with `SHARDINGSPHERE_HINT:`, and the attribute names needs to be `SHARDING_DATABASE_VALUE` and `SHARDING_TABLE_VALUE`.
The comment format only supports `/* */` for now. The content needs to start with `SHARDINGSPHERE_HINT:`, and optional attributes include:

- Use `SHARDING_DATABASE_VALUE` to specify sharding key value of data source.
- Use `SHARDING_TABLE_VALUE` to specify sharding key value of table.
- `{table}.SHARDING_DATABASE_VALUE`: used to add the data source sharding value corresponding to `{table}` table, multiple attributes are separated by commas;
- `{table}.SHARDING_TABLE_VALUE`: used to add the table sharding value corresponding to `{table}` table, multiple attributes are separated by commas.

> Users can use `SHARDING_DATABASE_VALUE` to set sharding value in hint route to some certain sharding database without sharding tables.
##### Codes:

```sql
/* SHARDINGSPHERE_HINT: SHARDING_DATABASE_VALUE=1, SHARDING_TABLE_VALUE=1 */
/* SHARDINGSPHERE_HINT: t_order.SHARDING_DATABASE_VALUE=1, t_order.SHARDING_TABLE_VALUE=1 */
SELECT * FROM t_order;
```

Expand Down

0 comments on commit 06f5dd7

Please sign in to comment.