How to Query the Top 10 Largest Tables in a Database

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: 怎么查询一个database最大的10个表

| username: tidb狂热爱好者

How to query the top 10 largest tables in a database
I remember there is an SQL statement to query directly.

| username: TI表弟 | Original post link

How to understand the maximum? Storage capacity? Number of rows?

| username: TI表弟 | Original post link

You can try show stats_meta

| username: tidb狂热爱好者 | Original post link

Number of rows and number of bytes, with the number of bytes being the maximum.

| username: TI表弟 | Original post link

| username: tidb菜鸟一只 | Original post link

SELECT
TABLE_SCHEMA,
TABLE_NAME,
(DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024 / 1024 AS use_gb,
t.TABLE_ROWS,
DATA_FREE / 1024 / 1024 / 1024 AS free_gb
FROM
information_schema.TABLES t
WHERE
TABLE_SCHEMA = ‘hniot’
ORDER BY use_gb DESC;

| username: TiDBer_pkQ5q1l0 | Original post link

The default value of tidb_dml_batch_size is 2000. You can adjust it according to your needs.

| username: tidb狂热爱好者 | Original post link

Thank you, everyone.

| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.