Evaluation of Relational Operations: Other Techniques

Similar documents
Evaluation of Relational Operations: Other Techniques

Evaluation of Relational Operations: Other Techniques

Implementation of Relational Operations: Other Operations

Evaluation of Relational Operations

Evaluation of relational operations

Evaluation of Relational Operations

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

Overview of Query Evaluation. Chapter 12

Evaluation of Relational Operations: Other Techniques. Chapter 14 Sayyed Nezhadi

Implementation of Relational Operations. Introduction. CS 186, Fall 2002, Lecture 19 R&G - Chapter 12

CAS CS 460/660 Introduction to Database Systems. Query Evaluation II 1.1

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

CS 4604: Introduction to Database Management Systems. B. Aditya Prakash Lecture #10: Query Processing

Database Applications (15-415)

15-415/615 Faloutsos 1

Database Applications (15-415)

Evaluation of Relational Operations. Relational Operations

CompSci 516 Data Intensive Computing Systems

Overview of Query Evaluation. Overview of Query Evaluation

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

ECS 165B: Database System Implementa6on Lecture 7

Overview of Query Evaluation

CSIT5300: Advanced Database Systems

Implementation of Relational Operations

Administriva. CS 133: Databases. General Themes. Goals for Today. Fall 2018 Lec 11 10/11 Query Evaluation Prof. Beth Trushkowsky

RELATIONAL OPERATORS #1

Overview of Implementing Relational Operators and Query Evaluation

Principles of Data Management. Lecture #9 (Query Processing Overview)

CS330. Query Processing

QUERY EXECUTION: How to Implement Relational Operations?

Evaluation of Relational Operations

Database Systems. Announcement. December 13/14, 2006 Lecture #10. Assignment #4 is due next week.

Overview of Query Processing. Evaluation of Relational Operations. Why Sort? Outline. Two-Way External Merge Sort. 2-Way Sort: Requires 3 Buffer Pages

Cost-based Query Sub-System. Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications. Last Class.

Midterm Review CS634. Slides based on Database Management Systems 3 rd ed, Ramakrishnan and Gehrke

R & G Chapter 13. Implementation of single Relational Operations Choices depend on indexes, memory, stats, Joins Blocked nested loops:

Advances in Data Management Query Processing and Query Optimisation A.Poulovassilis

Query Processing: The Basics. External Sorting

Implementing Joins 1

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

Introduction to Data Management. Lecture 14 (SQL: the Saga Continues...)

External Sorting Implementing Relational Operators

Schema for Examples. Query Optimization. Alternative Plans 1 (No Indexes) Motivating Example. Alternative Plans 2 With Indexes

Database Applications (15-415)

Query Optimization. Schema for Examples. Motivating Example. Similar to old schema; rname added for variations. Reserves: Sailors:

Query Optimization. Schema for Examples. Motivating Example. Similar to old schema; rname added for variations. Reserves: Sailors:

Overview of Query Evaluation

CompSci 516 Data Intensive Computing Systems. Lecture 11. Query Optimization. Instructor: Sudeepa Roy

Overview of DB & IR. ICS 624 Spring Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa

Relational Query Optimization. Highlights of System R Optimizer

Database Management System

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

Examples of Physical Query Plan Alternatives. Selected Material from Chapters 12, 14 and 15

Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications. Administrivia. Administrivia. Faloutsos/Pavlo CMU /615

Spring 2017 QUERY PROCESSING [JOINS, SET OPERATIONS, AND AGGREGATES] 2/19/17 CS 564: Database Management Systems; (c) Jignesh M.

192 Chapter 14. TotalCost=3 (1, , 000) = 6, 000

Evaluation of Relational Operations. SS Chung

ATYPICAL RELATIONAL QUERY OPTIMIZER

Chapter 12: Query Processing. Chapter 12: Query Processing

TotalCost = 3 (1, , 000) = 6, 000

Query Evaluation Overview, cont.

Relational Query Optimization

Relational Algebra. Chapter 4, Part A. Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1

Final Exam Review. Kathleen Durant CS 3200 Northeastern University Lecture 22

Relational Query Optimization. Overview of Query Evaluation. SQL Refresher. Yanlei Diao UMass Amherst October 23 & 25, 2007

SQL: Queries, Programming, Triggers. Basic SQL Query. Conceptual Evaluation Strategy. Example of Conceptual Evaluation. A Note on Range Variables

CSE 444: Database Internals. Section 4: Query Optimizer

Database Management Systems. Chapter 4. Relational Algebra. Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1

Query Evaluation Overview, cont.

Principles of Data Management. Lecture #12 (Query Optimization I)

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

Lecture 3 SQL - 2. Today s topic. Recap: Lecture 2. Basic SQL Query. Conceptual Evaluation Strategy 9/3/17. Instructor: Sudeepa Roy

Enterprise Database Systems

Chapter 12: Query Processing

CSE 544 Principles of Database Management Systems

Database System Concepts

Lecture 3 More SQL. Instructor: Sudeepa Roy. CompSci 516: Database Systems

Operator Implementation Wrap-Up Query Optimization

Chapter 13: Query Processing

Relational Query Optimization

CSE 444: Database Internals. Sec2on 4: Query Op2mizer

Sorting a file in RAM. External Sorting. Why Sort? 2-Way Sort of N pages Requires Minimum of 3 Buffers Pass 0: Read a page, sort it, write it.

Database Applications (15-415)

Relational Query Languages. Preliminaries. Formal Relational Query Languages. Example Schema, with table contents. Relational Algebra

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

! 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

Final Exam Review. Kathleen Durant PhD CS 3200 Northeastern University

Relational algebra. Iztok Savnik, FAMNIT. IDB, Algebra

CIS 330: Applied Database Systems

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

Course No: 4411 Database Management Systems Fall 2008 Midterm exam

Overview of Storage and Indexing

CSIT5300: Advanced Database Systems

Relational Algebra. Note: Slides are posted on the class website, protected by a password written on the board

SQL. Chapter 5 FROM WHERE

What happens. 376a. Database Design. Execution strategy. Query conversion. Next. Two types of techniques

SQL: Queries, Constraints, Triggers

Tree-Structured Indexes

7. Query Processing and Optimization

Transcription:

Evaluation of Relational Operations: Other Techniques Chapter 14, Part B Database Management Systems 3ed, R. Ramakrishnan and Johannes Gehrke 1

Using an Index for Selections Cost depends on #qualifying tuples, and clustering. Cost of finding qualifying data entries, plus Cost of retrieving records (could be large w/o clustering). E.g., assuming uniform distribution of names, about 10% of tuples qualify (100 pages, 10000 tuples). With a clustered index, cost is little more than 100 I/Os; if unclustered, upto 10000 I/Os! Important refinement for unclustered indexes: 1. Find qualifying data entries. 2. Sort the rid s of the data records to be retrieved. 3. Fetch rids in order. Database Management Systems 3ed, R. Ramakrishnan and Johannes Gehrke 2

Two Approaches to General Selections First approach: Find the most selective access path, retrieve tuples using it, The, apply any remaining terms that don t match the index: Most selective access path: An index or file scan that we estimate will require the fewest page I/Os. E.g., day<8/9/94 AND bid=5 AND sid=3. A B+ tree index on day can be used; then, bid=5 and sid=3 must be checked for each retrieved tuple. Similarly, a hash index on <bid, sid> could be used; day<8/9/94 must then be checked. Database Management Systems 3ed, R. Ramakrishnan and Johannes Gehrke 3

Intersection of Rids Second approach (if we have 2 or more matching indexes that use Alternatives (2) or (3) for data entries): Get sets of rids of data records using each matching index. Then intersect these sets of rids Retrieve the records and apply any remaining terms. E.g., day<8/9/94 AND bid=5 AND sid=3 If we have a B+ tree index on day and an index on sid, both using Alternative (2), we can: Retrieve rids of records satisfying day<8/9/94 using the first Retrieve rids of recs satisfying sid=3 using the second Intersect Retrieve records and check bid=5. Database Management Systems 3ed, R. Ramakrishnan and Johannes Gehrke 4

The Projection Operation An approach based on sorting: Modify Pass 0 of external sort to eliminate unwanted fields. Tuples in runs are smaller than input tuples (due to eliminated attributes). Modify merging passes to eliminate duplicates. Thus, number of result tuples smaller than input (due to eliminated duplicates). Cost: In Pass 0, read original relation (size M) Write out same number of smaller tuples SELECT DISTINCT R.sid, R.bid FROM Reserves R In merging passes, fewer tuples written out in each pass. E.g., using Reserves example, 1000 input pages reduced to 250 in Pass 0 if size ratio is 0.25 Database Management Systems 3ed, R. Ramakrishnan and Johannes Gehrke 5

Projection Based on Hashing Partitioning phase: Read R using one input buffer. For each tuple, discard unwanted fields, apply hash function h1 to choose one of B-1 output buffers. Result is B-1 partitions (of tuples with no unwanted fields). 2 tuples from different partitions guaranteed to be distinct. Duplicate elimination phase: For each partition, read it and build an in-memory hash table, using hash fn h2 (<> h1) on all fields, while discarding duplicates. Cost: For partitioning, read R, write out each tuple, but with fewer fields. This is read in next phase. Database Management Systems 3ed, R. Ramakrishnan and Johannes Gehrke 6

Discussion of Projection Sort-based approach is the standard; better handling of skew and result is sorted. If an index on the relation contains all wanted attributes in its search key, can do index-only scan. Apply projection techniques to data entries (much smaller!) If an ordered (i.e., tree) index contains all wanted attributes as prefix of search key, can do even better: Retrieve data entries in order (index-only scan), discard unwanted fields, compare adjacent tuples to check for duplicates. Database Management Systems 3ed, R. Ramakrishnan and Johannes Gehrke 7

Set Operations Intersection and cross-product special cases of join. Union (Distinct) and Except are similar Sorting based approach to union: Sort both relations (on combination of all attributes). Scan sorted relations and merge them. Hash based approach to union: Partition R and S using hash function h. For each S-partition, build in-memory hash table (using h2), scan corr. R-partition and add tuples to table while discarding duplicates. Database Management Systems 3ed, R. Ramakrishnan and Johannes Gehrke 8

Aggregate Operations (AVG, MIN, etc.) Without grouping: In general, requires scanning the relation. Given index whose search key includes all attributes in the SELECT or WHERE clauses, can do index-only scan. With grouping: Two Approaches: Sort on group-by attributes, then scan relation and compute aggregate for each group. Hashing on group-by attributes. When can we do aggregation with group-by using an index-only plan? Database Management Systems 3ed, R. Ramakrishnan and Johannes Gehrke 9

Summary A virtue of relational DBMSs: queries are composed of a few basic operators; the implementation of these operators can be carefully tuned (and it is important to do this!). Many alternative implementation techniques for each operator; no universally superior technique for most operators. Must consider available alternatives for each operation in a query and choose best one based on system statistics, etc. This is part of the broader task of optimizing a query composed of several ops. Database Management Systems 3ed, R. Ramakrishnan and Johannes Gehrke 10