B树、B+树学习之一(MD版,不断更新中)
前言
这篇帖子原本写于2015年,写于厦门,时至今日(2019年11月5日)来看,感觉当时记录笔记,缺乏一个完整的思路,记录的不好,不方便以后的阅读,今天刚好又遇到了B数的学习,那么把它修改一下。
原本的帖子不是用MD写的,不利于编辑,只好删除掉,重新用MD格式来编辑。
正文
个人理解,现在,B树主要的一个应用是数据库存储引擎(InnoDB),用B树的原因,是为了更少地访问磁盘,更快地检索到数据的位置。(关于这一点,《算法导论》在介绍B树时,也是这样地描写的)
所以,这里要对磁盘的很多概念有所了解。
磁盘RPM
磁盘参数RPM是Revolutions Per Minute的缩写
revolution
n. 革命;旋转;运行;循环
这么说,旋转就是革命了。
《算法导论》第三版第279页:
对存储在磁盘上的一颗大的B树,通常看到分支因子在50~2000之间,具体取决于一个关键字相对于一页的大小。一个大的分支因子可以大大地降低树的高度以及查找任何一个关键字所需的磁盘存取次数。
块的概念
参考:http://oss.org.cn/kernel-book/ch09/9.1.htm,很可惜,这个网站已经不能访问了,只能参考《深入理解Linux内核》了。
9.1 基本概念
在上一章中,我们把Ext2、Minix、Ext等实际可使用的文件系统称为具体文件系统。具体文件系统管理的是一个逻辑空间,这个逻辑空间就象一个大的数组,数组的每个元素就是文件系统操作的基本单位——逻辑块,逻辑块是从0开始编号的,而且,逻辑块是连续的。与逻辑块相对的是物理块,物理块是数据在磁盘上的存取单位,也就是每进行一次I/O操作,最小传输的数据大小。我们知道数据是存储在磁盘的扇区中的,那么扇区是不是物理块呢?或者物理块是多大呢?这涉及到文件系统效率的问题。
参考维基百科
In computing (specifically data transmission and data storage), a block, sometimes called a physical record, is a sequence of bytes or bits, usually containing some whole number of records, having a maximum length, a block size.[1] Data thus structured are said to be blocked. The process of putting data into blocks is called blocking, while deblocking is the process of extracting data from blocks. Blocked data is normally stored in a data buffer and read or written a whole block at a time.
In the 1970s IBM introduced the Direct Access Storage Device (DASD) with fixed-block architecture using sizes of 512, 1024, 2048, or 4096 bytes. Cray Research had an 819 disk controller in 1975 that transferred 512 64-bit words (4096 bytes) per sector. Later,[specify] hard disk drives supporting 1,024-byte sectors began to be integrated into consumer electronics devices such as portable media players and digital video cameras.[citation needed] However, by far the majority of hard drives shipped up to the start of the 2010s still used the traditional 512-byte sector size.
从这里感觉,sector和block是一个概念。
参考这里,看到:
树的阶数如何翻译,应该用order
https://en.wikipedia.org/wiki/Tree_(data_structure)。
block的概念
https://en.wikipedia.org/wiki/Block_(data_storage)。
定义
根据 Knuth 的定义,一个 m 阶的B树是一个有以下属性的树:
每一个节点最多有 m 个子节点
每一个非叶子节点(除根节点)最少有 ⌈m/2⌉ 个子节点
如果根节点不是叶子节点,那么它至少有两个子节点
有 k 个子节点的非叶子节点拥有 k − 1 个键
所有的叶子节点都在同一层
总结
今天先整理到这里,明天继续完善,今天还没有涉及到B树的主要概念,只是涉及到了磁盘的一些概念。
参考
http://blog.****.net/liuaigui/article/details/6168186。
http://stackoverflow.com/questions/12345804/difference-between-blocks-and-sectors
https://en.wikipedia.org/wiki/Disk_sector
http://baike.baidu.com/view/110462.htm 这里是我原来所学的
http://oss.org.cn/kernel-book/ch09/9.1.htm 物理块的概念
https://en.wikipedia.org/wiki/B-tree
http://blog.****.net/v_july_v/article/details/6530142 这个帖子介绍的比较详细