简体   繁体   中英

Mysql B+ Tree implementation

Mysql uses B+ tree for implementing indexes. Lets say my primary index is of type (name, age, city). Can someone throw some light how Mysql implements a B+ tree on these kinds of keys ?

My hunch is that it treats the whole tuple as a key and it treats it like a partial order. Eg:

(John, 24, New Jersey) < (John, 24, New York) < (John, 25, New Jersey) < (John, 25, New York)

(John, 24, New Jersey) < (John, 24, New York) < (John, 25, New Jersey) < (John, 25, New York)

Yes, that's why it is important in which order you lay out columns in a key.

The key won't be of any help if you do not look for values that can be satisfied from looking at the start of it - eg when you filter for age and/or city , but not for name , the key can't be used. On the other hand, if you'd filter for name only, the key would be used.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM