recap
play

Recap CS 525: Advanced Database We have discussed - PDF document

2013-02-06 Recap CS 525: Advanced Database We have discussed Organization ConvenIonal Indices 06: Even more index B-trees structures Hashing Boris Glavic


  1. 2013-­‑02-­‑06 ¡ Recap ¡ CS 525: Advanced Database • We ¡have ¡discussed ¡ Organization – ConvenIonal ¡Indices ¡ 06: Even more index – B-­‑trees ¡ structures – Hashing ¡ Boris Glavic – Trade-­‑offs ¡ – MulI-­‑key ¡indices ¡ – MulI-­‑dimensional ¡indices ¡ Slides: ¡adapted ¡from ¡a ¡course ¡taught ¡by ¡ ¡ Hector ¡Garcia-­‑Molina, ¡Stanford ¡InfoLab ¡ ¡ • … ¡but ¡no ¡example ¡ CS ¡525 ¡ Notes ¡6 ¡-­‑ ¡More ¡Indices ¡ 1 ¡ CS ¡525 ¡ Notes ¡6 ¡-­‑ ¡More ¡Indices ¡ 2 ¡ Today ¡ Grid Index Key 2 • MulI-­‑dimensional ¡index ¡structures ¡ X 1 X 2 …… X n – kd-Trees (very similar to example before) V 1 – Grid File (Grid Index) V 2 – Quad Trees Key 1 – R Trees – Partitioned Hash V n – ... • Bitmap-­‑indices ¡ To records with key1=V 3, key2=X 2 • Tries ¡ CS ¡525 ¡ Notes ¡6 ¡-­‑ ¡More ¡Indices ¡ 3 ¡ CS 525 Notes 5 - Hashing 4 CLAIM CLAIM • Can quickly find records with • Can quickly find records with – key 1 = V i ∧ Key 2 = X j – key 1 = V i ∧ Key 2 = X j – key 1 = V i – key 1 = V i – key 2 = X j – key 2 = X j • And ¡also ¡ranges…. ¡ – E.g., ¡ ¡ ¡key ¡1 ¡ ≥ ¡V i ¡ ¡ ∧ ¡ ¡key ¡2 ¡< ¡X j ¡ CS 525 Notes 5 - Hashing 5 CS 525 Notes 5 - Hashing 6 1 ¡

  2. 2013-­‑02-­‑06 ¡ • How do we find entry i,j in linear structure? • How do we find entry i,j in linear structure? max number of max number of i, j i, j position S+0 position S+0 i values N=4 i values N=4 0, ¡0 0, ¡0 position S+1 position S+1 0, ¡1 0, ¡1 position S+2 position S+2 0, ¡2 0, ¡2 position S+3 position S+3 0, ¡3 0, ¡3 pos(i, j) = pos(i, j) = S + iN + j position S+4 position S+4 1, ¡0 1, ¡0 1, ¡1 1, ¡1 1, ¡2 1, ¡2 Issue: Cells must be same size, 1, ¡3 1, ¡3 2, ¡0 2, ¡0 and N must be constant! position S+9 position S+9 2, ¡1 2, ¡1 2, ¡2 2, ¡2 2, ¡3 2, ¡3 Issue: Some cells may overflow, 3, ¡0 3, ¡0 some may be sparse... CS 525 Notes 5 - Hashing 7 CS 525 Notes 5 - Hashing 8 With indirection: Solution: Use Indirection Buckets • Grid can be regular without wasting space X1 X2 X3 -­‑-­‑ ¡ V 1 -­‑-­‑ ¡ • We do have price of indirection -­‑-­‑ ¡ V 2 -­‑-­‑ ¡ -­‑-­‑ ¡ -­‑-­‑ ¡ V 3 * Grid only -­‑-­‑ ¡ V 4 contains -­‑-­‑ ¡ -­‑-­‑ ¡ pointers to buckets -­‑-­‑ ¡ -­‑-­‑ ¡ -­‑-­‑ ¡ -­‑-­‑ ¡ Buckets -­‑-­‑ ¡ -­‑-­‑ ¡ CS 525 Notes 5 - Hashing 9 CS 525 Notes 5 - Hashing 10 Can also index grid on value ranges Grid files Salary Grid Good for multiple-key search + ¡ Space, management overhead 0-­‑20K ¡ 1 ¡ -­‑ ¡ (nothing is free) 20K-­‑50K ¡ 2 ¡ 50K-­‑ ¡ 8 3 ¡ Need partitioning ranges that evenly -­‑ ¡ split keys 1 ¡ 2 ¡ 3 ¡ Linear ¡Scale ¡ Toy ¡ Sales ¡ Personnel ¡ CS 525 Notes 5 - Hashing 11 CS 525 Notes 5 - Hashing 12 2 ¡

  3. 2013-­‑02-­‑06 ¡ EX: ParIIoned ¡hash ¡funcIon ¡ 000 h1(toy) =0 Idea: 001 h1(sales) =1 010110 ¡1110010 ¡ 010 h1(art) =1 011 . Key1 Key2 100 h2(10k) =01 101 h1 ¡ h2 ¡ 110 h2(20k) =11 111 h2(30k) =01 h2(40k) =00 . <Fred,toy,10k>,<Joe,sales,10k> Insert ¡ <Sally,art,30k> CS 525 Notes 5 - Hashing 13 CS 525 Notes 5 - Hashing 14 EX: EX: 000 000 h1(toy) =0 h1(toy) =0 <Fred> ¡ 001 001 h1(sales) =1 <Fred> ¡ h1(sales) =1 <Joe><Jan> ¡ 010 010 <Mary> ¡ h1(art) =1 h1(art) =1 011 011 . . 100 100 <Sally> ¡ h2(10k) =01 h2(10k) =01 101 101 <Joe><Sally> ¡ 110 110 h2(20k) =11 h2(20k) =11 <Tom><Bill> ¡ 111 111 h2(30k) =01 h2(30k) =01 <Andy> ¡ h2(40k) =00 h2(40k) =00 . . <Fred,toy,10k>,<Joe,sales,10k> Find ¡Emp. ¡with ¡Dept. ¡= ¡Sales ¡ ¡ ∧ ¡ ¡Sal=40k ¡ Insert ¡ <Sally,art,30k> CS 525 Notes 5 - Hashing 15 CS 525 Notes 5 - Hashing 16 EX: EX: 000 000 h1(toy) =0 h1(toy) =0 <Fred> ¡ <Fred> ¡ 001 001 <Joe><Jan> ¡ <Joe><Jan> ¡ h1(sales) =1 h1(sales) =1 010 010 <Mary> ¡ <Mary> ¡ h1(art) =1 h1(art) =1 011 011 . . 100 100 <Sally> ¡ <Sally> ¡ h2(10k) =01 h2(10k) =01 101 101 110 110 h2(20k) =11 h2(20k) =11 <Tom><Bill> ¡ <Tom><Bill> ¡ 111 111 h2(30k) =01 h2(30k) =01 <Andy> ¡ <Andy> ¡ h2(40k) =00 h2(40k) =00 . . Find ¡Emp. ¡with ¡Sal=30k ¡ Find ¡Emp. ¡with ¡Dept. ¡= ¡Sales ¡ ¡ ∧ ¡ ¡Sal=40k ¡ CS 525 Notes 5 - Hashing 17 CS 525 Notes 5 - Hashing 18 3 ¡

  4. 2013-­‑02-­‑06 ¡ EX: EX: 000 000 h1(toy) =0 h1(toy) =0 <Fred> ¡ <Fred> ¡ 001 001 h1(sales) =1 <Joe><Jan> ¡ h1(sales) =1 <Joe><Jan> ¡ 010 010 <Mary> ¡ <Mary> ¡ h1(art) =1 h1(art) =1 011 011 . . 100 100 <Sally> ¡ <Sally> ¡ h2(10k) =01 101 h2(10k) =01 101 110 110 h2(20k) =11 h2(20k) =11 <Tom><Bill> ¡ <Tom><Bill> ¡ 111 111 h2(30k) =01 h2(30k) =01 <Andy> ¡ <Andy> ¡ h2(40k) =00 h2(40k) =00 . . Find ¡Emp. ¡with ¡Sal=30k ¡ Find ¡Emp. ¡with ¡Dept. ¡= ¡Sales ¡ CS 525 Notes 5 - Hashing 19 CS 525 Notes 5 - Hashing 20 EX: R-­‑tree ¡ 000 h1(toy) =0 <Fred> ¡ • Nodes ¡can ¡store ¡up ¡to ¡ M ¡entries ¡ 001 h1(sales) =1 <Joe><Jan> ¡ 010 <Mary> ¡ – Minimum ¡fill ¡requirement ¡(depends ¡on ¡variant) ¡ h1(art) =1 011 . • Each ¡node ¡rectangle ¡in ¡ n -­‑dimensional ¡space ¡ 100 <Sally> ¡ h2(10k) =01 101 – Minimum ¡Bounding ¡Rectangle ¡(MBR) ¡of ¡its ¡ 110 h2(20k) =11 <Tom><Bill> ¡ children ¡ 111 h2(30k) =01 <Andy> ¡ • MBRs ¡of ¡siblings ¡are ¡allowed ¡to ¡overlap ¡ h2(40k) =00 – Different ¡from ¡B-­‑trees ¡ . Find ¡Emp. ¡with ¡Dept. ¡= ¡Sales ¡ • balanced ¡ CS 525 Notes 5 - Hashing 21 CS ¡525 ¡ Notes ¡6 ¡-­‑ ¡More ¡Indices ¡ 22 ¡ R-­‑tree ¡-­‑ ¡Search ¡ [5-­‑7] ¡ [9-­‑15] ¡ [13-­‑19] ¡ [20-­‑24] ¡ [12-­‑16] ¡ [2-­‑4] ¡ • Point ¡Search ¡ Data ¡Space ¡ – Search ¡for ¡p ¡= ¡<x i , ¡y i > ¡ [5] ¡ [6] ¡ [7] ¡ – Keep ¡list ¡of ¡potenIal ¡nodes ¡ [24] ¡ [20] ¡ [24] ¡ [13] ¡ [14] ¡ [18] ¡ [19] ¡ • Needed ¡because ¡of ¡overlap ¡ [4] ¡ [2] ¡ [2] ¡ [3] ¡ – Traverse ¡to ¡child ¡if ¡MBR ¡of ¡ child ¡contains ¡p ¡ [9] ¡ [11] ¡ [15] ¡ [15] ¡ [16] ¡ [12] ¡ CS ¡525 ¡ Notes ¡6 ¡-­‑ ¡More ¡Indices ¡ 23 ¡ CS ¡525 ¡ Notes ¡6 ¡-­‑ ¡More ¡Indices ¡ 24 ¡ 4 ¡

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend