mysql 确定字段的存储大小

发布于 2024-10-08 08:09:32 字数 193 浏览 1 评论 0原文

我想知道是否有mysql命令来确定mysql字段当前使用的实际存储大小。

也许类似“showused_storage myfield FROM ... WHERE ...”之类的东西,

奇怪的是我能找到这样的东西。

(同样对于 postgresql 也很有趣)

非常感谢!

i would like to know if there is a mysql command to determine the currently used actual storage size of a mysql field.

Maybe something like "show used_storage myfield FROM ... WHERE ..."

Oddly I couln'd find anything like this.

(The same for postgresql would be interessting too)

Thanks a lot!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

挽你眉间 2024-10-15 08:09:32

对于 PostgreSQL,您可以使用

SELECT your_column, pg_column_size(your_column)
FROM your_table

此类函数的完整列表在手册中
http://www.postgresql.org/docs/current/static/functions -admin.html

For PostgreSQL you can use

SELECT your_column, pg_column_size(your_column)
FROM your_table

A complete list of this kind of functions is in the manual
http://www.postgresql.org/docs/current/static/functions-admin.html

杯别 2024-10-15 08:09:32

如果您使用的是字符数据字段,最简单的方法是

SELECT SUM(LENGTH(myField)) From MyTable

如果您使用的是某种数字数据类型,您只需获取行数,然后将其乘以大小,例如 4 表示 INTEGER,或 8 表示 DOUBLE。

但它不会反映磁盘上实际占用的大小。这可能更难找到。即使它是准确的,由于碎片和其他因素,表的实际大小也可能远远大于所有列的总大小。

您可以通过以下方式获取整个表的大小(和索引大小):

SHOW TABLE STATUS LIKE 'MyTable';

如果您仅将所需的列复制到新的临时表中,您可能能够更真实地了解您的字段实际占用了多少空间到磁盘上。

If you are using a character data field, the simplest would be

SELECT SUM(LENGTH(myField)) From MyTable

If you are using some numerical data type, you could just get a count on the rows, and multiply it by the size, for instance 4 for INTEGER, or 8 for DOUBLE.

It won't reflect the actual size taken up on disk however. This is probably a lot more difficult to find out. And even if it was accurate, the actual size of the table could be much more than the total size of all the columns due to fragmentation and other factors.

You can get the size (and index size) of an entire table with:

SHOW TABLE STATUS LIKE 'MyTable';

If you copy out just the column you want to a new temporary table, you may be able to get a more realistic view of how much space your field is actually taking up on disk.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文