Download presentation
Presentation is loading. Please wait.
Published byErnest Hoover Modified over 9 years ago
1
Fan Qi fan.qi@nus.edu.sg Database Lab 1, com1 #01-08 CS3223 Tutorial 8
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 Subquery flatterning
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... 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 C D A B If Q is optimal, all its subquery are optimal
6
Question 1 (A)
7
Question 1 (B) 137 180 97
8
Question 1 (C) A Implies B U A A
9
Question 2 Equiwidth histogram with 3 buckets 9 distinct value Each bucket has 3 distinct values
10
Question 3 Access Methods: Table Scan Clustered B+ tree (age, sal) Hash Index on (eid) Unclustered B+ tree (sal) Hash Index on (age)
11
Question 3 (a) Access Methods: Table Scan Clustered B+ tree (age, sal) Hash Index on (eid) Unclustered B+ tree (sal) Hash Index on (age) 20,000 Not Applicable
12
Question 3 (b) Access Methods: Table Scan Clustered B+ tree (age, sal) Hash Index on (eid) Unclustered B+ tree (sal) Hash Index on (age) Not Applicable 2,000 + 20,000
13
Question 3 (c) Access Methods: Table Scan Clustered B+ tree (age, sal) Hash Index on (eid) Unclustered B+ tree (sal) Hash Index on (age) Not Applicable
14
Question 3 (d) Access Methods: Table Scan Clustered B+ tree (age, sal) Hash Index on (eid) Unclustered B+ tree (sal) Hash Index on (age) Not Applicable 2,000 + 1 Not Applicable
15
Question 3 (e) Access Methods: Table Scan Clustered B+ tree (age, sal) Hash Index on (eid) Unclustered B+ tree (sal) Hash Index on (age) Not Applicable
16
Question 3 (f) Access Methods: Table Scan Clustered B+ tree (age, sal) Hash Index on (eid) Unclustered B+ tree (sal) Hash Index on (age) Not Applicable 2,000 + 20,000
17
Question 3 (g) Access Methods: Table Scan Clustered B+ tree (age, sal) Hash Index on (eid) Unclustered B+ tree (sal) Hash Index on (age) Not Applicable
18
Question 3 (h) Access Methods: Table Scan Clustered B+ tree (age, sal) Hash Index on (eid) Unclustered B+ tree (sal) Hash Index on (age) Not Applicable
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.