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

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

Review. Relational Query Optimization. Query Optimization Overview (cont) Query Optimization Overview. Cost-based Query Sub-System

Overview of Implementing Relational Operators and Query Evaluation

Relational Query Optimization

CS330. Query Processing

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

Overview of Query Evaluation. Overview of Query Evaluation

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

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

Query Processing and Query Optimization. Prof Monika Shah

Overview of Query Evaluation

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

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

Administrivia. CS 133: Databases. Cost-based Query Sub-System. Goals for Today. Midterm on Thursday 10/18. Assignments

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

Relational Query Optimization. Highlights of System R Optimizer

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

Query Evaluation Overview, cont.

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

Query Evaluation Overview, cont.

Implementation of Relational Operations

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

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

Administrivia. Relational Query Optimization (this time we really mean it) Review: Query Optimization. Overview: Query Optimization

QUERY OPTIMIZATION E Jayant Haritsa Computer Science and Automation Indian Institute of Science. JAN 2014 Slide 1 QUERY OPTIMIZATION

Relational Query Optimization. Overview of Query Evaluation. SQL Refresher. Yanlei Diao UMass Amherst March 8 and 13, 2007

Evaluation of Relational Operations

Evaluation of Relational Operations. Relational Operations

An SQL query is parsed into a collection of query blocks optimize one block at a time. Nested blocks are usually treated as calls to a subroutine

Evaluation of relational operations

External Sorting Implementing Relational Operators

CompSci 516 Data Intensive Computing Systems

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

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

Overview of Query Evaluation. Chapter 12

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

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

ECS 165B: Database System Implementa6on Lecture 7

15-415/615 Faloutsos 1

Query Evaluation (i)

Query Evaluation! References:! q [RG-3ed] Chapter 12, 13, 14, 15! q [SKS-6ed] Chapter 12, 13!

Overview of Query Processing

Evaluation of Relational Operations

Database Applications (15-415)

Implementation of Relational Operations: Other Operations

Evaluation of Relational Operations

Operator Implementation Wrap-Up Query Optimization

Database Applications (15-415)

Database Applications (15-415)

Database Applications (15-415)

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

Query Processing and Optimization

QUERY OPTIMIZATION [CH 15]

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

Evaluation of Relational Operations. SS Chung

CSIT5300: Advanced Database Systems

Overview of Query Evaluation

CSIT5300: Advanced Database Systems

Implementing Joins 1

Database Applications (15-415)

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

ATYPICAL RELATIONAL QUERY OPTIMIZER

Evaluation of Relational Operations: Other Techniques

CS330. Some Logistics. Three Topics. Indexing, Query Processing, and Transactions. Next two homework assignments out today Extra lab session:

Evaluation of Relational Operations: Other Techniques

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

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

Query Optimization in Relational Database Systems

Evaluation of Relational Operations: Other Techniques

DBMS Query evaluation

Relational Query Optimization

CSE 444: Database Internals. Section 4: Query Optimizer

Lassonde School of Engineering Winter 2016 Term Course No: 4411 Database Management Systems

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

Query Optimization. Query Optimization. Optimization considerations. Example. Interaction of algorithm choice and tree arrangement.

Hash-Based Indexing 165

IMPORTANT: Circle the last two letters of your class account:

CSE 444: Database Internals. Sec2on 4: Query Op2mizer

Query Optimization. Kyuseok Shim. KDD Laboratory Seoul National University. Query Optimization

Chapter 12: Query Processing

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

Dtb Database Systems. Announcement

System R Optimization (contd.)

Database Management System

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

Principles of Data Management. Lecture #13 (Query Optimization II)

Chapter 12: Query Processing

Query and Join Op/miza/on 11/5

Administrivia# CS#133:#Databases# CostXbased#Query#SubXSystem# Goals#for#Today# Lab#3#starts#next#week# No#problem#set#out#this#week#

Module 9: Query Optimization

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

CSIT5300: Advanced Database Systems

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

Συστήματα Διαχείρισης Βάσεων Δεδομένων

CPSC 421 Database Management Systems. Lecture 19: Physical Database Design Concurrency Control and Recovery

Database System Concepts

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

Query Processing & Optimization

EECS 647: Introduction to Database Systems

Introduction to Query Processing and Query Optimization Techniques. Copyright 2011 Ramez Elmasri and Shamkant Navathe

Transcription:

Relational Query Optimization R & G Chapter 13 Review Implementation of single Relational Operations Choices depend on indexes, memory, stats, Joins Blocked nested loops: simple, exploits extra memory Indexed nested loops: best if 1 rel small and one indexed Sort/Merge Join good with small amount of memory, bad with duplicates Hash Join fast (enough memory), bad with skewed data

Query Optimization Overview Query can be converted to relational algebra Rel. Algebra converted to tree, joins as branches Each operator has implementation choices Operators can also be applied in different order! SELECT S. FROM R, S WHERE R.sid=S.sid AND R.bid=100 AND S.rating>5 π () σ (bid=100 rating > 5) ( >< ) Query Optimization Overview (cont) Plan: Tree of R.A. ops, with choice of algorithm for each op. Each operator typically implemented using a `pull interface: when an operator is `pulled for the next output tuples, it `pulls on its inputs and computes them. Two main issues: For a given query, what plans are considered? Algorithm to search plan space for cheapest (estimated) plan. How is the cost of a plan estimated? Ideally: Want to find best plan. Reality: Avoid worst plans!

Query Sub-System Architecture Query Parser Query Optimizer Plan Generator Plan Cost Estimator Catalog Manager Query Plan Evaluator Schema for Examples (sid: integer, : string, rating: integer, age: real) (sid: integer, bid: integer, day: dates, rname: string) As seen in previous two lectures : Each tuple is 40 bytes long, 100 tuples per page, 1000 pages. : Each tuple is 50 bytes long, 80 tuples per page, 500 pages.

Motivating Example SELECT S. FROM R, S WHERE R.sid=S.sid AND R.bid=100 AND S.rating>5 RA Tree: Motivating Example Cost: 500+500*1000 I/Os By no means the worst plan! SELECT S. FROM R, S WHERE R.sid=S.sid AND R.bid=100 AND S.rating>5 Misses several opportunities: selections could have been `pushed earlier, no use is made of any available indexes, etc. Goal of optimization: To find more efficient plans that compute the same answer. Plan: (Simple Nested loops)

Alternative Plans 1 (No Indexes) Main difference: push selects. With 5 buffers, cost of plan: (Scan; write to temp T1) bid=100 Scan (1000) + write temp T1 (10 pages, if we have 100 boats, uniform distribution). Scan (500) + write temp T2 (250 pages, if have 10 ratings). Sort T1 (2*2*10), sort T2 (2*3*250), merge (10+250) (Sort-Merge Join) (Scan; rating > 5 write to temp T2) Total: 3560 page I/Os. If use BNL join, join = 10+4*250, total cost = 2770. Can also `push projections, but must be careful! T1 has only sid, T2 only sid, : T1 fits in 3 pgs, cost of BNL under 250 pgs, total < 2000. Alt Plan 2: Indexes, Pipelining With clustered index on bid of, we get 100,000/100 = 1000 tuples on 1000/100 = 10 pages. INL with pipelining (outer is not materialized). Projecting out unnecessary fields from outer doesn t help. Join column sid is a key for. At most one matching tuple, unclustered index on sid OK. Decision not to push rating>5 before the join is based on availability of sid index on. (Use hash index; do bid=100 not write result to temp) rating > 5 (Index Nested Loops, with pipelining ) Cost: Selection of tuples (10 I/Os); then, for each, must get matching tuple (1000*1.2); total 1210 I/Os.

What is needed for optimization? Iterator Interface Cost Estimation Statistics and Catalogs Size Estimation and Reduction Factors Iterator Interface A note on implementation: Relational operators at nodes support uniform iterator interface: Open( ), get_next( ), close( ) Alternative if pipelining (i.e. a push -based approach. Can combine using special operators.

Summary Query optimization is an important task in a relational DBMS. Must understand optimization in order to understand the performance impact of a given database design (relations, indexes) on a workload (set of queries). Two parts to optimizing a query: Consider a set of alternative plans. Must prune search space; typically, left-deep plans only. Must estimate cost of each plan that is considered. Must estimate size of result and cost for each plan node. Key issues: Statistics, indexes, operator implementations.