Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

How well do your tables fit in buffer pool

DZone's Guide to

How well do your tables fit in buffer pool

· Database Zone ·
Free Resource

Databases are better when they can run themselves. CockroachDB is a SQL database that automates scaling and recovery. Check it out here.

In XtraDB we have the table INNODB_BUFFER_POOL_PAGES_INDEX which shows which pages belong to which indexes in which tables. Using thing information and standard TABLES table we can see how well different tables fit in buffer pool.
SQL:

1.
mysql> SELECT d.*,round(100*cnt*16384/(data_length+index_length),2) fit FROM (SELECT schema_name,table_name,count(*) cnt,sum(dirty),sum(hashed) FROM INNODB_BUFFER_POOL_PAGES_INDEX GROUP BY schema_name,table_name ORDER BY cnt DESC LIMIT 20) d JOIN TABLES ON (TABLES.table_schema=d.schema_name AND TABLES.table_name=d.table_name);
2.
+-------------+---------------------+---------+------------+-------------+--------+
3.
| schema_name | table_name | cnt | sum(dirty) | sum(hashed) | fit |
4.
+-------------+---------------------+---------+------------+-------------+--------+
5.
| db | table1 | 1699133 | 13296 | 385841 | 87.49 |
6.
| db | table2 | 1173272 | 17399 | 11099 | 98.42 |
7.
| db | table3 | 916641 | 7849 | 15316 | 94.77 |
8.
| db | table4 | 86999 | 1555 | 75554 | 87.42 |
9.
| db | table5 | 32701 | 7997 | 30082 | 91.61 |
10.
| db | table6 | 31990 | 4495 | 25681 | 102.97 |
11.
| db | table7 | 1 | 0 | 0 | 100.00 |
12.
+-------------+---------------------+---------+------------+-------------+--------+
13.
7 rows IN SET (26.45 sec)

You can also see in one of the cases the value shown is a bit over 100% - I am not sure where it comes from but more pages reported to belong to the table in buffer pool than on disk. Though it seems to work well enough for estimation purposes.

Databases should be easy to deploy, easy to use, and easy to scale. If you agree, you should check out CockroachDB, a scalable SQL database built for businesses of every size. Check it out here. 

Topics:

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}