david gond
david gond

Reputation: 51

How does innodb know whether a page is leaf page or non-leaf page?

I have been reading mysql internals for a few of weeks,and a problem puzzled

me always.We all know leaf page acts as index in a B+ tree data structure and

the real data stored on the non-leaf page.But how can i know which one is

leafpage or non-leaf page? someone plz enlight me?tks.

Upvotes: 0

Views: 232

Answers (1)

akuzminsky
akuzminsky

Reputation: 2258

There is a PAGE_LEVEL field in the page header. If it's zero it's a leaf page.

https://github.com/twindb/undrop-for-innodb/blob/master/c_parser.c#L657

int leaf_page = mach_read_from_2(page + PAGE_HEADER + PAGE_LEVEL) == 0;

We all know leaf page acts as index in a B+ tree data structure and the real data stored on the non-leaf page.

This sentence doesn't make sense. You can say a table is stored in an index called PRIMARY or (GEN_CLUSTER_INDEX if a unique index is used as a primary index). The PRIMARY index is a B+ tree. The key of the index is the primary key fields. In non-leaf pages the key is the key, the value - is page id of a page below. In the leaf pages the key is the key again, but the value is the rest of table fields.

A secondary index is also a B+ tree. The key of the index is secondary key fields and the value is the primary key of the records.

Upvotes: 3

Related Questions