如题, 尝试了以下三种查询,结果相差甚远。如何正确评估表大小呢??
SELECT
db_name,
table_name,
ROUND(SUM(total_size / cnt), 2) Approximate_Size,
ROUND(SUM(total_size / cnt / (SELECT
ROUND(AVG(value), 2)
FROM
METRICS_SCHEMA.store_size_amplification
WHERE
value > 0)),
2) Disk_Size
FROM
(SELECT
db_name,
table_name,
region_id,
SUM(Approximate_Size) total_size,
COUNT(*) cnt
FROM
information_schema.TIKV_REGION_STATUS
WHERE
db_name = 'test'
AND table_name IN ('example_table2')
GROUP BY db_name , table_name , region_id) tabinfo
GROUP BY db_name , table_name;
±--------±---------------±-----------------±----------+
| db_name | table_name | Approximate_Size | Disk_Size |
±--------±---------------±-----------------±----------+
| test | example_table2 | 647.00 | 599.07 |
±--------±---------------±-----------------±----------+
select
table_schema ,
table_name,
table_rows ,
truncate(data_length/1024/1024, 2) as 'data(MB)',
truncate(index_length/1024/1024, 2) as 'index(MB)'
from information_schema.tables
where table_schema='test'
and table_name='example_table2'
order by data_length desc, index_length desc;
±-------------±---------------±-----------±---------±----------+
| table_schema | table_name | table_rows | data(MB) | index(MB) |
±-------------±---------------±-----------±---------±----------+
| test | example_table2 | 8000000 | 256.34 | 122.07 |
±-------------±---------------±-----------±---------±----------+
select A.*
from INFORMATION_SCHEMA.TABLE_STORAGE_STATS A , information_schema.tables B
where A.table_id=b.TIDB_TABLE_ID and A.table_schema='test' and A.table_name='example_table2';
±-------------±---------------±---------±-----------±-------------±-------------------±-----------±-----------+
| TABLE_SCHEMA | TABLE_NAME | TABLE_ID | PEER_COUNT | REGION_COUNT | EMPTY_REGION_COUNT | TABLE_SIZE | TABLE_KEYS |
±-------------±---------------±---------±-----------±-------------±-------------------±-----------±-----------+
| test | example_table2 | 178 | 3 | 1 | 0 | 36 | 532480 |
±-------------±---------------±---------±-----------±-------------±-------------------±-----------±-----------+
1 row in set (0.03 sec)