Overview of File Organizations and Indexing Jianlin Feng School of Software SUN YAT-SEN UNIVERSITY courtesy of Joe Hellerstein for some slides.

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
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,
Tree-Structured Indexes
Introduction to Database Systems1 Records and Files Storage Technology: Topic 3.
Indexes and B-Trees Lecture 9 R & G Chapters 8 & 9
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.
File Organizations and Indexing Lecture 5 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 (part 1)
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 Lecture 4 R&G Chapter 8 "If you don't find it in the index, look very carefully through the entire catalogue." -- Sears,
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,
1 v es/SIGMOD98.asp.
Murali Mani Overview of Storage and Indexing (based on slides from Wisconsin)
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.1 CAS CS 460/660 Introduction to Database Systems File Organization Slides from UC Berkeley.
1 Overview of Storage and Indexing Chapter 8 1. Basics about file management 2. Introduction to indexing 3. First glimpse at indices and workloads.
DBMS Internals: Storage February 27th, Representing Data Elements Relational database elements: A tuple is represented as a record CREATE TABLE.
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.
Indexing - revisited CS 186, Fall 2012 R & G Chapter 8.
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.
1 Overview of Storage and Indexing Chapter 8 (part 1)
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 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.
File Organizations and Indexing
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.
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.
CS 405G: Introduction to Database Systems Instructor: Jinze Liu Fall 2007.
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
Record Storage, File Organization, and Indexes
CS222P: Principles of Data Management Notes #6 Index Overview and ISAM Tree Index Instructor: Chen Li.
Lecture 12 Lecture 12: Indexing.
Introduction to Database Systems File Organization and Indexing
Overview of Storage and Indexing
CS222: Principles of Data Management Notes #09 Indexing Performance
File Organizations and Indexing
File Organizations and Indexing
Overview of Storage and Indexing
CS222P: Principles of Data Management Notes #09 Indexing Performance
Overview of Storage and Indexing
CS222/CS122C: Principles of Data Management Lecture #4 Catalogs, File Organizations Instructor: Chen Li.
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
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 #08 Comparisons of Indexes and Indexing Performance Instructor: Chen Li.
CS222P: Principles of Data Management UCI, Fall 2018 Notes #04 Schema versioning and File organizations Instructor: Chen Li.
Presentation transcript:

Overview of File Organizations and Indexing Jianlin Feng School of Software SUN YAT-SEN UNIVERSITY courtesy of Joe Hellerstein for some slides

Context Query Optimization and Execution Relational Operators Files and Access Methods Buffer Management Disk Space Management DB

Goal for Today Big picture of overheads for data access  We’ll simplify things to get focused  Still, a bit of discipline: Clearly identify assumptions Then estimate cost in a principled way Foundation for query optimization  Can’t choose the fastest scheme without an estimate of speed!

Alternative File Organizations Many alternatives exist, each good for some situations, and not so good in others:  Heap files: Suitable when typical access is a file scan retrieving all records.  Sorted Files: Best for retrieval in search key order, or only a “range” of records is needed.  Clustered Files (with Indexes): Coming soon…

Cost Model for Analysis B: The number of data blocks R: Number of records per block D: (Average) time to read or write disk block Average-case analyses for uniform random workloads We will ignore:  Sequential vs. Random I/O  Pre-fetching  Any in-memory costs * Good enough to show the overall trends!

More Assumptions Single record insert and delete. Equality selection  exactly one match For Heap Files:  Insert always appends to end of file. For Sorted Files:  Files compacted after deletions.  Selections on search key.

Cost of Operations B: The number of data pages R: Number of records per page D: (Average) time to read or write disk page Heap FileSorted FileClustered File Scan all records Equality Search Range Search Insert Delete

Cost of Operations B: The number of data pages R: Number of records per page D: (Average) time to read or write disk page Heap FileSorted FileClustered File Scan all records BD Equality Search Range Search Insert Delete

Cost of Operations B: The number of data pages R: Number of records per page D: (Average) time to read or write disk page Heap FileSorted FileClustered File Scan all records BD Equality Search 0.5 BD(log 2 B) * D Range Search Insert Delete

Cost of Operations B: The number of data pages R: Number of records per page D: (Average) time to read or write disk page Heap FileSorted FileClustered File Scan all records BD Equality Search 0.5 BD(log 2 B) * D Range Search BD[(log 2 B) + #match pg]*D Insert Delete

Cost of Operations B: The number of data pages R: Number of records per page D: (Average) time to read or write disk page Heap FileSorted FileClustered File Scan all records BD Equality Search 0.5 BD(log 2 B) * D Range Search BD[(log 2 B) + #match pg]*D Insert 2D((log 2 B)+B)D Delete

Cost of Operations B: The number of data pages R: Number of records per page D: (Average) time to read or write disk page Heap FileSorted FileClustered File Scan all records BD Equality Search 0.5 BD(log 2 B) * D Range Search BD[(log 2 B) + #match pg]*D Insert 2D((log 2 B)+B)D Delete 0.5BD + D((log 2 B)+B)D

Indexes Allow record retrieval by value in one or more fields  Find all students in the “CS” department  Find all students with a gpa > 3 Index : disk-based data structure for fast lookup by value  Search key: any subset of columns in the relation.  Search key need not be a key of the relation Can have multiple items matching a lookup Index contains a collection of data entries  Items associated with each search key value k  Data entries come in various forms, as we’ll see

1 st Question to Ask About Indexes What kinds of selections (lookups) do they support?  Selection:  Equality selections (op is =)?  Range selections (op is one of, =, BETWEEN)?  More exotic selections? 2-dimensional ranges (“east of Berkeley and west of Truckee and North of Fresno and South of Eureka”)  Or n-dimensional 2-dimensional radii (“within 2 miles of Soda Hall”)  Or n-dimensional Ranking queries (“10 restaurants closest to Berkeley”) Regular expression matches, genome string matches, etc. One common n-dimensional index: R-tree

Index Breakdown What selections does the index support Representation of data entries in index  i.e., what kind of info is the index actually storing? 3 alternatives here Clustered vs. Unclustered Indexes Single Key vs. Composite Indexes Tree-based, hash-based, other

Alternatives for Data Entry k* in Index Three alternatives: 1. Actual data record (with key value k) 2., rid: record id 3. Choice is orthogonal to the indexing technique.  B+ trees, hash-based structures, R trees, GiSTs, … Can have multiple (different) indexes per file.  E.g. file sorted by age, with a hash index on salary, and a B+tree index on name.

Alternatives for Data Entries (Contd.) Alternative 1: Actual data record (with key value k)  Index as a file organization for records Alongside Heap files or sorted files  At most one Alternative 1 index per relation  No “pointer lookups” to get data records

Alternatives for Data Entries (Contd.) Alternative 2 and Alternative 3  Must use Alternatives 2 or 3 to support >1 index per relation.  Alternative 3 more compact than Alternative 2, but variable sized data entries even if search keys are of fixed length.  For large rid lists, data entry spans multiple blocks!

Index Classification Clustered vs. Unclustered: Clustered index:  order of data records the same as, or `close to’, order of index data entries  A file can be clustered on at most one search key.  Cost of retrieving data records through index varies greatly based on whether index is clustered or not!  Alternative 1 implies clustered, but not vice-versa. Note: another definition of “clustering”  Data mining, AI, statistics

Clustered vs. Unclustered Index Alternative 2 data entries, data records in a Heap file.  To build clustered index, first sort the Heap file with some free space on each block for future inserts  Overflow blocks may be needed for inserts. Thus, order of data records is `close to’, but not identical to, the sort order. Index entries Data entries direct search for (Index File) (Data file) Data Records data entries Data entries Data Records CLUSTERED UNCLUSTERED

Unclustered vs. Clustered Indexes Clustered Pros  Efficient for range searches  Supports some types of compression More soon  Possible locality benefits Disk scheduling, prefetching, etc. Clustered Cons  More expensive to maintain on the fly or “sloppily” via reorganizations Heap file usually only packed to 2/3 to accommodate inserts

Cost of Operations B: The number of data pages R: Number of records per page D: (Average) time to read or write disk page Heap FileSorted FileClustered File Scan all records BD 1.5 BD Equality Search 0.5 BD(log 2 B) * D(log F 1.5B+1) * D Range Search BD[(log 2 B) + #match pg]*D [(log F 1.5B) + #match pg]*D Insert 2D((log 2 B)+B)D((log F 1.5B)+2) * D Delete 0.5BD + D((log 2 B)+B)D (because R,W 0.5) ((log F 1.5B)+2) * D

Composite Search Keys Search on a combination of fields.  Equality query: Every field value is equal to a constant value. E.g. wrt index: age=20 and sal =75  Range query: Some field value is not a constant. E.g.: age > 20; or age=20 and sal > 10 Data entries in index can be sorted by search key to support range queries.  Lexicographic order  Like the dictionary, but on fields, not letters! sue1375 bob cal joe nameagesal 12,20 12,10 11,80 13,75 20,12 10,12 75,13 80, Data records sorted by name Data entries in index sorted by Data entries sorted by Examples of composite key indexes using lexicographic order.

Summary File Layer manages access to records in pages.  Record and page formats depend on fixed vs. variable-length.  Free space management is an important issue.  Slotted page format supports variable length records and allows records to move on page. 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.

Summary (Contd.) Data entries in index can be one of 3 alternatives: (1) actual data records, (2) pairs, or (3) pairs.  Choice orthogonal to indexing structure (i.e., tree, hash, etc.). Usually 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. Catalog relations store information about relations, indexes and views.