Mysql – How are page splits determined internally in MySQL

database-internalsinnodbMySQLpage-splits

Going through this answer for a stack-overflow question, I found a fact that

In The physical structure of InnoDB index pages I describe the Last Insert Position, Page Direction, and Number of Inserts in Page Direction fields of each index page. This is how the tracking for ascending vs. descending order is done (as left vs. right, though). With each insert, the last inserted record is compared to the currently inserted one, and if the insert is in the same "direction", the counter is incremented. This counter is then checked to determine the page split behavior; whether to split in half or create a new, empty page

It is understood that page split up is based on Number of Inserts in Page Direction

But , I wonder whether there will be threshold for "Number of Inserts in Page Direction" to initiate page split up? Any particular logic behind setting "Page Direction" flag?

I am curious in getting these concepts with a working example with asap details!!! All efforts welcome.

Best Answer

The author is talking about PAGE_N_DIRECTION. This has nothing to do with triggering splitting, which is performed by page_dir_split_slot. Splitting/merging is determined by a MIN and MAX on the directory slot

/* The maximum and minimum number of records owned by a directory slot. The
number may drop below the minimum in the first and the last slot in the
directory. */
#define PAGE_DIR_SLOT_MAX_N_OWNED 8
#define PAGE_DIR_SLOT_MIN_N_OWNED 4

You don't split when you fall under MIN, you merge (via page_dir_balance_slot).

PAGE_N_DIRECTION is for an optimization,

Try a search shortcut based on the last insert.