版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Chapter8
Indexing2023/11/8Indexing2Indexing8.1TheConceptofIndexing8.2DiskStorage8.3TheB-TreeIndex8.4ClusteredandNon-ClusteredIndexes8.5AHashPrimaryIndex8.6ThrowingDartsatRandomSlots2023/11/8Indexing38.1TheConceptofIndexingIndexanindexislikeacardcataloginalibrary.Eachcard(entry)has:(keyvalue,row-pointer)keyvalueisforlookuprow-pointer(ROWID)isenoughtolocaterowondisk(oneI/O)2023/11/8Indexing48.1TheConceptofIndexingIndex:(keyvalue,row-pointer)EntriesareplacedinAlphabeticalorderbylookupkeyin"B-tree"(usually),alsomightbehashed.Anindexisalotlikememoryresidentstructures.Butindexisdiskresident.Likethedataitself,oftenwon'tallfitinmemoryatonce.Indexcanberegardedasatablewithtwocolumns:keyvalueandrow-pointer2023/11/8Indexing58.1TheConceptofIndexingFigure8.1:theSQLCreateIndexStatementCREATE[UNIQUE]INDEXindexname
ONtablename(colname
[ASC|DESC]{,colname
[ASC|DESC]...});DROPINDEXindexname;UNIQUEkeyvalueandrowisone-to-onewecanuseUNIQUEINDEXtoimplementUNIQUEconstraintsinCreateTableStatement.2023/11/8Indexing68.1TheConceptofIndexingExample8.1.1createindexcitiesxoncustomers(city);eachindexkeyvalue(i.e.,cityname)inthecitiesxindexcancorrespondtoalargenumberofdifferentcustomersrows.2023/11/8Indexing78.1TheConceptofIndexingExample8.1.2createuniqueindexcidxoncustomers(cid);eachindexkeyvalueinthecidxindexonlycorrespondtoacustomersrows.Indexkeyisquitedifferentfromrelationalconceptofprimarykeyorcandidatekey.But,wecanuseUNIQUEINDEXandNOTNULLtoimplementprimarykeyorcandidatekey.2023/11/8Indexing88.1TheConceptofIndexingIndexingAfterbeingcreated,indexissortedandplacedondisk.Sortisbycolumnvalueascordesc,asinSORTBYdescriptionofSelectstatement.NOTELATERCHANGEStoatableareimmediatelyreflectedintheindex,don'thavetocreateanewindex.2023/11/8Indexing98.2DiskStorageDatabaseStorageComputermemoryveryfastbutVolatile(挥发性的)storage.Diskstorageveryslowbutnon-volatileandverycheap.2023/11/8Indexing108.2DiskStoragemainmemorysecondarystoragetertiarystoragecachememorytapeCDdisksizesmallbigspeedfastslowcosthighlow2023/11/8Indexing118.2DiskStorageDiskAccessSeektime .008secondsThediskarmmovesinorouttothepropercylinderposition.Rotationallatency .004secondsThediskplatterrotatestotheproperangularposition.Transfertime .0005secondsThediskarmreads/writesthediskpageontheappropriatesurface.accessmemory:10-8~10-7seconds2023/11/8Indexing128.2DiskStorageMemoryBuffer(Figure8.2,pg.472)Readpagesintomemorybuffersocanaccessthem.Oncetorightplaceondisk,transfertimeischeap.Everytimewantapagefromdisk,hashondkpgaddr,h(dkpgaddr)toentryinHashlookasidetabletoseeifthatpageisalreadyinbuffer.2023/11/8Indexing138.2DiskStorageMemoryBuffer(cont.)AdvantagessaveddiskI/OfindsomethingforCPUtodowhilewaitingforI/O.Thisisoneoftheadvantagesofmulti-usertimesharing.CandoCPUworkforotheruserswhilewaitingforthisdiskI/O.2023/11/8Indexing148.2DiskStorageCreateTablespaceinORACLEFigure8.3,pg.476TablespacemadeupofOSfilescross2023/11/8Indexing158.2DiskStorageDataStoragePagesandRowPointers(Figure8.6,pg.480)Arowonmostarchitecturesisacontiguoussequenceofbytes.Nrowsplacedononepage(calledaBlockinORACLE).Headerinfonamesthekindofpage(datasegment,indexsegment),andthepagenumber(inORACLEtheOSfileandpagenumber).2023/11/8Indexing168.2DiskStorageROWsinpageRowsaddedrighttoleftfromrightendonblock.RowDirectoryentrieslefttorightonleftafterheader.Giveoffsetsofcorrespondingrowbeginnings.Providenumberofrowslotonpage.2023/11/8Indexing178.2DiskStorageWhennewrowadded,tellimmediatelyifwehavefreespacefornewdirectoryentryandnewrow.Conceptually,allspaceinmiddle,implieswhendeleterowandreclaimspacemustshifttofillingap.Alsomighthave"TableDirectory"inblockwhenhaveCLUSTER.2023/11/8Indexing188.2DiskStorageDiskPointerArowinatablecanbeuniquelyspecifiedwiththepagenumber(P)andslotnumber(S).RowsExtendingOverSeveralPagesProductVariations2023/11/8Indexing19Indexing8.1TheConceptofIndexing8.2DiskStorage8.3TheB-TreeIndex8.4ClusteredandNon-ClusteredIndexes8.5AHashPrimaryIndex8.6ThrowingDartsatRandomSlots2023/11/8Indexing208.3TheB-TreeIndexTheB-TreeEachnodeofthetreetakesupafulldiskpagehasalotoffanout2023/11/8Indexing21CreateIndexstatementinORACLECREATE[UNIQUE|BITMAP]INDEX[schema.]indexnameONtablename(colname
[ASC|DESC]{,colname
[ASC|DESC]…})[TABLESPACEtblespace
]
[STORAGE...][PCTFREEn
][
][NOSORT]UNIQUE|BITMAPASC|DESCTABLESPACEPCTFREENOSORT2023/11/8Indexing228.3TheB-TreeIndexCreatingIndexreadsthroughallrowsondisk(assumeN)pullsout(keyvalue,rowid)pairsforeachrowGetfollowinglist(inorderbykeyvals)putoutondisk(keyval1,rowid1)(keyval2,rowid2)...(keyvalN,rowidN)IfhaveNOSORTclause,rowsareinrightorder,sodon’thavetosort.2023/11/8Indexing23createuniqueindexsdxonS(sno)NOSORT;createindexndxonS(name)PCTFREE25;18PHShenS8817MASenS7717CSWangS6619PHLinS5518CSLoS4418MAXuS3317CSLiS2218CSLuS11agedeptnamesnoROWID8S87S76S65S54S43S32S21S1ROWIDsnoTableSIndexsdxIndexndxnameROWIDLi2Lin5Lo4Lu1Sen7Shen8Wang6Xu32023/11/8Indexing24Example8.3.1(pg.486)IdeaofBinarySearch/*binsearch:returnKsothatarr[K].keyval==x,or-1ifnomatch;*/intbinsearch(intx){intprobe=3,diff=2;while(diff>0){ /*loopuntilKtoreturn*/if(probe<=6&&x>arr[probe].keyval)probe=probe+diff;elseprobe=probe-diff;diff=diff/2;} /*wehavereachedfinalK*/if(probe<=6&&x==arr[probe].keyval)returnprobe;elseif(probe+1<=6&&x==arr[probe+1].keyval)returnprobe+1;elsereturn-1;}2023/11/8Indexing258.3TheB-TreeIndexExp8.3.2BinaryofaMillionIndexEntriesnumberofentries:1000000(106)sizeofentry:8bytessizeofdiskpage:2kbytesnumberofentriesineachdiskpage:250totalnumberofdiskpages:4000log24000
+1
≈13averagenumberofdiskI/O2023/11/8Indexing268.3TheB-TreeIndexExample8.3.3B-TreeStructureLayoutallentriesonleafnodesLevel1:RootNodeLevel2~LevelN-1:DirectoryNodesLevel2~LevelN-1:DirectoryNodesLevelN:LeafNode2023/11/8Indexing278.3TheB-TreeIndexTheStructureofB-TreeNodeK1,K2,…,Kmarekeyvalues,andK1<K2<…<Kmnismaximumnumberofkeyvalueinanode
LeafNode:
(n+1)/2
m
nPiisaROWIDwhichkeyvalueisKi(i=1,2,…,m)Pm+1isapointertonextleafnodeP1K1P2K2……PmKmPm+12023/11/8Indexing288.3TheB-TreeIndexRootNode:1
m
nInterNode:
(n-1)/2
m
nPiisapointertochildnode(rootnodeofsub-treeTi)foreachkeyvalueKonsub-treeTi,wehaveIfi=1: K<K1If1<i
m: Ki-1
K<KiIfi=m+1: K
KmP1K1P2K2……PmKmPm+12023/11/8Indexing298.3TheB-TreeIndexExample:leafnode(n=3)2023/11/8Indexing308.3TheB-TreeIndexExample:directoryorrootnode(n=3)2023/11/8Indexing31Example8.3.3(cont.)numberofentries:1000000(106)sizeofentry:8bytessizeofdiskpage:2kbytesnumberofentriesineachnode(diskpage)2k/8≈250totalnumberofleafnode1000000/250=4000totalnumberofdirectorynode:4000/250=16rootnodeaveragenumberofdiskI/O3(depthoftheB-Tree)
+1=4(rootnode)+(directorynode)+(leafnode)2023/11/8Indexing328.3TheB-TreeIndexHowtocreateanindexsortallentriesonleafnodescreatedirectory,anddirectorytodirectoryFanoutfofB-TreethemaximumnumberofentriesonaB-TreenodeDepthofB-TreeIftotalnumberofrowsisN,thendepth=logf(N)2023/11/8Indexing338.3TheB-TreeIndexDynamicchangesintheB-treeFigure8.12(pg.491)InsertfollowingkeyvaluesintoB-Tree(n=3)7,96,41,39,88,65,55,62Ideaof[PCTFREEn]2023/11/8Indexing34Def8.3.1:PropertiesoftheB-Tree(B+Tree)Everynodeisdisksizedandresidesinawell-definedlocationonthedisk.Nodesabovetheleaflevelcontaindirectoryentries,with(n–1)separatorkeysandndiskpointerstolower-levelB-treenodes.Nodesattheleaflevelcontainentrieswith(keyval,ROWID)pairspointingtoindividualrowsindexed.Allnodesbelowtherootareatleasthalffullwithentryinformation.Thisisnotoftenenforcedaftermultipledeletes.Therootnodecontainsatleasttwoentries(onekeyvalue).exceptwhenonlyonerowisindexedandtherootisaleafnode.2023/11/8Indexing358.3TheB-TreeIndexAlgorithmonB-Treesearchinsertdeleteupdate=delete+insert2023/11/8Indexing368.3TheB-TreeIndexTheORACLEBitmapIndexAbitmapindexusesONEbitmapforeachdistinctkeyval.AbitmaptakestheplaceofaROWIDlist,specifyingasetofrows.onebitvsaROWID(row)1:therowhavethekeyval0:therowdon’thavethekeyvalExampleFigure8.18(pg.501)2023/11/8Indexing378.4ClusteredandNon-ClusteredIndexesTheideaofaclusteredindexTherowsofthetableareinthesameorderastheindexentries—bykeyvalue.Inmostdatabaseproducts,defaultplacemenofrowsondatapagesondiskisinorderby
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026上半年云南开放大学招聘管理人员1人备考题库附参考答案详解(突破训练)
- 2026上半年安徽事业单位联考霍山县招聘43人备考题库附答案详解(突破训练)
- 2026广东广州花都区狮岭镇益群小学临聘教师招聘1人备考题库附参考答案详解(培优)
- 2026上半年黑龙江齐齐哈尔大学招聘硕士人员27人备考题库及答案详解(真题汇编)
- 2026四川巴中天坛生物通江血浆站招聘护士、医生的备考题库含答案详解(模拟题)
- 2026中国医学科学院医药生物技术研究所社会招聘18人备考题库附参考答案详解ab卷
- 2026云南昭通市市场监督管理局招聘城镇公益性岗位工作人员2人的备考题库含答案详解
- 2026四川成都经开建工集团有限公司招聘项目制工作人员6人备考题库附答案详解(综合题)
- 2026北京航空航天大学可靠性与系统工程学院聘用编软件测试工程师F岗招聘2人备考题库附参考答案详解(b卷)
- 2026内蒙古包头西部人才集团为春风十里招聘工作人员备考题库附参考答案详解ab卷
- (2026年春新版本)人教版二年级数学下册全册教案
- DB15-T 4265-2026 零碳产业园配套新能源规划编制规范
- 2025年度康复科护理质控工作总结与2026年规划
- 2026年保育员初级考试试题及答案
- 2025至2030电阻式随机存取存储器行业调研及市场前景预测评估报告
- 新人培训主播课件
- 2026年苏州工业园区服务外包职业学院单招职业技能考试备考试题附答案详解
- 铝合金门窗安装打胶方案
- 贵州省贵阳市2024-2025学年高一上学期期末监测物理试卷(含解析)
- 管路开挖施工方案(3篇)
- 兽药行业兽药研发工程师岗位招聘考试试卷及答案
评论
0/150
提交评论