Here is the statement used to create the mysql_query_rules table:
CREATETABLEmysql_query_rules (
rule_id INTEGERPRIMARY KEY AUTOINCREMENT NOT NULL,
active INTCHECK (active IN (0,1)) NOT NULL DEFAULT 0,
username VARCHAR,
schemaname VARCHAR,
flagIN INTNOT NULL DEFAULT 0,
client_addr VARCHAR,
proxy_addr VARCHAR,
proxy_port INT,
digest VARCHAR,
match_digest VARCHAR,
match_pattern VARCHAR,
negate_match_pattern INTCHECK (negate_match_pattern IN (0,1)) NOT NULL DEFAULT 0,
re_modifiers VARCHAR DEFAULT 'CASELESS',
flagOUT INT,
replace_pattern VARCHAR,
destination_hostgroup INT DEFAULT NULL,
cache_ttl INTCHECK(cache_ttl >0),
reconnect INTCHECK (reconnect IN (0,1)) DEFAULT NULL,
timeout INT UNSIGNED,
retries INTCHECK (retries>=0AND retries <=1000),
delay INT UNSIGNED,
mirror_flagOUT INT UNSIGNED,
mirror_hostgroup INT UNSIGNED,
error_msg VARCHAR,
sticky_conn INTCHECK (sticky_conn IN (0,1)),
multiplex INTCHECK (multiplex IN (0,1)),
log INTCHECK (log IN (0,1)),
apply INTCHECK(apply IN (0,1)) NOT NULL DEFAULT 0,
comment VARCHAR)
The fields have the following semantics 語義:
rule_id - the unique id of the rule. Rules are processed in rule_id order 唯一的規則id編號,規則按照rule_id的順序執行的
active - only rules with active=1 will be considered by the query processing module active=1 的時候,查詢模塊才會考慮這一條規則
username - filtering criteria 準確的 matching username. If is non-NULL, a query will match only if the connection is made with the correct username username 用來匹配精確的用戶名,如果它是一個非空的值,查詢將會只匹配從這個username發起的查詢
schemaname - filtering criteria matching schemaname. If is non-NULL, a query will match only if the connection uses schemaname as default schema 用來指定連接進來匹配的shcemaname
flagIN, flagOUT, apply - these allow us to create "chains of rules" that get applied one after the other. An input flag value is set to 0, and only rules with flagIN=0 are considered at the beginning. When a matching rule is found for a specific query, flagOUT is evaluated and if NOT NULL the query will be flagged with the specified flag in flagOUT. If flagOUT differs from flagIN , the query will exit the current chain and enters a new chain of rules having flagIN as the new input flag. If flagOUT matches flagIN, the query will be re-evaluate again against the first rule with said flagIN. This happens until there are no more matching rules, or apply is set to 1 (which means this is the last rule to be applied) 這三個是重要的配置。它們是用來創建各個規則之間的規則鏈的,也就是用來進行連接多個規則的。如果一條規則中定義的輸入標識符為0,那么只有包含輸入標識符為0 的規則才會在一開始就應用這條規則。當被匹配到的規則被發現是一個特定的查詢,在輸出標識符是非空的情況下,這個查詢會被打上對應的輸出標識符。如果輸出標識符和輸入標識符不一致,查詢將離開當前的規則鏈并且進入到下一個規則中(這個規則的輸入標識符和前面的輸出標識符一致),它將會成為下一條規則的輸入標識符。如果輸出標識符和輸入標識符一致,查詢將會回到前面標記有同樣標識符的規則中。這種情形會循環發生,直到沒有更多的匹配規則,如果apply被設置為1,就意味著這是規則鏈中的最后一條規則,規則將在這里被終止。
client_addr - match traffic from a specific source 匹配發起查詢的應用的IP
proxy_addr - match incoming traffic on a specific local IP 匹配查詢指定的本地的proxysql的IP
proxy_port - match incoming traffic on a specific local port 指定本地proxysql的查詢端口
digest - match queries with a specific digest, as returned bystats_mysql_query_digest.digest 匹配查詢指定的摘要,可以在stats_mysql_query_digest.diges列中查到,不指定的化會被自動分配一個
match_digest - regular expression that matches the query digest. See also mysql-query_processor_regex 匹配查詢摘要的正則表達式 類型有兩種 PCRE 和 RE2 默認是PCRE
match_pattern - regular expression that matches the query text. See also mysql-query_processor_regex匹配文本內容的正則表達式
negate_match_pattern - if this is set to 1, only queries not matching the query text will be considered as a match. This acts as a NOT operator in front of the regular expression matching against match_pattern or match_digest 如果這個參數被設置為1,只有沒有被匹配到的查詢規則的查詢會被執行。它是一個正則相反的操作,和match_pattern or match_digest兩個參數相對應。
re_modifiers - comma separated list of options to modify the behavior of the RE engine. WithCASELESS the match is case insensitive. With GLOBAL the replace is global (replaces all matches and not just the first). For backward compatibility, only CASELESS is the enabled by default. See also mysql-query_processor_regex for more details.逗號隔開的列表選項來用來修改正則引擎的操作。caseless 選項表明不進行遞歸,只能夠匹配到查詢中的第一個匹配到的字符串。global選項下,也就是全局選項下,能夠替換到查詢語句中所有的陪匹配到的文本。為了向后兼容,默認設置的是 caseless.
replace_pattern - this is the pattern with which to replace the matched pattern. It's done using RE2::Replace, so it's worth taking a look at the online documentation for that:https://github.com/google/re2/blob/master/re2/re2.h#L378. Note that this is optional, and when this is missing, the query processor will only cache, route, or set other parameters without rewriting. 被替換成為的字符。根據規則,將被匹配到的內容替換成為這個參數下面的內容。這是一個可選項目,如果沒有值,查詢過程將被緩存、路由或者設置為其他沒有重寫的參數,就是不進行任何的替換。
destination_hostgroup - route matched queries to this hostgroup. This happens unless there is a started transaction and the logged in user has the transaction_persistent flag set to 1 (seemysql_users table). 指定目的組的編號,只有在起了事務和登錄的用戶ransaction_persistent flag被設置為1 的時候才生效。ransaction_persistent flag默認就是被設置為1
cache_ttl - the number of milliseconds for which to cache the result of the query. Note: in ProxySQL 1.1 cache_ttl was in seconds 緩沖查詢結果的毫秒數 proxysql是按秒為單位的
reconnect - feature not used 現在還沒有使用
timeout - the maximum timeout in milliseconds with which the matched or rewritten query should be executed. If a query run for longer than the specific threshold, the query is automatically killed. If timeout is not specified, global variable mysql-default_query_timeoutapplies 匹配或者重定向能夠占用的最大的超時時間。如果一個查詢執行了超過設置閾值的大小,它會被自動kill。如果時間沒有被設置,會默認使用mysql-default_query_timeout;默認10個小時 mysql-default_query_timeout | 36000000
retries - the maximum number of times a query needs to be re-executed in case of detected failure during the execution of the query. If retries is not specified, global variable mysql-query_retries_on_failure applies 當一個查詢失敗后,它重新去執行的最大次數。如果沒有設置,默認是 1 | mysql-query_retries_on_failure | 1 |
delay - number of milliseconds to delay the execution of the query. This is essentially 基本上 a throttling 壓制 mechanism and QoS, allowing to give priority to some queries instead of others. This value is added to the mysql-default_query_delay global variable that applies to all queries. Future version of ProxySQL will provide a more advanced throttling mechanism.延遲執行查詢的毫秒數。這是一個限制機制,用來提高某些查詢的優先級別。默認是0,以后的版本會更高級的延遲機制。
mirror_flagOUT and mirror_hostgroup - setting related to mirroring . 沒查到這個,沒文檔
error_msg - query will be blocked, and the specified error_msg will be returned to the client 查詢被阻斷后,返回給客戶端的錯誤信息
sticky_conn - not implemented yet 未使用
multiplex - If 0, multiplex will be disabled. If 1, multiplex could be re-enabled if there are is not any other conditions preventing this (like user variables or transactions). Default is NULL, thus not modifying multiplexing policies 如果是0 會禁止多路復用,如果是1,會使用多路復用(當其他的條件和多路復用沒有沖突的時候,比如用戶變量或者事務)。
log - query will be logged 是否寫入日志
comment - free form text field, usable for a descriptive comment of the query rule 對規則的語言描述,說明它的功能