Docsity

Tree Structure - E-Commerce - Lecture Slides, Slides of Fundamentals of E-Commerce

Toggle sidebar
bg1
B-Tree Structure
•Index node is a sequence of [pointer, key] pairs
•K1 < K2 < … < Kn-2 < Kn-1
•P1 points to a node containing keys < K1
•Pi points to a node containing keys in range [Ki-1, Ki)
•Pn points to a node containing keys > Kn-1
•So, K ´1 < K ´2 < … < K ´n-2 < K ´n-1
Ki Pi Ki+1 K1 P1 Kn-1 Pn
. . . . . .
K´i P´i K´i+1
K´1 P´1 K´n-1 P´n
. . . . . .
Docsity.com
pf3
pf4
pf5
pf8

Partial preview of the text

Download Tree Structure - E-Commerce - Lecture Slides and more Slides Fundamentals of E-Commerce in PDF only on Docsity!

B-Tree Structure

•^

Index node is a sequence of [pointer, key] pairs

-^

K

1

< K

2

< … < K

n-

< K

n-

•^

P

1

points to a node containing keys < K

1

•^

P

points to a node containing keys in range [Ki

i-

, K

)i

•^

P

n^

points to a node containing keys > K

n-

•^

So, K ´

1

< K ´

2

< … < K ´

n-

< K ´

n-

K

i^

P

i^

K

i+

K

1

P

1

K

n-

P

n

K´

i^

P´

i^

K´

i+

K´

1

P´

1

K´

n-

P´

n

Example n=

•^

Notice that leaves are sorted by key, left-to-right

-^

Search for value v by following path from the root

-^

If key = 8 bytes, ptr = 2 bytes, page = 4K, then n = 409

-^

So 3-level index has up to 68M leaves (

•^

At 20 records per leaf, that’s 136M records

B-Tree Observations

-^

Delete algorithm merges adjacent nodes < 50% full,but rarely used in practice

-^

Root and most level-1 nodes are cached, to reducedisk accesses

-^

Secondary (non-clustered) index - Leaves contain[key, record id] pairs.

-^

Primary (clustered) index - Leaves contain records

-^

Use key prefix for long (string) key values^ –

drop prefix and add to suffix as you move down the tree

Key Range Locks

-^

Lock on B-tree key range is a cheap predicate lock

  • Select Dept Where ((Budget > 250)

and (Budget < 350))

-^

lock the key range [221, 352) record

  • only useful when query is on an

indexed field

•^

Commonly used with multi-granularity locking– Insert/delete locks record and intention-write locks range– MGL tree defines a fixed set of predicates, and thereby

avoids predicate satisfiability

B-tree Locking

•^

Root lock on a B-tree is a bottleneck

-^

Use tree locking to relieve it

-^

Problem: node splits

-^

So, don’t unlock a node till you’re sure its child won’t split(i.e. has space for an insert)

-^

Implies different locking rules for different ops(search vs. insert/update)

X

P

C

If you unlock P before splitting C,then you have to back up and lockP again, which breaks the treelocking protocol.

B-link Optimization

•^

B-link tree - Each node has a side pointer to the next

-^

After searching a node, you can release its lock beforelocking its child^ –

r

[P] r 1

[P] r 2

[C] w 2

[C] w 2

[C´] w 2

[P] r 2

[C] r 1

[C´] 1

P

C

X

X

P

C´

C •^

Searching has the same behavior as if it locked the childbefore releasing the parent … and ran later (after the insert)