I/O-Algorithms Lars Arge Spring 2011 March 8, 2011.

Slides:



Advertisements
Similar presentations
Temporal Databases S. Srinivasa Rao April 12, 2007
Advertisements

Chapter 4: Trees Part II - AVL Tree
I/O-Algorithms Lars Arge Fall 2014 September 25, 2014.
0 Course Outline n Introduction and Algorithm Analysis (Ch. 2) n Hash Tables: dictionary data structure (Ch. 5) n Heaps: priority queue data structures.
B+-Trees (PART 1) What is a B+ tree? Why B+ trees? Searching a B+ tree
External Memory Geometric Data Structures
Multiversion Access Methods - Temporal Indexing. Basics A data structure is called : Ephemeral: updates create a new version and the old version cannot.
I/O-Algorithms Lars Arge University of Aarhus February 21, 2005.
I/O-Algorithms Lars Arge Aarhus University February 27, 2007.
CSE332: Data Abstractions Lecture 9: B Trees Dan Grossman Spring 2010.
1 B trees Nodes have more than 2 children Each internal node has between k and 2k children and between k-1 and 2k-1 keys A leaf has between k-1 and 2k-1.
I/O-Algorithms Lars Arge Aarhus University February 13, 2007.
I/O-Algorithms Lars Arge Spring 2009 February 2, 2009.
I/O-Algorithms Lars Arge Aarhus University February 16, 2006.
I/O-Algorithms Lars Arge Aarhus University February 7, 2005.
I/O-Algorithms Lars Arge University of Aarhus February 13, 2005.
Temporal Indexing MVBT. Temporal Indexing Transaction time databases : update the last version, query all versions Queries: “Find all employees that worked.
I/O-Algorithms Lars Arge Spring 2009 April 28, 2009.
I/O-Algorithms Lars Arge University of Aarhus March 1, 2005.
Temporal Indexing MVBT. Temporal Indexing Transaction time databases : update the last version, query all versions Queries: “Find all employees that worked.
I/O-Algorithms Lars Arge Spring 2009 March 3, 2009.
I/O-Algorithms Lars Arge Aarhus University February 6, 2007.
I/O-Algorithms Lars Arge Aarhus University March 5, 2008.
I/O-Efficient Structures for Orthogonal Range Max and Stabbing Max Queries Second Year Project Presentation Ke Yi Advisor: Lars Arge Committee: Pankaj.
I/O-Algorithms Lars Arge Aarhus University April 16, 2008.
I/O-Algorithms Lars Arge Aarhus University February 9, 2006.
TTIT33 Algorithms and Optimization – DALG Lecture 6 Jan Maluszynski - HT TTIT33- Algorithms and optimization Algorithms Lecture 5 Balanced Search.
I/O-Algorithms Lars Arge Aarhus University March 9, 2006.
I/O-Algorithms Lars Arge Aarhus University February 14, 2008.
I/O-Algorithms Lars Arge Aarhus University March 6, 2007.
©Silberschatz, Korth and Sudarshan12.1Database System Concepts Chapter 12: Part B Part A:  Index Definition in SQL  Ordered Indices  Index Sequential.
I/O-Algorithms Lars Arge University of Aarhus March 7, 2005.
1 Geometric index structures April 15, 2004 Based on GUW Chapter , [Arge01] Sections 1, 2.1 (persistent B- trees), 3-4 (static versions.
B + -Trees (Part 1) Lecture 20 COMP171 Fall 2006.
1 Database indices Database Systems manage very large amounts of data. –Examples: student database for NWU Social Security database To facilitate queries,
B + -Trees (Part 1). Motivation AVL tree with N nodes is an excellent data structure for searching, indexing, etc. –The Big-Oh analysis shows most operations.
CSE 326: Data Structures B-Trees Ben Lerner Summer 2007.
1 Database Tuning Rasmus Pagh and S. Srinivasa Rao IT University of Copenhagen Spring 2007 February 8, 2007 Tree Indexes Lecture based on [RG, Chapter.
Homework #3 Due Thursday, April 17 Problems: –Chapter 11: 11.6, –Chapter 12: 12.1, 12.2, 12.3, 12.4, 12.5, 12.7.
B + -Trees COMP171 Fall AVL Trees / Slide 2 Dictionary for Secondary storage * The AVL tree is an excellent dictionary structure when the entire.
CS4432: Database Systems II
Indexing. Goals: Store large files Support multiple search keys Support efficient insert, delete, and range queries.
Heavily based on slides by Lars Arge I/O-Algorithms Thomas Mølhave Spring 2012 February 9, 2012.
B-Tree. B-Trees a specialized multi-way tree designed especially for use on disk In a B-tree each node may contain a large number of keys. The number.
1 B Trees - Motivation Recall our discussion on AVL-trees –The maximum height of an AVL-tree with n-nodes is log 2 (n) since the branching factor (degree,
External Memory Algorithms for Geometric Problems Piotr Indyk (slides partially by Lars Arge and Jeff Vitter)
B-trees and kd-trees Piotr Indyk (slides partially by Lars Arge from Duke U)
Bin Yao Spring 2014 (Slides were made available by Feifei Li) Advanced Topics in Data Management.
Trevor Brown – University of Toronto B-slack trees: Space efficient B-trees.
Mehdi Mohammadi March Western Michigan University Department of Computer Science CS Advanced Data Structure.
12.1 Chapter 12: Indexing and Hashing Spring 2009 Sections , , Problems , 12.7, 12.8, 12.13, 12.15,
Lars Arge Presented by Or Ozery. I/O Model Previously defined: N = # of elements in input M = # of elements that fit into memory B = # of elements per.
B + -Trees. Motivation An AVL tree with N nodes is an excellent data structure for searching, indexing, etc. The Big-Oh analysis shows that most operations.
Starting at Binary Trees
1 Tree Indexing (1) Linear index is poor for insertion/deletion. Tree index can efficiently support all desired operations: –Insert/delete –Multiple search.
Lecture 2: External Memory Indexing Structures CS6931 Database Seminar.
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture17.
Lecture 11COMPSCI.220.FS.T Balancing an AVLTree Two mirror-symmetric pairs of cases to rebalance the tree if after the insertion of a new key to.
Review for Exam 2 Topics covered (since exam 1): –Splay Tree –K-D Trees –RB Tree –Priority Queue and Binary Heap –B-Tree For each of these data structures.
External Memory Geometric Data Structures Lars Arge Duke University June 27, 2002 Summer School on Massive Datasets.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 B+-Tree Index Chapter 10 Modified by Donghui Zhang Nov 9, 2005.
COMP 5704 Project Presentation Parallel Buffer Trees and Searching Cory Fraser School of Computer Science Carleton University, Ottawa, Canada
Temporal Indexing MVBT. Temporal Indexing Transaction time databases : update the last version, query all versions Queries: “Find all employees that worked.
Michal Balas1 I/O-efficient Point Location using Persistent B-Trees Lars Arge, Andrew Danner, and Sha-Mayn Teh Department of Computer Science, Duke University.
Multiway Search Trees Data may not fit into main memory
Temporal Indexing MVBT.
Temporal Indexing MVBT.
Advanced Topics in Data Management
Storage and Indexing.
General External Merge Sort
Presentation transcript:

I/O-Algorithms Lars Arge Spring 2011 March 8, 2011

Lars Arge I/O-algorithms 2 I/O-Model Parameters N = # elements in problem instance B = # elements that fits in disk block M = # elements that fits in main memory K = # output size in searching problem We often assume that M>B 2 I/O: Movement of block between memory and disk D P M Block I/O

Lars Arge I/O-algorithms 3 Fundamental Bounds Internal External Scanning: N Sorting: N log N Permuting Searching:

Lars Arge I/O-algorithms 4 External Search Trees BFS blocking: –Block height –Output elements blocked  Rangesearch in I/Os Optimal: O(N/B) space and query

Lars Arge I/O-algorithms 5 B-trees Seems very difficult to maintain BFS blocking during rotation BFS-blocking naturally corresponds to tree with fan-out B-trees balanced by allowing node degree to vary –Rebalancing performed by splitting and merging nodes

Lars Arge I/O-algorithms 6 (a,b)-tree uses linear space and has height (a,b)-tree T is an (a,b)-tree (a≥2 and b≥2a-1) –All leaves on the same level (contain between a and b elements) –Except for the root, all nodes have degree between a and b –Root has degree between 2 and b  tree

Lars Arge I/O-algorithms 7 (a,b)-Tree Insert Insert: Search and insert element in leaf v DO v has b+1 elements/children Split v: make nodes v’ and v’’ with and elements insert element (ref) in parent(v) (make new root if necessary) v=parent(v) Insert touch nodes v v’v’’

Lars Arge I/O-algorithms 8 (a,b)-Tree Delete Delete: Search and delete element from leaf v DO v has a-1 elements/children Fuse v with sibling v’: move children of v’ to v delete element (ref) from parent(v) (delete root if necessary) If v has >b (and ≤ a+b-1<2b) children split v v=parent(v) Delete touch nodes v v

Lars Arge I/O-algorithms 9 (a,b)-tree properties: –If b=2a-1 every update can cause many rebalancing operations –If b≥2a update only cause O(1) rebalancing operations amortized –If b>2a rebalancing operations amortized *Both somewhat hard to show –If b=4a easy to show that update causes rebalance operations amortized (a,b)-Tree insert delete (2,3)-tree

Lars Arge I/O-algorithms 10 Summary/Conclusion: B-tree B-trees: (a,b)-trees with a,b = –O(N/B) space –O(log B N+T/B) query –O(log B N) update B-trees with elements in the leaves sometimes called B + -tree Construction in I/Os –Sort elements and construct leaves –Build tree level-by-level bottom-up

Lars Arge I/O-algorithms 11 Summary/Conclusion: B-tree B-tree with branching parameter b and leaf parameter k (b,k≥8) –All leaves on same level and contain between 1/4k and k elements –Except for the root, all nodes have degree between 1/4b and b –Root has degree between 2 and b B-tree with leaf parameter –O(N/B) space –Height – amortized leaf rebalance operations – amortized internal node rebalance operations B-tree with branching parameter B c, 0<c≤1, and leaf parameter B –Space O(N/B), updates, queries

Lars Arge I/O-algorithms 12 Secondary Structures When secondary structures used, a rebalance on v often require O(w(v)) I/Os (w(v) is weight of v) –If inserts have to be made below v between operations  O(1) amortized split bound  amortized insert bound Nodes in standard B-tree do not have this property In internal memory BB[  ]-trees have the desired property –But rebalanced using rotations

Lars Arge I/O-algorithms 13 Weight-balanced B-tree Idea: Combination of B-tree and BB[  ]-tree –Weight constraint on nodes instead of degree constraint –Rebalancing performed using split/fuse as in B-tree Weight-balanced B-tree with parameters b and k (b>8, k≥8) –All leaves on same level and contain between k/4 and k elements –Internal node v at level l has w(v) < –Except for the root, internal node v at level l has w(v)> –The root has more than one child Internal node degree between and level l-1 level l

Lars Arge I/O-algorithms 14 Weight-balanced B-tree Insert Search for relevant leaf u and insert new element Traverse path from u to root: –If level l node v now has w(v)=b l k+1 then split into nodes v’ and v’’ with and Algorithm correct since such that and –touch nodes Weight-balance property: – updates below v’ and v’’ before next rebalance operation

Lars Arge I/O-algorithms 15 Weight-balanced B-tree Delete Search for relevant leaf u and delete element Traverse path from u to root: –If level l node v now has then fuse with sibling into node v’ with –If now then split into nodes with weight and Algorithm correct and touch nodes Weight-balance property: – updates below v’ and v’’ before next rebalance operation

Lars Arge I/O-algorithms 16 Summary/Conclusion: Weight-balanced B-tree Weight-balanced B-tree with branching parameter b and leaf parameter k=Ω(B) –O(N/B) space –Height – rebalancing operations after update –Ω(w(v)) updates below v between consecutive operations on v Weight-balanced B-tree with branching parameter B c and leaf parameter B –Updates in and queries in I/Os Construction bottom-up in I/O

Lars Arge I/O-algorithms 17 Persistent B-tree In some applications we are interested in being able to access previous versions of data structure –Databases –Geometric data structures (later) Partial persistence: –Update current version (getting new version) –Query all versions We would like to have partial persistent B-tree with –O(N/B) space – N is number of updates performed – update – query in any version

Lars Arge I/O-algorithms 18 Persistent B-tree Easy way to make B-tree partial persistent –Copy structure at each operation –Maintain “version-access” structure (B-tree) Good query in any version, but –O(N/B) I/O update –O(N 2 /B) space i i+2 i+1 update i+3 i i+2 i+1

Lars Arge I/O-algorithms 19 Persistent B-tree Idea: Elements augmented with “existence interval” and stored in one structure Persistent B-tree with parameter b (>16): –Directed graph *Nodes contain elements augmented with existence interval *At any time t, nodes with elements alive at time t form B-tree with leaf and branching parameter b –B-tree with leaf and branching parameter b on indegree 0 node  If b=B: –Query at any time t in I/Os

Lars Arge I/O-algorithms 20 Persistent B-tree: Updates Updates performed as in B-tree To obtain linear space we maintain new-node invariant: –New node contains between and alive elements and no dead elements

Lars Arge I/O-algorithms 21 Persistent B-tree Insert Search for relevant leaf u and insert new element If u contains B+1 elements: Block overflow –Version split: Mark u dead and create new node u’ with x alive element –If : Strong overflow –If : Strong underflow –If then recursively update parent(l): Delete reference to u and insert reference to u’

Lars Arge I/O-algorithms 22 Persistent B-tree Insert Strong overflow ( ) –Split v into u’ and u’’ with elements each ( ) –Recursively update parent(u): Delete reference to l and insert reference to v’ and v’’ Strong underflow ( ) –Merge x elements with y live elements obtained by version split on sibling ( ) –If then (strong overflow) perform split into nodes with (x+y)/2 elements each ( ) –Recursively update parent(u): Delete two insert one/two references

Lars Arge I/O-algorithms 23 Persistent B-tree Delete Search for relevant leaf u and mark element dead If u contains alive elements: Block underflow –Version split: Mark u dead and create new node u’ with x alive element –Strong underflow ( ): Merge (version split) and possibly split (strong overflow) –Recursively update parent(u): Delete two references insert one or two references

Lars Arge I/O-algorithms 24 Persistent B-tree Insert Delete done Block overflow Block underflow done Version split Strong overflow Strong underflow MergeSplit done Strong overflow Split done -1,+1 -1,+2 -2,+2 -2,+1 0,0

Lars Arge I/O-algorithms 25 Persistent B-tree Analysis Update: –Search and “rebalance” on one root-leaf path Space: O(N/B) –At least updates in leaf in existence interval –When leaf u dies *At most two other nodes are created *At most one block over/underflow one level up (in parent(l))  –During N updates we create: * leaves * nodes i levels up  blocks

Lars Arge I/O-algorithms 26 Summary/Conclusion: Persistent B-tree Persistent B-tree –Update current version –Query all versions Efficient implementation obtained using existence intervals –Standard technique  During N operations –O(N/B) space – update – query

Lars Arge I/O-algorithms 27 Other B-tree Variants Level-balanced B-trees –Global instead of local balancing strategy –Whole subtrees rebuilt when too many nodes on a level –Used when parent pointers and divide/merge operations needed String B-trees –Used to maintain and search (variable length) strings

Lars Arge I/O-algorithms 28 B-tree Construction In internal memory we can sort N elements in O(N log N) time using a balanced search tree: –Insert all elements one-by-one (construct tree) –Output in sorted order using in-order traversal Same algorithm using B-tree use I/Os –A factor of non-optimal As discussed we could build B-tree bottom-up in I/Os –But what about persistent B-tree? –In general we would like to have dynamic data structure to use in algorithms  I/O operations

Lars Arge I/O-algorithms 29 Main idea: Logically group nodes together and add buffers –Insertions done in a “lazy” way – elements inserted in buffers –When a buffer runs full elements are pushed one level down –Buffer-emptying in O(M/B) I/Os  every block touched constant number of times on each level  inserting N elements (N/B blocks) costs I/Os Buffer-tree Technique B B M elements fan-out M/B

Lars Arge I/O-algorithms 30 Definition: –B-tree with branching parameter and leaf parameter B –Size M buffer in each internal node Updates: –Add time-stamp to insert/delete element –Collect B elements in memory before inserting in root buffer –Perform buffer-emptying when buffer runs full Basic Buffer-tree $m$ blocks M B

Lars Arge I/O-algorithms 31 Basic Buffer-tree Note: –Buffer can be larger than M during recursive buffer-emptying *Elements distributed in sorted order  at most M elements in buffer unsorted –Rebalancing needed when “leaf-node” buffer emptied *Leaf-node buffer-emptying only performed after all full internal node buffers are emptied $m$ blocks M B

Lars Arge I/O-algorithms 32 Basic Buffer-tree Internal node buffer-empty: –Load first M (unsorted) elements into memory and sort them –Merge elements in memory with rest of (already sorted) elements –Scan through sorted list while *Removing “matching” insert/deletes *Distribute elements to child buffers –Recursively empty full child buffers Emptying buffer of size X takes O(X/B+M/B)=O(X/B) I/Os $m$ blocks M

Lars Arge I/O-algorithms 33 Basic Buffer-tree Buffer-empty of leaf node with K elements in leaves –Sort buffer as previously –Merge buffer elements with elements in leaves –Remove “matching” insert/deletes obtaining K’ elements –If K’<K then *Add K-K’ “dummy” elements and insert in “dummy” leaves Otherwise *Place K elements in leaves *Repeatedly insert block of elements in leaves and rebalance Delete dummy leaves and rebalance when all full buffers emptied K

Lars Arge I/O-algorithms 34 Basic Buffer-tree Invariant: Buffers of nodes on path from root to emptied leaf-node are empty  Insert rebalancing (splits) performed as in normal B-tree Delete rebalancing: v’ buffer emptied before fuse of v –Necessary buffer emptyings performed before next dummy- block delete –Invariant maintained v v v’ v v’’

Lars Arge I/O-algorithms 35 Basic Buffer-tree Analysis: –Not counting rebalancing, a buffer-emptying of node with X ≥ M elements (full) takes O(X/B) I/Os  total full node emptying cost I/Os –Delete rebalancing buffer-emptying (non-full) takes O(M/B) I/Os  cost of one split/fuse O(M/B) I/Os –During N updates *O(N/B) leaf split/fuse * internal node split/fuse  Total cost of N operations: I/Os

Lars Arge I/O-algorithms 36 Basic Buffer-tree Emptying all buffers after N insertions: Perform buffer-emptying on all nodes in BFS-order  resulting full-buffer emptyings cost I/Os empty non-full buffers using O(M/B)  O(N/B) I/Os  N elements can be sorted using buffer tree in I/Os $m$ blocks M B

Lars Arge I/O-algorithms 37 Batching of operations on B-tree using M-sized buffers – I/O updates amortized –All buffers emptied in I/Os One-dim. rangesearch operations can also be supported in I/Os amortized –Search elements handle lazily like updates –All elements in relevant sub-trees reported during buffer-emptying –Buffer-emptying in O(X/B+T’/B), where T’ is reported elements Using buffer technique persistent B-tree built in I/O Summary/Conclusion: Buffer-tree $m$ blocks

Lars Arge I/O-algorithms 38 Basic buffer tree can be used in external priority queue To delete minimal element: –Empty all buffers on leftmost path –Delete elements in leftmost leaf and keep in memory –Deletion of next M minimal elements free –Inserted elements checked against minimal elements in memory I/Os every O(M) delete  amortized Buffered Priority Queue B

Lars Arge I/O-algorithms 39 Other External Priority Queues Buffer technique can be used on other priority queue structures –Heap –Tournament tree Priority queue supporting update often used in graph algorithms – on tournament tree –Major open problem to do it in I/Os Worst case efficient priority queue has also been developed –B operations require I/Os

Lars Arge I/O-algorithms 40 Other Buffer-tree Technique Results Attaching  (B) size buffers to normal B-tree can also be use to improve update bound Buffered segment tree –Has been used in batched range searching and rectangle intersection algorithm Has been used on String B-tree to obtain I/O-efficient string sorting algorithms

Lars Arge I/O-algorithms 41 Summary/Conclusions: Fund. Data Structures B-tree –O(N/B) space, O(log B N) update, O(log B N+T/B) query Weight-balanced B-tree –Ω(w(v)) updates below v between consecutive operations on v Persistent B-tree –Query in any previous version Buffer tree –Batching of operations to obtain bounds

Lars Arge I/O-algorithms 42 References External Memory Geometric Data Structures Lecture notes by Lars Arge. –Section 4-5