proxysql mysql_query_rules 翻譯

mhabbyo發表於2017-02-06

MySQL Query Rules

Here is the statement used to create the mysql_query_rules table:

CREATE TABLE mysql_query_rules (
    rule_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
    active INT CHECK (active IN (0,1)) NOT NULL DEFAULT 0,
    username VARCHAR,
    schemaname VARCHAR,
    flagIN INT NOT NULL DEFAULT 0,
    client_addr VARCHAR,
    proxy_addr VARCHAR,
    proxy_port INT,
    digest VARCHAR,
    match_digest VARCHAR,
    match_pattern VARCHAR,
    negate_match_pattern INT CHECK (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 INT CHECK(cache_ttl > 0),
    reconnect INT CHECK (reconnect IN (0,1)) DEFAULT NULL,
    timeout INT UNSIGNED,
    retries INT CHECK (retries>=0 AND retries <=1000),
    delay INT UNSIGNED,
    mirror_flagOUT INT UNSIGNED,
    mirror_hostgroup INT UNSIGNED,
    error_msg VARCHAR,
    sticky_conn INT CHECK (sticky_conn IN (0,1)),
    multiplex INT CHECK (multiplex IN (0,1)),
    log INT CHECK (log IN (0,1)),
    apply INT CHECK(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
  • flagINflagOUTapply - 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 對規則的語言描述,說明它的功能

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29291882/viewspace-2133129/,如需轉載,請註明出處,否則將追究法律責任。

相關文章