Hi Markus,

I had a small doubt in the below article

http://use-the-index-luke.com/sql/anatomy/slow-indexes

Consider the search for “57” in Figure 1.3 again. There are obviously two matching entries in the index. At least two entries are the same, to be more precise: the next leaf node could have further entries for “57”. The database must read the next leaf node to see if there are any more matching entries. That means that an index lookup not only needs to perform the tree traversal, it also needs to follow the leaf node chain.

Only an index in the branch node will guide us to the correct leaf node wherein we can search for the required index from the internal indexes of the leaf node.If we traverse from one leaf node to other using the double linked list as mentioned above,wouldn't it break the b tree traversal wherein the leaf nodes are pointed to by the indexes from the branch node ?

Update :

Updating the question to make it clear.Not sure if it helps though as I couldn't get a pictorial representation to depict the query.

Below is the path that was followed for the lookup 57

branchnode(bn1) entry 83 -- > branchnode(bn2) entry 57 ----> leafnode(ln1) with multiple 57 entry's.

I believe the statement [it also needs to follow the leaf node chain] means follow from one leaf node(ln1) to the next leaf node(ln2) (using the list pointer) so as to search for entry's which match 57 in the leafnode(ln2).

So there can be a situation wherein we have to traverse from leafnonde(ln1) to leafnode(ln2) assuming ln2 has further entry's with value 57.Am i right in this assumption or did I get it wrong here itself ? Or does this mean searching for all the entry's with value 57 in ln1 itself.

The maximum entry in ln1 is defined by the entry in bn2 which got us there,so in our case as 57 entry from bn2 got us to ln1,the maximum entry value in ln1 can be at the max 57.So,even if there were multiple 57 entry's all of them should be in ln1 itself and they would not cross over to other leafnode(ln2) as that would disturb the order of entry's in bn2.

This might be a silly doubt,but I wanted to get this clarified so that its easy for me to understand further topics.

Thanks.

asked Apr 07 '14 at 20:27

crackerplace's gravatar image

crackerplace
6114

edited Apr 08 '14 at 20:36


One Answer:

I'm not sure if I got your question. Well, I'm actually pretty sure I don't!

However, be B-tree traversal and the potential follow up of the doubly linked list are best though of two distinct processes which doen't influence each other. First, you must find the first matching leaf node (using the B-tree to benefit from log(n) scalability) then you might need to follow the leaf node chain to find all matching entries (with linear scalability).

UPDATE

So there can be a situation wherein we have to traverse from leafnonde(ln1) to leafnode(ln2) assuming ln2 has further entry's with value 57.Am i right in this assumption...

All right so far.

This one, however, is wrong:

So,even if there were multiple 57 entry's all of them should be in ln1 itself and they would not cross over to other leafnode(ln2) as that would disturb the order of entry's in bn2.

Just assume ln2 (not shown in the picture) has the entries 57, 57, 83.

That is still perfectly possible because bn2 just says the max value on ln2 is 83 (and it is in this example). You must not forget that the space per node is limited. The system must be capable to handle thousands of 57 values. In that case you'd even have multiple 57-entries in branch nodes.

answered Apr 08 '14 at 09:07

Markus%20Winand's gravatar image

Markus Winand ♦♦
93651120

edited Apr 09 '14 at 08:49

@markus Just updated the question.Sorry for the confusion.

(Apr 08 '14 at 20:05) crackerplace

Thanks Markus,this is clear now.The way you have explained indexes from the basics and with examples is awesome.Thanks.

(Apr 09 '14 at 21:20) crackerplace