Click here to load reader

CS3223 Tutorial 8

  • Upload
    ted

  • View
    94

  • Download
    0

Embed Size (px)

DESCRIPTION

CS3223 Tutorial 8. Fan Qi [email protected] 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. - PowerPoint PPT Presentation

Citation preview

CS3223 Tutorial 2

Fan Qi [email protected] Lab 1, com1 #01-08CS3223 Tutorial 8Query OptimizationSimilar to other optimization Optimize by search

Two main factor:Search Space: how many candidatesEvaluation function : how to judge which candidate is good

Search SpaceQuery PlanQuery OptimizationSearch Space EnumerationRelational Algebra EquivalencesQuery rewrite:View rewriteSemantic rewriteSubquery flatterning Query OptimizationEvaluation function:A.K.A cost model

Evaluate query plan based on statistical informationAssumptions:Independence, Uniform distribution, inclusion assumptionReduction FactorSelectivity Histogram:EquiwidthEquidepthNumber of RowsPer Column Distinct ValuePer Column Value DistributionCombined Column Value DistributionAvailable Index...Query OptimizationWhat if we know both ?

Dynamic programming optimizationOptimal SubstructureCDABIf Q is optimal, all its subquery are optimalQuestion 1 (A)

Question 1 (B)

13718097Question 1 (C)AImpliesBUAAQuestion 2 Equiwidth histogram with 3 buckets 9 distinct valueEach bucket has 3 distinct values

Question 3Access Methods:Table ScanClustered B+ tree (age, sal)Hash Index on (eid)Unclustered B+ tree (sal)Hash Index on (age)Question 3 (a) Access Methods:Table ScanClustered B+ tree (age, sal)Hash Index on (eid)Unclustered B+ tree (sal)Hash Index on (age)20,000Not ApplicableNot ApplicableQuestion 3 (b) Access Methods:Table ScanClustered B+ tree (age, sal)Hash Index on (eid)Unclustered B+ tree (sal)Hash Index on (age)Not ApplicableNot Applicable2,000 + 20,000Question 3 (c) Access Methods:Table ScanClustered B+ tree (age, sal)Hash Index on (eid)Unclustered B+ tree (sal)Hash Index on (age)Not ApplicableNot ApplicableNot ApplicableQuestion 3 (d) Access Methods:Table ScanClustered B+ tree (age, sal)Hash Index on (eid)Unclustered B+ tree (sal)Hash Index on (age)Not Applicable2,000 + 1Not ApplicableQuestion 3 (e) Access Methods:Table ScanClustered B+ tree (age, sal)Hash Index on (eid)Unclustered B+ tree (sal)Hash Index on (age)Not ApplicableNot ApplicableQuestion 3 (f) Access Methods:Table ScanClustered B+ tree (age, sal)Hash Index on (eid)Unclustered B+ tree (sal)Hash Index on (age)Not Applicable2,000 + 20,000Question 3 (g) Access Methods:Table ScanClustered B+ tree (age, sal)Hash Index on (eid)Unclustered B+ tree (sal)Hash Index on (age)Not ApplicableNot ApplicableQuestion 3 (h) Access Methods:Table ScanClustered B+ tree (age, sal)Hash Index on (eid)Unclustered B+ tree (sal)Hash Index on (age)Not ApplicableNot ApplicableThank you!Happy Good Friday & Easter !