功能
INFORMATION_SCHEMA.GLOBAL_INDEX_PARTITIONS 视图用于查询分区全局二级索引(Partitioned GSI)的底层分区结构。每条记录对应一个分区 GSI 子索引的信息,包括子索引的标识、基索引的分区定义以及子索引自身的分区信息,可用于排查分区 GSI 的数据分布和分区裁剪是否正确。该视图通过关联数据字典表
mysql.indexes 和 mysql.index_partitions 实现,仅返回分区 GSI 子索引(options 中包含 global_type=3;)的数据。适用版本
TDSQL Boundless V21.6.4.0 及以上版本。
字段说明
字段名 | 类型 | 描述 |
BASE_GSI_TINDEX_ID | INT UNSIGNED | 分区 GSI 基索引的 tindex_id。一个分区 GSI 只有一个基索引,用来记录该 GSI 有多少子分区。 |
PART_GSI_TINDEX_ID | INT UNSIGNED | 分区 GSI 子索引的 tindex_id。每个子索引对应 GSI 的一个物理分区,拥有独立的数据对象和列族。 |
BASE_GSI_PART_INFO | MEDIUMTEXT | 基索引的完整分区元信息,编码在 options 字符串中(key=value; 格式)。包含分区类型(如 part_type=1 表示 RANGE)、分区表达式、分区数等关键参数。 |
PART_GSI_PART_INFO | MEDIUMTEXT | 子索引的分区元信息,编码在 options 字符串中(key=value; 格式)。包含该子分区在 GSI 中的位置(如 RANGE 的边界值、HASH 的分区编号等)。 |
说明:
options 字符串中包含的分区元数据字段(以 key=value; 分隔):global_type=3:表示该记录为分区 GSI 子索引。part_type:分区类型(1=RANGE, 2=HASH 等)。part_func:分区函数表达式。num_parts:分区总数。对于 RANGE 分区:
range_value 为边界值。对于 HASH 分区:
hash_part 为分区编号。通过对比不同子索引的
PART_GSI_PART_INFO,可以校验所有子分区的分布是否符合预期。常用查询
-- 查询某个表上所有分区 GSI 的子索引分布SELECTp.BASE_GSI_TINDEX_ID,p.PART_GSI_TINDEX_ID,p.BASE_GSI_PART_INFO,p.PART_GSI_PART_INFOFROM information_schema.GLOBAL_INDEX_PARTITIONS pWHERE p.BASE_GSI_TINDEX_ID IN (SELECT data_obj_idFROM information_schema.META_CLUSTER_DATA_OBJECTSWHERE schema_name = 'your_database'AND table_name = 'your_table'AND data_obj_type = 'BASE_GLOBAL_INDEX')ORDER BY p.PART_GSI_TINDEX_ID;-- 校验某个分区 GSI 的子分区数是否与建表时的 PARTITIONS N 一致SELECTd.data_obj_name AS gsi_name,COUNT(*) AS actual_partitionsFROM information_schema.GLOBAL_INDEX_PARTITIONS pJOIN information_schema.META_CLUSTER_DATA_OBJECTS dON p.BASE_GSI_TINDEX_ID = d.data_obj_idWHERE d.schema_name = DATABASE()AND d.table_name = 'orders'AND d.data_obj_type = 'BASE_GLOBAL_INDEX'GROUP BY d.data_obj_name;
示例
以一张按
user_id 哈希分区、带分区 GSI g_user_id(HASH 8 个分区)的订单表为例:CREATE TABLE orders (id BIGINT NOT NULL,order_no VARCHAR(32) NOT NULL,user_id BIGINT NOT NULL,merchant_id BIGINT NOT NULL,region_id INT NOT NULL,category_id INT NOT NULL,amount_cents BIGINT NOT NULL,created_day DATE NOT NULL,PRIMARY KEY (id),INDEX g_user_id (user_id) GLOBAL PARTITION BY HASH(user_id) PARTITIONS 8) ENGINE=ROCKSDB PARTITION BY HASH(id) PARTITIONS 4;-- 查看 orders 表上 g_user_id 分区 GSI 的子索引信息SELECTd.data_obj_name AS gsi_name,p.BASE_GSI_TINDEX_ID,p.PART_GSI_TINDEX_ID,LEFT(p.PART_GSI_PART_INFO, 80) AS part_info_abbrFROM information_schema.GLOBAL_INDEX_PARTITIONS pJOIN information_schema.META_CLUSTER_DATA_OBJECTS dON p.BASE_GSI_TINDEX_ID = d.data_obj_idAND d.schema_name = DATABASE()AND d.table_name = 'orders'AND d.data_obj_type = 'BASE_GLOBAL_INDEX'ORDER BY p.PART_GSI_TINDEX_ID;
预期输出(共 8 行,对应 HASH 的 8 个子分区):
+-------------+--------------------+--------------------+----------------------------------------+| gsi_name | BASE_GSI_TINDEX_ID | PART_GSI_TINDEX_ID | part_info_abbr |+-------------+--------------------+--------------------+----------------------------------------+| orders.g_us | 101 | 201 | hash_part=0;global_type=3;part_type=2; || orders.g_us | 101 | 202 | hash_part=1;global_type=3;part_type=2; || orders.g_us | 101 | 203 | hash_part=2;global_type=3;part_type=2; || orders.g_us | 101 | 204 | hash_part=3;global_type=3;part_type=2; || orders.g_us | 101 | 205 | hash_part=4;global_type=3;part_type=2; || orders.g_us | 101 | 206 | hash_part=5;global_type=3;part_type=2; || orders.g_us | 101 | 207 | hash_part=6;global_type=3;part_type=2; || orders.g_us | 101 | 208 | hash_part=7;global_type=3;part_type=2; |+-------------+--------------------+--------------------+----------------------------------------+
相关文档
视图/表 | 说明 |
分区 GSI 的功能说明、语法和使用指南。 | |
提供数据对象的元数据信息(data_obj_id、data_obj_name、data_obj_type 等),可与本视图通过 BASE_GSI_TINDEX_ID 关联查询 GSI 名称。 |