Logo
Shadow

Shadow #

SyntaxDescription
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 shadowRuleRULES [FROM databaseName]
SHOW SHADOW TABLE RULES [FROM databaseName]View shadow table
COUNT SHADOW RULECount 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 shadowAlgorithmCreate default shadow algorithm
ALTER DEFAULT SHADOW ALGORITHM shadowAlgorithmModify default shadow algorithm
DROP DEFAULT SHADOW ALGORITHM [IF EXISTS]Delete default shadow algorithm
SHOW DEFAULT SHADOW ALGORITHMView 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

NameData typeDescription
ruleNameIDENTIFIERRule name
storageUnitNameIDENTIFIERStorage unit name
tableNameIDENTIFIERShadow table name
algorithmNameIDENTIFIERShadow algorithm name
shadowAlgorithmTypeSTRINGShadow algorithm type
  • Duplicate ruleName cannot be created

  • storageUnitMapping specifies the mapping relationship between the source database and the shadow library. You need to use the storage unit managed by RDL, please refer to storage unit

  • shadowAlgorithm can act on multiple shadowTableRule at the same time

  • shadowAlgorithmType please refer to shadow built-in algorithms

  • shadowTableRule can be reused by different shadowRuleDefinition, so when executing DROP SHADOW RULE, the corresponding shadowTableRule will not be removed

  • shadowAlgorithm can be reused by different shadowTableRule, so when executing ALTER SHADOW RULE, the corresponding shadowAlgorithm will not be removed

  • algorithmName will be automatically generated according to ruleName, tableName, shadowAlgorithmType and algorithm collection index. The default name is default_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

NameData typeDescription
ruleNameIDENTIFIERRule name
storageUnitNameIDENTIFIERStorage unit name
tableNameIDENTIFIERShadow table name
algorithmNameIDENTIFIERShadow algorithm name
shadowAlgorithmTypeSTRINGShadow algorithm type
  • storageUnitMapping specifies the mapping relationship between the source database and the shadow library. You need to use the storage unit managed by RDL, please refer to storage unit
  • shadowAlgorithm can act on multiple shadowTableRule at the same time
  • shadowAlgorithmType currently supports VALUE_MATCH, REGEX_MATCH and SIMPLE_HINT
  • shadowTableRule can be reused by different shadowRuleDefinition, so when executing DROP SHADOW RULE, the corresponding shadowTableRule will not be removed
  • shadowAlgorithm can be reused by different shadowTableRule, so when executing ALTER SHADOW RULE, the corresponding shadowAlgorithm will not be removed
  • algorithmName will be automatically generated according to ruleName, tableName, shadowAlgorithmType and algorithm collection index. The default name is default_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

NameData typeDescription
ruleNameIDENTIFIERRule name

Example

DROP SHADOW RULE shadow_rule;

4. View Shadow Rule #

SHOW SHADOW shadowRule | RULES [FROM databaseName]
shadowRule: 
    RULE ruleName

Parameter Description

NameData typeDescription
ruleNameIDENTIFIERRule 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

ColumnDescription
rule_nameRule name
source_nameSource database
shadow_nameShadow database
shadow_tableShadow 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

ColumnDescription
shadow_tableShadow table
shadow_algorithm_nameShadow algorithm name

6. Delete Shadow Algorithm #

DROP SHADOW ALGORITHM algorithmName [, algorithmName] ...

Parameter Description

NameData typeDescription
algorithmNameIDENTIFIERShadow algorithm name
  • shadowAlgorithm can be reused by different shadowTableRule, so when executing ALTER SHADOW RULE, the corresponding shadowAlgorithm will not be removed
  • In used shadowAlgorithm cannot 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

ColumnDescription
shadow_algorithm_nameShadow algorithm name
typeAlgorithm type
propsAlgorithm properties
is_defaultWhether 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

ColumnData typeDescription
shadow_algorithm_nameIDENTIFIERShadow algorithm name
typeSTRINGAlgorithm type
  • shadowAlgorithm can be reused by different shadowTableRule, so when executing ALTER SHADOW RULE, the corresponding shadowAlgorithm will not be removed
  • algorithmName will be automatically generated according to ruleName, tableName, shadowAlgorithmType and algorithm collection index. The default name is default_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

ColumnData typeDescription
shadow_algorithm_nameIDENTIFIERShadow algorithm name
typeSTRINGAlgorithm type
  • shadowAlgorithm can be reused by different shadowTableRule, so when executing ALTER SHADOW RULE, the corresponding shadowAlgorithm will not be removed
  • algorithmName will be automatically generated according to ruleName, tableName, shadowAlgorithmType and algorithm collection index. The default name is default_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;