CS122 Lecture 10 Winter Term,
|
|
- Meredith Tucker
- 5 years ago
- Views:
Transcription
1 CS122 Lecture 10 Winter Term,
2 2 Last Time: Plan Cos0ng Last time, introduced ways of approximating plan costs Number of rows each plan node produces Amount of disk IO the plan must perform Database must collect statistics for each table Total number of rows, total number of blocks, average size of each row Minimum/maximum value for each column, number of distinct values for each column Approximations are very basic; probably inaccurate! As long as slow plans cost more than fast ones, it s Qine
3 3 Other Plan Nodes Project: Π (r) Π A (r), where A is a simple column- reference n Π = n r (no duplicate- elimination in SQL!) V(A, Π A ) = V(A, r) Similarly, min/max don t change Π E (r), where E is an expression possibly with functions Again, n Π = n r For V(E, Π E )/min(e, Π E )/max(e, Π E ), no idea! Either need to guess, or we need more knowledge about E. E.g. just guess V(E, Π E ) = n Π
4 4 Other Plan Nodes (2) Grouping/aggregation: G1,G2, G E1,E2, (r) Gi can be either column- references or expressions Ei can be simple aggregate function calls, or more advanced expressions involving aggregate functions SELECT SUM(CASE WHEN a < b THEN 1 ELSE 0 END) FROM t; SELECT MIN(a) + MAX(b) FROM t; For simple column- references in grouping attributes: n G = V(G1, r) V(G2, r) V(G1, G) = V(G1, r), etc.
5 5 Other Plan Nodes (3) Grouping/aggregation: G1,G2, G E1,E2, (r) For simple column- references and simple aggregates: Guess COUNT(A), SUM(A), AVG(A) will produce different values for each group. e.g. V(COUNT(A), G) = n G Can be a bit more clever with MIN(A) and MAX(A) Could guess V(MIN(A), G) = n G as before Note that MIN(A)/MAX(A) will always select an existing value of A from input relation A better guess: V(MIN(A), G) = min(v(a, r), n G )
6 6 Summary Plan Cos0ng Plan costing is a very imprecise process Almost certainly inaccurate, except in very simple cases Hopefully estimates are good enough to guide plan selection (Most databases provide ways to give the optimizer hints about plan optimization.) These estimates are simply one way of estimating costs Different assumptions, or different kinds of statistics, will produce different costing estimates Still, an essential part of query planning! Collecting useful table stats, then making reasonably accurate estimates from them, greatly improves DB query performance (Becomes very obvious when table stats are inaccurate )
7 7 Equivalent Plans? Previously had this query: SELECT * FROM t1, t2 WHERE t1.a = t2.a AND t2.b > 5; σ t1.a = t2.a t2.b > 5 σ t2.b > 5 θ t1.a = t2.a θ true θ t1.a = t2.a t1 t2 t1 t2 t1 t2 t2.b > 5 How do we know these plans are actually equivalent?
8 8 Equivalent Plans Two plans are equivalent if they produce the same results for every legal database instance A legal database instance satisqies all constraints Generally, the order of tuples is irrelevant If sorting is not speciqied on results, two equivalent plans may generate results in different orders Equivalence rules specify different forms of an expression that are equivalent Can prove that these rules hold for all legal databases Can use them to transform query plans into equivalent (but hopefully faster) plans
9 9 Simple Equivalence Rules Cascade of σ: σ θ1 θ2 (E) = σ θ1 (σ θ2 (E)) σ is commutative: σ θ1 (σ θ2 (E)) = σ θ2 (σ θ1 (E)) Selections, Cartesian products, and theta- joins: σ θ (E1 E2) = E1 θ E2 σ θ1 (E1 θ2 E2) = E1 θ1 θ2 E2 Theta- joins are commutative: E1 θ E2 = E2 θ E1
10 10 Theta Join Equivalence Rules Natural joins are associative: (E1 E2) E3 = E1 (E2 E3) Theta- joins are also associative, but it s a bit trickier: (E1 θ1 E2) θ2 θ3 E3 = E1 θ1 θ3 (E2 θ2 E3) θ1 only refers to attributes in E1 and/or E2 θ2 only refers to attributes in E2 and/or E3 θ3 only refers to attributes in E1 and/or E3 Any of these conditions might also simply be true
11 11 Theta Join Equivalence Rules (2) Can sometimes distribute selects over theta- joins: σ θ1 (E1 θ E2) = σ θ1 (E1) θ E2 θ1 only refers to attributes in E1 σ θ1 θ2 (E1 θ E2) = σ θ1 (E1) θ σ θ2 (E2) θ1 only refers to attributes in E1 θ2 only refers to attributes in E2
12 12 Equivalence Rules Many other equivalence rules besides these Cover grouping, projects, outer joins, set operations, duplicate elimination, sorting, etc. Grouping: σ θ ( A G F (E)) is equivalent to A G F (σ θ (E)) as long as θ only involves attributes in A! Outer joins: σ θ (E1 E2) is equivalent to σ θ (E1) E2 θ only involves attributes in E1
13 13 Equivalence Rules Equivalence rules allow us to transform plans, and know the results will not change: σ t1.a = t2.a t2.b > 5 σ t2.b > 5 σ θ (E1 E2) = E1 θ E2 θ t1.a = t2.a θ true θ t1.a = t2.a t1 t2 t1 t2 t1 t2 t2.b > 5 σ θ2 (E1 θ E2) = E1 θ (σ θ2 (E2))
14 14 Outer Join Transforma0ons Need to be very careful transforming outer joins: Obviously correct equivalences for natural joins / theta joins don t necessarily hold for outer joins! Is σ θ (E1 E2) equivalent to E1 σ θ (E2)? θ only uses attributes in E2 These are not equivalent. Example: r(a, B) with one row { (1, 2) } s(b, C) with one row { (2, 3) } θ is C = 1 σ C=1 (r s) = { } (empty relation), but r σ C=1 (s) = { (1, 2, null) }
15 15 Outer Join Transforma0ons (2) Need to be very careful transforming outer joins: Obviously correct equivalences for natural joins / theta joins don t necessarily hold for outer joins! Is (E1 E2) E3 equivalent to E1 (E2 E3)? These are not equivalent. Example: r(a, B) with one row { (1, 2) } s(a, C) with one row { (2, 3) } t(a, D) with one row { (1, 4) } (r s) t = { (1, 2, null) } t = { (1, 2, null, 4) } r (s t) = r { (2, 3, null) } = { (1, 2, null, null) }
16 16 Query Plan Op0miza0on Generally understand how to map SQL queries to plans Ignoring subqueries in SELECT and WHERE clauses for the time being Understand how to implement basic plan nodes Still a lot of optimizations to cover though A query can be evaluated by many different plans How do we Qind an optimal plan to evaluate a query? Many different approaches All depend on equivalence rules to guide generation of equivalent plans
17 17 Heuris0c Plan Op0miza0on Can transform plans purely based on heuristics Guidelines for what plans will generally be better Uses equivalence rules, but no plan costing! Example: Perform selects as early as possible! Would properly handle our previous example: Push predicates down the plan- tree as far as possible σ t1.a = t2.a t2.b > 5 Perform selects as θ t1.a = t2.a θ true early as possible! t1 t2 t1 t2 t2.b > 5
18 18 Heuris0c Plan Op0miza0on (2) Unfortunately, heuristics don t always work σ t1.a = t2.a t2.b > 5 Scenario: t1 is a small table t2 is very large, and has an index on a, but no index on b! If t2.b > 5 is applied Qirst, join can t use t2 s index to Qind rows t1 t2 Perform selects as θ t1.a = t2.a θ true early as possible! t1 t2 Would greatly improve join performance in this case t2.b > 5 Would likely be faster to perform σ t2.b>5 ( ) last, in this case!
19 19 Cost- Based Plan Op0miza0on Clearly gain a beneqit from estimating a plan s cost Gives us feedback about whether alternative is actually likely to be better Cost-based optimizers explore query plan space, and choose the best one based on the estimated cost Could exhaustively enumerate all equivalent plans Assign each plan a cost, and choose the best one! Unfortunately, plan space is often extremely large Just picking a join ordering produces many options
20 20 Example: Join Ordering Given n relations to join: r 1, r 2,, r n Join is a binary operation r 1 r 2 may have a different cost than r 2 r 1 Produces (2(n 1))! / (n 1)! different orderings! (See Practice Exercise in textbook for details.) n = 3 12 orderings n = orderings n = 5 1,680 orderings! n = 6 30,240 orderings!! n = 7 665,280 orderings!!!
21 21 Exhaus0ve Plan Enumera0on Pursuing this strategy requires careful implementation Must represent plans in a very space- efqicient manner E.g. memoize subplans, so that common subplans are represented in memory only once Some query planners use exhaustive plan enumeration Volcano and Cascades projects used this approach SQLServer s optimizer is based on these projects
22 22 Guided Plan Enumera0on Most query planners are satisqied with any good plan Don t let the perfect become the enemy of the good. Constrain the plan search- space in various ways E.g. some planners only consider left-deep join trees For n tables, only have n! join orders to consider Is also very friendly to pipelined evaluation e.g. nested loops don t have a whole subplan to evaluate over and over, for inner relation Rely more on higher- level heuristics t4 Don t just repeatedly apply Qine- grained t3 equivalence rules t1 t2 t5
23 23 Guided Plan Enumera0on (2) Many queries involve joins of multiple tables (Also, subqueries in SELECT and WHERE can often be transformed into joins.) A common (non- exhaustive) optimization strategy: Perform high- level transformations at SQL AST level Flattening subqueries into a larger top- level query with joins Apply heuristics based on strategies that generally improve query performance Focus speciqically on task of choosing a good join order Use plan costing to evaluate whether alternatives are actually better!
24 24 BoOom- Up: Dynamic Programming Can enumerate plans in a bottom-up approach, or a top-down approach Example: bottom- up approach Use dynamic programming to search the plan- space Decompose plan into smallest subplans; choose best implementation for each subplan, and record its cost When building up larger subplans, reuse earlier work: simply choose best way to combine earlier subplans Usually produces very good plans but not always the best Can t take advantage of higher- level, whole- plan optimizations
25 25 Top- Down: Branch and Bound Example: top- down approach Use branch- and- bound strategy Generate a good query plan using heuristics, then compute its cost C Use C as an upper bound for plans we will consider When applying transformations, immediately discard any plan with a cost larger than C If we Qind a plan with a lower cost, lower C to the new cost Upper- bound cost C can guide when to stop optimizing If C is still really large, keep looking for better plans If C is small, additional effort is probably unnecessary
26 26 Op0mizing Join Order Given: r1 r2 r3 r4 r5 Need to devise the optimal join order (along with the optimal join algorithms, access paths, etc.) For n = 5, there are 1680 different join orderings Assume we know the optimal join order for r1 r2 r3 Want to know optimal order for (r1 r2 r3) r4 r5 Really don t need to keep Qiguring out the optimal order for r1 r2 r3 over and over again! Just reuse the subplan and associated cost already computed for r1 r2 r3, when trying orders with r4, r5
27 27 BoOom- Up Join Op0mizer Finding join order with dynamic programming: Step 1: Determine optimal way to access each relation directly (including index optimizations based on predicates, etc.) Compute a cost for each access Step 2: Determine optimal way to join each pair of relations, using results computed in step 1, along with the computed costs Step 3 N: Repeat, adding another relation at each step, reusing earlier results, until optimal way to join all N relations is found
28 28 LeS- Deep Join Orders Some databases limit join ordering to left- deep orders Reduces total number of join orders down to n! Facilitates pipelining (particularly if stuck with nested- loops join) Easy to constrain bottom- up algorithm to only explore left- deep join orders: When adding another relation to a subplan, always add it on right side of the new join operation, with subplan the on left side t3 t4 t5 t1 t2
29 29 Top- Down Join Op0mizer Another version of the same algorithm, written in a more top- down style: (Database System Concepts, 6 ed, p.600) /* S is a set of relations to join */ procedure FindBestPlan(S) if (bestplan[s].cost ) /* best plan is already computed */ return bestplan[s] if (S contains only 1 relation) set bestplan[s].plan, bestplan[s].cost based on best way of accessing S else set bestplan[s].cost = for each non- empty proper subset S1 of S P1 = FindBestPlan(S1) P2 = FindBestPlan(S S1) A = best algorithm for joining results of P1 and P2 cost = P1.cost + P2.cost + cost of A if (cost < bestplan[s].cost) bestplan[s].cost = cost bestplan[s].plan = join P1 and P2 using algorithm A return bestplan[s]
30 30 Top- Down Join Op0mizer (2) More complicated to constrain this to only produce left- deep join trees Left and right subplans being considered are for one or more relations Not just adding in a single relation each iteration Still, not too hard to adjust this algorithm to generate left- deep join trees Also, enumerating subsets at each level is repetitive and uses extra memory
31 31 Improving the Join Op0mizer This optimization approach doesn t always produce the best join order At each step, we only keep the optimal solution we Qind The lowest- cost solution to a subproblem may force more costly operations higher up in the plan- tree Selinger- style plan optimization: Besides keeping lowest- cost solution for each problem, also keep solutions that produce interesting orders Sometimes, a higher- level operation can use the slightly costlier ordered result to reduce overall costs
32 32 Selinger- Style Op0miza0on Selinger- style plan optimization Uses dynamic programming to generate plans Also keep more expensive subplans that produce results in interesting orders Subplans that are slower than the fastest one found, but that produce results in possibly useful orderings e.g. subplans whose results are ordered on the same attributes as a higher- level ORDER BY operation e.g. subplans whose results are ordered on the same attributes as a higher- level join operation Can take advantage of higher- level optimizations than simple dynamic programming
33 33 Selinger- Style Op0miza0on (2) Named after Pamela Selinger Worked on planner/optimizer for System R Helped to develop many of the plan- costing approaches used in most databases today System R was an early relational database research project at IBM Many critical accomplishments: System R s SEQUEL language is basis of our SQL Use of plan- costing estimates and dynamic programming in plan optimization Demonstrated feasibility of transaction processing
34 34 System- R Join Op0mizer Slightly altered version of bottom- up approach: For each available ordering of results, record the optimal plan that produces that result- order Also record optimal plan that produces unordered results unless an ordered result s cost is already lower than this! Step 1: For each relation: Examine indexes to determine what result- orderings are available For each possible result- ordering, determine the optimal plan for accessing the relation (also applying relevant predicates, etc.) Also determine optimal plan for unordered access. If this is costlier than some ordered result, discard this plan.
35 35 System- R Join Op0mizer (2) Step 2: Again, compute optimal plans to join pairs of relations Given two relations r1 and r2: Consider all plans for joining r1 and r2, based on Step 1 results Some of these plans will also produce ordered results Partition plans into groups based on their join orderings, and save optimal plan for each join order Discard the unordered plan if some ordered plan is more efqicient Continue this process until all N relations are joined Join planner may produce multiple ways to join input tables Query planner can choose a join- plan based on overall query requirements (e.g. top- level ORDER BY or GROUP BY clause)
36 36 System- R Join Op0mizer (3) Usually aren t that many interesting orders to consider Tables might have 1-3 indexes, only a few of which are relevant for each join operation being considered Considering result- orderings doesn t add substantial memory overhead to the join optimizer Can really improve optimizer results in cases where the result- ordering can be leveraged for faster queries
Advanced Databases. Lecture 4 - Query Optimization. Masood Niazi Torshiz Islamic Azad university- Mashhad Branch
Advanced Databases Lecture 4 - Query Optimization Masood Niazi Torshiz Islamic Azad university- Mashhad Branch www.mniazi.ir Query Optimization Introduction Transformation of Relational Expressions Catalog
More informationIntroduction Alternative ways of evaluating a given query using
Query Optimization Introduction Catalog Information for Cost Estimation Estimation of Statistics Transformation of Relational Expressions Dynamic Programming for Choosing Evaluation Plans Introduction
More informationQuery Processing & Optimization
Query Processing & Optimization 1 Roadmap of This Lecture Overview of query processing Measures of Query Cost Selection Operation Sorting Join Operation Other Operations Evaluation of Expressions Introduction
More informationQuery Optimization. Shuigeng Zhou. December 9, 2009 School of Computer Science Fudan University
Query Optimization Shuigeng Zhou December 9, 2009 School of Computer Science Fudan University Outline Introduction Catalog Information for Cost Estimation Estimation of Statistics Transformation of Relational
More informationChapter 14: Query Optimization
Chapter 14: Query Optimization Database System Concepts 5 th Ed. See www.db-book.com for conditions on re-use Chapter 14: Query Optimization Introduction Transformation of Relational Expressions Catalog
More informationQuery Optimization. Chapter 13
Query Optimization Chapter 13 What we want to cover today Overview of query optimization Generating equivalent expressions Cost estimation 432/832 2 Chapter 13 Query Optimization OVERVIEW 432/832 3 Query
More informationCS122 Lecture 4 Winter Term,
CS122 Lecture 4 Winter Term, 2014-2015 2 SQL Query Transla.on Last time, introduced query evaluation pipeline SQL query SQL parser abstract syntax tree SQL translator relational algebra plan query plan
More informationChapter 14 Query Optimization
Chapter 14 Query Optimization Chapter 14: Query Optimization! Introduction! Catalog Information for Cost Estimation! Estimation of Statistics! Transformation of Relational Expressions! Dynamic Programming
More informationChapter 14 Query Optimization
Chapter 14 Query Optimization Chapter 14: Query Optimization! Introduction! Catalog Information for Cost Estimation! Estimation of Statistics! Transformation of Relational Expressions! Dynamic Programming
More informationChapter 14 Query Optimization
Chapter 14: Query Optimization Chapter 14 Query Optimization! Introduction! Catalog Information for Cost Estimation! Estimation of Statistics! Transformation of Relational Expressions! Dynamic Programming
More informationContents Contents Introduction Basic Steps in Query Processing Introduction Transformation of Relational Expressions...
Contents Contents...283 Introduction...283 Basic Steps in Query Processing...284 Introduction...285 Transformation of Relational Expressions...287 Equivalence Rules...289 Transformation Example: Pushing
More informationChapter 11: Query Optimization
Chapter 11: Query Optimization Chapter 11: Query Optimization Introduction Transformation of Relational Expressions Statistical Information for Cost Estimation Cost-based optimization Dynamic Programming
More informationQuery processing and optimization
Query processing and optimization These slides are a modified version of the slides of the book Database System Concepts (Chapter 13 and 14), 5th Ed., McGraw-Hill, by Silberschatz, Korth and Sudarshan.
More informationChapter 13: Query Optimization. Chapter 13: Query Optimization
Chapter 13: Query Optimization Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Chapter 13: Query Optimization Introduction Equivalent Relational Algebra Expressions Statistical
More informationSQL QUERY EVALUATION. CS121: Relational Databases Fall 2017 Lecture 12
SQL QUERY EVALUATION CS121: Relational Databases Fall 2017 Lecture 12 Query Evaluation 2 Last time: Began looking at database implementation details How data is stored and accessed by the database Using
More informationChapter 12: Query Processing
Chapter 12: Query Processing Overview Catalog Information for Cost Estimation $ Measures of Query Cost Selection Operation Sorting Join Operation Other Operations Evaluation of Expressions Transformation
More informationCS122 Lecture 8 Winter Term,
CS122 Lecture 8 Winter Term, 2014-2015 2 Other Join Algorithms Nested- loops join is generally useful, but slow Most joins involve equality tests against attributes Such joins are called equijoins Two
More informationAdvanced Database Systems
Lecture IV Query Processing Kyumars Sheykh Esmaili Basic Steps in Query Processing 2 Query Optimization Many equivalent execution plans Choosing the best one Based on Heuristics, Cost Will be discussed
More informationDatabase System Concepts
Chapter 14: Optimization Departamento de Engenharia Informática Instituto Superior Técnico 1 st Semester 2007/2008 Slides (fortemente) baseados nos slides oficiais do livro c Silberschatz, Korth and Sudarshan.
More informationParser: SQL parse tree
Jinze Liu Parser: SQL parse tree Good old lex & yacc Detect and reject syntax errors Validator: parse tree logical plan Detect and reject semantic errors Nonexistent tables/views/columns? Insufficient
More informationDBMS Y3/S5. 1. OVERVIEW The steps involved in processing a query are: 1. Parsing and translation. 2. Optimization. 3. Evaluation.
Query Processing QUERY PROCESSING refers to the range of activities involved in extracting data from a database. The activities include translation of queries in high-level database languages into expressions
More informationIntroduction to Query Processing and Query Optimization Techniques. Copyright 2011 Ramez Elmasri and Shamkant Navathe
Introduction to Query Processing and Query Optimization Techniques Outline Translating SQL Queries into Relational Algebra Algorithms for External Sorting Algorithms for SELECT and JOIN Operations Algorithms
More informationCMSC424: Database Design. Instructor: Amol Deshpande
CMSC424: Database Design Instructor: Amol Deshpande amol@cs.umd.edu Databases Data Models Conceptual representa1on of the data Data Retrieval How to ask ques1ons of the database How to answer those ques1ons
More informationCS122 Lecture 5 Winter Term,
CS122 Lecture 5 Winter Term, 2017-2018 2 Last Time: SQL Join Expressions Last time, began discussing SQL join syntax Original SQL form: SELECT FROM t1, t2, WHERE P Any join conditions are specified in
More informationCopyright 2016 Ramez Elmasri and Shamkant B. Navathe
CHAPTER 19 Query Optimization Introduction Query optimization Conducted by a query optimizer in a DBMS Goal: select best available strategy for executing query Based on information available Most RDBMSs
More informationCS 4604: Introduction to Database Management Systems. B. Aditya Prakash Lecture #10: Query Processing
CS 4604: Introduction to Database Management Systems B. Aditya Prakash Lecture #10: Query Processing Outline introduction selection projection join set & aggregate operations Prakash 2018 VT CS 4604 2
More informationOverview of Implementing Relational Operators and Query Evaluation
Overview of Implementing Relational Operators and Query Evaluation Chapter 12 Motivation: Evaluating Queries The same query can be evaluated in different ways. The evaluation strategy (plan) can make orders
More informationCSE 544 Principles of Database Management Systems. Magdalena Balazinska Fall 2007 Lecture 9 - Query optimization
CSE 544 Principles of Database Management Systems Magdalena Balazinska Fall 2007 Lecture 9 - Query optimization References Access path selection in a relational database management system. Selinger. et.
More informationCS122 Lecture 3 Winter Term,
CS122 Lecture 3 Winter Term, 2017-2018 2 Record-Level File Organization Last time, finished discussing block-level organization Can also organize data files at the record-level Heap file organization A
More informationPrinciples of Data Management. Lecture #12 (Query Optimization I)
Principles of Data Management Lecture #12 (Query Optimization I) Instructor: Mike Carey mjcarey@ics.uci.edu Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Today s Notable News v B+ tree
More informationAlgorithms for Query Processing and Optimization. 0. Introduction to Query Processing (1)
Chapter 19 Algorithms for Query Processing and Optimization 0. Introduction to Query Processing (1) Query optimization: The process of choosing a suitable execution strategy for processing a query. Two
More informationCS121 MIDTERM REVIEW. CS121: Relational Databases Fall 2017 Lecture 13
CS121 MIDTERM REVIEW CS121: Relational Databases Fall 2017 Lecture 13 2 Before We Start Midterm Overview 3 6 hours, multiple sittings Open book, open notes, open lecture slides No collaboration Possible
More informationRelational Query Optimization. Overview of Query Evaluation. SQL Refresher. Yanlei Diao UMass Amherst October 23 & 25, 2007
Relational Query Optimization Yanlei Diao UMass Amherst October 23 & 25, 2007 Slide Content Courtesy of R. Ramakrishnan, J. Gehrke, and J. Hellerstein 1 Overview of Query Evaluation Query Evaluation Plan:
More informationFaloutsos 1. Carnegie Mellon Univ. Dept. of Computer Science Database Applications. Outline
Carnegie Mellon Univ. Dept. of Computer Science 15-415 - Database Applications Lecture #14: Implementation of Relational Operations (R&G ch. 12 and 14) 15-415 Faloutsos 1 introduction selection projection
More informationMissing Information. We ve assumed every tuple has a value for every attribute. But sometimes information is missing. Two common scenarios:
NULL values Missing Information We ve assumed every tuple has a value for every attribute. But sometimes information is missing. Two common scenarios: Missing value. E.g., we know a student has some email
More informationQuery Optimization Overview. COSC 404 Database System Implementation. Query Optimization. Query Processor Components The Parser
COSC 404 Database System Implementation Query Optimization Query Optimization Overview The query processor performs four main tasks: 1) Verifies the correctness of an SQL statement 2) Converts the SQL
More informationChapter 3. Algorithms for Query Processing and Optimization
Chapter 3 Algorithms for Query Processing and Optimization Chapter Outline 1. Introduction to Query Processing 2. Translating SQL Queries into Relational Algebra 3. Algorithms for External Sorting 4. Algorithms
More informationRelational Databases
Relational Databases Jan Chomicki University at Buffalo Jan Chomicki () Relational databases 1 / 49 Plan of the course 1 Relational databases 2 Relational database design 3 Conceptual database design 4
More informationCS122 Lecture 15 Winter Term,
CS122 Lecture 15 Winter Term, 2014-2015 2 Index Op)miza)ons So far, only discussed implementing relational algebra operations to directly access heap Biles Indexes present an alternate access path for
More informationThe Extended Algebra. Duplicate Elimination. Sorting. Example: Duplicate Elimination
The Extended Algebra Duplicate Elimination 2 δ = eliminate duplicates from bags. τ = sort tuples. γ = grouping and aggregation. Outerjoin : avoids dangling tuples = tuples that do not join with anything.
More informationRelational Query Optimization
Relational Query Optimization Module 4, Lectures 3 and 4 Database Management Systems, R. Ramakrishnan 1 Overview of Query Optimization Plan: Tree of R.A. ops, with choice of alg for each op. Each operator
More informationQuery Optimization. Query Optimization. Optimization considerations. Example. Interaction of algorithm choice and tree arrangement.
COS 597: Principles of Database and Information Systems Query Optimization Query Optimization Query as expression over relational algebraic operations Get evaluation (parse) tree Leaves: base relations
More informationDATABASE PERFORMANCE AND INDEXES. CS121: Relational Databases Fall 2017 Lecture 11
DATABASE PERFORMANCE AND INDEXES CS121: Relational Databases Fall 2017 Lecture 11 Database Performance 2 Many situations where query performance needs to be improved e.g. as data size grows, query performance
More informationECS 165B: Database System Implementa6on Lecture 14
ECS 165B: Database System Implementa6on Lecture 14 UC Davis April 28, 2010 Acknowledgements: por6ons based on slides by Raghu Ramakrishnan and Johannes Gehrke, as well as slides by Zack Ives. Class Agenda
More informationRelational Query Optimization. Highlights of System R Optimizer
Relational Query Optimization Chapter 15 Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Highlights of System R Optimizer v Impact: Most widely used currently; works well for < 10 joins.
More informationReminders. Query Optimizer Overview. The Three Parts of an Optimizer. Dynamic Programming. Search Algorithm. CSE 444: Database Internals
Reminders CSE 444: Database Internals Lab 2 is due on Wednesday HW 5 is due on Friday Lecture 11 Query Optimization (part 2) CSE 444 - Winter 2017 1 CSE 444 - Winter 2017 2 Query Optimizer Overview Input:
More informationMidterm Review. Winter Lecture 13
Midterm Review Winter 2006-2007 Lecture 13 Midterm Overview 3 hours, single sitting Topics: Relational model relations, keys, relational algebra expressions SQL DDL commands CREATE TABLE, CREATE VIEW Specifying
More informationCOSC 404 Database System Implementation. Query Optimization. Dr. Ramon Lawrence University of British Columbia Okanagan
COSC 404 Database System Implementation Query Optimization Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca Query Optimization Overview COSC 404 - Dr. Ramon Lawrence The
More informationATYPICAL RELATIONAL QUERY OPTIMIZER
14 ATYPICAL RELATIONAL QUERY OPTIMIZER Life is what happens while you re busy making other plans. John Lennon In this chapter, we present a typical relational query optimizer in detail. We begin by discussing
More informationCh 5 : Query Processing & Optimization
Ch 5 : Query Processing & Optimization Basic Steps in Query Processing 1. Parsing and translation 2. Optimization 3. Evaluation Basic Steps in Query Processing (Cont.) Parsing and translation translate
More informationAdministrivia. CS 133: Databases. Cost-based Query Sub-System. Goals for Today. Midterm on Thursday 10/18. Assignments
Administrivia Midterm on Thursday 10/18 CS 133: Databases Fall 2018 Lec 12 10/16 Prof. Beth Trushkowsky Assignments Lab 3 starts after fall break No problem set out this week Goals for Today Cost-based
More informationOverview of Query Processing and Optimization
Overview of Query Processing and Optimization Source: Database System Concepts Korth and Silberschatz Lisa Ball, 2010 (spelling error corrections Dec 07, 2011) Purpose of DBMS Optimization Each relational
More informationSQL QUERIES. CS121: Relational Databases Fall 2017 Lecture 5
SQL QUERIES CS121: Relational Databases Fall 2017 Lecture 5 SQL Queries 2 SQL queries use the SELECT statement General form is: SELECT A 1, A 2,... FROM r 1, r 2,... WHERE P; r i are the relations (tables)
More informationCS122 Lecture 3 Winter Term,
CS122 Lecture 3 Winter Term, 2014-2015 2 Record- Level File Organiza3on Last time, :inished discussing block- level organization Can also organize data :iles at the record- level Heap &ile organization
More informationDatabase Tuning and Physical Design: Basics of Query Execution
Database Tuning and Physical Design: Basics of Query Execution Spring 2018 School of Computer Science University of Waterloo Databases CS348 (University of Waterloo) Query Execution 1 / 43 The Client/Server
More informationReview. Relational Query Optimization. Query Optimization Overview (cont) Query Optimization Overview. Cost-based Query Sub-System
Review Relational Query Optimization R & G Chapter 12/15 Implementation of single Relational Operations Choices depend on indexes, memory, stats, Joins Blocked nested loops: simple, exploits extra memory
More informationChapter 12: Query Processing
Chapter 12: Query Processing Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Overview Chapter 12: Query Processing Measures of Query Cost Selection Operation Sorting Join
More informationPrinciples of Data Management. Lecture #9 (Query Processing Overview)
Principles of Data Management Lecture #9 (Query Processing Overview) Instructor: Mike Carey mjcarey@ics.uci.edu Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Today s Notable News v Midterm
More informationTraditional Query Optimization
Chapter 2 Traditional Query Optimization This chapter sets the stage for the work covered in the rest of the thesis. Section 2.1 gives a brief overview of the important concerns and prior work in traditional
More informationAdvances in Data Management Query Processing and Query Optimisation A.Poulovassilis
1 Advances in Data Management Query Processing and Query Optimisation A.Poulovassilis 1 General approach to the implementation of Query Processing and Query Optimisation functionalities in DBMSs 1. Parse
More informationQuery Processing. Introduction to Databases CompSci 316 Fall 2017
Query Processing Introduction to Databases CompSci 316 Fall 2017 2 Announcements (Tue., Nov. 14) Homework #3 sample solution posted in Sakai Homework #4 assigned today; due on 12/05 Project milestone #2
More informationQuery Execution [15]
CSC 661, Principles of Database Systems Query Execution [15] Dr. Kalpakis http://www.csee.umbc.edu/~kalpakis/courses/661 Query processing involves Query processing compilation parsing to construct parse
More informationSchema for Examples. Query Optimization. Alternative Plans 1 (No Indexes) Motivating Example. Alternative Plans 2 With Indexes
Schema for Examples Query Optimization (sid: integer, : string, rating: integer, age: real) (sid: integer, bid: integer, day: dates, rname: string) Similar to old schema; rname added for variations. :
More informationCSE 544 Principles of Database Management Systems. Alvin Cheung Fall 2015 Lecture 7 - Query optimization
CSE 544 Principles of Database Management Systems Alvin Cheung Fall 2015 Lecture 7 - Query optimization Announcements HW1 due tonight at 11:45pm HW2 will be due in two weeks You get to implement your own
More informationCost-based Query Sub-System. Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications. Last Class.
Cost-based Query Sub-System Carnegie Mellon Univ. Dept. of Computer Science 15-415/615 - DB Applications Queries Select * From Blah B Where B.blah = blah Query Parser Query Optimizer C. Faloutsos A. Pavlo
More informationQuery Optimization. Introduction to Databases CompSci 316 Fall 2018
Query Optimization Introduction to Databases CompSci 316 Fall 2018 2 Announcements (Tue., Nov. 20) Homework #4 due next in 2½ weeks No class this Thu. (Thanksgiving break) No weekly progress update due
More informationCMSC 424 Database design Lecture 18 Query optimization. Mihai Pop
CMSC 424 Database design Lecture 18 Query optimization Mihai Pop More midterm solutions Projects do not be late! Admin Introduction Alternative ways of evaluating a given query Equivalent expressions Different
More informationSQL and Incomp?ete Data
SQL and Incomp?ete Data A not so happy marriage Dr Paolo Guagliardo Applied Databases, Guest Lecture 31 March 2016 SQL is efficient, correct and reliable 1 / 25 SQL is efficient, correct and reliable...
More informationQuery Optimization. Schema for Examples. Motivating Example. Similar to old schema; rname added for variations. Reserves: Sailors:
Query Optimization Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Schema for Examples (sid: integer, sname: string, rating: integer, age: real) (sid: integer, bid: integer, day: dates,
More information20761 Querying Data with Transact SQL
Course Overview The main purpose of this course is to give students a good understanding of the Transact-SQL language which is used by all SQL Server-related disciplines; namely, Database Administration,
More informationR & G Chapter 13. Implementation of single Relational Operations Choices depend on indexes, memory, stats, Joins Blocked nested loops:
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
More informationLecture #14 Optimizer Implementation (Part I)
15-721 ADVANCED DATABASE SYSTEMS Lecture #14 Optimizer Implementation (Part I) Andy Pavlo / Carnegie Mellon University / Spring 2016 @Andy_Pavlo // Carnegie Mellon University // Spring 2017 2 TODAY S AGENDA
More informationDatabase System Concepts
Chapter 13: Query Processing s Departamento de Engenharia Informática Instituto Superior Técnico 1 st Semester 2008/2009 Slides (fortemente) baseados nos slides oficiais do livro c Silberschatz, Korth
More informationQuery Processing and Query Optimization. Prof Monika Shah
Query Processing and Query Optimization Query Processing SQL Query Is in Library Cache? System catalog (Dict / Dict cache) Scan and verify relations Parse into parse tree (relational Calculus) View definitions
More informationQuery Processing Strategies and Optimization
Query Processing Strategies and Optimization CPS352: Database Systems Simon Miner Gordon College Last Revised: 10/25/12 Agenda Check-in Design Project Presentations Query Processing Programming Project
More information2.3 Algorithms Using Map-Reduce
28 CHAPTER 2. MAP-REDUCE AND THE NEW SOFTWARE STACK one becomes available. The Master must also inform each Reduce task that the location of its input from that Map task has changed. Dealing with a failure
More informationQuerying Data with Transact SQL
Course 20761A: Querying Data with Transact SQL Course details Course Outline Module 1: Introduction to Microsoft SQL Server 2016 This module introduces SQL Server, the versions of SQL Server, including
More informationUniversity of Waterloo Midterm Examination Solution
University of Waterloo Midterm Examination Solution Winter, 2011 1. (6 total marks) The diagram below shows an extensible hash table with four hash buckets. Each number x in the buckets represents an entry
More informationAn 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
QUERY OPTIMIZATION 1 QUERY OPTIMIZATION QUERY SUB-SYSTEM 2 ROADMAP 3. 12 QUERY BLOCKS: UNITS OF OPTIMIZATION An SQL query is parsed into a collection of query blocks optimize one block at a time. Nested
More informationDetecting Logical Errors in SQL Queries
Detecting Logical Errors in SQL Queries Stefan Brass Christian Goldberg Martin-Luther-Universität Halle-Wittenberg, Institut für Informatik, Von-Seckendorff-Platz 1, D-06099 Halle (Saale), Germany (brass
More information15-415/615 Faloutsos 1
Carnegie Mellon Univ. Dept. of Computer Science 15-415/615 - DB Applications Lecture #14: Implementation of Relational Operations (R&G ch. 12 and 14) 15-415/615 Faloutsos 1 Outline introduction selection
More informationSQL: Data Manipulation Language. csc343, Introduction to Databases Diane Horton Winter 2017
SQL: Data Manipulation Language csc343, Introduction to Databases Diane Horton Winter 2017 Introduction So far, we have defined database schemas and queries mathematically. SQL is a formal language for
More informationSQL: csc343, Introduction to Databases Renée J. Miller and Fatemeh Nargesian and Sina Sina Meraji. Winter 2018
SQL: csc343, Introduction to Databases Renée J. Miller and Fatemeh Nargesian and Sina Sina Meraji Winter 2018 Introduction So far, we have defined database schemas and queries mathematically. SQL is a
More informationImplementation of Relational Operations. Introduction. CS 186, Fall 2002, Lecture 19 R&G - Chapter 12
Implementation of Relational Operations CS 186, Fall 2002, Lecture 19 R&G - Chapter 12 First comes thought; then organization of that thought, into ideas and plans; then transformation of those plans into
More informationNotes. Some of these slides are based on a slide set provided by Ulf Leser. CS 640 Query Processing Winter / 30. Notes
uery Processing Olaf Hartig David R. Cheriton School of Computer Science University of Waterloo CS 640 Principles of Database Management and Use Winter 2013 Some of these slides are based on a slide set
More informationRELATIONAL DATA MODEL: Relational Algebra
RELATIONAL DATA MODEL: Relational Algebra Outline 1. Relational Algebra 2. Relational Algebra Example Queries 1. Relational Algebra A basic set of relational model operations constitute the relational
More informationCS330. Query Processing
CS330 Query Processing 1 Overview of Query Evaluation Plan: Tree of R.A. ops, with choice of alg for each op. Each operator typically implemented using a `pull interface: when an operator is `pulled for
More informationQuery Optimization. Schema for Examples. Motivating Example. Similar to old schema; rname added for variations. Reserves: Sailors:
Query Optimization atabase Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Schema for Examples (sid: integer, sname: string, rating: integer, age: real) (sid: integer, bid: integer, day: dates,
More informationRelational Algebra. ICOM 5016 Database Systems. Roadmap. R.A. Operators. Selection. Example: Selection. Relational Algebra. Fundamental Property
Relational Algebra ICOM 06 Database Systems Relational Algebra Dr. Amir H. Chinaei Department of Electrical and Computer Engineering University of Puerto Rico, Mayagüez Slides are adapted from: Introduction.
More informationCompSci 516 Data Intensive Computing Systems. Lecture 11. Query Optimization. Instructor: Sudeepa Roy
CompSci 516 Data Intensive Computing Systems Lecture 11 Query Optimization Instructor: Sudeepa Roy Duke CS, Fall 2017 CompSci 516: Database Systems 1 Announcements HW2 has been posted on sakai Due on Oct
More informationDatabase Applications (15-415)
Database Applications (15-415) DBMS Internals- Part VII Lecture 15, March 17, 2014 Mohammad Hammoud Today Last Session: DBMS Internals- Part VI Algorithms for Relational Operations Today s Session: DBMS
More informationQuery Processing. Debapriyo Majumdar Indian Sta4s4cal Ins4tute Kolkata DBMS PGDBA 2016
Query Processing Debapriyo Majumdar Indian Sta4s4cal Ins4tute Kolkata DBMS PGDBA 2016 Slides re-used with some modification from www.db-book.com Reference: Database System Concepts, 6 th Ed. By Silberschatz,
More informationCMP-3440 Database Systems
CMP-3440 Database Systems Relational DB Languages Relational Algebra, Calculus, SQL Lecture 05 zain 1 Introduction Relational algebra & relational calculus are formal languages associated with the relational
More informationOverview of Query Evaluation. Overview of Query Evaluation
Overview of Query Evaluation Chapter 12 Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Overview of Query Evaluation v Plan: Tree of R.A. ops, with choice of alg for each op. Each operator
More informationAdministrivia. Relational Query Optimization (this time we really mean it) Review: Query Optimization. Overview: Query Optimization
Relational Query Optimization (this time we really mean it) R&G hapter 15 Lecture 25 dministrivia Homework 5 mostly available It will be due after classes end, Monday 12/8 Only 3 more lectures left! Next
More informationAnnouncement. Reading Material. Overview of Query Evaluation. Overview of Query Evaluation. Overview of Query Evaluation 9/26/17
Announcement CompSci 516 Database Systems Lecture 10 Query Evaluation and Join Algorithms Project proposal pdf due on sakai by 5 pm, tomorrow, Thursday 09/27 One per group by any member Instructor: Sudeepa
More informationSQL Data Querying and Views
Course A7B36DBS: Database Systems Lecture 04: SQL Data Querying and Views Martin Svoboda Faculty of Electrical Engineering, Czech Technical University in Prague Outline SQL Data manipulation SELECT queries
More informationCSC 261/461 Database Systems Lecture 19
CSC 261/461 Database Systems Lecture 19 Fall 2017 Announcements CIRC: CIRC is down!!! MongoDB and Spark (mini) projects are at stake. L Project 1 Milestone 4 is out Due date: Last date of class We will
More informationPrinciples of Data Management. Lecture #13 (Query Optimization II)
Principles of Data Management Lecture #13 (Query Optimization II) Instructor: Mike Carey mjcarey@ics.uci.edu Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Today s Notable News v Reminder:
More informationIan Kenny. December 1, 2017
Ian Kenny December 1, 2017 Introductory Databases Query Optimisation Introduction Any given natural language query can be formulated as many possible SQL queries. There are also many possible relational
More information