All Products
Search
Document Center

PolarDB:Rule and topology query statements

Last Updated:Aug 27, 2026

This topic describes rule and topology query statements.

SHOW RULE [FROM tablename]

Usage:
  • show rule: Displays the sharding rule for each logical table in the current database.
  • show rule from tablename: Displays the sharding rule for a specified logical table.
mysql> 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 | dept_manager |         0 |                  | NULL                | 1                  |                  | NULL                | 1                  |
|    1 | emp          |         0 | emp_no           | hash                | 8                  | id               | hash                | 2                  |
|    2 | example      |         0 | shard_key        | hash                | 8                  |                  | NULL                | 1                  |
+------+--------------+-----------+------------------+---------------------+--------------------+------------------+---------------------+--------------------+
3 rows in set (0.01 sec)
            
Column descriptions:
  • BROADCAST: Specifies whether the table is a broadcast table (1 for yes, 0 for no).
  • DB_PARTITION_KEY: The database shard key. This column is empty if the database is not sharded.
  • DB_PARTITION_POLICY: The database sharding policy. Valid values include hash and date-based policies such as YYYYMM, YYYYDD, and YYYYWEEK.
  • DB_PARTITION_COUNT: The number of database shards.
  • TB_PARTITION_KEY: The table shard key. This column is empty if the table is not sharded.
  • TB_PARTITION_POLICY: The table sharding policy. Valid values include hash and date-based policies such as MM, DD, MMDD, and WEEK.
  • TB_PARTITION_COUNT: The number of table shards.

SHOW FULL RULE [FROM tablename]

Displays the detailed sharding rules for logical tables. This command provides more information than SHOW RULE.

mysql> 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 | dept_manager |         0 | NULL       |                     0 | SEQ_TEST_1487767780814RGKKSEQ_TEST_WNJG_0000_RDS   | NULL                                                | dept_manager    | NULL                               | NULL           | SEQ_TEST_1487767780814RGKKSEQ_TEST_WNJG_0000_RDS |
|    1 | emp          |         0 | NULL       |                     1 | SEQ_TEST_1487767780814RGKKSEQ_TEST_WNJG_{0000}_RDS | ((#emp_no,1,8#).longValue().abs() % 8)              | emp_{0}         | ((#id,1,2#).longValue().abs() % 2) | emp_no      id | SEQ_TEST_1487767780814RGKKSEQ_TEST_WNJG_0000_RDS |
|    2 | example      |         0 | NULL       |                     1 | SEQ_TEST_1487767780814RGKKSEQ_TEST_WNJG_{0000}_RDS | ((#shard_key,1,8#).longValue().abs() % 8).intdiv(1) | example         | NULL                               | shard_key      | SEQ_TEST_1487767780814RGKKSEQ_TEST_WNJG_0000_RDS |
+------+--------------+-----------+------------+-----------------------+----------------------------------------------------+-----------------------------------------------------+-----------------+------------------------------------+----------------+--------------------------------------------------+
3 rows in set (0.01 sec)
            
Column descriptions:
  • BROADCAST: Specifies whether the table is a broadcast table (1 for yes, 0 for no).
  • JOIN_GROUP: A reserved field that currently has no function.
  • ALLOW_FULL_TABLE_SCAN: Specifies whether a full table scan is permitted when a query omits the shard key. If set to 1, the system scans all physical tables for matching data.
  • DB_NAME_PATTERN: The naming pattern for physical databases. The {} in the pattern is a placeholder for a value calculated from DB_RULES_STR. The resulting number is padded with leading zeros to match the length of the placeholder.
  • DB_RULES_STR: The specific database sharding rule.
  • TB_NAME_PATTERN: The naming pattern for physical tables. The {} in the pattern is a placeholder for a value calculated from TB_RULES_STR. The resulting number is padded with leading zeros to match the length of the placeholder.
  • TB_RULES_STR: The table sharding rule.
  • PARTITION_KEYS: The set of shard keys. For tables sharded at both the database and table level, the database shard key appears before the table shard key.
  • DEFAULT_DB_INDEX: The database shard where a non-sharded table resides.

SHOW TOPOLOGY FROM tablename

Displays the data topology for a specified logical table. The result shows which database shards the table resides on and the corresponding physical tables (table shards) within each database shard.

mysql> 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      |
+------+--------------------------------------------------+------------+
16 rows in set (0.01 sec)
            

SHOW PARTITIONS FROM tablename

Displays the shard key(s) for a logical table. If the table has both a database shard key and a table shard key, both are returned, separated by a comma, with the database shard key listed first. If the table has only one shard key (either for database or table), only that key is returned.

mysql> show partitions from emp;
+-----------+
| KEYS      |
+-----------+
| emp_no,id |
+-----------+
1 row in set (0.00 sec)
            

SHOW BROADCASTS

Displays the list of broadcast tables.

mysql> show broadcasts;
+------+------------+
| ID   | TABLE_NAME |
+------+------------+
|    0 | brd2       |
|    1 | brd_tbl    |
+------+------------+
2 rows in set (0.01 sec)
            

SHOW DATASOURCES

Displays information about the underlying storage data sources, including the database name, database group name, connection information, username, storage type, read and write weights, and connection pool information.

mysql> 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 | mysql | 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 | mysql | 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 | mysql | 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 | mysql | 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 | mysql | 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 | mysql | 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 | mysql | 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 | mysql | 0    | 24   | 72   | 15           | 5000     | 0            | 1             | rds1ur80kcv8g3t6p3ol_seq_test_wnjg_0007_iiab | 10          | 10           |
+------+----------------------------+------------------------------------------------+--------------------------------------------------+----------------------------------------------------------------------------------+-----------+-------+------+------+------+--------------+----------+--------------+---------------+----------------------------------------------+-------------+--------------+
8 rows in set (0.01 sec)
            

Column descriptions:

  • Schema: The database name.
  • GROUP: A database group manages a set of databases that contain identical data, such as a primary database and its replicas created through ApsaraDB RDS for MySQL data replication. This feature primarily enables read/write splitting and primary/secondary switchover.
  • URL: The connection URL for the underlying ApsaraDB RDS for MySQL instance.
  • type: The underlying storage type. Currently, only ApsaraDB RDS for MySQL is supported.
  • READ_WEIGHT: Defines the read weight. The read/write splitting feature uses this weight to distribute read traffic. When the primary instance experiences high read pressure, PolarDB-X 1.0 routes read traffic to all instances in the database group according to their configured read weights, while still directing all write traffic to the primary instance.
  • WRITE_WEIGHT: The write weight.

SHOW NODE

Displays the cumulative read counts and read distribution for each physical database.

mysql> 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)
            

Column descriptions:

  • MASTER_READ_COUNT: The cumulative number of read queries processed by the primary ApsaraDB RDS for MySQL instance.
  • SLAVE_READ_COUNT: The cumulative number of read-only queries processed by the secondary ApsaraDB RDS for MySQL instances.
  • MASTER_READ_PERCENT: The percentage of read queries processed by the primary instance. Note: This column shows the actual historical percentage, not the configured weight.
  • SLAVE_READ_PERCENT: The percentage of read queries processed by the secondary instances. Note: This column shows the actual historical percentage, not the configured weight.
Note
  • Read-only queries within a transaction are always sent to the primary instance.
  • Because the MASTER_READ_PERCENT and SLAVE_READ_PERCENT columns represent cumulative historical data, they do not immediately reflect changes to the read weight configuration. A significant amount of time must pass for these values to accurately represent the new ratio.