Fan Qi Database Lab 1, com1 #01-08 CS3223 Tutorial 8
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
Query Optimization Search Space Enumeration Relational Algebra Equivalences Query rewrite: View rewrite Semantic rewrite Subquery flatterning
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...
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
Question 1 (A)
Question 1 (B)
Question 1 (C) A Implies B U A A
Question 2 Equiwidth histogram with 3 buckets 9 distinct value Each bucket has 3 distinct values
Question 3 Access Methods: Table Scan Clustered B+ tree (age, sal) Hash Index on (eid) Unclustered B+ tree (sal) Hash Index on (age)
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
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
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
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, Not Applicable
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
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
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
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