eastundersomecircumstances.Thestoragemanagerconsistsoftwocomponents,thebuffermanagerandthefilemanager.
1.Thefilemanagerkeepstrackofthelocationoffilesonthediskandobtainstheblockorblockscontainingafileonrequestfromthebuffermanager.Recallthatdisksaregenerallydividedintodiskblocks,whichareregionsofcontiguousstoragecontainingalargenumberofbytes,perhaps212or214(about4000to16,000bytes).
2.Thebuffermanagerhandlesmainmemory.Itobtainsblocksofdatafromthedisk,viathefilemanager,andchoosesapageofmainmemoryinwhichtostorethatblock.Thebuffermanagermaykeepadiskblockinmemoryisneededforanotherblock.Pagesarealsoreturnedtodiskwhenthetransactionmanagerrequiresis;seeSection1.2.4.
1.2.3TheQueryManager
Thejobofthequerymanageristoturnaqueryordatabasemanipulation.Whichmaybeexpressedataveryhighlevel(e.g.,asanSQLquery),intoasequenceofrequestsforstoreddatasuchasspecifictopplesofarelationorpartsofanindexonarelation.Oftenthehardestpartofthequery-processingtaskisqueryoptimization,thatis,theselectionofagoodqueryplanorsequenceofrequeststothestoragesystemthatwillanswerthequery.
Example1.2:supposethatabankhasadatabasewithtworelations:
1.Customersisatablegiving,foreachaccount,itsaccountnumber,,andaddress.
2.Accuntsisatablegiving,foreachaccounthasaprincipalowner,whoseSocialSecuritynumberisusedfortax-reportingpurposes;theremaybeotherownersofanaccount,butthesecannotbeknownfromthetworelationsgivenhere.
Supposealsothatthequery"findthebalancesofallaccountsofwhichSallyJonesistheprincipalowner"isasked.Thequerymanagermustfindaqueryplantoperformoftheserelations,aplanthatwillyieldtheanswertothequery.Thefewerstepstakentoanswerthequery,thebetterthequeryplanisIngeneral,thecostlystepsarethoseinwhichadiskblockiscopiedfromthediskintoapageofthebufferpoolbythestoragemanager,orapageiswrittenbackontothedisk.Thus,itisreasonabletocountonlythesedisk-blockoperationsinevaluatingthecostofaqueryplan.
Inordertoanswerthequery,weneedtoexaminethecustomer'srelationtofindtheSocialSecurityNumberofSallyJones(weassumethereisonlyonecustomerwiththatname,althoughinpracticetherecouldbeseveral).WethenneedtoexaminetheAccountsrelationtofindeveryaccountwiththatSocialSecuritynumberandprintthebalancesofthoseaccounts.
Asimplebutexpensiveplanistoexamineallthetopples(rows)ofthecustomer'srelationuntilwefindonewithSallyJonesasthecustomername.Onaverage,weshallhavetolookathalfofthetopplesbeforewefindtheonewewant.Sinceabankwillhavemanycustomers,thecustomer'srelationwilloccupymanydiskblocks,andthisstepwillbeveryexpensive.OncewehaveSallyJones'SocialSecuritynumber,wearenotyetdone.NowwehavetolookattheAccountstopplesandfindthosethathavetheselectedSocialSecuritynumber.Sincetheremaybeseveralsuchaccounts,wehavetolookatallthetopples.Atypicalbankwillhavemanyaccounts,sotheAccountsrelationwillalsooccupymanydiskblocks.Examiningthemallwillbequiteexpensive.
IfthereisanidesonthecustomernameforrelationCustomers,thenabetterplanexists.InsteadoflookingatthewholeCustomersrelation,weusetheindextofindonlythediskblockcontainingthetoppleforSallyJones.AswementionedintheboxinSection1.21,atypicalB-treeindexrequiresthatwelookatthreediskbocksoftheindexinordertofindwhatwewant.3OnemoreblockaccessgetsusthetoppleforSallyJones.
Ofcoursewestillneedtodothesecondstep:findingtheaccountswiththatSocialSecuritynumberintheAccountsrelation.Thatstepwillrequitemanydiskaccesses,typically.However,ifthereisanindexontheSocialsecuritynumberforrelationAccounts,thenwecanfindeachoftheblockscontainingoneoftheaccountswithagiveSocialSecuritynumberbygoingthroughthisindex.Todoso,wemustmake2or3diskaccessestogothroughtheindex,aswediscussedforindexedaccesstothecustomersrelation.Ifallthedesiredtopplesareondifferentdiskblocks,thenweshallhavetoaccesseachoftheseblocks.Butthereprobablyaren'ttoomanyaccountsforoneperson,sothisstepprobablyusesonlyafewdiskaccesses.Ifthesetwoindexesexist,thenwecananswerthequerywithperhaps6-10diskaccesses.Ifoneorbothofthemdonotexist,andwehavetouseoneofthepoorerqueryplans,thenthenumberofdiskaccessesmightbeinthehundredsorthousands,aswescananentire,largerelation.
ItmightappearfromExample1.2thatallthereistoqueryoptimizationistouseindexesiftheyexist.Infact,thereisagreatdealmoretothesubject.Complexqueriesoftenallowustoreorderoperations,andtheremaybeaverylargenumberofpossiblequeryplans,oftenexponentiallymanyinthesizeofthequery,Sometimeswehaveachoiceoftwoindexestouse,butwecannotuseboth.AstudyofthisimportantpartofDBMSimplementationisbeyondthescopeofthebook.
??
??
??
??
哈尔滨工业大学远程学院毕业论文
I
上一篇:
VB本科毕业论文-工资管理系统毕业论文+源码(论文和程序)
下一篇:
扛起年轻化大旗,哈弗F系玩转行业新风潮