广播表 #
语法 | 描述 | 类型 |
---|---|---|
CREATE BROADCAST TABLE RULE tableName [, tableName] … | 创建广播表 | RDL |
DROP BROADCAST TABLE RULE tableName [, tableName] … | 删除广播表 | RDL |
SHOW BROADCAST TABLE RULES [FROM databaseName] | 查看广播表 | RQL |
CREATE BROADCAST KEY_GENERATE_STRATEGY [IF NOT EXISTS] keyGenerateDefinition [, keyGenerateDefinition] … | 创建主键生成策略 | RDL |
ALTER BROADCAST KEY_GENERATE_STRATEGY keyGenerateDefinition [, keyGenerateDefinition] … | 修改主键生成策略 | RDL |
DROP BROADCAST KEY_GENERATE_STRATEGY [IF EXISTS] tableName [, tableName] … | 删除主键生成策略 | RDL |
SHOW BROADCAST (KEY_GENERATE_STRATEGIES | KEY_GENERATE_STRATEGY tableName ) [FROM databaseName] | 查看主键生成策略 |
keyGenerateDefinition:
tableName (COLUMN=columnName,algorithmDefinition)
algorithmDefinition:
TYPE(NAME=algorithmType [, PROPERTIES([propertiesDefinition])])
propertiesDefinition:
PROPERTIES (properties?)
property:
key=STRING_ EQ_ value=literal
参数说明
keyGenerateDefinition
主键生成策略定义tableName
广播表名称columnName
主键名称algorithmDefinition
算法定义algorithmType
主键生成算法类型propertiesDefinition
算法参数
1. 创建广播表 #
CREATE BROADCAST TABLE RULE tableName [, tableName] ...
参数说明
名称 | 数据类型 | 说明 |
---|---|---|
tableName | IDENTIFIER | 表名 |
示例
CREATE BROADCAST TABLE RULE t_a,t_b;
2. 删除广播表 #
DROP BROADCAST TABLE RULE tableName [, tableName] ...
参数说明
名称 | 数据类型 | 说明 |
---|---|---|
tableName | IDENTIFIER | 表名 |
示例
DROP BROADCAST TABLE RULE t_a;
3. 查看广播表 #
SHOW BROADCAST TABLE RULES [FROM databaseName]
参数说明
名称 | 数据类型 | 说明 |
---|---|---|
databaseName | IDENTIFIER | 逻辑库名称 |
示例
mysql> SHOW BROADCAST TABLE RULES;
+------------------------+
| broadcast_table |
+------------------------+
| t_1 |
| t_2 |
+------------------------+
2 rows in set (0.00 sec)
输出说明
列 | 说明 |
---|---|
broadcast_table | 广播表名称 |
4. 创建主键生成策略 #
示例
CREATE BROADCAST KEY_GENERATE_STRATEGY t_address (COLUMN=address_id,TYPE(NAME="snowflake"));
CREATE BROADCAST KEY_GENERATE_STRATEGY IF NOT EXISTS t_address (COLUMN=address_id,TYPE(NAME="snowflake"));
5. 修改主键生成策略 #
示例
ALTER BROADCAST KEY_GENERATE_STRATEGY t_address (COLUMN=address_id,TYPE(NAME="snowflake"));
不能修改算法类型,可修改算法参数
6. 删除主键生成策略 #
示例
DROP BROADCAST KEY_GENERATE_STRATEGY t_address;
DROP BROADCAST KEY_GENERATE_STRATEGY IF EXISTS t_address;
7. 查看主键生成策略 #
示例
mysql> SHOW BROADCAST KEY_GENERATE_STRATEGIES;
+-----------+------------+-----------------------------+------------------------------+
| name | column | key_generate_algorithm_type | key_generate_algorithm_props |
+-----------+------------+-----------------------------+------------------------------+
| t_address | address_id | snowflake | |
+-----------+------------+-----------------------------+------------------------------+
1 row in set (0.01 sec)
mysql> SHOW BROADCAST KEY_GENERATE_STRATEGIES FROM sharding_db;
+-----------+------------+-----------------------------+------------------------------+
| name | column | key_generate_algorithm_type | key_generate_algorithm_props |
+-----------+------------+-----------------------------+------------------------------+
| t_address | address_id | snowflake | |
+-----------+------------+-----------------------------+------------------------------+
1 row in set (0.03 sec)
mysql> SHOW BROADCAST KEY_GENERATE_STRATEGY t_address FROM sharding_db;
+-----------+------------+-----------------------------+------------------------------+
| name | column | key_generate_algorithm_type | key_generate_algorithm_props |
+-----------+------------+-----------------------------+------------------------------+
| t_address | address_id | snowflake | |
+-----------+------------+-----------------------------+------------------------------+
1 row in set (0.01 sec)
输出说明
列 | 说明 |
---|---|
name | 策略名称 |
column | 主键列名称 |
key_generate_algorithm_type | 算法类型 |
key_generate_algorithm_props | 算法参数 |