Logo
RAL Syntax

RAL Syntax #

RAL (Resource & Rule Administration Language) is responsible for the added-on features of hint, transaction type switch, resharding, sharding execute planning and so on.

Hint #

StatementFunctionExample
set readwrite_splitting hint source = [auto / write]For current connection, set read/write splitting routing strategy (automatic or forced to write data source)set readwrite_splitting hint source = write
set sharding hint database_value = yyFor current connection, set sharding value for database sharding only, yy: sharding valueset sharding hint database_value = 100
add sharding hint database_value xx= yyFor current connection, add sharding value for table, xx: logic table, yy: database sharding valueadd sharding hint database_value t_order = 100
add sharding hint table_value xx = yyFor current connection, add sharding value for table, xx: logic table, yy: table sharding valueadd sharding hint table_value t_order = 100
clear hintFor current connection, clear all hint settingsclear hint
clear [sharding hint / readwrite_splitting hint]For current connection, clear hint settings of sharding or readwrite splittingclear readwrite_splitting hint
show [sharding / readwrite_splitting] hint statusFor current connection, query hint settings of sharding or readwrite splittingshow readwrite_splitting hint status

Migration #

StatementFunctionExample
SHOW MIGRATION RULEShow migration ruleSHOW MIGRATION RULE
ALTER MIGRATION RULEAlter migration ruleALTER MIGRATION RULE (READ(RATE_LIMITER (TYPE(NAME='QPS’,PROPERTIES(‘qps'='5000’)))))
MIGRATE TABLE ds.schema.table INTO tableMigrate table from source to targetMIGRATE TABLE ds_0.public.t_order INTO t_order
SHOW MIGRATION LISTQuery running listSHOW MIGRATION LIST
SHOW MIGRATION STATUS jobIdQuery migration statusSHOW MIGRATION STATUS 1234
STOP MIGRATION jobIdStop migrationSTOP MIGRATION 1234
START MIGRATION jobIdStart the stopped migrationSTART MIGRATION 1234
CHECK MIGRATION jobIdData consistency checkCHECK MIGRATION 1234
SHOW MIGRATION CHECK ALGORITHMSShow available consistency check algorithmsSHOW MIGRATION CHECK ALGORITHMS
CHECK MIGRATION jobId BY TYPE(NAME=algorithmTypeName)Data consistency check with defined algorithmCHECK MIGRATION 1234 BY TYPE(NAME="DATA_MATCH”)
SHOW MIGRATION CHECK STATUS jobIdQuery data consistency check statusSHOW MIGRATION CHECK STATUS 1234
STOP MIGRATION CHECK jobIdStop data consistency checkSTOP MIGRATION CHECK 1234
DROP MIGRATION CHECK jobIdDrop data consistency checkDROP MIGRATION CHECK 1234
START MIGRATION CHECK jobIdStart data consistency checkSTART MIGRATION CHECK 1234
ROLLBACK MIGRATION jobIdRollback migrationROLLBACK MIGRATION 1234
COMMIT MIGRATION jobIdCommit migrationCOMMIT MIGRATION 1234

Reshard #

StatementFunctionExample
SHOW RESHARDING RULEShow resharding ruleSHOW RESHARDING RULE
ALTER RESHARDING RULEAlter resharding ruleALTER RESHARDING RULE (READ(RATE_LIMITER (TYPE(NAME='QPS’,PROPERTIES(‘qps'='5000’)))))
SHOW RESHARDING LISTQuery running listSHOW RESHARDING LIST
SHOW RESHARDING STATUS jobIdQuery resharding statusSHOW RESHARDING STATUS 1234
STOP RESHARDING jobIdStop reshardingSTOP RESHARDING 1234
START RESHARDING jobIdStart reshardingSTART RESHARDING 1234
CHECK RESHARDING jobIdData consistency check with algorithmCHECK RESHARDING 1234
SHOW RESHARDING CHECK ALGORITHMSShow available consistency check algorithmsSHOW RESHARDING CHECK ALGORITHMS
CHECK RESHARDING jobId BY TYPE(NAME=algorithmTypeName)Data consistency check with defined algorithmCHECK RESHARDING 1234 BY TYPE(NAME=DEFAULT)
SHOW RESHARDING CHECK STATUS jobIdQuery data consistency check statusSHOW RESHARDING CHECK STATUS 1234
STOP RESHARDING CHECK jobIdStop data consistency checkSTOP RESHARDING CHECK 1234
START RESHARDING CHECK jobIdStart data consistency checkSTART RESHARDING CHECK 1234
DROP RESHARDING CHECK jobIdDrop data consistency checkDROP RESHARDING CHECK 1234
STOP RESHARDING SOURCE WRITING jobIdThe source DBPlusEngine data source is discontinuedSTOP RESHARDING SOURCE WRITING 1234
FORCE? APPLY RESHARDING jobIdSwitch to target DBPlusEngine metadataAPPLY RESHARDING 1234
RESTORE RESHARDING SOURCE WRITING jobIdThe source DBPlusEngine data source resumes writingRESTORE RESHARDING SOURCE WRITING 1234
FORCE? COMMIT RESHARDING jobIdCommit reshardingCOMMIT RESHARDING 1234
ROLLBACK RESHARDING jobIdRollback reshardingROLLBACK RESHARDING 1234
AUTO RESHARD TABLE tableName BY ruleAutomatic mode for expansion and contractionAUTO RESHARD TABLE t_order BY(STORAGE_UNITS(ds_0, ds_1, ds_2), SHARDING_COLUMN=order_id, TYPE(NAME="hash_mod”,PROPERTIES(“sharding-count"="6”)), KEY_GENERATE_STRATEGY(COLUMN=order_id,TYPE(NAME="snowflake”)) );

Encryption #

StatementFunctionExample
SHOW ENCRYPTING RULEShow encryption ruleSHOW ENCRYPTING RULE
ALTER ENCRYPTING RULEAlter encryption ruleALTER ENCRYPTING RULE (READ(RATE_LIMITER (TYPE(NAME='QPS’,PROPERTIES(‘qps'='5000’)))))
SHOW ENCRYPTING LIST;Query running listSHOW ENCRYPTING LIST;
SHOW ENCRYPTING STATUS {jobId};Query task status, jobId: task IDSHOW ENCRYPTING STATUS 1234;
ENCRYPT TABLE {tableName};Start running task, tableName: table nameENCRYPT TABLE t_user;
COMMIT ENCRYPTING {jobId};Submit the encryption task, jobId: task id. The current version of commit only cleans up jobs, and subsequent versions will support commit and rollbackCOMMIT ENCRYPTING 1234;

Decryption #

StatementFunctionExample
SHOW DECRYPTING RULEShow decryption ruleSHOW DECRYPTING RULE
ALTER DECRYPTING RULEAlter decryption ruleALTER DECRYPTING RULE (READ(RATE_LIMITER (TYPE(NAME='QPS’,PROPERTIES(‘qps'='5000’)))))
SHOW DECRYPTING LIST;Query running listSHOW DECRYPTING LIST;
SHOW DECRYPTING STATUS {jobId};Query task status, jobId: task IDSHOW DECRYPTING STATUS 1234;
DECRYPT TABLE {tableName};Start running task, tableName: table nameDECRYPT TABLE t_user;
COMMIT DECRYPTING {jobId};Submit the decryption task, jobId: task id. The current version of commit only cleans up jobs, and subsequent versions will support commit and rollbackCOMMIT ENCRYPTING 1234;

Key Exchange #

StatementFunctionExample

| REENCRYPT TABLE WITH RULE tableName| Key exchange phase 1 | REENCRYPT TABLE WITH RULE t_encrypt ( COLUMNS((NAME=user_id,PLAIN=user_plain,CIPHER=user_cipher,ASSISTED_QUERY_COLUMN=user_assisted,LIKE_QUERY_COLUMN=user_like,ENCRYPT_ALGORITHM(TYPE(NAME='AES’,PROPERTIES(‘aes-key-value'='665544aaa’))),ASSISTED_QUERY_ALGORITHM(TYPE(NAME='AES’,PROPERTIES(‘aes-key-value'='523234abc’))), LIKE_QUERY_ALGORITHM(TYPE(NAME='CHAR_DIGEST_LIKE’))),(NAME=order_id, PLAIN=order_plain,CIPHER =order_cipher, ENCRYPT_ALGORITHM(TYPE(NAME='AES’,PROPERTIES(‘aes-key-value'='445533ccc’))))), QUERY_WITH_CIPHER_COLUMN=true);| | START REENCRYPTING {jobId}; | Key exchange phase 2 encryption, jobId: task id | START REENCRYPTING j54014fb26631db0f7149741422d86cc5dfe6;|

Key exchange phase 1 statement #

REENCRYPT TABLE WITH RULE tableName 

Parameter description

Parameter nameFunction
tableNameKey exchange table

Example

REENCRYPT TABLE WITH RULE t_encrypt (
COLUMNS(
(NAME=user_id,PLAIN=user_plain,CIPHER=user_cipher,ASSISTED_QUERY_COLUMN=user_assisted,LIKE_QUERY_COLUMN=user_like,ENCRYPT_ALGORITHM(TYPE(NAME='AES',PROPERTIES('aes-key-value'='665544aaa'))),ASSISTED_QUERY_ALGORITHM(TYPE(NAME='AES',PROPERTIES('aes-key-value'='523234abc'))), LIKE_QUERY_ALGORITHM(TYPE(NAME='CHAR_DIGEST_LIKE'))),
(NAME=order_id, PLAIN=order_plain,CIPHER =order_cipher, ENCRYPT_ALGORITHM(TYPE(NAME='AES',PROPERTIES('aes-key-value'='445533ccc'))))
), QUERY_WITH_CIPHER_COLUMN=true);

Key exchange phase 2 statement #

START REENCRYPTING jobId;

Parameter description

Parameter nameFunction
jobidKey exchange task id

Example

START REENCRYPTING jobId;

Circuit Breaker #

StatementFunctionExample
ALTER READWRITE_SPLITTING RULE [ groupName ] (ENABLE / DISABLE) storageUnitName [FROM databaseName]Enable or disable read data sourceALTER READWRITE_SPLITTING RULE group_1 ENABLE read_ds_1
[ENABLE / DISABLE] COMPUTE NODE instanceIdEnable or disable proxy instanceDISABLE COMPUTE NODE instance_1
SHOW COMPUTE NODESQuery proxy instance informationSHOW COMPUTE NODES
SHOW STATUS FROM READWRITE_SPLITTING (RULES / RULE groupName) [FROM databaseName]Query data sources status of readwrite splitting groupsSHOW STATUS FROM READWRITE_SPLITTING RULES

Global Rule #

StatementFunctionExample
SHOW AUTHORITY RULEQuery authority rule configurationSHOW AUTHORITY RULE
SHOW TRANSACTION RULEQuery transaction rule configurationSHOW TRANSACTION RULE
SHOW SQL_PARSER RULEQuery SQL parser rule configurationSHOW SQL_PARSER RULE
SHOW TRAFFIC[ RULES / RULE ruleName]Query the specified double routing rules or all double routing rulesSHOW TRAFFIC RULES;
CREATE TRAFFIC RULE sql_match_traffic (LABLES(xxx),TRAFFIC_ALGORITHM(TYPE(NAME=xxx,PROPERTIES(“key” = “value”))),LOAD_BALANCER(TYPE(NAME=xxx, PROPERTIES(“key"="value”))))Create a dual routing rule,TRAFFIC_ALGORITHM support SQL_MATCH and SQL_HINT two types;LOAD_BALANCER support RANDOM and ROUND_ROBIN two types.CREATE TRAFFIC RULE sql_match_traffic (LABLES(OLTP),TRAFFIC_ALGORITHM(TYPE(NAME=SQL_MATCH,PROPERTIES(“sql” = “SELECT * FROM t_order WHERE order_id = ?; UPDATE t_order SET order_id = ?;"))),LOAD_BALANCER(TYPE(NAME=RANDOM)))
ALTER TRANSACTION RULE(DEFAULT=xx,TYPE(NAME=xxx, PROPERTIES(“key1"="value1”,“key2"="value2”…)))Alter transaction rule configuration,DEFAULT: default transaction type,support LOCAL、XA、BASE; NAME: name of transaction manager, support Atomikos, Narayana and BitronixALTER TRANSACTION RULE(DEFAULT=XA,TYPE(NAME=Narayana, PROPERTIES(“databaseName"="jbossts”,“host"="127.0.0.1”)))
ALTER SQL_PARSER RULE SQL_COMMENT_PARSE_ENABLE=xx, PARSE_TREE_CACHE(INITIAL_CAPACITY=xx, MAXIMUM_SIZE=xx, CONCURRENCY_LEVEL=xx), SQL_STATEMENT_CACHE(INITIAL_CAPACITY=xxx, MAXIMUM_SIZE=xxx, CONCURRENCY_LEVEL=xxx)Alter SQL parser rule configuration, SQL_COMMENT_PARSE_ENABLE: whether to parse the SQL comment, PARSE_TREE_CACHE: local cache configuration of syntax tree, SQL_STATEMENT_CACHE: local cache of SQL statementALTER SQL_PARSER RULE SQL_COMMENT_PARSE_ENABLE=false, PARSE_TREE_CACHE(INITIAL_CAPACITY=10, MAXIMUM_SIZE=11, CONCURRENCY_LEVEL=1), SQL_STATEMENT_CACHE(INITIAL_CAPACITY=11, MAXIMUM_SIZE=11, CONCURRENCY_LEVEL=100)
ALTER TRAFFIC RULE sql_match_traffic (LABLES(xxx),TRAFFIC_ALGORITHM(TYPE(NAME=xxx,PROPERTIES(“key” = “value”))),LOAD_BALANCER(TYPE(NAME=xxx,PROPERTIES(“key"="value”))))Modify dual routing rules,TRAFFIC_ALGORITHM support SQL_MATCH and SQL_HINT two types;LOAD_BALANCER support RANDOM and ROUND_ROBIN two types.ALTER TRAFFIC RULE sql_match_traffic ( LABLES(OLTP),TRAFFIC_ALGORITHM(TYPE(NAME=SQL_MATCH,PROPERTIES(“sql” = “SELECT * FROM t_order WHERE order_id = ?; UPDATE t_order SET order_id = ?;"))),LOAD_BALANCER(TYPE(NAME=RANDOM)))
DROP TRAFFIC RULE ruleName [, ruleName]Delete double routing ruleDROP TRAFFIC RULE sql_match_traffic

Variable Management #

In DistSQL, attribute configuration names are separated by underscores.

StatementFunctionExample
SET DIST VARIABLE variable_name = xxvariable_name as Attribute Configuration of proxySET VARIABLE sql_show = true
SHOW DIST VARIABLESQuery all attribute configurations of the proxySHOW ALL VARIABLES
SHOW DIST VARIABLE WHERE name = variable_nameQuery the specified proxy attributeSHOW VARIABLE WHERE name = sql_show
  • Special variables

The special variables are not in Attribute Configuration of proxy, However, it can be dynamically managed through DistSQL:

StatementFunctionExample
SHOW DIST VARIABLE WHERE name = transaction_typeQuery Transaction TypeSHOW DIST VARIABLE WHERE name = transaction_type
SET DIST VARIABLE transaction_type = xxModify the transaction type of the current connection, support LOCAL, XA, BASESET DIST VARIABLE transaction_type = XA
SHOW DIST VARIABLE WHERE name = agent_plugins_enabledQuerying agent plugin enabling statusSHOW DIST VARIABLE WHERE name = agent_plugins_enabled
SET DIST VARIABLE agent_plugins_enabled = xxSet the enabling status of the agent plug-in. The value is BooleanSET DIST VARIABLE agent_plugins_enabled = true
SHOW DIST VARIABLE WHERE name = cached_connectionsQuery the number of connections currently cachedSHOW DIST VARIABLE WHERE name = cached_connections
SHOW DIST VARIABLE WHERE name = general_query_logQuerying the Full Log Enable StatusSHOW DIST VARIABLE WHERE name = general_query_log
SET DIST VARIABLE general_query_log = xxSet the Full Audit Log Enable StatusSET DIST VARIABLE general_query_log = true
SHOW DIST VARIABLE WHERE name = slow_query_logQuerying the Slow Log Enable StatusSHOW DIST VARIABLE WHERE name = slow_query_log
SET DIST VARIABLE slow_query_log = xxSet the Slow Log Enable StatusSET DIST VARIABLE slow_query_log = true
SHOW DIST VARIABLE WHERE name = long_query_timeQuery Slow Query ThresholdSHOW DIST VARIABLE WHERE name = long_query_time
SET DIST VARIABLE long_query_time = xxSet slow query threshold, unit is millisecondsSET DIST VARIABLE long_query_time = 5000

Other #

StatementFunctionExample
SHOW COMPUTE NODE INFOQuery the instance information of the proxySHOW COMPUTE NODE INFO
SHOW COMPUTE NODE MODEQuery the mode configuration of the proxySHOW COMPUTE NODE MODE
LABEL COMPUTE NODE instanceId WITH labelName [ , labelName ]Add tags to instances.LABEL COMPUTE NODE 10.7.7.136@3309 with olap,group_by
UNLABEL COMPUTE NODE instanceIdRemove all tags from instances.UNLABEL COMPUTE NODE 10.7.7.136@3309
UNLABEL COMPUTE NODE instanceId WITH labelNameRemoves the specified tags from the instanceUNLABEL COMPUTE NODE 10.7.7.136@3309 WITH group_by
RELABEL COMPUTE NODE instanceId with labelName [ , labelName ]Readd tags to the instances.(overwrite the original tags)RELABEL COMPUTE NODE 10.7.7.136@3309 with label_9, label_0
REFRESH TABLE METADATARefresh the metadata of all tablesREFRESH TABLE METADATA
REFRESH TABLE METADATA tableNameRefresh the metadata of the specified tableREFRESH TABLE METADATA t_order
REFRESH TABLE METADATA tableName FROM STORAGE UNIT storageUnitNameRefresh the tables’ metadata in the specified data sourceREFRESH TABLE METADATA t_order FROM STORAGE UNIT ds_1
REFRESH TABLE METADATA FROM STORAGE UNIT storageUnitName SCHEMA schemaNameRefresh the tables’ metadata in a schema of a specified data source. If there are no tables in the schema, the schema will be deleted.REFRESH TABLE METADATA FROM STORAGE UNIT ds_1 SCHEMA db_schema
SHOW TABLE METADATA tableName [, tableName] …Query table metadataSHOW TABLE METADATA t_order
EXPORT DATABASE CONFIGURATION [FROM databaseName] [TO FILE “filePath”]Export data sources and rule configurations to YAML formatEXPORT DATABASE CONFIGURATION FROM readwrite_splitting_db
IMPORT DATABASE CONFIGURATION FILE="file_path”Import data sources and rule configurations from YAML, only supports import into an empty databaseIMPORT DATABASE CONFIGURATION FILE = “/xxx/config-sharding.yaml”
SHOW RULES USED STORAGE UNIT storageUnitName [FROM databaseName]Query the rules for using the specified data source in databaseSHOW RULES USED STORAGE UNIT ds_0 FROM databaseName

Notice #

DBPlusEngine-Proxy does not support hint by default, to support it, set proxy-hint-enabled to true in conf/server.yaml.