- 论坛徽章:
- 0
|
dali 内存数据库系统结构
5.3 T-tree Indexes
Lehman and Carey10 proposed T-trees as a storage-efficient data structure for main memory databases. T-trees are based on AVL trees proposed by Adel'son Vel'skii and Landis.11 As in AVL trees, the height of left and right subtrees of a T-tree may differ by, at most, one. Unlike AVL trees, each node in a T-tree stores multiple key values in a sorted order rather than a single key value. To keep occupancy high, every internal node must contain a minimum number of key values (typically k&2, if k is the maximum number of keys that can be stored in a node).
Lehman and Carey10建议把T 树作为MMDB高效的存储数据结构。T树是基于Adel'son Vel'skii and Landis.11的AVL树。与在AVL树中一样,T树的左子树和右子树高多数情况下可以相差1。但和AVL树不同,T树的每个结点保存有序的多个键值而不是单个键值。为保证高利用率,每个内部节点必须包含最小数目的键值(典型的是k&2,如果K是一个节点能最大容纳的键值数)
Searching for a key value in a T-tree is a relatively straightforward process. For every node, a check is made to determine if the key value is bounded by the leftmost and the rightmost key values in the node; if this is the case, then the key value is returned if it is contained in the node. (If the key value is not returned, it is not contained in the tree.) If the key value is less than the leftmost key value, then the search moves to the left child; otherwise, the right child node is searched. The process is repeated until either the key is found or the node to be searched is null .
在T树中查找一个键值是一个相关的前向过程,对每个节点,要检查键值是不是在该节点中最左和最右的键值之间。如果是,并且包含该键值,那么直接返回键值。(如果键值没有返回,表示键值不包含在这棵树中)如果键值小于最左的键值,那么查询将对左子树进行,否则,将对右子树进行。这个过程将一直重复到键值疗找到或是查找的节点为空为止。
Insertions and deletions into the T-tree are a bit more complicated. In both cases, first a variant of the search described above is used to find the node that bounds the key value to be inserted/deleted. If there is room in the node for insertions, the key is placed in the node; otherwise, a new node is allocated for the key. For deletions, the key is deleted from the node, and the node itself is deallocated if:
向T树中插入和删除会复杂一点,在两种情况下,首先,使用与上面讨论不同的查找方法查询包含要插入/删除的键值取值范围的节点。如果在这个节点中有空间插入,那么键值写入这个节点中。否则,创建一个新的节点来保存这个键值。如果是删除,键从节点中删除,如果发生以下情况,节点自己将会被重分配空间:
The node becomes empty, or 节点变空
The number of keys in the node falls below the specified minimum and keys in the node can be accommodated in a different node. 该节点中键的数目低于键的下限值,这个节点中的键可以向其它节点调节。
Deletions from interior nodes may require keys to be moved up from lower nodes to ensure that occupancy requirements are met. In both insertions and deletions, allocation and deallocation of a node may unbalance the tree, making it necessary to perform rotations (RR, RL, LL, LR), as described in Lehman and Carey.10
删除内部节点时,为了保证利用率,可能会把键从低层的节点中向上移。在插入或者是删除时,节点的分配和再分配可能会导致树的不平衡,因此要进行适当的旋转(RR, RL, LL, LR),这和Lehman and Carey.10讨论的一样。
Our T-tree implementation supports next-key locking12 to avoid the phantom phenomenon. It also provides high concurrency by requiring operations on the T-tree to obtain a T-tree latch only for the duration of the operation, not the transaction. Insertions and deletions obtain the latch in X mode, while search operations obtain the latch in S mode.
我们的平衡树支持下一键锁定,这样可以避免幻象。通过要示对T树进行的操作要操作(而不是事务)期间必须拥有一个T树锁,它同样提供高并发性,插入和删除拥有X模式的锁,查询操作拥有S模式的锁。 |
|