MySQL Query Result Size – How to Get the Size of a SQL Query Result

explainMySQLmysql-5.6query-cache

How do you get the size (in bytes) of the result of a SQL query, in MySQL 5.6?

EXPLAIN will return the number of fetched rows, but not their size.

My aim is to evaluate common queries to know a lower bound value for query_cache_limit so that they can be served by the Query Cache.

Best Answer

There is no way.

  • EXPLAIN gives you an estimation; do not count on it being exact.
  • The number of bytes in a resultset is not directly available. And attempts to estimate will be fraught with errors.
  • The structure of the QC is another variable -- there is overhead to take into account.
  • Since every row for a table in the QC is purged when any write to the table occurs, the QC is rarely useful at all.