Data on External Storage

Similar documents
Chapter 1: overview of Storage & Indexing, Disks & Files:

Indexing. Chapter 8, 10, 11. Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1

Why Is This Important? Overview of Storage and Indexing. Components of a Disk. Data on External Storage. Accessing a Disk Page. Records on a Disk Page

Overview of Storage and Indexing

Overview of Storage and Indexing

Storage and Indexing

Overview of Storage and Indexing. Data on External Storage

Overview of Storage and Indexing

Modern Database Systems Lecture 1

Overview of Storage and Indexing

CompSci 516: Database Systems

Overview of Storage and Indexing

Announcements. Reading Material. Today. Different File Organizations. Selection of Indexes 9/24/17. CompSci 516: Database Systems

Review: Memory, Disks, & Files. File Organizations and Indexing. Today: File Storage. Alternative File Organizations. Cost Model for Analysis

The use of indexes. Iztok Savnik, FAMNIT. IDB, Indexes

Single Record and Range Search

Review of Storage and Indexing

Announcements. Reading Material. Recap. Today 9/17/17. Storage (contd. from Lecture 6)

Context. File Organizations and Indexing. Cost Model for Analysis. Alternative File Organizations. Some Assumptions in the Analysis.

External Sorting Implementing Relational Operators

INDEXES MICHAEL LIUT DEPARTMENT OF COMPUTING AND SOFTWARE MCMASTER UNIVERSITY

Chapter 12: Query Processing. Chapter 12: Query Processing

Indexes. File Organizations and Indexing. First Question to Ask About Indexes. Index Breakdown. Alternatives for Data Entries (Contd.

CAS CS 460/660 Introduction to Database Systems. File Organization and Indexing

Physical Disk Structure. Physical Data Organization and Indexing. Pages and Blocks. Access Path. I/O Time to Access a Page. Disks.

Overview of Storage and Indexing

Step 4: Choose file organizations and indexes

CS 443 Database Management Systems. Professor: Sina Meraji

Chapter 12: Query Processing

Lecture 8 Index (B+-Tree and Hash)

Readings. Important Decisions on DB Tuning. Index File. ICOM 5016 Introduction to Database Systems

Advanced Database Systems

Overview of Indexing. Chapter 8 Part II. A glimpse at indices and workloads

Query Processing. Debapriyo Majumdar Indian Sta4s4cal Ins4tute Kolkata DBMS PGDBA 2016

Lecture 34 11/30/15. CMPSC431W: Database Management Systems. Instructor: Yu- San Lin

Overview of Storage & Indexing (i)

Introduction to Data Management. Lecture #13 (Indexing)

CSIT5300: Advanced Database Systems

CS542. Algorithms on Secondary Storage Sorting Chapter 13. Professor E. Rundensteiner. Worcester Polytechnic Institute

Systems Infrastructure for Data Science. Web Science Group Uni Freiburg WS 2014/15

Chapter 13: Query Processing

! A relational algebra expression may have many equivalent. ! Cost is generally measured as total elapsed time for

Chapter 13: Query Processing Basic Steps in Query Processing

Introduction to Data Management. Lecture 14 (Storage and Indexing)

Tree-Structured Indexes

Storing Data: Disks and Files

Database design and implementation CMPSCI 645. Lecture 08: Storage and Indexing

Database System Concepts

Lecture 31 11/16/15. CMPSC431W: Database Management Systems. Instructor: Yu- San Lin

CS122A: Introduction to Data Management. Lecture #14: Indexing. Instructor: Chen Li

Physical Design. Elena Baralis, Silvia Chiusano Politecnico di Torino. Phases of database design D B M G. Database Management Systems. Pag.

Database Technology. Topic 7: Data Structures for Databases. Olaf Hartig.

Data Management for Data Science

Friday Nights with Databases!

Review. Support for data retrieval at the physical level:

ACCESS METHODS: FILE ORGANIZATIONS, B+TREE

Overview of Query Evaluation. Chapter 12

CSE 444: Database Internals. Lectures 5-6 Indexing

Announcement. Reading Material. Overview of Query Evaluation. Overview of Query Evaluation. Overview of Query Evaluation 9/26/17

Records in a file are grouped into buckets. Search key values are organized in a tree. The highest level is the root

Disks and Files. Storage Structures Introduction Chapter 8 (3 rd edition) Why Not Store Everything in Main Memory?

Query Processing & Optimization

Kathleen Durant PhD Northeastern University CS Indexes

CPSC 421 Database Management Systems. Lecture 11: Storage and File Organization

Lecture #16 (Physical DB Design)

3.1.1 Cost model Search with equality test (A = const) Scan

Indexing. Week 14, Spring Edited by M. Naci Akkøk, , Contains slides from 8-9. April 2002 by Hector Garcia-Molina, Vera Goebel

Evaluation of Relational Operations: Other Techniques

Implementing Relational Operators: Selection, Projection, Join. Database Management Systems, R. Ramakrishnan and J. Gehrke 1

CSE 562 Database Systems

Indexing Methods. Lecture 9. Storage Requirements of Databases

Disks & Files. Yanlei Diao UMass Amherst. Slides Courtesy of R. Ramakrishnan and J. Gehrke

L9: Storage Manager Physical Data Organization

Project is due on March 11, 2003 Final Examination March 18, pm to 10.30pm

Evaluation of Relational Operations: Other Techniques

Faloutsos 1. Carnegie Mellon Univ. Dept. of Computer Science Database Applications. Outline

Disks, Memories & Buffer Management

Storing Data: Disks and Files. Storing and Retrieving Data. Why Not Store Everything in Main Memory? Chapter 7

Storing and Retrieving Data. Storing Data: Disks and Files. Solution 1: Techniques for making disks faster. Disks. Why Not Store Everything in Tapes?

Hash-Based Indexing 165

Database Applications (15-415)

Storing Data: Disks and Files

Implementation of Relational Operations: Other Operations

Evaluation of Relational Operations: Other Techniques

Storing Data: Disks and Files

Chapter 12: Query Processing

CMPUT 391 Database Management Systems. Query Processing: The Basics. Textbook: Chapter 10. (first edition: Chapter 13) University of Alberta 1

Database Applications (15-415)

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

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

Storing Data: Disks and Files. Storing and Retrieving Data. Why Not Store Everything in Main Memory? Database Management Systems need to:

University of Waterloo Midterm Examination Sample Solution

Lecture 13. Lecture 13: B+ Tree

CSE 544 Principles of Database Management Systems. Magdalena Balazinska Winter 2009 Lecture 6 - Storage and Indexing

Storing and Retrieving Data. Storing Data: Disks and Files. Solution 1: Techniques for making disks faster. Disks. Why Not Store Everything in Tapes?

Database Applications (15-415)

Advanced Databases. Lecture 1- Query Processing. Masood Niazi Torshiz Islamic Azad university- Mashhad Branch

CSIT5300: Advanced Database Systems

Lecture 36 12/4/15. CMPSC431W: Database Management Systems. Instructor: Yu- San Lin

User Perspective. Module III: System Perspective. Module III: Topics Covered. Module III Overview of Storage Structures, QP, and TM

Transcription:

Advanced Topics in DBMS Ch-1: Overview of Storage and Indexing By Syed khutubddin Ahmed Assistant Professor Dept. of MCA Reva Institute of Technology & mgmt. Data on External Storage Prg1 Prg2 Prg3 DBMS stores vast quantities of data, and the data must persist across program executions. Therefore, data is stored on external storage devices such as disks and tapes. And fetched into main memory as needed for processing. 2 1

Page what is a page? Page: The unit of information read from or written to disk is a page. The size of a page is a DBMS parameter, and typical values are 4KB or 8KB. cost of page I/O The cost of page I/O (input from disk to main memory and output from memory to disk) dominates the cost of typical database operations, and database systems are carefully optimized to minimize this cost. 3 Disks: Points to remember Can retrieve random page at fixed cost But reading several consecutive pages is much cheaper than reading them in random order. Tapes (magnetic tapes): Can only read pages in sequence Cheaper than disks, used for archival storage. (Archival storage: data that may not be actively needed) 4 2

Record in a file Points to remember It has a unique identifier called a record id, or rid. Buffer manager: It is a layer of software to read Data into memory for processing, and written in to disk for persistent storage. 5 File organization: Points to remember Method of arranging a file of records on external storage. Record id (rid) is sufficient to physically locate record 6 3

Points to remember Indexes are data structures that allow us to find the record ids of records with given values in index search key fields Disk Space Manager: Manages the space on disks When the files and file Layers needs additional space to hold new records in a file, it asks the disk space manager to allocate 7 Alternative File Organizations Many alternatives exist: 1. Heap (random order) files: Suitable for retrieving all records. 2. Sorted Files: Best if records must be retrieved in some order, or only a `range of records is needed. 8 4

Alternative File Organizations 3. Indexes: A Data structures to organize records via trees or hashing. An index file consists of records (called index entries) of the form Search-key pointer Index files are typically much smaller than the original file Why do we need index? Like sorted files, they speed up searches. Updates are much faster than in sorted files. 9 Points with respect to index: We can also create additional indexes on a given collection of data records, each with a different search key, to speed up search operations. Ex: Indexes We can store the records with an index on employee age. Additionally, we can create an auxiliary index file based on salary, to speed up queries involving salary. 10 5

We use the term data entry to refer to the records stored in an index file. A data entry with search key value k, denoted as k* contains enough information to locate data records with search key value k. We can access data entries in easy manner by arranging the data entries in many alternative ways. 11 Alternatives for Data Entry k* in an Index Three alternatives: 1. Data entry k* is an actual data record (with search key value k) 2. A data entry is a (k, rid) pair, where rid is the record id of a data record with search key k. 3. A data entry is a <k, rid-list> pair, where rid-list is a list of records with search key value k. 12 6

Alternatives for Data Entry k* in Index Alternative 1: Alternative (1) is used for the index that stores actual data records. At most one index on a given collection of data records can use Alternative 1. 13 Alternatives for Data Entry k* in Index Alternative 2 and 3: Data entries typically much smaller than data records. So, better than Alternative 1 with large data records, especially if search keys are small. 14 7

Clustered Indexes if a file is organized based on ordering of data records or close to the ordering of data entries in some index, we say that the index as a clustered index, Otherwise, it is an unclustered index 15 Clustered Indexes 16 8

Clustered Indexes An index that uses Alternative (1) is clustered An index that uses Alternative (2) or (3) can be a clustered index only if the data records are sorted on the search key field. 17 Clustered Indexes 18 9

UNClustered Indexes 19 Clustered indexes in Practice: In practice, files are rarely kept sorted because it is too expensive to maintain when the data is updated. In practice: Clustered Indexes Alternative(1) Clustered index Alternatives (2) or (3) unclustered. 20 10

Clustered Indexes The Cost of using an Index: If the index is clustered, the rids point to a contiguous collection of records If the index is unclustered, rid points to a distinct data page, leading to as many data page l/os. 21 Clustered Indexes 22 11

Clustered Indexes When do we need clustered index: Dept-ID Emp-1 Emp-2 Emp-3 If you want to create an index on a non-unique key, such as Dept-id. There could be several employees in each department. Here we use a clustering index, where all employees belonging to the same Dept- ID are considered 23 Clustered Indexes Types of indexes: Primary index Secondary index Primary index: (an index that uses alternative- 1 is called primary index) Secondary index: (an index that uses alternative-2 & 3 is called secondary index) 24 12

Index Data Structure Two types of Index Data Structures: 1) Hash based Indexing 2) Tree Based Indexing 25 Hash-Based Indexing: used to quickly find records that have a given search key value. Example: if employee records is hashed on the name field, we can retrieve all records about Johny. Here records in a file are grouped in buckets Records from a bucket can be found by using Hash function. 26 13

Hash-Based Indexing: 27 Tree-Based Indexing: The data entries are arranged in sorted order by search key value. and a hierarchical search data structure is maintained. 28 14

Tree Structured index 29 Fan-out (F): Tree based indexing Defn: The average number of children for a non-leaf node is called the fan-out of the tree. If every non-leaf node has n children, a tree of height h has n h leaf pages. In practice, F (fan-out) is at least 100, which means a tree of height four contains 100 million leaf pages. 30 15

Comparison of File Organizations: The files and indexes are organized according to the composite search key (age, sal) and all selection operations are specified on these fields. Compare 31 Different File organizations are: 1. File of randomly ordered employee records, or heap file. 2. File of employee records sorted on (age, sal). 3. Clustered B+ tree file with search key (age, sal). 4. Heap file with an unclustered B+ tree index on (age, sal). 5. Heap file with an unclustered hash index on (age, sal). 32 16

Our goal is to select best file organization We can keep the records unsorted or sort them 33 The operations we consider to organize a file are 1) Scan 2) Search with Equality Selection (=) 3) Search with Range Selection (< or >) 4) Insert a Record 5) Delete a Record 34 17

The operations we consider to organize a file are 1) Scan (Fetch all records in the file) 2) Search with Equality Selection (=) Ex: Find the employee record for the employee with age 23 and sal 50 3) Search with Range Selection (< or >) Find all employee records with age greater than 35 35 The operations we consider to organize a file are 4) Insert a Record identify the page in the file into which the new record must be inserted, fetch that page from disk, modify it to include the new record, and then write back the modified page 5) Delete a Record identify the page that contains the record, fetch it from disk, modify it, and write it back 36 18

Cost Model Why to use cost model? Cost model that allows us to estimate the cost (in terms of execution time) of different database operations We use the following short terms to identify the cost: B number of data pages with no wasted space R number of records per page. D avg time to read or write a disk page C the average time to process a record H time required to apply the hash function to a record. F the fan-out 37 19

Cost Model Typical values today are: D = 15 milliseconds, C and H = 100 nanoseconds 39 Heap Files When do we call a File is a Heap file? Or Heap sort File or Heap sorted Data? What is the Difference between Heap sort arrangement and Binary Search arrachgement 40 20

Heap Files Scan: The cost is B(D +RC) The cost is B(D +RC) because we must retrieve each of B pages taking time D per page, and for each page, process R records taking time C per record. 41 Heap Files Search with Equality Selection: Here the selection is specified on a candidate key. On average, we must scan half the file, assuming that the record exists in the first half, if the record exists in second half then it is the entire scan we did. The cost is O.5B(D + RC). 42 21

Heap Files Search with Range Selection: The entire file must be scanned because qualifying records could appear anywhere in the file, and we do not know how many qualifying records exist. The cost is B(D + RC). 43 Insert: We assume that records are always inserted at the end of the file. We must fetch the last page in the file, add the record, and write the page back. The cost is 2D + C. Heap Files 44 22

Delete: Heap Files We must find the record, remove the record from the page, and write the modified page back. We assume that no attempt is made to compact the file to reclaim the free space created by deletions, for simplicity. The cost is the cost of searching plus C + D. 45 Scan: Sorted Files The cost is B(D +RC) because all pages must be examined. Search with Equality Selection: 1. We assume that the equality selection matches the sort order (age, sal). 2. In other words, we assume that a selection condition is specified on at least the first field in the composite key (e.g., age = 30). 3. If not (e.g., selection sal = 50 or department = "Toy"), the sort order does not help us and the cost is identical to that for a heap file. Cost (log 2 B) if matches 1 and 2 Else it is same as SCAN 46 23

Sorted Files Search with range selection: data pages are sequentially retrieved until a record is found that does not satisfy the range selection; this is similar to an equality search with many qualifying records. Cost cost of search + the cost of retrieving the set of records that satisfy the search Insert B (D + RC) Delete B (D + RC) 47 clustered Files 48 24

Clustered Files Search with Equality Selection: If several records qualify (e.g., "Find all employees aged 18"), they are guaranteed to be adjacent to each other due to the sorting on age, and so the cost of retrieving all such records is the cost of locating the first such record (Dlog p 1.5B + Clog 2 R) plus the cost of reading all the qualifying records in sequential order. 49 Clustered Files Search with Range Selection: Again assuming that the range selection matches the composite key, the first record that satisfies the selection is located as it is for search with equality. Subsequently, data pages are sequentially retrieved (using the next and previous links at the leaf level) until a record is found that does not satisfy the range selection S + number of matching pages S I/O s required for equality search 50 25

Heap File: A heap file has good storage efficiency and supports fast scanning and insertion of records. However, it is slow for searches and deletions. Sorted File: Comparison of I/O Costs A sorted file also offers good storage efficiency. But insertion and deletion of records is slow. Searches are faster than in heap files. It is worth noting that, in a real DBMS, a file is almost never kept fully sorted. 51 Comparison of I/O Costs Clustered File: A clustered file offers all the advantages of a sorted file and supports inserts and deletes efficiently. Searches are even faster than in sorted files, although a sorted file can be faster when a large number of records are retrieved sequentially, because of blocked I/O efficiencies. 52 26

Comparison of I/O Costs Unclustered tree and Hash indexes: Unclustered tree and hash indexes offer fast searches, insertion, and deletion, but scans and range searches with many matches are slow. Hash indexes are a little faster on equality searches, but they do not support range searches. 53 Indexes and Performance Tuning: Clustered Index Organization: Example-1: SELECT E.dno FROM Employee E WHERE E.age > 40 If we have a B+ tree index on age we can satisfy the selection E. age> 40. What if virtually everyone is older than 40. we gain little by using an index on age; a sequential scan of the relation would do almost as well. However, suppose that only 10 percent of the employees are older than 40. Now, the index is useful. 54 27

Indexes and Performance Tuning: Example-2: aggregate operations can influence the choice of indexes: SELECT E.dno, COUNT(*) FROM Employees E GROUP BY E.dno plan -1 sort Employees on dno to compute the count of employees for each dno. Plan -2 an index-hash or B+ tree on dno is available, we can answer this query by scanning only the index. (better plan is plan-2) Note : It does not matter whether the index is clustered because we never retrieve tuples of Employees. 55 Indexes and Performance Tuning: Composite Search Keys: The search key for an index can contain several fields; such keys are called composite search keys or concatenated keys 11,80 11 12,10 12,20 name age sal 12 12 13,75 bob 12 10 13 <age, sal> cal 11 80 <age> joe 12 20 10,12 sue 13 75 10 20,12 75,13 Data records sorted by name 20 75 80,11 80 <sal, age> <sal> 56 28

Performance tuning using Composite Search Keys A Composite Search key in an Equality query: If the search key is composite key it is dependent on a constant in search with Equality query. Example: retrieve all data entries with age = 20 and sal = 10. The hashed file organization supports only equality queries, since a hash function identifies the bucket containing desired records only if a value is specified for each field in the search key. 57 Composite Search Keys Composite Search key in a range query: in a range query not all fields in the search key are bound to constants. Example retrieve all data entries with age >20; this query implies that any value is acceptable for the sal field. As another example of a range query, we can ask to retrieve all data entries with age < 30 and sal > 40. Nate that the index cannot help on the query sal > 40, because, intuitively, the index organizes records by age first and then sal. 58 29

Composite Search Keys Advantages of Using Composite Key: support a broader range of queries because it matches more selection conditions. since data entries in a composite index contain more information about the data record the opportunities for index-only evaluation strategies are increased. 59 Index Specification in SQL: 1999 The SQL: 1999 standard does not include any statement for creating or dropping index structures. In fact, the standard does not even require SQL implementations to support indexes in practice, of course, every commercial relational DBMS supports one or more kinds of indexes. Example to create a B+ tree index: CREATE INDEX IndAgeRating ON Students WITH STRUCTURE = BTREE, KEY = (age, gpa) 61 30