84
1 Univerzální B-stromy (UB-Stromy) Michal Krátký, [email protected] http://www.cs.vsb.cz/kratky Rudolf Bayer Vícerozměrná přístupová metoda

Univerzální B-stromy (UB-Stromy)

  • Upload
    shima

  • View
    44

  • Download
    0

Embed Size (px)

DESCRIPTION

Univerzální B-stromy (UB-Stromy). V ícerozměrná přístupová metoda. Rudolf Bayer. Michal Krátký, [email protected] http://www.cs.vsb.cz/kratky. Obsah. Úvod Vícerozměrná data Principy UB-stromů Algoritmus vkládání bodu Algoritmus výpočtu Z-adresy Algoritmus rozsahového dotazu - PowerPoint PPT Presentation

Citation preview

Page 1: Univerzální B-stromy  (UB-Stromy)

1

Univerzální B-stromy (UB-Stromy)

Michal Krátký, [email protected]://www.cs.vsb.cz/kratky

Rudolf Bayer

Vícerozměrná přístupová metoda

Page 2: Univerzální B-stromy  (UB-Stromy)

2

Obsah• Úvod• Vícerozměrná data• Principy UB-stromů• Algoritmus vkládání bodu• Algoritmus výpočtu Z-adresy• Algoritmus rozsahového dotazu• Práce s nebodovými objekty• Složitosti algoritmů, výhody

Page 3: Univerzální B-stromy  (UB-Stromy)

3

Úvod

• UB-strom je vícerozměrná přístupová metoda

• autorem je Rudolf Bayer, další výzkum Volker Markl

• Využívá Z-uspořádání a B-stromů

Page 4: Univerzální B-stromy  (UB-Stromy)

4

Vícerozměrná data• Kartézským součinem domén atributů vznikne

vícerozměrný prostor • n-tice (řádek, tuple, entita, objekt) je bodem v

n-dimenzionálním prostoru a je takto indexován• Prostorová blízkost umožňuje shlukování

těchto bodů pro uložení na diskové stránky => snížení počtu přístupů na disk => rychlejší operace

• Využití v data warehousingu, GIS, ...

Page 5: Univerzální B-stromy  (UB-Stromy)

5

1

0 1

1, 2)Z(

s

j

d

i

idjjixx

• Z(x) počítá pro každou n-tici Z-adresu (tj. jeho pozici na Z-křivce)• Z-hodnoty jsou efektivně počítány tzv. bitovým prokládáním (bit-interleaving)

Pro x a binární reprezentaci každého atributu xi = x i,s-1 x i,s-2 ... x i,0 definujeme Z-hodnotu Z(x):

Z-uspořádání

Page 6: Univerzální B-stromy  (UB-Stromy)

6

10 54 1716 2120

32 76 1918 2322

98 1312 2524 2928

1110 1514 2726 3130

3332 3736 4948 5352

3534 3938 5150 5554

4140 4544 5756 6160

4342 4746 5958 6362

10 32 54 76

1

0

4

2

5

3

7

6

(a) (b)

Z-uspořádání pro univerzum 8x8

Page 7: Univerzální B-stromy  (UB-Stromy)

7

Z-region [4 : 20]

4 20

UB-Stromové dělení:[0 : 3],[4 : 20],[21 : 35], [36 : 47],[48 : 63]

Z-region [] je prostor pokrytý intervalem na Z-křivce.

Z-regiony/UB-stromy

Page 8: Univerzální B-stromy  (UB-Stromy)

8

V listech B-stromu jsou uloženy n-tice náležící k danému Z-regionu

UB-index

UB-soubor

V uzlu B-stromu jsou

uloženy adresy Z-regionů

UB-strom

Page 9: Univerzální B-stromy  (UB-Stromy)

9

Algoritmus vkládání boduVstup: x: bod, který má být vložen do UB-StromuVýstup: žádný

= Z(x)find [ : ] in the UB-Tree, such that Ł Łretrieve page( : )insert x into page( : )if count( : ) > C choose[ : ], so that ½C - Ł count( : ) Ł ½C + split page( : ) into page( : ) and page(1 : )end if

Page 10: Univerzální B-stromy  (UB-Stromy)

10

Ukázka vkládání bodů

Page 11: Univerzální B-stromy  (UB-Stromy)

11

Zdrojový kódZdrojový kód

Insert(Tuple tuple) { Zaddress za = Z(tuple); BtreeInsert(za, tuple);}

Ubvalue findSplitPoint(Tuple t1, Tuple t2){ /* nalezení optimální Z-adresy mezi t1 a t2 */}

B-StromB-Strom

Z-adresa

UB-StromUB-Strom

Page 12: Univerzální B-stromy  (UB-Stromy)

12

Zdrojový kódZdrojový kód

Insert(Tuple tuple) { Zaddress za = Z(tuple); BtreeInsert(za, tuple);}

Ubvalue findSplitPoint(Tuple t1, Tuple t2){ /* nalezení optimální Z-adresy mezi t1 a t2 */}

UB-StromUB-Strom

B-StromB-Strom

Z-adresa

Page 13: Univerzální B-stromy  (UB-Stromy)

13

Zdrojový kódZdrojový kód

Insert(Tuple tuple) { Zaddress za = Z(tuple); BtreeInsert(za, tuple);}

Ubvalue findSplitPoint(Tuple t1, Tuple t2){ /* nalezení optimální Z-adresy mezi t1 a t2 */}

UB-StromUB-Strom

B-StromB-Strom

Z-adresa

Page 14: Univerzální B-stromy  (UB-Stromy)

14

Zdrojový kódZdrojový kód

Insert(Tuple tuple) { Zaddress za = Z(tuple); BtreeInsert(za, tuple);}

Ubvalue findSplitPoint(Tuple t1, Tuple t2){ /* nalezení optimální Z-adresy mezi t1 a t2 */}

UB-StromUB-Strom

B-StromB-Strom

Z-adresa

Page 15: Univerzální B-stromy  (UB-Stromy)

15

Po vložení dalších dvou bodů ...

Page 16: Univerzální B-stromy  (UB-Stromy)

16

Zdrojový kódZdrojový kód

Insert(Tuple tuple) { Zaddress za = Z(tuple); BtreeInsert(za, tuple);}

Ubvalue findSplitPoint(Tuple t1, Tuple t2){ /* nalezení optimální Z-adresy mezi t1 a t2 */}

B-StromB-Strom

Z-adresa

UB-StromUB-Strom

Page 17: Univerzální B-stromy  (UB-Stromy)

17

Zdrojový kódZdrojový kód

Insert(Tuple tuple) { Zaddress za = Z(tuple); BtreeInsert(za, tuple);}

Ubvalue findSplitPoint(Tuple t1, Tuple t2){ /* nalezení optimální Z-adresy mezi t1 a t2 */}

B-StromB-Strom

Z-adresa

UB-StromUB-Strom

Page 18: Univerzální B-stromy  (UB-Stromy)

18

Zdrojový kódZdrojový kód

Insert(Tuple tuple) { Zaddress za = Z(tuple); BtreeInsert(za, tuple);}

Ubvalue findSplitPoint(Tuple t1, Tuple t2){ /* nalezení optimální Z-adresy mezi t1 a t2 */}

UB-StromUB-Strom

B-StromB-Strom

Z-adresa

Page 19: Univerzální B-stromy  (UB-Stromy)

19

Zdrojový kódZdrojový kód

Insert(Tuple tuple) { Zaddress za = Z(tuple); BtreeInsert(za, tuple);}

Ubvalue findSplitPoint(Tuple t1, Tuple t2){ /* nalezení optimální Z-adresy mezi t1 a t2 */}

UB-StromUB-Strom

Z-adresa

B-StromB-Strom

Page 20: Univerzální B-stromy  (UB-Stromy)

20

Zdrojový kódZdrojový kód

Insert(Tuple tuple) { Zaddress za = Z(tuple); BtreeInsert(za, tuple);}

Ubvalue findSplitPoint(Tuple t1, Tuple t2){ /* nalezení optimální Z-adresy mezi t1 a t2 */}

UB-StromUB-Strom

Z-adresa

B-StromB-Strom

Page 21: Univerzální B-stromy  (UB-Stromy)

21

UB-StromUB-StromZdrojový kódZdrojový kód

Insert(Tuple tuple) { Zaddress za = Z(tuple); BtreeInsert(za, tuple);}

Ubvalue findSplitPoint(Tuple t1, Tuple t2){ /* nalezení optimální Z-adresy mezi t1 a t2 */}

Z-adresa

B-StromB-Strom

Page 22: Univerzální B-stromy  (UB-Stromy)

22

Zdrojový kódZdrojový kód

Insert(Tuple tuple) { Zaddress za = Z(tuple); BtreeInsert(za, tuple);}

Ubvalue findSplitPoint(Tuple t1, Tuple t2){ /* nalezení optimální Z-adresy mezi t1 a t2 */}

UB-StromUB-Strom

Z-adresa

B-StromB-Strom

Page 23: Univerzální B-stromy  (UB-Stromy)

23

Z-adresa

B-StromB-Strom

UB-StromUB-StromZdrojový kódZdrojový kód

Insert(Tuple tuple) { Zaddress za = Z(tuple); BtreeInsert(za, tuple);}

Ubvalue findSplitPoint(Tuple t1, Tuple t2){ /* nalezení optimální Z-adresy mezi t1 a t2 */}

Page 24: Univerzální B-stromy  (UB-Stromy)

24

UB-StromUB-Strom

Z-adresa

B-StromB-Strom

Zdrojový kódZdrojový kód

Insert(Tuple tuple) { Zaddress za = Z(tuple); BtreeInsert(za, tuple);}

Ubvalue findSplitPoint(Tuple t1, Tuple t2){ /* nalezení optimální Z-adresy mezi t1 a t2 */}

Page 25: Univerzální B-stromy  (UB-Stromy)

25

Zdrojový kódZdrojový kód

Insert(Tuple tuple) { Zaddress za = Z(tuple); BtreeInsert(za, tuple);}

Ubvalue findSplitPoint(Tuple t1, Tuple t2){ /* nalezení optimální Z-adresy mezi t1 a t2 */}

UB-StromUB-Strom

Z-adresa

B-StromB-Strom

Page 26: Univerzální B-stromy  (UB-Stromy)

26

Zdrojový kódZdrojový kód

Insert(Tuple tuple) { Zaddress za = Z(tuple); BtreeInsert(za, tuple);}

Ubvalue findSplitPoint(Tuple t1, Tuple t2){ /* nalezení optimální Z-adresy mezi t1 a t2 */}

UB-StromUB-Strom

Z-adresa

B-StromB-Strom

Page 27: Univerzální B-stromy  (UB-Stromy)

27

UB-StromUB-Strom

Z-adresa

B-StromB-Strom

UB-StromUB-Strom

Z-adresa

B-StromB-Strom

Page 28: Univerzální B-stromy  (UB-Stromy)

28

UB-StromUB-Strom

Z-adresa

B-StromB-Strom

UB-StromUB-Strom

Z-adresa

B-StromB-Strom

Page 29: Univerzální B-stromy  (UB-Stromy)

29

Zdrojový kódZdrojový kód

Insert(Tuple tuple) { Zaddress za = Z(tuple); BtreeInsert(za, tuple);}

Ubvalue findSplitPoint(Tuple t1, Tuple t2){ /* nalezení optimální Z-adresy mezi t1 a t2 */}

UB-StromUB-Strom

Z-adresa

B-StromB-Strom

Page 30: Univerzální B-stromy  (UB-Stromy)

30

Zdrojový kódZdrojový kód

Insert(Tuple tuple) { Zaddress za = Z(tuple); BtreeInsert(za, tuple);}

Ubvalue findSplitPoint(Tuple t1, Tuple t2){ /* nalezení optimální Z-adresy mezi t1 a t2 */}

UB-StromUB-Strom

Z-adresa

B-StromB-Strom

Page 31: Univerzální B-stromy  (UB-Stromy)

31

Zdrojový kódZdrojový kód

Insert(Tuple tuple) { Zaddress za = Z(tuple); BtreeInsert(za, tuple);}

Ubvalue findSplitPoint(Tuple t1, Tuple t2){ /* nalezení optimální Z-adresy mezi t1 a t2 */}

UB-StromUB-Strom

Z-adresa

B-StromB-Strom

Page 32: Univerzální B-stromy  (UB-Stromy)

32

Po vložení dalších bodů obsahuje UB-strom 5 Z-regionů ..

Page 33: Univerzální B-stromy  (UB-Stromy)

33

Zdrojový kódZdrojový kód

Insert(Tuple tuple) { Zaddress za = Z(tuple); BtreeInsert(za, tuple);}

Ubvalue findSplitPoint(Tuple t1, Tuple t2){ /* nalezení optimální Z-adresy mezi t1 a t2 */}

UB-StromUB-Strom

Z-adresa

B-StromB-Strom

Page 34: Univerzální B-stromy  (UB-Stromy)

34

Zdrojový kódZdrojový kód

Insert(Tuple tuple) { Zaddress za = Z(tuple); BtreeInsert(za, tuple);}

Ubvalue findSplitPoint(Tuple t1, Tuple t2){ /* nalezení optimální Z-adresy mezi t1 a t2 */}

UB-StromUB-Strom

Z-adresa

B-StromB-Strom

Page 35: Univerzální B-stromy  (UB-Stromy)

35

Zdrojový kódZdrojový kód

Insert(Tuple tuple) { Zaddress za = Z(tuple); BtreeInsert(za, tuple);}

Ubvalue findSplitPoint(Tuple t1, Tuple t2){ /* nalezení optimální Z-adresy mezi t1 a t2 */}

UB-StromUB-Strom

Z-adresa

B-StromB-Strom

Page 36: Univerzální B-stromy  (UB-Stromy)

36

Zdrojový kódZdrojový kód

Insert(Tuple tuple) { Zaddress za = Z(tuple); BtreeInsert(za, tuple);}

Ubvalue findSplitPoint(Tuple t1, Tuple t2){ /* nalezení optimální Z-adresy mezi t1 a t2 */}

UB-StromUB-Strom

Z-adresa

B-StromB-Strom

Page 37: Univerzální B-stromy  (UB-Stromy)

37

Zdrojový kódZdrojový kód

Insert(Tuple tuple) { Zaddress za = Z(tuple); BtreeInsert(za, tuple);}

Ubvalue findSplitPoint(Tuple t1, Tuple t2){ /* nalezení optimální Z-adresy mezi t1 a t2 */}

UB-StromUB-Strom

Z-adresa

B-StromB-Strom

Page 38: Univerzální B-stromy  (UB-Stromy)

38

A po vložení dalších bodů ...

Page 39: Univerzální B-stromy  (UB-Stromy)

39

Zdrojový kódZdrojový kód

Insert(Tuple tuple) { Zaddress za = Z(tuple); BtreeInsert(za, tuple);}

Ubvalue findSplitPoint(Tuple t1, Tuple t2){ /* nalezení optimální Z-adresy mezi t1 a t2 */}

UB-StromUB-Strom

Z-adresa

B-StromB-Strom

Page 40: Univerzální B-stromy  (UB-Stromy)

40

Zdrojový kódZdrojový kód

Insert(Tuple tuple) { Zaddress za = Z(tuple); BtreeInsert(za, tuple);}

Ubvalue findSplitPoint(Tuple t1, Tuple t2){ /* nalezení optimální Z-adresy mezi t1 a t2 */}

UB-StromUB-Strom

Z-adresa

B-StromB-Strom

Page 41: Univerzální B-stromy  (UB-Stromy)

41

Zdrojový kódZdrojový kód

Insert(Tuple tuple) { Zaddress za = Z(tuple); BtreeInsert(za, tuple);}

Ubvalue findSplitPoint(Tuple t1, Tuple t2){ /* nalezení optimální Z-adresy mezi t1 a t2 */}

UB-StromUB-Strom

Z-adresa

B-StromB-Strom

Page 42: Univerzální B-stromy  (UB-Stromy)

42

Výpočet Z-adresy

Page 43: Univerzální B-stromy  (UB-Stromy)

43

_ _ _ _ _ _ _ _ _ _

1 0 0 1 0 1 1 0 0 1

(25,18)

Z-adresa

_ _ _ _ _ _ _ _ _ _

_ _ _ _ _ _ _ _ _ _

Atribut 2 Atribut 1Bitové řetězce

Atribut 1Atribut 2

Z-adresa

UB-strom

1

Zdrojový kódZdrojový kód

Zaddress Z(Tuple tuple) { Zaddress za = 0; int pos = 0, bit ; for (bit = 0; bit < maxbits(tuple); bit++) { foreach attribute of tuple do { if (attribute[bit] exists) { if (attribute[bit] is set)

ZaddressSetBit(&za, pos); pos++;

} } } return za;}

Page 44: Univerzální B-stromy  (UB-Stromy)

44

_ _ _ _ _ _ _ _ _ _

1 0 0 1 0 1 1 0 0 1

(25,18)

Z-adresa

_ _ _ _ _ _ _ _ _ _

_ _ _ _ _ _ _ _ _ _

Atribut 2 Atribut 1Bitové řetězce

Atribut 1Atribut 2

Z-adresa

UB-strom

1 1

Zdrojový kódZdrojový kód

Zaddress Z(Tuple tuple) { Zaddress za = 0; int pos = 0, bit ; for (bit = 0; bit < maxbits(tuple); bit++) { foreach attribute of tuple do { if (attribute[bit] exists) { if (attribute[bit] is set)

ZaddressSetBit(&za, pos); pos++;

} } } return za;}

Page 45: Univerzální B-stromy  (UB-Stromy)

45

_ _ _ _ _ _ _ _ _ _

1 0 0 1 0 1 1 0 0 1

(25,18)

Z-adresa

_ _ _ _ _ _ _ _ _ _

_ _ _ _ _ _ _ _ _ _

Atribut 2 Atribut 1Bitové řetězce

Atribut 1Atribut 2

Z-adresa

UB-strom

1 1 0

Zdrojový kódZdrojový kód

Zaddress Z(Tuple tuple) { Zaddress za = 0; int pos = 0, bit ; for (bit = 0; bit < maxbits(tuple); bit++) { foreach attribute of tuple do { if (attribute[bit] exists) { if (attribute[bit] is set)

ZaddressSetBit(&za, pos); pos++;

} } } return za;}

Page 46: Univerzální B-stromy  (UB-Stromy)

46

_ _ _ _ _ _ _ _ _ _

1 0 0 1 0 1 1 0 0 1

(25,18)

Z-adresa

_ _ _ _ _ _ _ _ _ _

_ _ _ _ _ _ _ _ _ _

Atribut 2 Atribut 1Bitové řetězce

Atribut 1Atribut 2

Z-adresa

UB-strom

1 1 0 1

Zdrojový kódZdrojový kód

Zaddress Z(Tuple tuple) { Zaddress za = 0; int pos = 0, bit ; for (bit = 0; bit < maxbits(tuple); bit++) { foreach attribute of tuple do { if (attribute[bit] exists) { if (attribute[bit] is set)

ZaddressSetBit(&za, pos); pos++;

} } } return za;}

Page 47: Univerzální B-stromy  (UB-Stromy)

47

_ _ _ _ _ _ _ _ _ _

1 0 0 1 0 1 1 0 0 1

(25,18)

Z-adresa

_ _ _ _ _ _ _ _ _ _

_ _ _ _ _ _ _ _ _ _

Atribut 2 Atribut 1Bitové řetězce

Atribut 1Atribut 2

Z-adresa

UB-strom

1 1 0 1 0

Zdrojový kódZdrojový kód

Zaddress Z(Tuple tuple) { Zaddress za = 0; int pos = 0, bit ; for (bit = 0; bit < maxbits(tuple); bit++) { foreach attribute of tuple do { if (attribute[bit] exists) { if (attribute[bit] is set)

ZaddressSetBit(&za, pos); pos++;

} } } return za;}

Page 48: Univerzální B-stromy  (UB-Stromy)

48

_ _ _ _ _ _ _ _ _ _

1 0 0 1 0 1 1 0 0 1

(25,18)

Z-adresa

_ _ _ _ _ _ _ _ _ _

_ _ _ _ _ _ _ _ _ _

Atribut 2 Atribut 1Bitové řetězce

Atribut 1Atribut 2

Z-adresa

UB-strom

1 1 0 1 0 0

Zdrojový kódZdrojový kód

Zaddress Z(Tuple tuple) { Zaddress za = 0; int pos = 0, bit ; for (bit = 0; bit < maxbits(tuple); bit++) { foreach attribute of tuple do { if (attribute[bit] exists) { if (attribute[bit] is set)

ZaddressSetBit(&za, pos); pos++;

} } } return za;}

Page 49: Univerzální B-stromy  (UB-Stromy)

49

_ _ _ _ _ _ _ _ _ _

1 0 0 1 0 1 1 0 0 1

(25,18)

Z-adresa

_ _ _ _ _ _ _ _ _ _

_ _ _ _ _ _ _ _ _ _

Atribut 2 Atribut 1Bitové řetězce

Atribut 1Atribut 2

Z-adresa

UB-strom

1 1 0 1 0 0 1

Zdrojový kódZdrojový kód

Zaddress Z(Tuple tuple) { Zaddress za = 0; int pos = 0, bit ; for (bit = 0; bit < maxbits(tuple); bit++) { foreach attribute of tuple do { if (attribute[bit] exists) { if (attribute[bit] is set)

ZaddressSetBit(&za, pos); pos++;

} } } return za;}

Page 50: Univerzální B-stromy  (UB-Stromy)

50

_ _ _ _ _ _ _ _ _ _

1 0 0 1 0 1 1 0 0 1

(25,18)

Z-adresa

_ _ _ _ _ _ _ _ _ _

_ _ _ _ _ _ _ _ _ _

Atribut 2 Atribut 1Bitové řetězce

Atribut 1Atribut 2

Z-adresa

UB-strom

1 1 0 1 0 0 1 0

Zdrojový kódZdrojový kód

Zaddress Z(Tuple tuple) { Zaddress za = 0; int pos = 0, bit ; for (bit = 0; bit < maxbits(tuple); bit++) { foreach attribute of tuple do { if (attribute[bit] exists) { if (attribute[bit] is set)

ZaddressSetBit(&za, pos); pos++;

} } } return za;}

Page 51: Univerzální B-stromy  (UB-Stromy)

51

_ _ _ _ _ _ _ _ _ _

1 0 0 1 0 1 1 0 0 1

(25,18)

Z-adresa

_ _ _ _ _ _ _ _ _ _

_ _ _ _ _ _ _ _ _ _

Atribut 2 Atribut 1Bitové řetězce

Atribut 1Atribut 2

Z-adresa

UB-stromUB-strom

1 1 0 1 0 0 1 0 0

Zdrojový kódZdrojový kód

Zaddress Z(Tuple tuple) { Zaddress za = 0; int pos = 0, bit ; for (bit = 0; bit < maxbits(tuple); bit++) { foreach attribute of tuple do { if (attribute[bit] exists) { if (attribute[bit] is set)

ZaddressSetBit(&za, pos); pos++;

} } } return za;}

Page 52: Univerzální B-stromy  (UB-Stromy)

52

_ _ _ _ _ _ _ _ _ _

1 0 0 1 0 1 1 0 0 1

(25,18)

Z-adresa

_ _ _ _ _ _ _ _ _ _

_ _ _ _ _ _ _ _ _ _

Atribut 2 Atribut 1Bitové řetězce

Atribut 1Atribut 2

Z-adresa

UB-stromUB-strom

1 1 0 1 0 0 1 0 0 1

Zdrojový kódZdrojový kód

Zaddress Z(Tuple tuple) { Zaddress za = 0; int pos = 0, bit ; for (bit = 0; bit < maxbits(tuple); bit++) { foreach attribute of tuple do { if (attribute[bit] exists) { if (attribute[bit] is set)

ZaddressSetBit(&za, pos); pos++;

} } } return za;}

Page 53: Univerzální B-stromy  (UB-Stromy)

53

Algoritmus vymazání bodu 1/2Vstup: x: bod, který má být vymazán z UB-stromu Výstup: žádný

= Z(x)search [ : ] in the UB-Tree, such that Ł Ł retrieve page( : )delete x from page( : )if count( : ) < ½ C - merge page( : ) with the neighboring page( + 1 : ) into page( : )

Page 54: Univerzální B-stromy  (UB-Stromy)

54

if count( : ) > C choose [ : ] with count( : ) Ł ½ C - and count( + 1 : ) Ł ½ C - split page( : ) into page( : ) and page( + 1: ) end ifend if

Algoritmus vymazání bodu 2/2

Page 55: Univerzální B-stromy  (UB-Stromy)

55

Algoritmus bodového dotazu

Vstup: x: bod zadaný zaindexovanými atributyVýstup: x: bod se všemi atributy

= Z(x)find [ :] in the UB-Tree, such that ŁŁretrieve page( : ) into main memorysearch content of page( : ) to find x

Page 56: Univerzální B-stromy  (UB-Stromy)

56

SELECT * FROM table WHERE (A1 BETWEEN a1 AND b1) AND (A2 BETWEEN a2 AND b2) AND

.....(An BETWEEN an AND bn)

Vícerozměrný rozsahový dotaz

Page 57: Univerzální B-stromy  (UB-Stromy)

57

Algoritmus rozsahového dotazu

Vstup: y,z: body definující dotazovací okno Z(y) < Z(z)Výstup: X: výsledná množina

= Z(y); = Z(z); X = Ćrepeat find [: ] in the UB-Tree, such that Ł Ł X = X Č {(x1, ... ,xd’) [ : ] | (x1, ... ,xd) [[ y, z]]} = Z-address of the first point intersecting the query box with > until >

Page 58: Univerzální B-stromy  (UB-Stromy)

58

Ukázka rozsahového dotazu

Page 59: Univerzální B-stromy  (UB-Stromy)

59

UB-stromUB-strom

BB**-strom-strom

linelineární Z-prostorární Z-prostor

rangeQuery(Tuple ql, Tuple qh) { Zaddress start = Z(ql); Zaddress cur = start; Zaddress end = Z(qh); Page page = {};

while (1) { cur = getRegionSeparator(cur); page = getPage(cur); outputMatchingTuples(page, ql, qh); if ( cur >= end ) break; cur = getNextZAddress(cur, start, end); }}

Zdrojový kódZdrojový kód

Page 60: Univerzální B-stromy  (UB-Stromy)

60

rangeQuery(Tuple ql, Tuple qh) { Zaddress start = Z(ql); Zaddress cur = start; Zaddress end = Z(qh); Page page = {};

while (1) { cur = getRegionSeparator(cur); page = getPage(cur); outputMatchingTuples(page, ql, qh); if ( cur >= end ) break; cur = getNextZAddress(cur, start, end); }}

Zdrojový kódZdrojový kód UB-stromUB-strom

BB**-strom-strom

linelineární Z-prostorární Z-prostor

Page 61: Univerzální B-stromy  (UB-Stromy)

61

rangeQuery(Tuple ql, Tuple qh) { Zaddress start = Z(ql); Zaddress cur = start; Zaddress end = Z(qh); Page page = {};

while (1) { cur = getRegionSeparator(cur); page = getPage(cur); outputMatchingTuples(page, ql, qh); if ( cur >= end ) break; cur = getNextZAddress(cur, start, end); }}

Zdrojový kódZdrojový kód UB-stromUB-strom

BB**-strom-strom

linelineární Z-prostorární Z-prostor

Page 62: Univerzální B-stromy  (UB-Stromy)

62

rangeQuery(Tuple ql, Tuple qh) { Zaddress start = Z(ql); Zaddress cur = start; Zaddress end = Z(qh); Page page = {};

while (1) { cur = getRegionSeparator(cur); page = getPage(cur); outputMatchingTuples(page, ql, qh); if ( cur >= end ) break; cur = getNextZAddress(cur, start, end); }}

Zdrojový kódZdrojový kód UB-stromUB-strom

BB**-strom-strom

linelineární Z-prostorární Z-prostor

Page 63: Univerzální B-stromy  (UB-Stromy)

63

rangeQuery(Tuple ql, Tuple qh) { Zaddress start = Z(ql); Zaddress cur = start; Zaddress end = Z(qh); Page page = {};

while (1) { cur = getRegionSeparator(cur); page = getPage(cur); outputMatchingTuples(page, ql, qh); if ( cur >= end ) break; cur = getNextZAddress(cur, start, end); }}

Zdrojový kódZdrojový kód UB-stromUB-strom

BB**-strom-strom

linelineární Z-prostorární Z-prostor

Page 64: Univerzální B-stromy  (UB-Stromy)

64

rangeQuery(Tuple ql, Tuple qh) { Zaddress start = Z(ql); Zaddress cur = start; Zaddress end = Z(qh); Page page = {};

while (1) { cur = getRegionSeparator(cur); page = getPage(cur); outputMatchingTuples(page, ql, qh); if ( cur >= end ) break; cur = getNextZAddress(cur, start, end); }}

Zdrojový kódZdrojový kód UB-stromUB-strom

BB**-strom-strom

linelineární Z-prostorární Z-prostor

Page 65: Univerzální B-stromy  (UB-Stromy)

65

rangeQuery(Tuple ql, Tuple qh) { Zaddress start = Z(ql); Zaddress cur = start; Zaddress end = Z(qh); Page page = {};

while (1) { cur = getRegionSeparator(cur); page = getPage(cur); outputMatchingTuples(page, ql, qh); if ( cur >= end ) break; cur = getNextZAddress(cur, start, end); }}

Zdrojový kódZdrojový kód UB-stromUB-strom

BB**-strom-strom

linelineární Z-prostorární Z-prostor

Page 66: Univerzální B-stromy  (UB-Stromy)

66

rangeQuery(Tuple ql, Tuple qh) { Zaddress start = Z(ql); Zaddress cur = start; Zaddress end = Z(qh); Page page = {};

while (1) { cur = getRegionSeparator(cur); page = getPage(cur); outputMatchingTuples(page, ql, qh); if ( cur >= end ) break; cur = getNextZAddress(cur, start, end); }}

Zdrojový kódZdrojový kód UB-stromUB-strom

BB**-strom-strom

linelineární Z-prostorární Z-prostor

Page 67: Univerzální B-stromy  (UB-Stromy)

67

rangeQuery(Tuple ql, Tuple qh) { Zaddress start = Z(ql); Zaddress cur = start; Zaddress end = Z(qh); Page page = {};

while (1) { cur = getRegionSeparator(cur); page = getPage(cur); outputMatchingTuples(page, ql, qh); if ( cur >= end ) break; cur = getNextZAddress(cur, start, end); }}

Zdrojový kódZdrojový kód UB-stromUB-strom

BB**-strom-strom

linelineární Z-prostorární Z-prostor

Page 68: Univerzální B-stromy  (UB-Stromy)

68

rangeQuery(Tuple ql, Tuple qh) { Zaddress start = Z(ql); Zaddress cur = start; Zaddress end = Z(qh); Page page = {};

while (1) { cur = getRegionSeparator(cur); page = getPage(cur); outputMatchingTuples(page, ql, qh); if ( cur >= end ) break; cur = getNextZAddress(cur, start, end); }}

Zdrojový kódZdrojový kód UB-stromUB-strom

BB**-strom-strom

linelineární Z-prostorární Z-prostor

Page 69: Univerzální B-stromy  (UB-Stromy)

69

rangeQuery(Tuple ql, Tuple qh) { Zaddress start = Z(ql); Zaddress cur = start; Zaddress end = Z(qh); Page page = {};

while (1) { cur = getRegionSeparator(cur); page = getPage(cur); outputMatchingTuples(page, ql, qh); if ( cur >= end ) break; cur = getNextZAddress(cur, start, end); }}

Zdrojový kódZdrojový kód UB-stromUB-strom

BB**-strom-strom

linelineární Z-prostorární Z-prostor

Page 70: Univerzální B-stromy  (UB-Stromy)

70

rangeQuery(Tuple ql, Tuple qh) { Zaddress start = Z(ql); Zaddress cur = start; Zaddress end = Z(qh); Page page = {};

while (1) { cur = getRegionSeparator(cur); page = getPage(cur); outputMatchingTuples(page, ql, qh); if ( cur >= end ) break; cur = getNextZAddress(cur, start, end); }}

Zdrojový kódZdrojový kód UB-stromUB-strom

BB**-strom-strom

linelineární Z-prostorární Z-prostor

Page 71: Univerzální B-stromy  (UB-Stromy)

71

rangeQuery(Tuple ql, Tuple qh) { Zaddress start = Z(ql); Zaddress cur = start; Zaddress end = Z(qh); Page page = {};

while (1) { cur = getRegionSeparator(cur); page = getPage(cur); outputMatchingTuples(page, ql, qh); if ( cur >= end ) break; cur = getNextZAddress(cur, start, end); }}

Zdrojový kódZdrojový kód UB-stromUB-strom

BB**-strom-strom

linelineární Z-prostorární Z-prostor

Page 72: Univerzální B-stromy  (UB-Stromy)

72

rangeQuery(Tuple ql, Tuple qh) { Zaddress start = Z(ql); Zaddress cur = start; Zaddress end = Z(qh); Page page = {};

while (1) { cur = getRegionSeparator(cur); page = getPage(cur); outputMatchingTuples(page, ql, qh); if ( cur >= end ) break; cur = getNextZAddress(cur, start, end); }}

Zdrojový kódZdrojový kód UB-stromUB-strom

BB**-strom-strom

linelineární Z-prostorární Z-prostor

Page 73: Univerzální B-stromy  (UB-Stromy)

73

rangeQuery(Tuple ql, Tuple qh) { Zaddress start = Z(ql); Zaddress cur = start; Zaddress end = Z(qh); Page page = {};

while (1) { cur = getRegionSeparator(cur); page = getPage(cur); outputMatchingTuples(page, ql, qh); if ( cur >= end ) break; cur = getNextZAddress(cur, start, end); }}

Zdrojový kódZdrojový kód UB-stromUB-strom

BB**-strom-strom

linelineární Z-prostorární Z-prostor

Page 74: Univerzální B-stromy  (UB-Stromy)

74

rangeQuery(Tuple ql, Tuple qh) { Zaddress start = Z(ql); Zaddress cur = start; Zaddress end = Z(qh); Page page = {};

while (1) { cur = getRegionSeparator(cur); page = getPage(cur); outputMatchingTuples(page, ql, qh); if ( cur >= end ) break; cur = getNextZAddress(cur, start, end); }}

Zdrojový kódZdrojový kód UB-stromUB-strom

BB**-strom-strom

linelineární Z-prostorární Z-prostor

Page 75: Univerzální B-stromy  (UB-Stromy)

75

rangeQuery(Tuple ql, Tuple qh) { Zaddress start = Z(ql); Zaddress cur = start; Zaddress end = Z(qh); Page page = {};

while (1) { cur = getRegionSeparator(cur); page = getPage(cur); outputMatchingTuples(page, ql, qh); if ( cur >= end ) break; cur = getNextZAddress(cur, start, end); }}

Zdrojový kódZdrojový kód UB-stromUB-strom

BB**-strom-strom

linelineární Z-prostorární Z-prostor

Page 76: Univerzální B-stromy  (UB-Stromy)

76

rangeQuery(Tuple ql, Tuple qh) { Zaddress start = Z(ql); Zaddress cur = start; Zaddress end = Z(qh); Page page = {};

while (1) { cur = getRegionSeparator(cur); page = getPage(cur); outputMatchingTuples(page, ql, qh); if ( cur >= end ) break; cur = getNextZAddress(cur, start, end); }}

Zdrojový kódZdrojový kód UB-stromUB-strom

BB**-strom-strom

linelineární Z-prostorární Z-prostor

Page 77: Univerzální B-stromy  (UB-Stromy)

77

Práce s obecnými objekty 1/3

Page 78: Univerzální B-stromy  (UB-Stromy)

78

Práce s obecnými objekty 2/3

Page 79: Univerzální B-stromy  (UB-Stromy)

79

• pro objekt o je vytvořen ohraničující obdélník bb(o)

• pro objekt o jsou uloženy identifikátory Id(o) pro každý region, který o protíná

• objekt sám je uložen mimo UB-strom

• o může protínat pouze regiony, které jsou protínány bb(o)

Práce s obecnými objekty 3/3

Page 80: Univerzální B-stromy  (UB-Stromy)

80

Vložení obecného objektu

1. Výpočet bb(o)

2. for all regions R which intersect bb(o) do

if R intersects o then insert Id(o) into R

// může dojít k rozštěpení R ...

Page 81: Univerzální B-stromy  (UB-Stromy)

81

Vyhledání objektů v zadaném okně

1. Nalezneme všechny regiony a získáme korespondující stránky dotazovacího okna q (stránky obsahují identifikátory Id(o) pro všechny objekty o, které protínají tyto regiony).

2. Pro všechny Id(o) zjišťujeme, zda o protíná q.

Page 82: Univerzální B-stromy  (UB-Stromy)

82

Složitosti algoritmů• bodový dotaz: O(logk N), kde N je počet

n-tic, k = 1/2M, M je kapacita stránky

• rozsahový dotaz: r*O(logk N), kde r je počet regionů protínajících dotazovací okno

• vložení bodu (n-tice): O(logk N)

• vložení objektu: r*O(logk N), kde r je počet regionů protínajících bb(o)

• vymazání bodu: O(logk N)

• vymazání objektu: r*O(logk N)

Page 83: Univerzální B-stromy  (UB-Stromy)

83

Výhody UB-stromů

• Garance logaritmické časové složitosti v nejhorším případě pro vkládání, mazání a bodové dotazy

• Shlukování n-tic na diskové stránky při jejich prostorové blízkosti

• Dobré průměrné využití paměti

• Efektivní rozsahové dotazy

Page 84: Univerzální B-stromy  (UB-Stromy)

84

Odkazy• http://mistral.in.tum.de• R. Bayer. The Universal B-Tree for multidimensional

indexing, http://mistral.in.tum.de/results/publications/ TUMI9637.pdf

• V. Markl. MISTRAL: Processing Relational Queries using a Multidimensional Access Technique, http://mistral.in.tum.de/results/publications/Mar99.pdf

• http://www.cs.vsb.cz/~dis• http://www.cs.vsb.cz/kratky/ub-tree