Is it possible to get the size in bytes of the results of an sql query in MySQL?
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?
println("Total number of rows in ResultSet object = "+rowCount); Simply iterate on ResultSet object and increment rowCount to obtain size of ResultSet object in java. rowCount = rs. getRow();
You can include the actual execution plan of the query in the Results window of SSMS, which will display an estimated row size for the results. Multiply that by the number of rows to get your result.
CHAR is a fixed length string data type, so any remaining space in the field is padded with blanks. CHAR takes up 1 byte per character. So, a CHAR(100) field (or variable) takes up 100 bytes on disk, regardless of the string it holds.
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
To build on Angelin's solution, if your data contains nulls, you'll want to add IFNULL to each column:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With