Modify the data page size of Innodb to optimize the MySQL method

  • 2020-11-03 22:37:29
  • OfStack

We know that the data page of Innodb is 16K, which is a hard and fast rule. There is no change in the system. We hope that MySQL can also support multiple data page sizes like Oracle1 in the future.
But sometimes 16K is a little too big in practice, especially when many businesses move to MySQL when Oracle or SQL SERVER are running well and IO is growing too much.
You'll want to change the data page size.
In fact, the data page size of innodb can also be changed, but it needs to be changed at the source layer and then MySQL under rebuild1.
Change method:
(Take es19EN-5.1.38 source code as an example)
Position in storage/innobase/include/univ i, in univ. i find: UNIV_PAGE_SIZE



/*
  DATABASE VERSION CONTROL
  ========================
*/
 
/* The universal page size of the database */
#define UNIV_PAGE_SIZE     (2 * 8192) /* NOTE! Currently, this has to be a
   power of 2 */
/* The 2-logarithm of UNIV_PAGE_SIZE: */
#define UNIV_PAGE_SIZE_SHIFT 14
 
/* Maximum number of parallel threads in a parallelized operation */
#define UNIV_MAX_PARALLELISM 32

UNIV_PAGE_SIZE is the data page size, default is 16K. The following note indicates that this value can be set to 2 to the power. For the value can be set to 4 k, 8 k, 16 k, 32 K, 64 K, in also have no meaning.
At the same time, after changing UNIV_PAGE_SIZE, it is necessary to change UNIV_PAGE_SIZE_SHIFT. The value is 2 to the power of UNIV_PAGE_SIZE, so the data page is set as follows:



#define UNIV_PAGE_SIZE_SHIFT 12 if UNIV_PAGE_SIZ=4K
#define UNIV_PAGE_SIZE_SHIFT 13 if UNIV_PAGE_SIZ=8K
#define UNIV_PAGE_SIZE_SHIFT 15 if UNIV_PAGE_SIZ=32K

Example:
Change the data page of innodb to 8K, and modify accordingly to:



/*
  DATABASE VERSION CONTROL
  ========================
*/
 
/* The universal page size of the database */
#define UNIV_PAGE_SIZE     8192  /* NOTE! Currently, this has to be a
   power of 2 */
/* The 2-logarithm of UNIV_PAGE_SIZE: */
#define UNIV_PAGE_SIZE_SHIFT 13
 
/* Maximum number of parallel threads in a parallelized operation */
#define UNIV_MAX_PARALLELISM 32

Recompile, then test test, test again. Good luck!


Related articles: