access path selection in a relational dbms
play

Access Path Selection in a Relational DBMS Original Slides by - PowerPoint PPT Presentation

Access Path Selection in a Relational DBMS Original Slides by Presentation: Stephen Ingram Modified by: Rachel Pottinger Why bother to optimize? Queries must be executed and execution takes time There are multiple execution plans


  1. Access Path Selection in a Relational DBMS Original Slides by Presentation: Stephen Ingram Modified by: Rachel Pottinger

  2. Why bother to optimize? • Queries must be executed and execution takes time • There are multiple execution plans for most queries • Some plans cost less than others

  3. Simple Example • SELECT * FROM A,B,C WHERE A.n = B.n AND B.m = C.m • A = 100 tuples • B = 50 tuples • C = 2 tuples • Which plan is cheaper? – Join( C, Join( A, B ) ) – Join( A, Join( B, C ) )

  4. How did we find the right one? 1. Measure the cost of each query 2. Enumerate possibilities 3. Pick the least expensive one • Is that all?

  5. But the search space is too big • Just for this simple join example, we have a factorial search space ( n! ) • Just to remind you, – 20! = 2,432,902,008,176,640,000 • So now what do we do?

  6. Use Statistics • For each relation keep track of – Cardinality of tuples – Cardinality of pages – Etc. • Use these statistics in conjunction with – Predicates – Interesting Orders

  7. Predicates • Predicates like =, >, NOT, etc. reduce the number of tuples • THUS: Evaluate predicates as early as possible

  8. Interesting Orders • GROUP BY and ORDER BY or sort- merge joins generate interesting orders • We must consider WHEN we generate the interesting order into the cost of a plan • Ordering it first may be cheaper than sorting later even though it is initially cheaper to leave it unsorted

  9. But… • Statistics alone cannot save us – Expensive to compute – Can’t keep track of all joint statistics • Compromise on statistics – Periodically update stats for each relation • Compromise on search – Dynamic programming approach

  10. Dynamic programming (Wikipedia) • Optimal substructure means that optimal solutions of subproblems can be used to find the optimal solutions of the overall problem. 1. Break the problem into smaller subproblems. 2. Solve these problems optimally using this three-step process recursively. 3. Use these optimal solutions to construct an optimal solution for the original problem.

  11. Optimal Substructure in Joins • An N-Join is really just a sequence of 2-Joins – 2-join becomes a single composite relation • Important fact: The method to join to composite is independent of the ordering of the composite • Find the cheapest join of a subset of the N tables and store (memoization) • This costs 2 n , which is << n!

  12. From the Top • Enumerate access paths to each relation – Sequential scans – Interesting orders • Enumerate access paths to join a second relation to these results (if there is a predicate to do so) – Nested loop (unordered) – Merge (interesting order) • Compare with equivalent solutions found so far but only keep the cheapest

  13. Example Schema

  14. Example Query

  15. Example Initial Access Paths

  16. Example Search Tree

  17. 2 Relations Nested Loop

  18. 2 Relations Merge Join

  19. Prune and 3 Relations

  20. Major Contributions of Paper • Cost based optimization – Statistics – CPU utilization (for sorts, etc.) • Dynamic programming approach • Interesting Orders

  21. Discussion • The authors mention that one of the key contributions of their path selector is the inclusion of CPU utilization into the cost formulas. With the current advancements in technology concerning processors, storage and storage systems, would this concern be changed now and how would this affect the cost function? • How does understanding access path selection affect how we think about interpreting/understanding databses, data management or how we interact with data? What do you think is the value of understanding this beyond a precursory understanding?

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend