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

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

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

Review of Storage and Indexing

Storage and Indexing

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

Overview of Storage and Indexing

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

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

Overview of Storage and Indexing

CompSci 516: Database Systems

Overview of Storage and Indexing

Overview of Storage and Indexing. Data on External Storage

Single Record and Range Search

CSIT5300: Advanced Database Systems

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

CS 4604: Introduc0on to Database Management Systems. B. Aditya Prakash Lecture #11: Query Processing and Midterm Review

Friday Nights with Databases!

Overview of Query Evaluation. Chapter 12

Lecture #16 (Physical DB Design)

INDEXES MICHAEL LIUT DEPARTMENT OF COMPUTING AND SOFTWARE MCMASTER UNIVERSITY

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

Introduction to Data Management. Lecture #17 (Physical DB Design!)

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

Lecture 26 10/28/15. CMPSC431W: Database Management Systems. Instructor: Yu- San Lin

Modern Database Systems Lecture 1

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

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

Overview of Storage and Indexing

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

Data on External Storage

Step 4: Choose file organizations and indexes

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

Lecture 3 08/28/15. CMPSC431W: Database Management Systems. Instructor: Yu- San Lin

Database Applications (15-415)

CompSci 516 Data Intensive Computing Systems

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

Lecture 2 08/26/15. CMPSC431W: Database Management Systems. Instructor: Yu- San Lin

Evaluation of relational operations

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

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

CS 443 Database Management Systems. Professor: Sina Meraji

Overview of Implementing Relational Operators and Query Evaluation

Physical Database Design and Tuning. Review - Normal Forms. Review: Normal Forms. Introduction. Understanding the Workload. Creating an ISUD Chart

Evaluation of Relational Operations: Other Techniques

CS330. Query Processing

Evaluation of Relational Operations: Other Techniques

CSE 444: Database Internals. Section 4: Query Optimizer

Overview of Query Evaluation. Overview of Query Evaluation

Relational Query Optimization. Highlights of System R Optimizer

Physical Database Design and Tuning. Chapter 20

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

Database Applications (15-415)

Evaluation of Relational Operations: Other Techniques

Implementation of Relational Operations: Other Operations

Evaluation of Relational Operations

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

Relational Query Optimization

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

Overview of Query Evaluation

Physical Database Design and Tuning

External Sorting Implementing Relational Operators

Database Applications (15-415)

Administrivia. Physical Database Design. Review: Optimization Strategies. Review: Query Optimization. Review: Database Design

QUERY OPTIMIZATION [CH 15]

System R Optimization (contd.)

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:

Lecture Notes Topic: Query Optimization

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

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

ECS 165B: Database System Implementa6on Lecture 7

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

Lecture 29 11/4/15. CMPSC431W: Database Management Systems. Instructor: Yu- San Lin

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

CSE 444: Database Internals. Sec2on 4: Query Op2mizer

15-415/615 Faloutsos 1

CSIT5300: Advanced Database Systems

Query Evaluation Overview, cont.

Database Management System

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

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

CSIT5300: Advanced Database Systems

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

Overview. Understanding the Workload. Physical Database Design And Database Tuning. Chapter 20

Query Evaluation Overview, cont.

Course No: 4411 Database Management Systems Fall 2008 Midterm exam

RELATIONAL OPERATORS #1

Overview of Query Processing

Midterm Exam #2 (Version A) CS 122A Winter 2017

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

Query Evaluation (i)

CS 186, Fall 2002, Lecture 8 R&G, Chapter 4. Ronald Graham Elements of Ramsey Theory

Database Applications (15-415)

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

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

Database Design and Tuning

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

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

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

ATYPICAL RELATIONAL QUERY OPTIMIZER

Transcription:

CMPSC431W: Database Management Systems Lecture 36 12/4/15 Instructor: Yu- San Lin yusan@psu.edu Course Website: hcp://www.cse.psu.edu/~yul189/cmpsc431w Slides based on McGraw- Hill & Dr. Wang- Chien Lee 1

Example of Composite Search Keys 11,80 12,10 12,20 13,75 <age, sal> 10,12 20,12 75,13 80,11 <sal, age> name age sal bob cal Data entries in index sorted by <sal,age> 12 11 joe 12 10 80 20 sue 13 75 Data records sorted by name 11 12 12 13 <age> 10 20 75 80 <sal> Data entries sorted by <sal> Using lexicographic order 2

Composite Search Keys To retrieve Emp records with age = 30 AND sal = 40 Which is a becer index? (a) <age, sal> (b) age (c) sal Choice of index key orthogonal to clustering etc. If condidon is: 20 < age < 30 AND 30 < sal <50 What is a becer index? If condidon is: age = 30 AND 30 < sal < 50 Which is a becer index? (a) Clustered <age, sal> index (b) clustered <sal, age> index Composite indexes are larger updated more oeen 3

Index- Only Execudon Plans Some queries can be answered without retrieving any tuples from one or more of the reladons involved if a suitable index is available SELECT E.dno, COUNT(*) FROM Emp E GROUP BY E.dno SELECT E.dno, MIN(E.sal) FROM Emp E GROUP BY E.dno SELECT AVG(E.sal) FROM Emp E WHERE E.age = 25 AND E.sal BETWEEN 30 AND 50 4

Index- Only Execudon Plans (cont.) Index- only plans are possible if we have a tree index with key <dno, age> or with key <age, dno> Which is becer for the lee query? SELECT E.dno, COUNT(*) FROM Emp E WHERE E.age = 30 GROUP BY E.dno SELECT E.dno, COUNT(*) FROM Emp E WHERE E.age >= 30 GROUP BY E.dno 5

Summary Many alternadves file organizadons exist, each appropriate in some situadon If selecdon queries are frequent, sordng the file or building an index is important Hash- based only good for search Sorted files and tree- based indexes best for range search; also good for equality search Index is a collecdon of data entries plus a way to quickly find entries with given key values 6

Summary (cont.) Data entries can be actual data records, <key, rid> pairs or <key, rid- list> pairs Can have several indexes on a given file of data records, each with a different search key Indexes can be classified as clustered v.s. unclustered, primary v.s., secondary. Differences have important consequences for udlity/performance 7

Summary (cont.) Indexes must be chosen to speed up important queries Indexes maintenance overhead on updates to key fields Choose indexes that can help many queries Build indexes to support index- only strategies Clustering is an important decision; only one index on a given reladon can be clustered Order of fields in composite index key can be important 8

CHAPTER 12: OVERVIEW OF QUERY EVALUATION 9

Overview How queries are evaluated in a reladonal DMBS? Evaluadon plans How are they represented? Implementadon of reladonal operators What are the alternadves for retrieving data? Query opdmizadon 10

Query Execudon Plan An extended form of reladonal algebra Tree of reladonal algebra operators Each operator may have alternadve algorithms The operators serve as building blocks for query evaluadon Each operator typically implemented using a pull interface The implementadons of the operators are carefully opdmized for good performance 11

Query Execudon Plan: Example Given the following SQL: SELECT S.sname FROM Reserves R, Sailors S WHERE R.sid = S.sid AND R.bid = 100 AND S.rating > 5 What is the reladonal algebra? 12

Query Execudon Plan: Example (cont.) Reladonal algebra tree based on the reladonal algebra we just wrote: 13

Query Execudon Plan: Example (cont.) Query execudon plan #1: 14

Query Execudon Plan: Example (cont.) Query execudon plan #2: 15

Query Opdmizadon Queries can be represented in many combinadons of operators and alternadve algorithms The process of finding a good execudon plan is called query opdmizadon Basic task is to consider several alternadve execudon plan for a query 16

Query Opdmizadon (cont.) Two main issues in query opdmizadon For a given query, what plans are considered? Algorithm to search plan space for cheapest (esdmated) plan How is the cost of a plan esdmated? Ideally, we want to find the best plan. But pracdcally, we avoid the worst plans. 17

Algorithms for Reladonal Operadons Selecdon Cost depends on # qualifying tuples Projecdon Expensive part is to remove duplicates Sordng Useful for eliminadng duplicate copies Join Expensive buy common operadons 18

Types of Joins R S Nested loop join For each tuple in R, scan the endre S Index nested loop join Scan R and for each tuple use the index on S to find matching tuples in S Sort- merge join Sort both R and S on the join acributes, and scan them to find matches 19

Cost Esdmadon For each plan considered, must esdmate cost Must esdmate cost of each operadon in plan tree Depends on input cardinalides Also depends on the types of operadons (sequendal scan, index scan, joins, etc.) Must also esdmate size of result for each operadon in tree Use informadon about the input reladons 20

Don t Forget Homework #6 due on 12/11 Project demo #2 this week Expectadon: almost done, close to what you will present to the whole class in final presentadon Project final presentadon: 12/9 & 12/11 Final exam review session: 12/14 Final exam 12/16 8-9.50 a.m. @362 Willard Accumuladve 21