思路话语

。Arlen:思想有多远你就能走多远...

再说聚簇索引 page split

innodb的primary key就是聚簇索引,其特点是,叶节点上存放着数据,那么当数据超过16k时,怎么办?是不是如下图一样?

 MyISAM has no clustered index, so the data isn’t physically ordered by any index (it’s in insertion order), but in InnoDB, the rows are physically ordered by the primary key. That means there can be page splits as rows are inserted between other rows — if there are too many rows to fit on a page, the page has to be split.

http://www.xaprb.com/blog/2006/07/04/how-to-exploit-mysql-index-optimizations/

看了下面的这一段后,我突然想清楚了:要知道,innodb的btree是一棵多路平衡树,当插入的数据超过一页大小时,btree会裂解出一个新的page来,上面的同一个非叶节点同时指向旧的page和这个新的page。每个索引的叶节点还是只有一个page。

 之所以做这样的推断,是因为btree的索引键值是可以重复的(即多个连续的叶节点page拥有同一个索引键值),看下图:

 

另外一段关于page split的文字:

Tables built upon clustered indexes are subject to page splits when new rows are
inserted, or when a row’s primary key is updated such that the row must be
moved.
A page split happens when a row’s key value dictates that the row must
be placed into a page that is full of data. The storage engine must split the page
into two to accommodate the row. Page splits can cause a table to use more

space on disk. 

High performance MySQL》 

 

再有,我用b+tree的演示程序,完整的模拟出了当往一个已经满值的page插入datarow,引起page split的过程:

已经有如下的一棵btree(node slot假设设为4,即page的大小是4个数据行): 


此时再插入一行数据为0,键值仍为1 的数据之后,页发生了split,整棵树变成了这样:

 

 

顺便也验证了:当数据量增多时,有可能会增高树的高度。 

演示工具:https://files.cnblogs.com/Arlen/stx-wxbtreedemo-0.8.3-win32.zip

from:http://www.linbuluo.com/

posted on 2010-07-02 13:43  Arlen  阅读(682)  评论(0编辑  收藏  举报

导航