在b-树中,您可以将键和数据存储在内部节点和叶节点中,但在b+树中,您必须仅将数据存储在叶节点中。

在b+树中这样做有什么好处吗?

为什么不在所有地方都使用b-树而不是b+树,因为直觉上它们看起来更快?

我的意思是,为什么需要在b+树中复制键(数据)?


当前回答

B+树是一种平衡的树,其中从树的根到叶子的每条路径都是相同的长度,树的每个非叶子节点都有[n/2]到[n]个子节点,其中n对于特定的树是固定的。它包含索引页和数据页。 二叉树的每个父节点只有两个子节点,而B+树的每个父节点可以有不同数量的子节点

其他回答

Adegoke A, Amit

我想你们忽略的一个关键点是数据和指针之间的区别,就像本节中解释的那样。

指针:指向其他节点的指针。

数据:—在数据库索引的上下文中,数据只是另一个指向其他地方的真实数据(行)的指针。

因此在B树的情况下,每个节点都有三个信息键,指向与键相关的数据的指针和指向子节点的指针。

在B+树中,内部节点保存指向子节点的键和指针,而叶节点保存指向相关数据的键和指针。这允许为给定大小的节点提供更多的键数。节点大小主要由块大小决定。

每个节点拥有更多键的好处已经在上面解释过了,这样可以节省我的输入工作量。

B+树相对于B树的主要优点是,它们允许您通过删除指向数据的指针来打包更多指向其他节点的指针,从而增加扇出并潜在地降低树的深度。

缺点是,当您可能在内部节点中找到匹配时,无法提前退出。但由于这两种数据结构都有巨大的扇出,绝大多数匹配都将在叶节点上,这使得B+树的平均效率更高。

In a B tree search keys and data are stored in internal or leaf nodes. But in a B+-tree data is stored only in leaf nodes. Full scan of a B+ tree is very easy because all data are found in leaf nodes. Full scan of a B tree requires a full traversal. In a B tree, data may be found in leaf nodes or internal nodes. Deletion of internal nodes is very complicated. In a B+ tree, data is only found in leaf nodes. Deletion of leaf nodes is easy. Insertion in B tree is more complicated than B+ tree. B+ trees store redundant search keys but B tree has no redundant value. In a B+ tree, leaf node data is ordered as a sequential linked list but in a B tree the leaf node cannot be stored using a linked list. Many database systems' implementations prefer the structural simplicity of a B+ tree.

**

B-Tree的主要缺点是遍历键的难度 按顺序。B+树保留了的快速随机访问属性 b -树,同时也允许快速顺序访问

** 参考:Data Structures Using C//作者:Aaro M Tenenbaum

http://books.google.co.in/books?id=X0Cd1Pr2W0gC&pg=PA456&lpg=PA456&dq=drawback+of+B-Tree+is+the+difficulty+of+Traversing+the+keys+sequentially&source=bl&ots=pGcPQSEJMS&sig=F9MY7zEXYAMVKl_Sg4W-0LTRor8&hl=en&sa=X&ei=nD5AUbeeH4zwrQe12oCYAQ&ved=0CDsQ6AEwAg#v=onepage&q=drawback%20of%20B-Tree%20is%20the%20difficulty%20of%20Traversing%20the%20keys%20sequentially&f=false

The primary distinction between B-tree and B+tree is that B-tree eliminates the redundant storage of search key values.Since search keys are not repeated in the B-tree,we may not be able to store the index using fewer tree nodes than in corresponding B+tree index.However,since search key that appear in non-leaf nodes appear nowhere else in B-tree,we are forced to include an additional pointer field for each search key in a non-leaf node. Their are space advantages for B-tree, as repetition does not occur and can be used for large indices.