Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the byte size of resultset in an SQL query?

Tags:

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?

like image 412
Raj Avatar asked Dec 24 '10 03:12

Raj


People also ask

How do you find the size of a ResultSet?

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();

How do I find the size of a SQL query result?

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.

How many bytes is a CHAR in SQL?

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.


2 Answers

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

like image 87
ajreal Avatar answered Oct 24 '22 07:10

ajreal


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 
like image 24
futilerebel Avatar answered Oct 24 '22 06:10

futilerebel