Docsity

B-Tree vs. B+-Tree: Key Differences and Multi-Key Indexing - Prof. Yicheng Tu, Study notes of Deductive Database Systems

Toggle sidebar
bg1
B-Tree vs. B+-Tree
Key differences:
B-Tree intermediate nodes are able to contain pointers to raw data instead of just pointers to children.
Each node in a B-Tree has a key value and two pointers, as opposed to the one pointer in a B+ tree.
One pointer points to raw data (or null), and the other points to a child node (or null).
B+-Trees benefit range queries by having leaf nodes chained together on the same level.
Advantages of B
1. Searching can potentially be faster as the tree does not always need to be traversed down to the
leaf nodes in all cases.
2. Total number of tree nodes is smaller because an intermediate node can hold data, and does not
have to be an extra layer above an extra leaf node.
Disadvantages of B
1. Fanout will be smaller, and the tree height will increase.
2. Insertion/Deletion are very non-trivial, even more so than B+ trees, causing maintenance to be
more difficult.
B-trees are useful, and are used in some special cases, such as the storage of a long string, or an
unknown size string, when copying the data in multiple levels of a B+-tree would be inefficient and
much more costly than smaller data structures.
For the most part, the advantages of using a B-tree for general-purpose indexing are much less than the
disadvantages of using them.
Multi-key index
All of the previous indexes studied in class have been based on a single attribute. These aren't always
beneficial with complex queries.
Take an index over the two keys: (B_date,Salary) How do you order/compare this type of index?
As single attributes, it was simple:
Salary -> 50k > 30k
B_date -> 10/05/65 > 08/15/73 (If you order by age instead of time)
Take an example with the following keys: (10/08/65,30k) and (08/15/73,50k)
entry in the node
pf3

Partial preview of the text

Download B-Tree vs. B+-Tree: Key Differences and Multi-Key Indexing - Prof. Yicheng Tu and more Study notes Deductive Database Systems in PDF only on Docsity!

B-Tree vs. B+-Tree Key differences: B-Tree intermediate nodes are able to contain pointers to raw data instead of just pointers to children. Each node in a B-Tree has a key value and two pointers, as opposed to the one pointer in a B+ tree. One pointer points to raw data (or null), and the other points to a child node (or null). B+-Trees benefit range queries by having leaf nodes chained together on the same level. Advantages of B

  1. Searching can potentially be faster as the tree does not always need to be traversed down to the leaf nodes in all cases.
  2. Total number of tree nodes is smaller because an intermediate node can hold data, and does not have to be an extra layer above an extra leaf node. Disadvantages of B
  3. Fanout will be smaller, and the tree height will increase.
  4. Insertion/Deletion are very non-trivial, even more so than B+ trees, causing maintenance to be more difficult. B-trees are useful, and are used in some special cases, such as the storage of a long string, or an unknown size string, when copying the data in multiple levels of a B+-tree would be inefficient and much more costly than smaller data structures. For the most part, the advantages of using a B-tree for general-purpose indexing are much less than the disadvantages of using them. Multi-key index All of the previous indexes studied in class have been based on a single attribute. These aren't always beneficial with complex queries. Take an index over the two keys: (B_date,Salary) How do you order/compare this type of index? As single attributes, it was simple: Salary -> 50k > 30k B_date -> 10/05/65 > 08/15/73 (If you order by age instead of time) Take an example with the following keys: (10/08/65,30k) and (08/15/73,50k)

Lexicographical Ordering: <attribute 1,attribute 2> Use attribute 1 as the primary ordering key... row 1: <a1, b1> row 2: <a2, b2> if a1>a2 then row 1 > row 2 if a1<a2 then row 1< row 2 if a1=a2 then compare b1 and b There is a ranking order of all attributes in the vector. The primary ordering key has the highest rank, and each following attribute in the vector has a decreasing rank. Ranking order has a huge impact on the performance of queries. select * from Employee where B_date='10/08/65' and Salary=50k On purely equality-based queries like this, the order really has little effect. Either you traverse lower into the tree and scan less entries, or you traverse higher in the tree and scan more entries. select * from Employee where B_date='10/08/65' and Salary<50k For this query, it would be best to choose B_date as the primary ordering key, and Salary as secondary. This way, you can find people with a specific birthday, and traverse through their salaries. If it was done the other way around, you would search through all people with a salary of less than 50k, which would include people with birthdays you aren't looking for. select * from Employee where B_date<'10/08/65' and Salary=50k For this query, it would be best to choose Salary as the primary ordering key, and B_date as secondary. This way, you can find people with a specific salary, and traverse through their birthdays. If it was done the other way around, you would search through all people with a birthday of less than 10/08/65, which would include people with salaries you aren't looking for. A general rule regarding indexes: (A1,A2,.....,An)=T Queries that ask for a prefix of T (a subset of all elements in T) will benefit from a multi-key index. Application Development around Databases 3-Tier business architecture: Presentation Tier Translates computational tasks into a form that is friendly to a human user Web Server Logic Tier Logical decisions and commands based on data Application Server Data Tier Storage/Query processing of data DBMS