首批通过分布式安全可靠测评,为关键业务系统打造
如何查询索引大小
更新时间:2026-02-03 07:06
本文介绍在 OceanBase 数据库中查询索引大小的方法。
适用版本
OceanBase 数据库 V2.x 版本。
操作步骤
目前,OceanBase 数据库无法通过内部视图查询某个索引的容量,只能通过合并后,查看索引占用空间的方式查询索引大小。
手动执行合并。
obclient> ALTER SYSTEM MAJOR FREEZE;通过索引所在的源表表名
table_name查询源表的table_id。obclient> SELECT table_id FROM __all_virtual_table WHERE table_name = 'fruit'; +------------------+ | table_id | +------------------+ | 1100611139453780 | +------------------+ 1 row in set (0.00 sec)使用字段
data_table_id查找索引信息SELECT table_id,table_name FROM __all_virtual_table WHERE data_table_id = '1100611139453780'; +------------------+----------------------------------+ | table_id | table_name | +------------------+----------------------------------+ | 1100611139453781 | __idx_1100611139453780_fruit_ind | +------------------+----------------------------------+ 1 row in set (0.03 sec)查询索引占用空间。
select * from oceanbase.__all_virtual_storage_stat where table_id=1100611139453780 and sstable_id=1100611139453781\G *************************** 1. row *************************** tenant_id: 1001 svr_ip: xxx.xxx.xx.xxx svr_port: 2882 table_id: 1100611139453780 partition_cnt: 0 partition_id: 9 major_version: 45 minor_version: 0 sstable_id: 1100611139453781 role: 2 data_checksum: 1416545402 column_checksum: [8569968498,0,7364804318] macro_blocks: data_blocks:[300-1-0-0[4294967596]]lob_blocks:[] occupy_size: 16882166 used_size: 18874368 row_count: 480000 store_type: 1 progressive_merge_start_version: 0 progressive_merge_end_version: 100 ...根据查询结果,
used_size表示 SSTable 占用的空间,row_count表示索引的行数。