本文介紹了規則和拓撲類查詢語句。
SHOW RULE [FROM tablename]
使用說明:
show rule
:查看資料庫下每一個邏輯表的拆分情況;show rule from tablename
:查看資料庫下指定邏輯表的拆分情況。
SHOW RULE;
+----+------------+-----------+------------------+---------------------+--------------------+------------------+---------------------+--------------------+
| ID | TABLE_NAME | BROADCAST | DB_PARTITION_KEY | DB_PARTITION_POLICY | DB_PARTITION_COUNT | TB_PARTITION_KEY | TB_PARTITION_POLICY | TB_PARTITION_COUNT |
+----+------------+-----------+------------------+---------------------+--------------------+------------------+---------------------+--------------------+
| 0 | k_1 | 0 | k | hash | 40 | k | hash | 2 |
| 1 | k_2 | 0 | k | hash | 40 | k | hash | 2 |
| 2 | sbtest1 | 0 | id | hash | 40 | id | hash | 2 |
| 3 | t1 | 0 | id | hash | 40 | id | hash | 4 |
+----+------------+-----------+------------------+---------------------+--------------------+------------------+---------------------+--------------------+
4 rows in set (0.05 sec)
重要列詳解:
- BROADCAST:是否為廣播表(0:否,1:是);
- DB_PARTITION_KEY:分庫的拆分鍵,沒有分庫的話,值為空白;
- DB_PARTITION_POLICY:分庫的拆分策略,取值包括雜湊或YYYYMM、YYYYDD、YYYYWEEK等日期策略;
- DB_PARTITION_COUNT:分庫數;
- TB_PARTITION_KEY:分表的拆分鍵,沒有分表的話,值為空白;
- TB_PARTITION_POLICY:分表的拆分策略,取值包括雜湊或MM、DD、MMDD、WEEK等日期策略;
- TB_PARTITION_COUNT:分表數。
SHOW FULL RULE [FROM tablename]
查看資料庫下邏輯表的拆分規則,比SHOW RULE
指令展示的資訊更加詳細。
SHOW FULL RULE;
+----+------------+-----------+------------+-----------------------+----------------------+--------------------------------------------------+-------------------+----------------------------------------+----------------+--------------------+
| ID | TABLE_NAME | BROADCAST | JOIN_GROUP | ALLOW_FULL_TABLE_SCAN | DB_NAME_PATTERN | DB_RULES_STR | TB_NAME_PATTERN | TB_RULES_STR | PARTITION_KEYS | DEFAULT_DB_INDEX |
+----+------------+-----------+------------+-----------------------+----------------------+--------------------------------------------------+-------------------+----------------------------------------+----------------+--------------------+
| 0 | k_1 | 0 | NULL | 1 | TEST1_{000000}_GROUP | ((#k,1,80#).longValue().abs() % 80).intdiv(2) | k_1_cewR_{00} | ((#k,1,80#).longValue().abs() % 80) | k | TEST1_SINGLE_GROUP |
| 1 | k_2 | 0 | NULL | 1 | TEST1_{000000}_GROUP | ((#k,1,80#).longValue().abs() % 80).intdiv(2) | k_2_1xsQ_{00} | ((#k,1,80#).longValue().abs() % 80) | k | TEST1_SINGLE_GROUP |
| 2 | sbtest1 | 0 | NULL | 1 | TEST1_{000000}_GROUP | ((#id,1,80#).longValue().abs() % 80).intdiv(2) | sbtest1_wO5k_{00} | ((#id,1,80#).longValue().abs() % 80) | id | TEST1_SINGLE_GROUP |
| 3 | t1 | 0 | NULL | 1 | TEST1_{000000}_GROUP | ((#id,1,160#).longValue().abs() % 160).intdiv(4) | t1_EMrC_{000} | ((#id,1,160#).longValue().abs() % 160) | id | TEST1_SINGLE_GROUP |
+----+------------+-----------+------------+-----------------------+----------------------+--------------------------------------------------+-------------------+----------------------------------------+----------------+--------------------+
重要列詳解:
- BROADCAST:是否為廣播表(0:否,1:是);
- JOIN_GROUP:保留欄位,暫時無意義。
- ALLOW_FULL_TABLE_SCAN:分庫分表在沒有指定分表索引值的情況下是否允許查詢資料,如果配置為true,此時需要掃描每一個物理表來尋找出合格資料,簡稱為全表掃描;
- DB_NAME_PATTERN:DB_NAME_PATTERN中{}之間的0為預留位置,執行SQL時會被DB_RULES_STR計算出的值替代,並保持位元。比如,DB_NAME_PATTERN的值為SEQ_{0000}_RDS,DB_RULES_STR的值為[1,2,3,4],則會產生4個DB_NAME,分別為SEQ_0001_RDS、SEQ_0002_RDS、SEQ_0003_RDS、SEQ_0004_RDS;
- DB_RULES_STR:具體的分庫規則;
- TB_NAME_PATTERN:TB_NAME_PATTERN中{}之間的0為預留位置,執行SQL時會被TB_RULES_STR計算出的值替代,並保持位元。比如,TB_NAME_PATTERN的值為table_{00},TB_RULES_STR的值為[1,2,3,4,5,6,7,8],則會產生8張表,分別為table_01、table_02、table_03、table_04、table_05、table_06、table_07、table_08;
- TB_RULES_STR:分表規則;
- PARTITION_KEYS:分庫和分表鍵集合,對於既分庫又分表的情形,分庫鍵在前,分表鍵在後;
- DEFAULT_DB_INDEX:單庫單表存放的分庫。
SHOW TOPOLOGY FROM tablename
查看指定邏輯表的拓撲分布,展示該邏輯表儲存在哪些分庫中,每個分庫下包含哪些分表。
SHOW TOPOLOGY FROM EMP;
+------+--------------------------------------------------+------------+
| ID | GROUP_NAME | TABLE_NAME |
+------+--------------------------------------------------+------------+
| 0 | SEQ_TEST_1487767780814RGKKSEQ_TEST_WNJG_0000_RDS | emp_0 |
| 1 | SEQ_TEST_1487767780814RGKKSEQ_TEST_WNJG_0000_RDS | emp_1 |
| 2 | SEQ_TEST_1487767780814RGKKSEQ_TEST_WNJG_0001_RDS | emp_0 |
| 3 | SEQ_TEST_1487767780814RGKKSEQ_TEST_WNJG_0001_RDS | emp_1 |
| 4 | SEQ_TEST_1487767780814RGKKSEQ_TEST_WNJG_0002_RDS | emp_0 |
| 5 | SEQ_TEST_1487767780814RGKKSEQ_TEST_WNJG_0002_RDS | emp_1 |
| 6 | SEQ_TEST_1487767780814RGKKSEQ_TEST_WNJG_0003_RDS | emp_0 |
| 7 | SEQ_TEST_1487767780814RGKKSEQ_TEST_WNJG_0003_RDS | emp_1 |
| 8 | SEQ_TEST_1487767780814RGKKSEQ_TEST_WNJG_0004_RDS | emp_0 |
| 9 | SEQ_TEST_1487767780814RGKKSEQ_TEST_WNJG_0004_RDS | emp_1 |
| 10 | SEQ_TEST_1487767780814RGKKSEQ_TEST_WNJG_0005_RDS | emp_0 |
| 11 | SEQ_TEST_1487767780814RGKKSEQ_TEST_WNJG_0005_RDS | emp_1 |
| 12 | SEQ_TEST_1487767780814RGKKSEQ_TEST_WNJG_0006_RDS | emp_0 |
| 13 | SEQ_TEST_1487767780814RGKKSEQ_TEST_WNJG_0006_RDS | emp_1 |
| 14 | SEQ_TEST_1487767780814RGKKSEQ_TEST_WNJG_0007_RDS | emp_0 |
| 15 | SEQ_TEST_1487767780814RGKKSEQ_TEST_WNJG_0007_RDS | emp_1 |
+------+--------------------------------------------------+------------+
SHOW PARTITIONS FROM tablename
查看分庫分表鍵集合,分庫鍵和分表鍵之間用逗號分割。如果最終結果有兩個值,說明是既分庫又分表的情形,第一個是分庫鍵,第二個是分表鍵。如果結果只有一個值,說明是分庫不分表的情形,該值是分庫鍵。
SHOW PARTITIONS FROM EMP;
+-----------+
| KEYS |
+-----------+
| emp_no,id |
+-----------+
1 row in set (0.00 sec)
SHOW BROADCASTS
查看廣播表列表。
SHOW BROADCASTS;
+------+------------+
| ID | TABLE_NAME |
+------+------------+
| 0 | brd2 |
| 1 | brd_tbl |
+------+------------+
2 rows in set (0.01 sec)
SHOW DATASOURCES
查看底層儲存資訊,包含資料庫名、資料庫分組名、串連資訊、使用者名稱、底層儲存類型、讀寫權重、串連池資訊等。
SHOW DATASOURCES;
+------+----------------------------+------------------------------------------------+--------------------------------------------------+----------------------------------------------------------------------------------+-----------+-------+------+------+------+--------------+----------+--------------+---------------+----------------------------------------------+-------------+--------------+
| ID | SCHEMA | NAME | GROUP | URL | USER | TYPE | INIT | MIN | MAX | IDLE_TIMEOUT | MAX_WAIT | ACTIVE_COUNT | POOLING_COUNT | ATOM | READ_WEIGHT | WRITE_WEIGHT |
+------+----------------------------+------------------------------------------------+--------------------------------------------------+----------------------------------------------------------------------------------+-----------+-------+------+------+------+--------------+----------+--------------+---------------+----------------------------------------------+-------------+--------------+
| 0 | seq_test_1487767780814rgkk | rds1ur80kcv8g3t6p3ol_seq_test_wnjg_0000_iiab_1 | SEQ_TEST_1487767780814RGKKSEQ_TEST_WNJG_0000_RDS | jdbc:mysql://rds1ur80kcv8g3t6p3ol.mysql.rds.aliyuncs.com:3306/seq_test_wnjg_0000 | jnkinsea0 | xdb | 0 | 24 | 72 | 15 | 5000 | 0 | 1 | rds1ur80kcv8g3t6p3ol_seq_test_wnjg_0000_iiab | 10 | 10 |
| 1 | seq_test_1487767780814rgkk | rds1ur80kcv8g3t6p3ol_seq_test_wnjg_0001_iiab_2 | SEQ_TEST_1487767780814RGKKSEQ_TEST_WNJG_0001_RDS | jdbc:mysql://rds1ur80kcv8g3t6p3ol.mysql.rds.aliyuncs.com:3306/seq_test_wnjg_0001 | jnkinsea0 | xdb | 0 | 24 | 72 | 15 | 5000 | 0 | 1 | rds1ur80kcv8g3t6p3ol_seq_test_wnjg_0001_iiab | 10 | 10 |
| 2 | seq_test_1487767780814rgkk | rds1ur80kcv8g3t6p3ol_seq_test_wnjg_0002_iiab_3 | SEQ_TEST_1487767780814RGKKSEQ_TEST_WNJG_0002_RDS | jdbc:mysql://rds1ur80kcv8g3t6p3ol.mysql.rds.aliyuncs.com:3306/seq_test_wnjg_0002 | jnkinsea0 | xdb | 0 | 24 | 72 | 15 | 5000 | 0 | 1 | rds1ur80kcv8g3t6p3ol_seq_test_wnjg_0002_iiab | 10 | 10 |
| 3 | seq_test_1487767780814rgkk | rds1ur80kcv8g3t6p3ol_seq_test_wnjg_0003_iiab_4 | SEQ_TEST_1487767780814RGKKSEQ_TEST_WNJG_0003_RDS | jdbc:mysql://rds1ur80kcv8g3t6p3ol.mysql.rds.aliyuncs.com:3306/seq_test_wnjg_0003 | jnkinsea0 | xdb | 0 | 24 | 72 | 15 | 5000 | 0 | 1 | rds1ur80kcv8g3t6p3ol_seq_test_wnjg_0003_iiab | 10 | 10 |
| 4 | seq_test_1487767780814rgkk | rds1ur80kcv8g3t6p3ol_seq_test_wnjg_0004_iiab_5 | SEQ_TEST_1487767780814RGKKSEQ_TEST_WNJG_0004_RDS | jdbc:mysql://rds1ur80kcv8g3t6p3ol.mysql.rds.aliyuncs.com:3306/seq_test_wnjg_0004 | jnkinsea0 | xdb | 0 | 24 | 72 | 15 | 5000 | 0 | 1 | rds1ur80kcv8g3t6p3ol_seq_test_wnjg_0004_iiab | 10 | 10 |
| 5 | seq_test_1487767780814rgkk | rds1ur80kcv8g3t6p3ol_seq_test_wnjg_0005_iiab_6 | SEQ_TEST_1487767780814RGKKSEQ_TEST_WNJG_0005_RDS | jdbc:mysql://rds1ur80kcv8g3t6p3ol.mysql.rds.aliyuncs.com:3306/seq_test_wnjg_0005 | jnkinsea0 | xdb | 0 | 24 | 72 | 15 | 5000 | 0 | 1 | rds1ur80kcv8g3t6p3ol_seq_test_wnjg_0005_iiab | 10 | 10 |
| 6 | seq_test_1487767780814rgkk | rds1ur80kcv8g3t6p3ol_seq_test_wnjg_0006_iiab_7 | SEQ_TEST_1487767780814RGKKSEQ_TEST_WNJG_0006_RDS | jdbc:mysql://rds1ur80kcv8g3t6p3ol.mysql.rds.aliyuncs.com:3306/seq_test_wnjg_0006 | jnkinsea0 | xdb | 0 | 24 | 72 | 15 | 5000 | 0 | 1 | rds1ur80kcv8g3t6p3ol_seq_test_wnjg_0006_iiab | 10 | 10 |
| 7 | seq_test_1487767780814rgkk | rds1ur80kcv8g3t6p3ol_seq_test_wnjg_0007_iiab_8 | SEQ_TEST_1487767780814RGKKSEQ_TEST_WNJG_0007_RDS | jdbc:mysql://rds1ur80kcv8g3t6p3ol.mysql.rds.aliyuncs.com:3306/seq_test_wnjg_0007 | jnkinsea0 | xdb | 0 | 24 | 72 | 15 | 5000 | 0 | 1 | rds1ur80kcv8g3t6p3ol_seq_test_wnjg_0007_iiab | 10 | 10 |
+------+----------------------------+------------------------------------------------+--------------------------------------------------+----------------------------------------------------------------------------------+-----------+-------+------+------+------+--------------+----------+--------------+---------------+----------------------------------------------+-------------+--------------+
重要列詳解:
- SCHEMA:資料庫名;
- GROUP:資料庫分組名。分組的目標是管理多組資料完全相同的資料庫,比如通過 RDS(MySQL)進行資料複製後的主備資料庫。主要用來解決讀寫分離、主備切換的問題;
- URL:底層RDS(MySQL)的串連資訊;
- TYPE:底層儲存類型。
- READ_WEIGHT:讀權重。在主執行個體的讀壓力比較大的時候,可以通過讀寫分離功能將讀流量進行分流,減輕RDS主執行個體的壓力。PolarDB-X會自動識別讀寫流量,引導寫流量進入RDS主執行個體,讀流量則按配置的權重流向所有RDS執行個體;
- WRITE_WEIGHT:寫權重。
SHOW NODE
查看物理庫的讀寫次數(歷史累計資料)、讀寫權重(歷史累計資料)。
SHOW NODE;
+------+--------------------------------------------------+-------------------+------------------+---------------------+--------------------+
| ID | NAME | MASTER_READ_COUNT | SLAVE_READ_COUNT | MASTER_READ_PERCENT | SLAVE_READ_PERCENT |
+------+--------------------------------------------------+-------------------+------------------+---------------------+--------------------+
| 0 | SEQ_TEST_1487767780814RGKKSEQ_TEST_WNJG_0000_RDS | 12 | 0 | 100% | 0% |
| 1 | SEQ_TEST_1487767780814RGKKSEQ_TEST_WNJG_0001_RDS | 0 | 0 | 0% | 0% |
| 2 | SEQ_TEST_1487767780814RGKKSEQ_TEST_WNJG_0002_RDS | 0 | 0 | 0% | 0% |
| 3 | SEQ_TEST_1487767780814RGKKSEQ_TEST_WNJG_0003_RDS | 0 | 0 | 0% | 0% |
| 4 | SEQ_TEST_1487767780814RGKKSEQ_TEST_WNJG_0004_RDS | 0 | 0 | 0% | 0% |
| 5 | SEQ_TEST_1487767780814RGKKSEQ_TEST_WNJG_0005_RDS | 0 | 0 | 0% | 0% |
| 6 | SEQ_TEST_1487767780814RGKKSEQ_TEST_WNJG_0006_RDS | 0 | 0 | 0% | 0% |
| 7 | SEQ_TEST_1487767780814RGKKSEQ_TEST_WNJG_0007_RDS | 0 | 0 | 0% | 0% |
+------+--------------------------------------------------+-------------------+------------------+---------------------+--------------------+
8 rows in set (0.01 sec)
重要列詳解:
- MASTER_COUNT:RDS主執行個體處理的讀寫查詢次數(歷史累計資料);
- SLAVE_COUNT:RDS備執行個體處理的唯讀查詢次數(歷史累計資料);
- MASTER_PERCENT:RDS主執行個體處理的讀寫查詢佔比(注意該列顯示的是累計的實際資料佔比,並不是使用者配置的百分比);
- SLAVE_PERCENT:RDS備執行個體處理的讀寫查詢佔比(注意該列顯示的是累計的實際資料佔比,並不是使用者配置的百分比)。
說明
- 事務中的唯讀查詢會被發送到RDS主執行個體;
- 由於
MASTER_PERCENT
,SLAVE_PERCENT
這兩列代表的是歷史累計資料,更改讀寫權重的配比後,這幾個數值並不能立即反應最新的讀寫權重配比,需累計一段比較長的時間才行。