1 Overview of Storage and Indexing Chapter 8 (part 1)

Slides:



Advertisements
Similar presentations
Database Management Systems, R. Ramakrishnan and J. Gehrke1 File Organizations and Indexing Chapter 8 How index-learning turns no student pale Yet holds.
Advertisements

File Organizations and Indexing Chapter 8
Overview of Storage and Indexing
File Organizations and Indexing Lecture 4 R&G Chapter 8 "If you don't find it in the index, look very carefully through the entire catalogue." -- Sears,
Introduction to Database Systems1 Records and Files Storage Technology: Topic 3.
Overview of Storage and Indexing
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Overview of Storage and Indexing Chapter 8 “How index-learning turns no student pale Yet.
1 Overview of Storage and Indexing Chapter 8 (part 1)
Chapter 8 File organization and Indices.
1 File Organizations and Indexing Module 4, Lecture 2 “How index-learning turns no student pale Yet holds the eel of science by the tail.” -- Alexander.
1 Overview of Storage and Indexing Yanlei Diao UMass Amherst Feb 13, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
File Organizations and Indexing R&G Chapter 8 "If you don't find it in the index, look very carefully through the entire catalogue." -- Sears, Roebuck,
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Overview of Storage and Indexing Chapter 8 “How index-learning turns no student pale Yet.
File Organizations and Indexing Lecture 4 R&G Chapter 8 "If you don't find it in the index, look very carefully through the entire catalogue." -- Sears,
1 Overview of Storage and Indexing Chapter 8 1. Basics about file management 2. Introduction to indexing 3. First glimpse at indices and workloads.
Layers of a DBMS Query optimization Execution engine Files and access methods Buffer management Disk space management Query Processor Query execution plan.
Storage and Indexing February 26 th, 2003 Lecture 19.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 File Organizations and Indexing Chapter 8.
Overview of File Organizations and Indexing Jianlin Feng School of Software SUN YAT-SEN UNIVERSITY courtesy of Joe Hellerstein for some slides.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Overview of Storage and Indexing Chapter 8.
File Organizations and Indexing Lecture 4 R&G Chapter 8 "If you don't find it in the index, look very carefully through the entire catalogue." -- Sears,
1 IT420: Database Management and Organization Storage and Indexing 14 April 2006 Adina Crăiniceanu
Database Management Systems, R. Ramakrishnan and J. Gehrke1 File Organizations and Indexing Chapter 8 “How index-learning turns no student pale Yet holds.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Queries, Database Design, Constraint Enforcement Specify Schema + specify constraints.
Storage and Indexing1 Overview of Storage and Indexing.
1 Overview of Storage and Indexing Chapter 8 “How index-learning turns no student pale Yet holds the eel of science by the tail.” -- Alexander Pope ( )
DATABASE MANAGEMENT SYSTEMS TERM B. Tech II/IT II Semester UNIT-VIII PPT SLIDES Text Books: (1) DBMS by Raghu Ramakrishnan (2) DBMS by Sudarshan.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Overview of Storage and Indexing Chapter 8.
1 Overview of Storage and Indexing Chapter 8. 2 Data on External Storage  Disks: Can retrieve random page at fixed cost  But reading several consecutive.
Overview of Storage and Indexing Content based on Chapter 4 Database Management Systems, (Third Edition), by Raghu Ramakrishnan and Johannes Gehrke. McGraw.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Overview of Storage and Indexing Chapter 8 “How index-learning turns no student pale Yet.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Overview of Storage and Indexing Chapter 8 “If you don’t find it in the index, look very.
1 Database Systems ( 資料庫系統 ) October 29/31, 2007 Lecture #6.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Overview of Storage and Indexing Chapter 8.
Storage and Indexing. How do we store efficiently large amounts of data? The appropriate storage depends on what kind of accesses we expect to have to.
Indexing. 421: Database Systems - Index Structures 2 Cost Model for Data Access q Data should be stored such that it can be accessed fast q Evaluation.
Data on External Storage – File Organization and Indexing – Cluster Indexes - Primary and Secondary Indexes – Index data Structures – Hash Based Indexing.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Overview of Storage and Indexing Chapter 8.
1 Clustered vs. Unclustered Index Index entries Data entries direct search for (Index File) (Data file) Data Records data entries Data entries Data Records.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 File Organizations and Indexing Chapter 8 Jianping Fan Dept of Computer Science UNC-Charlotte.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Overview of Storage and Indexing Chapter 8.
1 Overview of Storage and Indexing Chapter 8. 2 Review: Architecture of a DBMS  A typical DBMS has a layered architecture.  The figure does not show.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Overview of Storage and Indexing Chapter 8.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Overview of Storage and Indexing Chapter 8 “If you don’t find it in the index, look very.
CS522 Advanced database Systems Huiping Guo Department of Computer Science California State University, Los Angeles 3. Overview of data storage and indexing.
CS222: Principles of Data Management Lecture #4 Catalogs, Buffer Manager, File Organizations Instructor: Chen Li.
CS522 Advanced database Systems
Pertemuan <<6>> Tempat Penyimpanan Data dan Indeks
Overview of Storage and Indexing
File Organizations Chapter 8 “How index-learning turns no student pale
CS222P: Principles of Data Management Notes #6 Index Overview and ISAM Tree Index Instructor: Chen Li.
Lecture 12 Lecture 12: Indexing.
Overview of Storage and Indexing
File Organizations and Indexing
File Organizations and Indexing
Overview of Storage and Indexing
Overview of Storage and Indexing
CS222/CS122C: Principles of Data Management Lecture #4 Catalogs, File Organizations Instructor: Chen Li.
Overview of Storage and Indexing
Indexing 1.
CS222/CS122C: Principles of Data Management Notes #6 Index Overview and ISAM Tree Index Instructor: Chen Li.
Storage and Indexing.
CS222p: Principles of Data Management Lecture #4 Catalogs, File Organizations Instructor: Chen Li.
General External Merge Sort
Overview of Storage and Indexing
CS222/CS122C: Principles of Data Management UCI, Fall 2018 Notes #05 Index Overview and ISAM Tree Index Instructor: Chen Li.
CS222/CS122C: Principles of Data Management UCI, Fall 2018 Notes #04 Schema versioning and File organizations Instructor: Chen Li.
File Organizations and Indexing
Overview of Storage and Indexing
CS222P: Principles of Data Management UCI, Fall 2018 Notes #04 Schema versioning and File organizations Instructor: Chen Li.
Presentation transcript:

1 Overview of Storage and Indexing Chapter 8 (part 1)

2 Motivation  DBMS stores vast quantities of data  Data is stored on external storage devices and fetched into main memory as needed for processing  Page is unit of information read from or written to disk. (in DBMS, a page may have size 8KB or more).  Data on external storage devices :  Disks: Can retrieve random page at fixed cost But reading several consecutive pages is much cheaper than reading them in random order  Tapes: Can only read pages in sequence Cheaper than disks; used for archival storage  Cost of page I/O dominates cost of typical database operations

3 Structure of a DBMS: Layered Architecture Query Optimization and Execution Relational Operators Files and Access Methods Buffer Management Disk Space Management DB These layers must consider concurrency control and recovery  external storage access  Disk space manager manages persistent data  Buffer manager stages pages from external storage to main memory buffer pool.  File and index layers make calls to buffer manager.

4 Files versus Indices  File organization :  Method of arranging a file of records on external storage.  Record id (rid) is sufficient to physically locate record  Indexes :  Indexes are data structures that allow to find record ids of records with given values in index search key fields

5 File Organizations  Heap (random order) files: Suitable when typical access is a file scan retrieving all records.  Sorted Files: Best if records must be retrieved in some order, or only a `range’ of records is needed.  Indexes: Data structures to organize records to optimize certain kinds of retrieval operations. Speed up searches for a subset of records, based on values in certain (“search key”) fields Updates are much faster than in sorted files.

6 Alternatives for Data Entry k* in Index  Data Entry : Records stored in index file  Given search key value k, provide for efficient retrieval of all data entries k* with value k.  In a data entry k*, alternatives include that we can store:  alternative 1: Full data record with key value k, or  alternative 2:, or  alternative 3:  Choice of above 3 alternative data entries is orthogonal to indexing technique used to locate data entries.  Example indexing techniques: B+ trees, hash-based structures, etc.

7 Alternatives for Data Entries  Alternative 1: Full data record with key value k  Index structure is file organization for data records (instead of a Heap file or sorted file).  At most one index on a given collection of data records can use Alternative 1. Otherwise, data records are duplicated, leading to redundant storage and potential inconsistency.  If data records are very large, this implies size of auxiliary information in index is also large.

8 Alternatives for Data Entries  Alternatives 2 ( ) and 3 ( ):  Data entries typically much smaller than data records.  Comparison:  Both better than Alternative 1 with large data records, especially if search keys are small.  Alternative 3 more compact than Alternative 2, but leads to variable sized data entries even if search keys are of fixed length.

9 Index Classification  Primary vs. secondary index :  If search key contains primary key, then called primary index.  Clustered vs. unclustered index :  If order of data records is the same as, or `close to’, order of data entries, then called clustered index.  Claim : Alternative 1 implies clustered. True ?  Claim : In practice, clustered also implies Alternative 1 (since sorted files are rare).  Observation 1:  A file can be clustered on at most one search key.  Observation 2:  Cost of retrieving data records through index varies greatly based on whether index is clustered or not !!

10 Index Clustered vs Unclustered  Observation 1:  Alternative 1 implies clustered. True ?  Observation 2:  In practice, clustered also implies Alternative 1 (since sorted files are rare).  Observation 3:  A file can be clustered on at most one search key.  Observation 4:  Cost of retrieving data records through index varies greatly based on whether index is clustered or not !!

11 Clustered vs. Unclustered Index Index entries Data entries direct search for (Index File) (Data file) Data Records data entries Data entries Data Records CLUSTERED UNCLUSTERED Suppose Alternative (2) is used for data entries,

12 Clustered vs. Unclustered Index  Use Alternative (2) for data entries  Data records are stored in Heap file.  To build clustered index, first sort the Heap file  Overflow pages may be needed for inserts.  Thus, order of data recs is close to (not identical to) sort order. Index entries Data entries direct search for (Index File) (Data file) Data Records data entries Data entries Data Records CLUSTERED UNCLUSTERED

13 B+ Tree Indexes  Index leaf pages contain data entries, and are chained (prev & next)  Index non-leaf pages have index entries; only used to direct searches: P 0 K 1 P 1 K 2 P 2 K m P m index entry Non-leaf Pages (Sorted by search key) Leaf

14 Example B+ Tree  Find: 29*? 28*? All > 15* and < 30*  Insert/delete: Find data entry in leaf, then change it. 2*3* Root *16* 33*34* 38* 39* 135 7*5*8*22*24* 27 27*29* Entries <= 17Entries > 17 Note how data entries in leaf level are sorted

15 Hash-Based Indexes  Index is a collection of buckets.  Bucket = primary page plus zero or more overflow pages.  Buckets contain data entries.  Hashing function h :  h ( r ) = bucket in which data entry for record r belongs.  h looks at search key fields of r.  No need for “index entries” in this scheme due to one-level index file  Good for equality selections.

16 Cost Model for Our Analysis  Notes:  We ignore CPU costs, for simplicity.  Measuring number of page I/Os ignores gains of pre- fetching a sequence of pages  Thus even I/O cost is only approximated.  Average-case analysis; based on simplistic assumptions. * Good enough to show overall trends!

17 Cost Model for Our Analysis Variables :  B: The number of data pages  R: Number of records per page  D: (Average) time to read or write disk page

18 Comparing File Organizations  Heap files (random order; insert at eof)  Sorted files, sorted on  Clustered B+ tree file, Alternative (1), search key  Heap file with unclustered B + tree index on search key (Alt 2)  Heap file with unclustered hash index on search key (Alt 2)

19 Operations to Compare  Scan: Fetch all records from disk  Equality search  Range selection  Insert a record  Delete a record

20 Assumptions in Our Analysis  Heap Files:  Equality selection on key; exactly one match.  Sorted Files:  Files compacted after deletions.  Indexes:  Alt (2), (3): data entry size = 10% size of record  Hash: No overflow buckets. 80% page occupancy => File size = 1.25 data size  Tree: 67% occupancy (this is typical). Implies file size = 1.5 data size  Scans:  Leaf levels of a tree-index are chained.  Index data-entries plus actual file scanned for unclustered indexes.  Range searches:  We use tree indexes to restrict set of data records fetched, but ignore hash indexes.

21 Cost of Operations * Several assumptions underlie these (rough) estimates!

22 Heap File ScanEqualityRangeInsertDelete BD0.5BDBD2DSearch + D On average scan half the file. Uniform distribution. Record can appear anywhere in the file. Add at the end. Fetch last page + add record + write page back B: The number of data pages R: Number of records per page D: (Average) time to read or write disk page

23 Sorted File ScanEqualityRangeInsertDelete BDDlog 2 BD(log 2 B+# pgs with match records) Search + BD Result is sorted. Equality selection matches the sort order. Binary search. Matching middle of file. Read later half and write. Same with insert. B: The number of data pages R: Number of records per page D: (Average) time to read or write disk page

24 Clustered B+ Tree Files ScanEqualityRangeInsertDelete 1.5BDDlog F 1.5BD(log F 1.5B +#pgs with match records) Search + D Search + one write same B: The number of data pages R: Number of records per page D: (Average) time to read or write disk page (1)Pages in clusered file are 67% occupancy (2)# pages = 1.5B (3)F (fan out)

25 Heap File with UnClustered Tree Index ScanEqualityRangeInsertDelete 0.15BD + RBD D(1+ log F 0.15B) D(log F 0.15B +#pgs with match records) D(3 + log F 0.15B) Search + 2D Read data entry: 0.15BD Fetch the employee record for each data entry in index(unclustered) Insert in heap file 2D Find right leaf page log F 0.15B, add new data entry, write back D B: The number of data pages R: Number of records per page D: (Average) time to read or write disk page (1)Pages in clusered file are 67% occupancy (2)F (fan out) (3)Index is a tenth the size of an employee data record (4)# pages = 0.1(1.5B) = 0.15B

26 Heap File with (UnClustered) Hash Index ScanEqualityRangeInsertDelete 0.125BD + RBD 2DBD4DSearch + 2D Read data entry: 0.15BD Fetch the employee record for each data entry in index(unclustered) Fetch data entry from index file Fetch data record from file Hash structure offers no help Scan entire heap file Insert record into heap file 2D Insert into index page and write back 2D Delete index D Delete data page D B: The number of data pages R: Number of records per page D: (Average) time to read or write disk page (1)Pages in clusered file are 80% occupancy (2)F (fan out) (3)Index is a 10th the size of an employee data record (4)# pages = 0.1(1.25B) = 0.125B

27 Cost of Operations B: The number of data pages R: Number of records per page D: (Average) time to read or write disk page D(3 + log F 0.15B) Search + 2D 4D Search + 2D No one file organization is uniformly superior in all situations !!!

28 Summary  Many alternative file organizations exist, each appropriate in some situation.  If selection queries are frequent, sorting the file or building an index is important.  Hash-based indexes only good for equality search.  Sorted files and tree-based indexes best for range search; also good for equality search.  Files rarely kept sorted in practice; B+ tree index is better.  Index is a collection of data entries plus a way to quickly find entries with given key values.

29 Summary  Data entries can be :  actual data records,  pairs, or  pairs.  Can have several indexes on a given file of data records, each with a different search key.  Indexes can be classified as clustered vs. unclustered,  Differences have important consequences for utility/performance of query processing