MySQL – Does InnoDB Buffer Pool Store BLOB?

blobbuffer-poolinnodbMySQL

I have several databases all in INNODB, 50GB are BLOB columns, only 700MB are not BLOB data. Tools as mysqltuner ask me to set innodb_buffer_pool_size = 51GB.

Does MySQL store the BLOB in RAM? If yes, how can I configure MYSQL so it doesn't use innodb_buffer_pool_size to store BLOB?

Best Answer

The InnoDB buffer pool stores copies of anything that is stored in database pages on disk. That includes:

  • Data (which is really the clustered primary index for each table)
  • Secondary indexes
  • Blobs/Text/Varchar that won't fit on data pages
  • Undo pages
  • Change buffer pages
  • etc.

There's no way you can exclude one of these types of pages. They all occupy the buffer pool from time to time, based on demand.

So strictly speaking, the only answer to your question of how to exclude InnoDB Blob data from the buffer pool is to use a different storage engine.

You could also exclude Blob/Text/Varchar columns from your queries. Just don't reference these columns in your query (avoid using SELECT *). InnoDB is smart enough to skip loading the extra pages of Blob/Text/Varchar data it doesn't have to.

But you should take the recommendation of tools like mysqltuner with a grain of salt. You don't necessarily need as much buffer pool as the total amount of data. In fact, it's more typical that you have an 80/20 rule going on: 80% of your queries are served by 20% of your data.

Your mileage may vary -- the types of queries you run determine what is the best compromise on size of buffer pool. You could give it a best-guess allocation, and then monitor the ratio of logical page reads vs. physical page I/O:

mysql> show global status like 'innodb_buffer_pool_read%s';
+----------------------------------+-----------+
| Variable_name                    | Value     |
+----------------------------------+-----------+
| Innodb_buffer_pool_read_requests | 151062817 |
| Innodb_buffer_pool_reads         | 3585      |
+----------------------------------+-----------+

Or the page hit rate:

mysql> show engine innodb status\G
...
----------------------
BUFFER POOL AND MEMORY
----------------------
...
Buffer pool hit rate 999 / 1000, young-making rate 36 / 1000 not 0 / 1000
...

If you don't like these ratios, then allocate more RAM to the buffer pool.