Shadow #
| Syntax | Description |
|---|---|
| CREATE SHADOW RULE shadowRuleDefinition [, shadowRuleDefinition] … | Create shadow rule |
| ALTER SHADOW RULE shadowRuleDefinition [, shadowRuleDefinition] … | Modify shadow rule |
| DROP SHADOW RULE ruleName [, ruleName] … | Delete shadow rule |
| SHOW SHADOW shadowRule | RULES [FROM databaseName] |
| SHOW SHADOW TABLE RULES [FROM databaseName] | View shadow table |
| COUNT SHADOW RULE | Count the number of shadow rules, this syntax will be deprecated in subsequent versions |
| DROP SHADOW ALGORITHM algorithmName [, algorithmName] … | Delete shadow algorithm |
| SHOW SHADOW ALGORITHMS [FROM databaseName] | View shadow algorithm |
| CREATE DEFAULT SHADOW ALGORITHM shadowAlgorithm | Create default shadow algorithm |
| ALTER DEFAULT SHADOW ALGORITHM shadowAlgorithm | Modify default shadow algorithm |
| DROP DEFAULT SHADOW ALGORITHM [IF EXISTS] | Delete default shadow algorithm |
| SHOW DEFAULT SHADOW ALGORITHM | View default shadow algorithm |
1. Create Shadow Algorithm #
CREATE SHADOW RULE shadowRuleDefinition [, shadowRuleDefinition] ...
shadowRuleDefinition: ruleName(storageUnitMapping, shadowTableRule [, shadowTableRule] ...)
storageUnitMapping: SOURCE=storageUnitName, SHADOW=storageUnitName
shadowTableRule: tableName(shadowAlgorithm [, shadowAlgorithm] ...)
shadowAlgorithm: TYPE(NAME=shadowAlgorithmType, PROPERTIES([algorithmProperties] ...))
algorithmProperties: algorithmProperty [, algorithmProperty] ...
algorithmProperty: key=value
Parameter Description
| Name | Data type | Description |
|---|---|---|
| ruleName | IDENTIFIER | Rule name |
| storageUnitName | IDENTIFIER | Storage unit name |
| tableName | IDENTIFIER | Shadow table name |
| algorithmName | IDENTIFIER | Shadow algorithm name |
| shadowAlgorithmType | STRING | Shadow algorithm type |
Duplicate
ruleNamecannot be createdstorageUnitMappingspecifies the mapping relationship between the source database and the shadow library. You need to use thestorage unitmanaged by RDL, please refer to storage unitshadowAlgorithmcan act on multipleshadowTableRuleat the same timeshadowAlgorithmTypeplease refer to shadow built-in algorithmsshadowTableRulecan be reused by differentshadowRuleDefinition, so when executingDROP SHADOW RULE, the correspondingshadowTableRulewill not be removedshadowAlgorithmcan be reused by differentshadowTableRule, so when executingALTER SHADOW RULE, the correspondingshadowAlgorithmwill not be removedalgorithmNamewill be automatically generated according toruleName,tableName,shadowAlgorithmTypeand algorithm collection index. The default name isdefault_shadow_algorithm.Example
CREATE SHADOW RULE 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]'))),
t_order_item(TYPE(NAME="VALUE_MATCH", PROPERTIES("operation"="insert","column"="user_id", "value"='1'))));
2. Modify Shadow Rule #
ALTER SHADOW RULE shadowRuleDefinition [, shadowRuleDefinition] ...
shadowRuleDefinition: ruleName(storageUnitMapping, shadowTableRule [, shadowTableRule] ...)
storageUnitMapping: SOURCE=storageUnitName, SHADOW=storageUnitName
shadowTableRule: tableName(shadowAlgorithm [, shadowAlgorithm] ...)
shadowAlgorithm: TYPE(NAME=shadowAlgorithmType, PROPERTIES([algorithmProperties] ...))
algorithmProperties: algorithmProperty [, algorithmProperty] ...
algorithmProperty: key=value
Parameter Description
| Name | Data type | Description |
|---|---|---|
| ruleName | IDENTIFIER | Rule name |
| storageUnitName | IDENTIFIER | Storage unit name |
| tableName | IDENTIFIER | Shadow table name |
| algorithmName | IDENTIFIER | Shadow algorithm name |
| shadowAlgorithmType | STRING | Shadow algorithm type |
storageUnitMappingspecifies the mapping relationship between the source database and the shadow library. You need to use thestorage unitmanaged by RDL, please refer to storage unitshadowAlgorithmcan act on multipleshadowTableRuleat the same timeshadowAlgorithmTypecurrently supportsVALUE_MATCH,REGEX_MATCHandSIMPLE_HINTshadowTableRulecan be reused by differentshadowRuleDefinition, so when executingDROP SHADOW RULE, the correspondingshadowTableRulewill not be removedshadowAlgorithmcan be reused by differentshadowTableRule, so when executingALTER SHADOW RULE, the correspondingshadowAlgorithmwill not be removedalgorithmNamewill be automatically generated according toruleName,tableName,shadowAlgorithmTypeand algorithm collection index. The default name isdefault_shadow_algorithm.
Example
ALTER SHADOW RULE 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]'))),
t_order_item(TYPE(NAME="VALUE_MATCH", PROPERTIES("operation"="insert","column"="user_id", "value"='1'))));
3. Delete Shadow Rule #
DROP SHADOW RULE ruleName [, ruleName] ...
Parameter Description
| Name | Data type | Description |
|---|---|---|
| ruleName | IDENTIFIER | Rule name |
Example
DROP SHADOW RULE shadow_rule;
4. View Shadow Rule #
SHOW SHADOW shadowRule | RULES [FROM databaseName]
shadowRule:
RULE ruleName
Parameter Description
| Name | Data type | Description |
|---|---|---|
| ruleName | IDENTIFIER | Rule name |
Example
View all shadow rule
mysql> SHOW SHADOW RULES;
+--------------------+-------------+-------------+--------------+
| rule_name | source_name | shadow_name | shadow_table |
+--------------------+-------------+-------------+--------------+
| shadow_rule_1 | ds_1 | ds_shadow_1 | t_order |
| shadow_rule_2 | ds_2 | ds_shadow_2 | t_order_item |
+--------------------+-------------+-------------+--------------+
2 rows in set (0.02 sec)
View specified shadow rule
mysql> SHOW SHADOW RULE shadow_rule_1;
+------------------+-------------+-------------+--------------+
| rule_name | source_name | shadow_name | shadow_table |
+------------------+-------------+-------------+--------------+
| shadow_rule_1 | ds_1 | ds_shadow_1 | t_order |
+------------------+-------------+-------------+--------------+
1 rows in set (0.01 sec)
Output Description
| Column | Description |
|---|---|
| rule_name | Rule name |
| source_name | Source database |
| shadow_name | Shadow database |
| shadow_table | Shadow table |
5. View Shadow Table Rule #
SHOW SHADOW TABLE RULES [FROM databaseName]
Example
mysql> SHOW SHADOW TABLE RULES;
+--------------+--------------------------------------------------------------------------------+
| shadow_table | shadow_algorithm_name |
+--------------+--------------------------------------------------------------------------------+
| t_order_1 | user_id_match_algorithm,simple_hint_algorithm_1 |
+--------------+--------------------------------------------------------------------------------+
1 rows in set (0.01 sec)
Output Description
| Column | Description |
|---|---|
| shadow_table | Shadow table |
| shadow_algorithm_name | Shadow algorithm name |
6. Delete Shadow Algorithm #
DROP SHADOW ALGORITHM algorithmName [, algorithmName] ...
Parameter Description
| Name | Data type | Description |
|---|---|---|
| algorithmName | IDENTIFIER | Shadow algorithm name |
shadowAlgorithmcan be reused by differentshadowTableRule, so when executingALTER SHADOW RULE, the correspondingshadowAlgorithmwill not be removed- In used
shadowAlgorithmcannot be dropped
7. View Shadow Algorithm #
SHOW SHADOW ALGORITHMS [FROM databaseName]
Example
mysql> SHOW SHADOW ALGORITHMS;
+-------------------------+--------------------+-------------------------------------------+----------------+
| shadow_algorithm_name | type | props | is_default |
+-------------------------+--------------------+-------------------------------------------+----------------+
| user_id_match_algorithm | REGEX_MATCH | operation=insert,column=user_id,regex=[1] | false |
| simple_hint_algorithm_1 | SIMPLE_HINT | shadow=true,foo=bar | false |
+-------------------------+--------------------+-------------------------------------------+----------------+
2 rows in set (0.01 sec)
Output Description
| Column | Description |
|---|---|
| shadow_algorithm_name | Shadow algorithm name |
| type | Algorithm type |
| props | Algorithm properties |
| is_default | Whether default |
8. Create Default Shadow Algorithm #
CREATE DEFAULT SHADOW ALGORITHM shadowAlgorithm
shadowAlgorithm: TYPE(NAME=shadowAlgorithmType, PROPERTIES([algorithmProperties] ...))
algorithmProperties: algorithmProperty [, algorithmProperty] ...
algorithmProperty: key=value
Parameter Description
| Column | Data type | Description |
|---|---|---|
| shadow_algorithm_name | IDENTIFIER | Shadow algorithm name |
| type | STRING | Algorithm type |
shadowAlgorithmcan be reused by differentshadowTableRule, so when executingALTER SHADOW RULE, the correspondingshadowAlgorithmwill not be removedalgorithmNamewill be automatically generated according toruleName,tableName,shadowAlgorithmTypeand algorithm collection index. The default name isdefault_shadow_algorithm.
Example
CREATE DEFAULT SHADOW ALGORITHM TYPE(NAME="SIMPLE_HINT", PROPERTIES("shadow"="true", "foo"="bar");
9. Modify Default Shadow Algorithm #
ALTER DEFAULT SHADOW ALGORITHM shadowAlgorithm
shadowAlgorithm: TYPE(NAME=shadowAlgorithmType, PROPERTIES([algorithmProperties] ...))
algorithmProperties: algorithmProperty [, algorithmProperty] ...
algorithmProperty: key=value
Parameter Description
| Column | Data type | Description |
|---|---|---|
| shadow_algorithm_name | IDENTIFIER | Shadow algorithm name |
| type | STRING | Algorithm type |
shadowAlgorithmcan be reused by differentshadowTableRule, so when executingALTER SHADOW RULE, the correspondingshadowAlgorithmwill not be removedalgorithmNamewill be automatically generated according toruleName,tableName,shadowAlgorithmTypeand algorithm collection index. The default name isdefault_shadow_algorithm.
Example
ALTER DEFAULT SHADOW ALGORITHM TYPE(NAME="SIMPLE_HINT", PROPERTIES("shadow"="false", "foo"="bar");
10. Delete Default Shadow Algorithm #
DROP DEFAULT SHADOW ALGORITHM [IF EXISTS]
Parameter Description
None
Example
DROP DEFAULT SHADOW ALGORITHM;
11. View Default Shadow Algorithm #
SHOW DEFAULT SHADOW ALGORITHM;
Parameter Description
None
Example
SHOW DEFAULT SHADOW ALGORITHM;