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

Preview:

DESCRIPTION

Univerzální B-stromy (UB-Stromy). V ícerozměrná přístupová metoda. Rudolf Bayer. Michal Krátký, michal.kratky@vsb.cz 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

1

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

Michal Krátký, michal.kratky@vsb.czhttp://www.cs.vsb.cz/kratky

Rudolf Bayer

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

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

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ů

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, ...

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í

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

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

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

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

10

Ukázka vkládání bodů

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

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

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

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

15

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

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

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

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

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

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

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

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

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 */}

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 */}

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

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

27

UB-StromUB-Strom

Z-adresa

B-StromB-Strom

UB-StromUB-Strom

Z-adresa

B-StromB-Strom

28

UB-StromUB-Strom

Z-adresa

B-StromB-Strom

UB-StromUB-Strom

Z-adresa

B-StromB-Strom

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

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

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

32

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

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

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

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

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

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

38

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

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

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

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

42

Výpočet Z-adresy

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;}

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;}

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;}

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;}

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;}

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;}

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;}

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;}

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;}

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;}

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( : )

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

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

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

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 >

58

Ukázka rozsahového dotazu

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

77

Práce s obecnými objekty 1/3

78

Práce s obecnými objekty 2/3

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

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 ...

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.

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)

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

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