欢迎来到天天文库
浏览记录
ID:27878209
大小:1.11 MB
页数:89页
时间:2018-12-05
《《查询优化》ppt课件》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、第6章查询优化本章内容参考数据库概念(第四版)byA.SilberschatzChapter14Optimization简介+自学本章要解决的关键问题如何找到具有最低求值代价的求值计划主要内容概述用于代价估算的统计信息关系代数表达式的转换基于代价的优化算法物化视图与视图维护概述一个给定查询有多种可选择的求值方法等价表达式一个操作有若干不同算法(Chapter5)一个查询求值方法的好坏带来的代价差别可能是巨大的例如:执行rXs后续选择r.A=s.B比执行一个同样条件的连接慢得多需要估算操作的代价依赖于数据库
2、维护的统计信息例如元组数,连接属性的不同值的数目,等等需要对中间结果估算统计信息以便对复杂表达式计算代价概述概述对一个表达式的查询求值方案的生成涉及几个步骤:生成逻辑上等价的表达式利用等价规则将一个表达式转换成另一个等价的表达式注解(Annotate)结果表达式以得到其他查询计划基于估算代价选择最廉价的计划整个过程称为基于代价的优化SQLConstructsSECLECT(DISTINCT)FROMWHERE3、s>GROUPBYHAVINGORDERBYSQLSemanticsTakeCartesianproductofFROMtablesProjectonlythosereferencedcolumnsWHERE:applyallfiltersinWHEREGROUPBY:formgroupsonresultsHAVING:applyfiltertogroupsORDERBY:makesureresults4、inrightorderDISTINCT:removeduplicatesQ:Isthis“operationalsemantics”efficient?Differentplans:mainlydifferentinthefirstthreeOptimization:DifferentStrategiesOptimalapproach:Enumerate(枚举)eachpossibleplanMeasureitsperformancebyrunningitPickthefastestoneHeurist5、icsapproach:fixedheuristicsallthewaythroughplanconstructione.g.:alwaysnestedloopjoins,indexedrelationasinnere.g.:orderrelationsfromsmallesttobiggestCost-basedOptimizationPlanspace:whatisthespaceofqueryplans?Costestimation:howtoestimatethecost,withoutexecu6、tingeach?Searchalgorithm:howtosearchthespace,asguidedbycostestimatesSpaceofQueryPlansSelections:algorithms:sequential,indexscanJoins:algorithms:nested-loop,sortmerge,hashOrdering/Grouping:canan“interestingorder”beproducedbyjoin/selections?algorithm:sortin7、g,hash-basedTheyinterleavewitheachother!HugeSpace!AssumptionstoHelpTypicalassumptionstohelpreducethespace:Projections:pusheddowntoreduce#ofcolumnsSelections:pusheddowntoreduce#ofrowsJoins:left-deepjoinsavoidCartesianproducts;delayitintheplanQ:howtoavoidCa8、rtesianproducts?Maymissanoptimalplan!Cost/SizeEstimationAccuraterelativelygoalistocompareplans,nottopredictexactcostmoreofanartthananexactscienceEachoperator:inputsize,cost,outputsizeestimatecostbasedoninputsizeesti
3、s>GROUPBYHAVINGORDERBYSQLSemanticsTakeCartesianproductofFROMtablesProjectonlythosereferencedcolumnsWHERE:applyallfiltersinWHEREGROUPBY:formgroupsonresultsHAVING:applyfiltertogroupsORDERBY:makesureresults
4、inrightorderDISTINCT:removeduplicatesQ:Isthis“operationalsemantics”efficient?Differentplans:mainlydifferentinthefirstthreeOptimization:DifferentStrategiesOptimalapproach:Enumerate(枚举)eachpossibleplanMeasureitsperformancebyrunningitPickthefastestoneHeurist
5、icsapproach:fixedheuristicsallthewaythroughplanconstructione.g.:alwaysnestedloopjoins,indexedrelationasinnere.g.:orderrelationsfromsmallesttobiggestCost-basedOptimizationPlanspace:whatisthespaceofqueryplans?Costestimation:howtoestimatethecost,withoutexecu
6、tingeach?Searchalgorithm:howtosearchthespace,asguidedbycostestimatesSpaceofQueryPlansSelections:algorithms:sequential,indexscanJoins:algorithms:nested-loop,sortmerge,hashOrdering/Grouping:canan“interestingorder”beproducedbyjoin/selections?algorithm:sortin
7、g,hash-basedTheyinterleavewitheachother!HugeSpace!AssumptionstoHelpTypicalassumptionstohelpreducethespace:Projections:pusheddowntoreduce#ofcolumnsSelections:pusheddowntoreduce#ofrowsJoins:left-deepjoinsavoidCartesianproducts;delayitintheplanQ:howtoavoidCa
8、rtesianproducts?Maymissanoptimalplan!Cost/SizeEstimationAccuraterelativelygoalistocompareplans,nottopredictexactcostmoreofanartthananexactscienceEachoperator:inputsize,cost,outputsizeestimatecostbasedoninputsizeesti
此文档下载收益归作者所有