1 / 19

CS3223 Tutorial 8

CS3223 Tutorial 8. Fan Qi fan.qi@nus.edu.sg Database Lab 1, com1 #01-08. Query Optimization. Similar to other optimization Optimize by search Two main factor: Search Space: how many candidates Evaluation function : how to judge which candidate is good. Search Space. Query Plan.

ted
Download Presentation

CS3223 Tutorial 8

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS3223 Tutorial 8 Fan Qi fan.qi@nus.edu.sg Database Lab 1, com1 #01-08

  2. Query Optimization • Similar to other optimization • Optimize by search • Two main factor: • Search Space: how many candidates • Evaluation function : how to judge which candidate is good Search Space Query Plan

  3. Query Optimization • Search Space Enumeration • Relational Algebra Equivalences • Query rewrite: • View rewrite • Semantic rewrite • Subqueryflatterning

  4. Query Optimization • Evaluation function: • A.K.A cost model • Evaluate query plan based on statistical information • Assumptions: • Independence, Uniform distribution, inclusion assumption • Reduction Factor • Selectivity • Histogram: • Equiwidth • Equidepth • Number of Rows • Per Column Distinct Value • Per Column Value Distribution • Combined Column Value Distribution • Available Index • ...

  5. Query Optimization • What if we know both ? • Dynamic programming optimization • Optimal Substructure If Q is optimal, all its subquery are optimal B A D C

  6. Question 1 (A) Cost of ? First Join: Second Join:

  7. Question 1 (B) Cost of ? 137 Cost of ? 180 Cost of ? 97

  8. Question 1 (C) Implies ? A A U A B

  9. Question 2 • Equiwidth histogram with 3 buckets • 9 distinct value • Each bucket has 3 distinct values

  10. Question 3 Table Scan data pages Clustered B+ tree (age, sal) : leaf page Height: Access Methods: Hash Index on (eid) : page (uniform distribution) Unclustered B+ tree (sal) : leaf page Height: Hash Index on (age) : pages (uniform distribution)

  11. Question 3 (a) Table Scan tuples Clustered B+ tree (age, sal) Access Methods: Hash Index on (eid) Not Applicable Unclustered B+ tree (sal) 20,000 Not Applicable Hash Index on (age)

  12. Question 3 (b) Table Scan tuples Clustered B+ tree (age, sal) Access Methods: Hash Index on (eid) Not Applicable Unclustered B+ tree (sal) Not Applicable Hash Index on (age) 2,000 + 20,000

  13. Question 3 (c) Table Scan tuples Clustered B+ tree (age, sal) Access Methods: Hash Index on (eid) Not Applicable Unclustered B+ tree (sal) Not Applicable Hash Index on (age) Not Applicable

  14. Question 3 (d) Table Scan tuple Clustered B+ tree (age, sal) Access Methods: Hash Index on (eid) 2,000 + 1 Unclustered B+ tree (sal) Not Applicable Hash Index on (age) Not Applicable

  15. Question 3 (e) Table Scan tuple Clustered B+ tree (age, sal) Access Methods: Hash Index on (eid) Not Applicable Unclustered B+ tree (sal) Hash Index on (age) Not Applicable

  16. Question 3 (f) Table Scan tuple Clustered B+ tree (age, sal) Access Methods: Hash Index on (eid) Not Applicable Unclustered B+ tree (sal) Hash Index on (age) 2,000 + 20,000

  17. Question 3 (g) Table Scan tuple Clustered B+ tree (age, sal) Access Methods: Hash Index on (eid) Not Applicable Unclustered B+ tree (sal) Hash Index on (age) Not Applicable

  18. Question 3 (h) Table Scan tuples Clustered B+ tree (age, sal) Access Methods: Hash Index on (eid) Not Applicable Unclustered B+ tree (sal) Not Applicable Hash Index on (age)

  19. Thank you! Happy Good Friday & Easter !

More Related