Data storage Tree indexes



Similar documents
Physical Data Organization

Previous Lectures. B-Trees. External storage. Two types of memory. B-trees. Main principles

DATABASE DESIGN - 1DL400

Indexing Big Data. Michael A. Bender. ingest data ?????? ??? oy vey

Big Data and Scripting. Part 4: Memory Hierarchies

Binary Heap Algorithms

CSE 326: Data Structures B-Trees and B+ Trees

Lecture 1: Data Storage & Index

From Last Time: Remove (Delete) Operation

External Memory Geometric Data Structures

B-Trees. Algorithms and data structures for external memory as opposed to the main memory B-Trees. B -trees

Unit Storage Structures 1. Storage Structures. Unit 4.3

CSE 326, Data Structures. Sample Final Exam. Problem Max Points Score 1 14 (2x7) 2 18 (3x6) Total 92.

CS 464/564 Introduction to Database Management System Instructor: Abdullah Mueen

In-Memory Databases MemSQL

Storage and File Structure

6. Storage and File Structures

Database Systems. Session 8 Main Theme. Physical Database Design, Query Execution Concepts and Database Programming Techniques

Symbol Tables. Introduction

Outline BST Operations Worst case Average case Balancing AVL Red-black B-trees. Binary Search Trees. Lecturer: Georgy Gimel farb

Overview of Storage and Indexing. Data on External Storage. Alternative File Organizations. Chapter 8

Databases and Information Systems 1 Part 3: Storage Structures and Indices

Chapter 6: Physical Database Design and Performance. Database Development Process. Physical Design Process. Physical Database Design

External Sorting. Why Sort? 2-Way Sort: Requires 3 Buffers. Chapter 13

Overview of Storage and Indexing

Sorting revisited. Build the binary search tree: O(n^2) Traverse the binary tree: O(n) Total: O(n^2) + O(n) = O(n^2)

Data Warehousing und Data Mining

Persistent Data Structures

Operating Systems CSE 410, Spring File Management. Stephen Wagner Michigan State University

root node level: internal node edge leaf node Data Structures & Algorithms McQuain

Storage in Database Systems. CMPSCI 445 Fall 2010

Tables so far. set() get() delete() BST Average O(lg n) O(lg n) O(lg n) Worst O(n) O(n) O(n) RB Tree Average O(lg n) O(lg n) O(lg n)

Chapter 13 File and Database Systems

Chapter 13 File and Database Systems

Data Structures Fibonacci Heaps, Amortized Analysis

File System Management

Persistent Binary Search Trees

COS 318: Operating Systems

CIS 631 Database Management Systems Sample Final Exam

SQL Query Evaluation. Winter Lecture 23

recursion, O(n), linked lists 6/14

Project Group High- performance Flexible File System 2010 / 2011

ICOM 6005 Database Management Systems Design. Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 2 August 23, 2001

6 March Array Implementation of Binary Trees

Binary Heaps. CSE 373 Data Structures

MS SQL Performance (Tuning) Best Practices:

Converting a Number from Decimal to Binary

Cpt S 223. School of EECS, WSU

CHAPTER 17: File Management

Chapter 13. Disk Storage, Basic File Structures, and Hashing

External Sorting. Chapter 13. Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1

Record Storage and Primary File Organization

Comp 5311 Database Management Systems. 16. Review 2 (Physical Level)

Questions 1 through 25 are worth 2 points each. Choose one best answer for each.

DATA STRUCTURES USING C

Chapter 13: Query Processing. Basic Steps in Query Processing

Merkle Hash Trees for Distributed Audit Logs

File Management. Chapter 12

INTRODUCTION The collection of data that makes up a computerized database must be stored physically on some computer storage medium.

Lecture 6: Binary Search Trees CSCI Algorithms I. Andrew Rosenberg

An Evaluation of Self-adjusting Binary Search Tree Techniques

File Management. Chapter 12

Cost Model: Work, Span and Parallelism. 1 The RAM model for sequential computation:

Fast Sequential Summation Algorithms Using Augmented Data Structures

Two Parts. Filesystem Interface. Filesystem design. Interface the user sees. Implementing the interface

- Easy to insert & delete in O(1) time - Don t need to estimate total memory needed. - Hard to search in less than O(n) time

R-trees. R-Trees: A Dynamic Index Structure For Spatial Searching. R-Tree. Invariants

In-memory databases and innovations in Business Intelligence

CS 2112 Spring Instructions. Assignment 3 Data Structures and Web Filtering. 0.1 Grading. 0.2 Partners. 0.3 Restrictions

Review of Hashing: Integer Keys

Quiz! Database Indexes. Index. Quiz! Disc and main memory. Quiz! How costly is this operation (naive solution)?

ProTrack: A Simple Provenance-tracking Filesystem

Chapter 2 Data Storage

Binary Search Trees 3/20/14

Binary Heaps * * * * * * * / / \ / \ / \ / \ / \ * * * * * * * * * * * / / \ / \ / / \ / \ * * * * * * * * * *

Copyright 2007 Ramez Elmasri and Shamkant B. Navathe. Slide 13-1

Chapter 12 File Management

Raima Database Manager Version 14.0 In-memory Database Engine

EFFICIENT EXTERNAL SORTING ON FLASH MEMORY EMBEDDED DEVICES

Physical Database Design Process. Physical Database Design Process. Major Inputs to Physical Database. Components of Physical Database Design

Chapter 13 Disk Storage, Basic File Structures, and Hashing.

Lecture 7: Concurrency control. Rasmus Pagh

B+ Tree Properties B+ Tree Searching B+ Tree Insertion B+ Tree Deletion Static Hashing Extendable Hashing Questions in pass papers

Chapter 8: Structures for Files. Truong Quynh Chi Spring- 2013

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

University of Massachusetts Amherst Department of Computer Science Prof. Yanlei Diao

CS711008Z Algorithm Design and Analysis

Binary Search Trees. Data in each node. Larger than the data in its left child Smaller than the data in its right child

A Comparison of Dictionary Implementations

Big Data Technology Map-Reduce Motivation: Indexing in Search Engines

Chapter 12 File Management

Chapter 12 File Management. Roadmap

Why Use Binary Trees?

Computers. Hardware. The Central Processing Unit (CPU) CMPT 125: Lecture 1: Understanding the Computer

Persistent Data Structures and Planar Point Location

Transcription:

Data storage Tree indexes Rasmus Pagh February 7 lecture 1

Access paths For many database queries and updates, only a small fraction of the data needs to be accessed. Extreme examples are looking or updating the single tuple with a given key value. General question: How do we access the relevant data, and not (much) more? Term.: Need efficient access paths. 2

Choices influencing access paths How are the tuples in the relations arranged? (this lecture) What kinds of indexes exist? (this lecture and later in course) Have we pre-computed (parts of) the information needed? (later in course) 3

Data storage in sequential files Storing meta-data: See textbook. A relation may be stored as a string, concatenating the tuples: (3, Kurt,27),(11, Jim,27),(89, Elvis,42) The tuples may be sorted according to some attribute(s), or unordered. Reading data is very efficient. Problem: How to accommodate changes to data: Insertions, deletions, modifications. 4

From your toolbox: Linked lists Linked (or doubly linked) lists give great flexibility: Insert a new tuple Delete a tuple Change the size of the data in a tuple Problem: One random memory access per item when reading the list. 5

Memory access cost Recall from last week: The speed of the CPU is 2-3 orders of magnitude larger than the speed of a RAM access (non-sequential). The speed of RAM access is 5-6 orders of magnitude faster than disk access (nonsequential). RAM vs disk analogy: Go to Australia to borrow a cup of sugar if your neighbor is not home! 6

Analysis and comparison I/O model, i.e., we count the number of block reads/writes. For now, assume that tuples have fixed length. Let B denote the number of tuples per block, and N total #tuples. Storage method Sequential file Linked list (sorted) Tablescan I/O N/B N Update I/O 2N/B O(1) * * If update location known 7

Aside: Main memory DBMSs It is increasingly common to store all (or all the most frequently accessed parts) in main memory. Still, non-volatile memory (hard drive, flash,...) is needed to provide durability in case of system crashes. Time-space trade-off persists: Slower memories are cheaper, i.e., can be used to store much more data. Also recall that even main memory, like disks, is blocked. 8

Problem session Think of a way of storing sorted relations on disk such that: Reading all data in the relation is efficient (close to the best possible efficiency). Inserting and deleting data is efficient (assume the location of update is known). Do the analysis in the I/O model. As before, assume that tuples have fixed length, and let B denote the number of tuples per block. 9

Amortized analysis Instead of analyzing the worst-case cost of a single operation, amortized analysis looks at the average cost of a sequence of operations. Example: An unordered sequential file must use 1 I/O for some insertions, but can do B insertions in 1 I/O using an internal memory buffer Conclusion: The amortized cost of an insertion is 1/B I/Os. Tiny! Same thing for your proposal? 10

Execise from hand-out Representation of relations Questions a), b), and c). 11

Searching sorted relations Suppose a sequential file of N tuples is sorted by an attribute, A. It can be searched for an A-value using binary search, in log 2 (N/B) I/Os. A (sorted) linked list may require a full traversal to locate an A-value. Storage method Tablescan Update Search Sequential file N/B 2N/B log 2 (N/B) Linked list (blocked) O(N/B) O(1) O(N/B) (sorted) 12

Adding a directory A sorted linked list may be searched more quickly if we have a directory: A sorted list with a representative key from each block (e.g., smallest key). A pointer to the block of each key. But how do we search the directory? Not so important if it fits in RAM. Otherwise, it seems that this problem is the same as the original problem... Is there any progress in this case? (Discussion on board.) 13

Coping with updates Easy solutions: Insertions: If room in the relevant block, ok. Otherwise insert in an overflow chain. (The ISAM solution.) Deletions: Just mark deleted, don t try to reuse space. More robust solution based on the lesson from linked lists: Introduce some slack to allow efficient updates. 14

B + -tree invariants on nodes Suppose a node (stored in a block) has space for B-1 keys and B pointers. Don't want blocks to be too empty: Should be at least half full. Let s see how this works out! (Board.) Only possible with an exception: The root may have as little as 1 key and 2 non-null pointers. 15

B + -tree properties Search and update cost O(depth) I/Os. A B + -tree of depth d holds at least 2 (B/2) d-1 keys Rewriting, this means that d < log B/2 (N/2) = O(log B N) Often the top level(s) will reside in internal memory. Then the operation time becomes O(log B (N/M)). 16

Problem session Argue that B + -trees are optimal in terms of search time among pointer-based indexes: Suppose we want to search among N keys, that internal memory can hold M pointers, and that a disk block can hold B pointers and B keys. Further, suppose that the only way of accessing disk blocks is by following pointers. Show that a search takes at least log B (N/M)=log(N/M)/log B I/Os in the worst case. Hint: Consider the size of the set of blocks that can be accessed in at most t=1,2, I/Os. 17

Aside: Sorting using B + -trees In internal memory, sorting can be done in O(N log N) time by inserting the N keys into a balanced search tree. The number of I/Os for sorting by inserting into a B-tree is O(N log B N). This is more than a factor B slower (!) than multiway mergesort (Feb 28 lecture). Moral: What works well on internal memory may fail miserably on disk. 18

From your toolbox: Search trees You may have seen: AVL-trees, redblack trees, or (2,4)-trees. All have maximum degree 2 or 4, and depth O(log N). How do they compare to B + -trees on external memory? Rough analysis: log(n) = log B (N)log(B) Factor around 5-10 depending mainly on the outdegree of the B + -tree. 19

Buffering in B-trees Relatively new technique to speed up updates in external search trees. Implicit in [Arge 1996] Explicit in [Brodal and Fagerberg 2003] Newer study by [Graefe 2007] We will consider an implementation that is based on constant degree search trees. Main idea: Use buffers to do many things in one I/O. (Board.) 20

Buffering summary Trees with outdegree B and O(1) give: Index B+-tree Buffered B-tree Search I/O O(log B N) O(log N) Update I/O O(log B N) O(log(N)/B) In general, the outdegree is a parameter that can be chosen to trade off search time and update time. (See [BF03] for such a trade-off.) 21

More on B-trees Claim in textbook: Rebalancing on higher levels of a B-tree occurs very rarely. This is true (in particular at the top levels), but a little hard to see. Easier seen for weight-balanced B-trees. Details in [Pagh03]. Just one of many B-tree variants 22

Yet more on B-trees In practice, variable length (possibly long) keys must be handled. Later in course: The String B-tree, an elegant solution that is efficient even for long strings. Space-saving trick: Key compression. See RG for details. Building a B-tree: Repeated insertion is much slower than bulk-loading the sorted list of keys. (Feb. 28) 23

Two types of indexes In a primary index, records are stored in an order determined by the search key. A relation can have at most one primary index. (Often on the primary key.) A secondary index cannot take advantage of any specific order. Must contain all keys and corresponding references to tuples ( dense ). Sometimes, a secondary index provides a faster access path than a primary index! (More about that next week.) 24

Summary We saw the basics of storing and indexing data on external memory. Many trade-offs (soft or hard): Space usage vs update efficiency. Update vs access efficiency. Optimizing for one kind of access may slow down another type of access. We have started thinking and analyzing in terms of I/Os. 25

Execise from hand-out B + -trees Questions a), b), and c). 26