MySQL 如何在 SQL 查询中获取结果集的字节大小?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4524019/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get the byte size of resultset in an SQL query?
提问by Raj
Is it possible to get the size in bytes of the results of an sql query in MySQL?
是否可以在 MySQL 中获取 sql 查询结果的大小(以字节为单位)?
For example:
例如:
select * from sometable;
ths returns 10000 rows. I don't want the rows but the size of the resultset in bytes. Is it possible?
ths 返回 10000 行。我不想要行,但想要结果集的大小(以字节为单位)。是否可以?
采纳答案by ajreal
select sum(row_size)
from (
select
char_length(column1)+
char_length(column2)+
char_length(column3)+
char_length(column4) ... <-- repeat for all columns
as row_size
from your_table
) as tbl1;
char_length
for enum
, set
might not accurate, please take note
char_length
对于enum
,set
可能不准确,请注意
回答by futilerebel
To build on Angelin's solution, if your data contains nulls, you'll want to add IFNULL to each column:
以 Angelin 的解决方案为基础,如果您的数据包含空值,您需要将 IFNULL 添加到每一列:
select sum(
ifnull(char_length(column1), 0) +
ifnull(char_length(column2), 0) +
ifnull(char_length(column3), 0) +
ifnull(char_length(column4), 0) ... <-- repeat for all columns
)
from your_table
回答by Angelin Nadar
simplify :
简化:
select sum(char_length(column1)+
char_length(column2)+
char_length(column3)+
char_length(column4) ... )<-- repeat for all columns
from your_table
You need to add IFNULL() to each columnas @futilerebel has mentioned
您需要将 IFNULL() 添加到@futilerebel 提到的每一列
回答by GrahamB
CHAR_LENGTH()
gets number of characters if unicode will be more bytes - use LENGTH()
for number of bytes:https://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_length
CHAR_LENGTH()
如果 unicode 将是更多字节,则获取字符数 -LENGTH()
用于字节数:https: //dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_length