All Products
Search
Document Center

PolarDB:Query partition topologies

Last Updated:Jun 06, 2024

PolarDB-X allows you to query the metadata of a partitioned table and the partition topology of the table by using multiple methods.

Use the PARTITIONS view

PolarDB-X is compatible with the INFORMATION_SCHEMA.PARTITIONS view of MySQL. PolarDB-X allows you to use the PARTITIONS view to query the metadata of each partition and its subpartitions. Example:

select * from information_schema.partitions where table_schema='autodb2' and table_name='test_tbl_part_name2' order by partition_name, subpartition_name;
+---------------+--------------+---------------------+----------------+-------------------+----------------------------+-------------------------------+------------------+---------------------+----------------------+-------------------------+-----------------------+--------------------------+------------+----------------+-------------+-----------------+--------------+-----------+-------------+-------------+------------+----------+-------------------+-----------+-----------------+
| TABLE_CATALOG | TABLE_SCHEMA | TABLE_NAME          | PARTITION_NAME | SUBPARTITION_NAME | PARTITION_ORDINAL_POSITION | SUBPARTITION_ORDINAL_POSITION | PARTITION_METHOD | SUBPARTITION_METHOD | PARTITION_EXPRESSION | SUBPARTITION_EXPRESSION | PARTITION_DESCRIPTION | SUBPARTITION_DESCRIPTION | TABLE_ROWS | AVG_ROW_LENGTH | DATA_LENGTH | MAX_DATA_LENGTH | INDEX_LENGTH | DATA_FREE | CREATE_TIME | UPDATE_TIME | CHECK_TIME | CHECKSUM | PARTITION_COMMENT | NODEGROUP | TABLESPACE_NAME |
+---------------+--------------+---------------------+----------------+-------------------+----------------------------+-------------------------------+------------------+---------------------+----------------------+-------------------------+-----------------------+--------------------------+------------+----------------+-------------+-----------------+--------------+-----------+-------------+-------------+------------+----------+-------------------+-----------+-----------------+
| def           | autodb2      | test_tbl_part_name2 | p1             | p1sp1             |                          1 |                             1 | KEY              | KEY                 | bid                  | id                      | 1                     | -4611686018427387899     |          0 |              0 |       16384 |            NULL |        16384 |      NULL | NULL        | NULL        | NULL       |     NULL |                   | default   | NULL            |
| def           | autodb2      | test_tbl_part_name2 | p1             | p1sp2             |                          1 |                             2 | KEY              | KEY                 | bid                  | id                      | 1                     | 3                        |          0 |              0 |       16384 |            NULL |        16384 |      NULL | NULL        | NULL        | NULL       |     NULL |                   | default   | NULL            |
| def           | autodb2      | test_tbl_part_name2 | p1             | p1sp3             |                          1 |                             3 | KEY              | KEY                 | bid                  | id                      | 1                     | 4611686018427387905      |          0 |              0 |       16384 |            NULL |        16384 |      NULL | NULL        | NULL        | NULL       |     NULL |                   | default   | NULL            |
| def           | autodb2      | test_tbl_part_name2 | p1             | p1sp4             |                          1 |                             4 | KEY              | KEY                 | bid                  | id                      | 1                     | 9223372036854775807      |          0 |              0 |       16384 |            NULL |        16384 |      NULL | NULL        | NULL        | NULL       |     NULL |                   | default   | NULL            |
| def           | autodb2      | test_tbl_part_name2 | p2             | p2sp1             |                          2 |                             1 | KEY              | KEY                 | bid                  | id                      | 9223372036854775807   | -4611686018427387899     |          0 |              0 |       16384 |            NULL |        16384 |      NULL | NULL        | NULL        | NULL       |     NULL |                   | default   | NULL            |
| def           | autodb2      | test_tbl_part_name2 | p2             | p2sp2             |                          2 |                             2 | KEY              | KEY                 | bid                  | id                      | 9223372036854775807   | 3                        |          0 |              0 |       16384 |            NULL |        16384 |      NULL | NULL        | NULL        | NULL       |     NULL |                   | default   | NULL            |
| def           | autodb2      | test_tbl_part_name2 | p2             | p2sp3             |                          2 |                             3 | KEY              | KEY                 | bid                  | id                      | 9223372036854775807   | 4611686018427387905      |          0 |              0 |       16384 |            NULL |        16384 |      NULL | NULL        | NULL        | NULL       |     NULL |                   | default   | NULL            |
| def           | autodb2      | test_tbl_part_name2 | p2             | p2sp4             |                          2 |                             4 | KEY              | KEY                 | bid                  | id                      | 9223372036854775807   | 9223372036854775807      |          0 |              0 |       16384 |            NULL |        16384 |      NULL | NULL        | NULL        | NULL       |     NULL |                   | default   | NULL            |
+---------------+--------------+---------------------+----------------+-------------------+----------------------------+-------------------------------+------------------+---------------------+----------------------+-------------------------+-----------------------+--------------------------+------------+----------------+-------------+-----------------+--------------+-----------+-------------+-------------+------------+----------+-------------------+-----------+-----------------+
8 rows in set (0.14 sec)

Execute the SHOW TOPOLOGY statement

You can execute the SHOW TOPOLOGY FROM #table_name statement to query the overall topology of a partitioned table and the physical location of each partition. The physical location refers to the data node on which each physical table resides. Example:

SHOW TOPOLOGY FROM test_tbl_part_name2 ORDER BY PARTITION_NAME, SUBPARTITION_NAME;
+------+----------------------+--------------------------------+----------------+-------------------+----------------+---------------------------+
| ID   | GROUP_NAME           | TABLE_NAME                     | PARTITION_NAME | SUBPARTITION_NAME | PHY_DB_NAME    | DN_ID                     |
+------+----------------------+--------------------------------+----------------+-------------------+----------------+---------------------------+
|    4 | AUTODB2_P00000_GROUP | test_tbl_part_name2_xds7_00000 | p1             | p1sp1             | autodb2_p00000 | polardbx-storage-0-master |
|    0 | AUTODB2_P00001_GROUP | test_tbl_part_name2_xds7_00001 | p1             | p1sp2             | autodb2_p00001 | polardbx-storage-1-master |
|    5 | AUTODB2_P00000_GROUP | test_tbl_part_name2_xds7_00002 | p1             | p1sp3             | autodb2_p00000 | polardbx-storage-0-master |
|    1 | AUTODB2_P00001_GROUP | test_tbl_part_name2_xds7_00003 | p1             | p1sp4             | autodb2_p00001 | polardbx-storage-1-master |
|    6 | AUTODB2_P00000_GROUP | test_tbl_part_name2_xds7_00004 | p2             | p2sp1             | autodb2_p00000 | polardbx-storage-0-master |
|    2 | AUTODB2_P00001_GROUP | test_tbl_part_name2_xds7_00005 | p2             | p2sp2             | autodb2_p00001 | polardbx-storage-1-master |
|    7 | AUTODB2_P00000_GROUP | test_tbl_part_name2_xds7_00006 | p2             | p2sp3             | autodb2_p00000 | polardbx-storage-0-master |
|    3 | AUTODB2_P00001_GROUP | test_tbl_part_name2_xds7_00007 | p2             | p2sp4             | autodb2_p00001 | polardbx-storage-1-master |
+------+----------------------+--------------------------------+----------------+-------------------+----------------+---------------------------+
8 rows in set (0.07 sec)

Use the TABLE_DETAIL view

You can use the INFORMATION_SCHEMA.TABLE_DETAIL view to query the percentage of data in each partition of a partitioned table and the read and write information of the partition. Example:

select table_name, partition_name, subpartition_name, percent, 
     rows_read, rows_inserted, rows_updated, rows_deleted from information_schema.table_detail  
     where table_schema='autodb2' and table_name='test_tbl_part_name2' 
     order by partition_name, subpartition_name;
+---------------------+----------------+-------------------+--------------------------------------+-----------+---------------+--------------+--------------+
| table_name          | partition_name | subpartition_name | percent                              | rows_read | rows_inserted | rows_updated | rows_deleted |
+---------------------+----------------+-------------------+--------------------------------------+-----------+---------------+--------------+--------------+
| test_tbl_part_name2 | p1             | p1sp1             | 0.00%├-------------------------┤     |         0 |             0 |            0 |            0 |
| test_tbl_part_name2 | p1             | p1sp2             | 0.00%├-------------------------┤     |         0 |             0 |            0 |            0 |
| test_tbl_part_name2 | p1             | p1sp3             | 0.00%├-------------------------┤     |         0 |             0 |            0 |            0 |
| test_tbl_part_name2 | p1             | p1sp4             | 0.00%├-------------------------┤     |         0 |             0 |            0 |            0 |
| test_tbl_part_name2 | p2             | p2sp1             | 0.00%├-------------------------┤     |         0 |             0 |            0 |            0 |
| test_tbl_part_name2 | p2             | p2sp2             | 0.00%├-------------------------┤     |         0 |             0 |            0 |            0 |
| test_tbl_part_name2 | p2             | p2sp3             | 0.00%├-------------------------┤     |         0 |             0 |            0 |            0 |
| test_tbl_part_name2 | p2             | p2sp4             | 0.00%├-------------------------┤     |         0 |             0 |            0 |            0 |
+---------------------+----------------+-------------------+--------------------------------------+-----------+---------------+--------------+--------------+
8 rows in set (0.10 sec)

You can also use the INFORMATION_SCHEMA.TABLE_DETAIL view to query the metadata specific to PolarDB-X tables, such as the table group to which a partitioned table belongs and the global index table to which the partitioned table belongs.