All Products
Search
Document Center

PolarDB:Rule and topology query statements

Last Updated:Mar 28, 2026

PolarDB-X provides a set of SHOW SQL statements for inspecting sharding configuration and data distribution at runtime. Use the following table to find the statement that matches your diagnostic goal.

GoalStatement
View sharding rules for all logical tablesSHOW RULE
View sharding rules including internal rule expressionsSHOW FULL RULE
View physical table distribution across database shardsSHOW TOPOLOGY FROM tablename
View the shard keys of a specific tableSHOW PARTITIONS FROM tablename
List all broadcast tablesSHOW BROADCASTS
View underlying data source details and connection pool statusSHOW DATASOURCES
View per-node read and write countsSHOW NODE

SHOW RULE [FROM tablename]

Returns the sharding configuration for logical tables: which shard key is used, the sharding policy, and the number of database and table shards.

Query all logical tables:

SHOW RULE;

Query a specific logical table:

SHOW RULE FROM tablename;

Example output:

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

Key columns:

ColumnDescription
BROADCASTWhether the table is a broadcast table. 0 = not a broadcast table; 1 = broadcast table.
DB_PARTITION_KEYDatabase shard key. Empty if no database sharding is configured.
DB_PARTITION_POLICYDatabase sharding policy: hash, or a date format such as YYYYMM, YYYYDD, or YYYYWEEK.
DB_PARTITION_COUNTNumber of database shards.
TB_PARTITION_KEYTable shard key. Empty if no table sharding is configured.
TB_PARTITION_POLICYTable sharding policy: hash, or a date format such as MM, DD, MMDD, or WEEK.
TB_PARTITION_COUNTNumber of table shards.

SHOW FULL RULE [FROM tablename]

Returns the same columns as SHOW RULE, plus the internal rule expressions used to compute shard assignments. Use this statement when you need to inspect the actual sharding algorithm or identify the default database shard for non-sharded tables.

Query all logical tables:

SHOW FULL RULE;

Query a specific logical table:

SHOW FULL RULE FROM tablename;

Example output:

+----+------------+-----------+------------+-----------------------+----------------------+--------------------------------------------------+-------------------+----------------------------------------+----------------+--------------------+
| 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 |
+----+------------+-----------+------------+-----------------------+----------------------+--------------------------------------------------+-------------------+----------------------------------------+----------------+--------------------+

Additional columns (beyond SHOW RULE):

ColumnDescription
JOIN_GROUPReserved field. Currently unused.
ALLOW_FULL_TABLE_SCANWhether queries without a shard key trigger a full table scan across all physical tables.
DB_NAME_PATTERNTemplate for database shard names. The {0} placeholder is replaced by the value computed from DB_RULES_STR, with zero-padding to preserve digit count. For example, SEQ_{0000}_RDS with values [1, 2, 3, 4] produces SEQ_0001_RDS, SEQ_0002_RDS, SEQ_0003_RDS, and SEQ_0004_RDS.
DB_RULES_STRThe database sharding rule expression.
TB_NAME_PATTERNTemplate for table shard names. Works like DB_NAME_PATTERN. For example, table_{00} with values [1..8] produces table_01 through table_08.
TB_RULES_STRThe table sharding rule expression.
PARTITION_KEYSThe set of shard keys. If both database sharding and table sharding are configured, the database shard key appears first.
DEFAULT_DB_INDEXThe database shard that stores non-sharded tables.

SHOW TOPOLOGY FROM tablename

Returns the physical distribution of a logical table: which database shards contain data and which table shards exist in each database shard.

SHOW TOPOLOGY FROM EMP;

Example output:

+------+--------------------------------------------------+------------+
| 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      |
+------+--------------------------------------------------+------------+

Each row maps one physical table shard (TABLE_NAME) to the database shard group (GROUP_NAME) that contains it.

SHOW PARTITIONS FROM tablename

Returns the shard keys configured for a specific table. The database shard key and table shard key are separated by a comma. If two values are returned, both database sharding and table sharding are configured — the first value is the database shard key and the second is the table shard key. If only one value is returned, only database sharding is configured.

SHOW PARTITIONS FROM EMP;

Example output:

+-----------+
| KEYS      |
+-----------+
| emp_no,id |
+-----------+
1 row in set (0.00 sec)

In this example, emp_no is the database shard key and id is the table shard key.

SHOW BROADCASTS

Returns all broadcast tables in the database.

SHOW BROADCASTS;

Example output:

+------+------------+
| ID   | TABLE_NAME |
+------+------------+
|    0 | brd2       |
|    1 | brd_tbl    |
+------+------------+
2 rows in set (0.01 sec)

SHOW DATASOURCES

Returns details about the underlying data sources, including connection URLs, connection pool configuration, and read/write weights.

SHOW DATASOURCES;

Example output:

+------+----------------------------+------------------------------------------------+--------------------------------------------------+----------------------------------------------------------------------------------+-----------+-------+------+------+------+--------------+----------+--------------+---------------+----------------------------------------------+-------------+--------------+
| 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           |
+------+----------------------------+------------------------------------------------+--------------------------------------------------+----------------------------------------------------------------------------------+-----------+-------+------+------+------+--------------+----------+--------------+---------------+----------------------------------------------+-------------+--------------+

Key columns:

ColumnDescription
SCHEMADatabase name.
GROUPDatabase group name. A database group manages primary and secondary ApsaraDB RDS for MySQL instances together, enabling read/write splitting and failover handling.
URLJDBC connection URL to the underlying ApsaraDB RDS for MySQL database.
TYPEType of the underlying storage.
READ_WEIGHTRead weight for this data source. PolarDB-X automatically routes write requests to the primary instance and distributes read requests across instances based on the configured read weights.
WRITE_WEIGHTWrite weight for this data source.

SHOW NODE

Returns read and write operation counts for each physical database node.

SHOW NODE;

Example output:

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

Key columns:

ColumnDescription
MASTER_READ_COUNTTotal read and write queries processed by the primary ApsaraDB RDS for MySQL instance.
SLAVE_READ_COUNTTotal read-only queries processed by the secondary ApsaraDB RDS for MySQL instances.
MASTER_READ_PERCENTPercentage of total queries handled by the primary instance. This reflects historical data; changes to read/write weight ratios take time to appear in these values.
SLAVE_READ_PERCENTPercentage of total queries handled by the secondary instances. Also reflects historical data.
Read-only queries inside transactions are sent to the primary instance, not to secondary instances.