Query Evaluation (i)

Similar documents
Overview of Query Processing

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

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

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

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

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

CS330. Query Processing

Overview of Query Evaluation. Overview of Query Evaluation

Overview of Implementing Relational Operators and Query Evaluation

Overview of Query Evaluation

Relational Query Optimization

Relational Query Optimization. Highlights of System R Optimizer

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

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

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:

Database Applications (15-415)

External Sorting Implementing Relational Operators

Operator Implementation Wrap-Up Query Optimization

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

Database Applications (15-415)

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

Overview of Query Evaluation. Chapter 12

Database Applications (15-415)

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

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

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

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

Evaluation of Relational Operations

15-415/615 Faloutsos 1

Evaluation of relational operations

Implementation of Relational Operations: Other Operations

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

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

SQL: Queries, Constraints, Triggers (iii)

The Database Language SQL (i)

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

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

Query Processing and Optimization

Query Evaluation Overview, cont.

Query Processing and Query Optimization. Prof Monika Shah

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

Course No: 4411 Database Management Systems Fall 2008 Midterm exam

Query Evaluation Overview, cont.

Overview of Query Evaluation

CSIT5300: Advanced Database Systems

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

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

ECS 165B: Database System Implementa6on Lecture 7

Database Applications (15-415)

CompSci 516 Data Intensive Computing Systems

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

Database Applications (15-415)

Implementation of Relational Operations

Evaluation of Relational Operations. Relational Operations

Evaluation of Relational Operations

ATYPICAL RELATIONAL QUERY OPTIMIZER

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

RELATIONAL OPERATORS #1

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

Transactions Processing (i)

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

SQL: Queries, Programming, Triggers

Evaluation of Relational Operations

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

Query Optimization in Relational Database Systems

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

CSE 444: Database Internals. Section 4: Query Optimizer

QUERY OPTIMIZATION [CH 15]

Evaluation of Relational Operations: Other Techniques

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

Overview of Storage & Indexing (i)

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

SQL: Queries, Constraints, Triggers

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

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:

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

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

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

Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa

Lecture Notes Topic: Query Optimization

Basic form of SQL Queries

Evaluation of Relational Operations: Other Techniques

Evaluation of Relational Operations. SS Chung

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

QUERY EXECUTION: How to Implement Relational Operations?

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

CSIT5300: Advanced Database Systems

Enterprise Database Systems

CSE 544 Principles of Database Management Systems. Magdalena Balazinska Fall 2007 Lecture 9 - Query optimization

System R Optimization (contd.)

SQL. Chapter 5 FROM WHERE

CIS 330: Applied Database Systems

Database Systems. October 12, 2011 Lecture #5. Possessed Hands (U. of Tokyo)

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

Database Systems ( 資料庫系統 )

Database Management Systems. Chapter 5

Announcements. Two typical kinds of queries. Choosing Index is Not Enough. Cost Parameters. Cost of Reading Data From Disk

Review: Query Evaluation Steps. Example Query: Logical Plan 1. What We Already Know. Example Query: Logical Plan 2.

Transcription:

ICS 421 Spring 2010 Query Evaluation (i) Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 2/9/2010 Lipyeow Lim -- University of Hawaii at Manoa 1

Query Enumerate Plans Estimate Cost Choose Best Plan Evaluate Query Plan Result A SCAN (sid=101) Optimizer SELECT * FROM WHERE sid=101 Sid=101 IDXSCAN (sid=101) fetch 32.0 Index(sid) 25.0 Pick B Evaluate Plan A B 2/9/2010 Lipyeow Lim -- University of Hawaii at Manoa 2

Query Enumerate Plans Estimate Cost Choose Best Plan Evaluate Query Plan Result Input : SQL Eg. SELECT-FROM-WHERE, CREATE TABLE, DROP TABLE statements Output: Some data structure to represent the query Relational algebra? Also checks syntax, resolves aliases, binds names in SQL to objects in the catalog How? 2/9/2010 Lipyeow Lim -- University of Hawaii at Manoa 3

Query Enumerate Plans Estimate Cost Choose Best Plan Evaluate Query Plan Result Enumerate Plans Input : a data structure representing the query Output: a collection of equivalent query evaluation plans Query Execution Plan (QEP): tree of database operators. high-level: RA operators are used low-level: RA operators with particular implementation algorithm. Plan enumeration: find equivalent plans Different QEPs that return the same results Query rewriting : transformation of one QEP to another equivalent QEP. 2/9/2010 Lipyeow Lim -- University of Hawaii at Manoa 4

Query Enumerate Plans Estimate Cost Choose Best Plan Evaluate Query Plan Result Estimate Cost Input : a collection of equivalent query evaluation plans Output: a cost estimate for each QEP in the collection Cost estimation: a mapping of a QEP to a cost Cost Model: a model of what counts in the cost estimate. Eg. Disk accesses, CPU cost Statistics about the data and the hardware are used. 2/9/2010 Lipyeow Lim -- University of Hawaii at Manoa 5

Query Enumerate Plans Estimate Cost Choose Best Plan Evaluate Query Plan Result Choose Best Plan Input : a collection of equivalent query evaluation plans and their cost estimate Output: best QEP in the collection The steps: enumerate plans, estimate cost, choose best plan collectively called the: Query Optimizer: Explores the space of equivalent plan for a query Chooses the best plan according to a cost model 2/9/2010 Lipyeow Lim -- University of Hawaii at Manoa 6

Query Enumerate Plans Estimate Cost Choose Best Plan Evaluate Query Plan Result Evaluate Query Plan Input : a QEP (hopefully the best) Output: Query results Often includes a code generation step to generate a lower level QEP in executable code. Query evaluation engine is a virtual machine that executes some code representing low level QEP. 2/9/2010 Lipyeow Lim -- University of Hawaii at Manoa 7

Query Execution Plans (QEPs) A tree of database operators: each operator is a RA operator with specific implementation Selection : Index Scan or Table Scan Projection π: Without DISTINCT : Table Scan With DISTINCT : requires sorting or index scan Join : Nested loop joins (naïve) Index nested loop joins Sort merge joins Sort : In-memory sort External sort 2/9/2010 Lipyeow Lim -- University of Hawaii at Manoa 8

QEP Examples SELECT S.sname FROM R, Sailors S WHERE R.sid=S.sid AND R.bid=100 AND S.rating>5 π S.sname π S.sname S.rating>5 AND R.bid=100 R.sid=S.sid Sailors π S.sname S.rating>5 R.bid=100 R.sid=S.sid Sailors π S.sname S.rating>5 AND R.bid=100 R.sid=S.sid (SCAN) On the fly On the fly Nested Loop Join Sailors (SCAN) R.bid=100 R.sid=S.sid (SCAN) On the fly Nested Loop Join Temp T1 S.rating>5 Sailors (SCAN) 2/9/2010 Lipyeow Lim -- University of Hawaii at Manoa 9

Access Paths An access path is a method of retrieving tuples. Eg. Given a query with a selection condition: File or table scan Index scan Index matching problem: given a selection condition, which indexes can be used for the selection, i.e., matches the selection? Selection condition normalized to conjunctive normal form (CNF), where each term is a conjunct Eg. (day<8/9/94 AND rname= Paul ) OR bid=5 OR sid=3 CNF: (day<8/9/94 OR bid=5 OR sid=3 ) AND (rname= Paul OR bid=5 OR sid=3) R.bid=100 π S.sname R.sid=S.sid On the fly Nested Loop Join S.rating>5 (SCAN) (SCAN) Sailors R.bid=100 Fetch Index(R.bid) (IDXSCAN) Temp T1 2/9/2010 Lipyeow Lim -- University of Hawaii at Manoa 10

Index Matching Q1: a=5 AND b=3 Q2: a=5 AND b>6 Q3: b=3 Q4: a=5 AND b=3 AND c=5 Q5: a>5 AND b=3 AND c=5 I1: Tree Index (a,b,c) I2: Tree Index (b,c,d) I3: Hash Index (a,b,c) A tree index matches a selection condition if the selection condition is a prefix of the index search key. A hash index matches a selection condition if the selection condition has a term attribute=value for every attribute in the index search key 2/9/2010 Lipyeow Lim -- University of Hawaii at Manoa 11

One Approach to Selections 1. Find the most selective access path, retrieve tuples using it 2. Apply remaining terms in selection not matched by the chosen access path The selectivity of an access path is the size of the result set (in terms of tuples or pages). Sometimes selectivity is also used to mean reduction factor: fraction of tuples in a table retrieved by the access path or selection condition. Eg. Consider the selection: day<8/9/94 AND bid=5 AND sid=3 Tree Index(day) Hash index (bid,sid) 2/9/2010 Lipyeow Lim -- University of Hawaii at Manoa 12