返回信息流1、通过select count(*) from 表名 可以得到准确的行数,我想问这条命令的内部操作是怎么样的?如果是一张2G的表用这表命令是把所有的信息扫一遍返回吗?如何得到一张表的估计行数,不需要十分准确
2、平均行数:通过show table status from 数据库名 可以得到每张表的信息 其中有
Avg_row_length , Data_length信息,我想问我要通过什么命令能够只得到这两个信息,另外我看网上说Data_length是指数据文件长度,我想问这个长度指的是啥?总共有多少个字节吗?
3、如何得到一张表的空间大小,空间大小可以是准确的也可以是近似的?
先拜谢大牛们
这是一条镜像帖。来源:北邮人论坛 / database / #4674同步于 2010/7/29
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Database机器人发帖
如何得到mysql一张表的空间大小,平均行数和总行数[求助]
RaulSpain007
2010/7/29镜像同步5 回复
订阅后,新回复会通过你的通知中心匿名送达。
5 条回复
是什么数据库系统?不同的数据库的实现不同
【 在 RaulSpain007 (Raul) 的大作中提到: 】
: 标 题: 如何得到一张表的空间大小,平均行数和总行数[求助]
: 发信站: 北邮人论坛 (Thu Jul 29 10:17:55 2010), 站内
:
: 1、通过select count(*) from 表名 可以得到准确的行数,我想问这条命令的内部操作是怎么样的?如果是一张2G的表用这表命令是把所有的信息扫一遍返回吗?如何得到一张表的估计行数,不需要十分准确
:
: 2、平均行数:通过show table status from 数据库名 可以得到每张表的信息 其中有
: Avg_row_length , Data_length信息,我想问我要通过什么命令能够只得到这两个信息,另外我看网上说Data_length是指数据文件长度,我想问这个长度指的是啥?总共有多少个字节吗?
:
: 3、如何得到一张表的空间大小,空间大小可以是准确的也可以是近似的?
:
: 先拜谢大牛们
: --
: 什么都不会的我飘过
:
: ※ 来源:·北邮人论坛 http://bbs.byr.cn·[FROM: 124.65.129.*]
第一个问题跟你使用的存储引擎有关系
MyISAM 的 COUNT(*) 不会去做 table-scan,它会有一个计数
InnoDB 会去做 table-scan,并且这个值可能是不准的
后面两个问题我没研究过
【 在 RaulSpain007 (Raul) 的大作中提到: 】
: mysql
【 在 RaulSpain007 的大作中提到: 】
: 1、通过select count(*) from 表名 可以得到准确的行数,我想问这条命令的内部操作是怎么样的?如果是一张2G的表用这表命令是把所有的信息扫一遍返回吗?如何得到一张表的估计行数,不需要十分准确
It depends on the feature of table. If you want to force the optimizer to create a seq scan plan, probably you have to do sth. in the kernel backend.
Or you want to try your luck, you can use explain to make sure how the executor did it.
: 2、平均行数:通过show table status from 数据库名 可以得到每张表的信息 其中有
: Avg_row_length , Data_length信息,我想问我要通过什么命令能够只得到这两个信息,另外我看网上说Data_length是指数据文件长度,我想问这个长度指的是啥?总共有多少个字节吗?
I don't understand why you need a cmd to fetch only those two data. But since this is static for each table, why not simply write a script to fetch those info out through a pipe or the file you stored those data. Data_length in my understanding, is the size of the table in memory. In another word, it is approximate the actual amount of allocated memory.
: ...................
3、如何得到一张表的空间大小,空间大小可以是准确的也可以是近似的?
I don't get it either. So which one you want? how much space a table occupies or how much memory it uses in the run time?
The first one you can simply check your size of table file, unless this is stream data.
The latter one can be done by using data_length and index_length. Those added up will make an approximate number.