




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、Database System Concepts, 5th Ed.Silberschatz, Korth and SudarshanSee www.db- for conditions on re-use Silberschatz, Korth and Sudarshan12.2Database System Concepts - 5th Edition, Aug 12, 2005.nBasic ConceptsnOrdered Indices nB+-Tree Index FilesnStatic HashingnDynamic Hashing nComparison of Ordered
2、Indexing and Hashing nIndex Definition in SQLnMultiple-Key AccessSilberschatz, Korth and Sudarshan12.3Database System Concepts - 5th Edition, Aug 12, 2005.nIndexing mechanisms used to speed up access to desired data.lE.g., author catalog in librarynSearch Key - attribute to set of attributes used to
3、 look up records in a file.nAn index file consists of records (called index entries) of the formnIndex files are typically much smaller than the original file nTwo basic kinds of indices:lOrdered indices: search keys are stored in sorted orderlHash indices: search keys are distributed uniformly acro
4、ss “buckets” using a “hash function”. search-keypointerSilberschatz, Korth and Sudarshan12.4Database System Concepts - 5th Edition, Aug 12, 2005.nAccess types supported efficiently. E.g., lrecords with a specified value in the attributelor records with an attribute value falling in a specified range
5、 of values.nAccess timenInsertion timenDeletion timenSpace overheadSilberschatz, Korth and Sudarshan12.5Database System Concepts - 5th Edition, Aug 12, 2005.nIn an ordered index, index entries are stored sorted on the search key value. E.g., author catalog in library.nPrimary index: in a sequentiall
6、y ordered file, the index whose search key specifies the sequential order of the file.lAlso called clustering indexlThe search key of a primary index is usually but not necessarily the primary key.nSecondary index: an index whose search key specifies an order different from the sequential order of t
7、he file. Also called non-clustering index.nIndex-sequential file: ordered sequential file with a primary index.Silberschatz, Korth and Sudarshan12.6Database System Concepts - 5th Edition, Aug 12, 2005.nDense index Index record appears for every search-key value in the file. Silberschatz, Korth and S
8、udarshan12.7Database System Concepts - 5th Edition, Aug 12, 2005.nSparse Index: contains index records for only some search-key values.lApplicable when records are sequentially ordered on search-keynTo locate a record with search-key value K we:lFind index record with largest search-key value KlSear
9、ch file sequentially starting at the record to which the index record pointsnLess space and less maintenance overhead for insertions and deletions.nGenerally slower than dense index for locating records.nGood tradeoff: sparse index with an index entry for every block in file, corresponding to least
10、search-key value in the block.Silberschatz, Korth and Sudarshan12.8Database System Concepts - 5th Edition, Aug 12, 2005.Silberschatz, Korth and Sudarshan12.9Database System Concepts - 5th Edition, Aug 12, 2005.nIf index does not fit in memory, access becomes expensive.nTo reduce number of disk acces
11、ses to index records, treat index kept on disk as a sequential file and construct a sparse index on it.louter index a sparse index of inner indexlinner index the index filenIf even outer index is too large to fit in main memory, yet another level of index can be created, and so on.nIndices at all le
12、vels must be updated on insertion or deletion from the file.Silberschatz, Korth and Sudarshan12.10Database System Concepts - 5th Edition, Aug 12, 2005.Silberschatz, Korth and Sudarshan12.11Database System Concepts - 5th Edition, Aug 12, 2005.nIf deleted record was the only record in the file with it
13、s particular search-key value, the search-key is deleted from the index also.nSingle-level index deletion:lDense indices deletion of search-key is similar to file record deletion.lSparse indices 4 if an entry for the search key exists in the index, it is deleted by replacing the entry in the index w
14、ith the next search-key value in the file (in search-key order). 4If the next search-key value already has an index entry, the entry is deleted instead of being replaced.Silberschatz, Korth and Sudarshan12.12Database System Concepts - 5th Edition, Aug 12, 2005.nSingle-level index insertion:lPerform
15、a lookup using the search-key value appearing in the record to be inserted.lDense indices if the search-key value does not appear in the index, insert it.lSparse indices if index stores an entry for each block of the file, no change needs to be made to the index unless a new block is created. 4If a
16、new block is created, the first search-key value appearing in the new block is inserted into the index.nMultilevel insertion (as well as deletion) algorithms are simple extensions of the single-level algorithmsSilberschatz, Korth and Sudarshan12.13Database System Concepts - 5th Edition, Aug 12, 2005
17、.nFrequently, one wants to find all the records whose values in a certain field (which is not the search-key of the primary index) satisfy some condition.lExample 1: In the account relation stored sequentially by account number, we want to find all accounts with a specified balance or range of balan
18、cesnWe can have a secondary index with an index record for each search-key valuel index record points to a bucket that contains pointers to all the actual records with that particular search-key value.Silberschatz, Korth and Sudarshan12.14Database System Concepts - 5th Edition, Aug 12, 2005.Silbersc
19、hatz, Korth and Sudarshan12.15Database System Concepts - 5th Edition, Aug 12, 2005.nSecondary indices have to be dense.nIndices offer substantial benefits when searching for records.nWhen a file is modified, every index on the file must be updated, Updating indices imposes overhead on database modif
20、ication.nSequential scan using primary index is efficient, but a sequential scan using a secondary index is expensive leach record access may fetch a new block from diskSilberschatz, Korth and Sudarshan12.16Database System Concepts - 5th Edition, Aug 12, 2005.nDisadvantage of indexed-sequential file
21、s: performance degrades as file grows, since many overflow blocks get created. Periodic reorganization of entire file is required.nAdvantage of B+-tree index files: automatically reorganizes itself with small, local, changes, in the face of insertions and deletions. Reorganization of entire file is
22、not required to maintain performance.nDisadvantage of B+-trees: extra insertion and deletion overhead, space overhead.nAdvantages of B+-trees outweigh disadvantages, and they are used extensively.B+-tree indices are an alternative to indexed-sequential files.Silberschatz, Korth and Sudarshan12.17Dat
23、abase System Concepts - 5th Edition, Aug 12, 2005.nAll paths from root to leaf are of the same lengthnEach node that is not a root or a leaf has between n/2 and n children.nA leaf node has between (n1)/2 and n1 valuesn If the root is a leaf (that is, there are no other nodes in the tree), it can hav
24、e between 0 and (n1) values.A B+-tree is a rooted tree satisfying the following properties:Silberschatz, Korth and Sudarshan12.18Database System Concepts - 5th Edition, Aug 12, 2005.nTypical nodelKi are the search-key values lPi are pointers to children (for non-leaf nodes) or pointers to records or
25、 buckets of records (for leaf nodes).nThe search-keys in a node are ordered K1 K2 K3 . . . Kn1Silberschatz, Korth and Sudarshan12.19Database System Concepts - 5th Edition, Aug 12, 2005.nFor i = 1, 2, . . ., n1, pointer Pi either points to a file record with search-key value Ki, or to a bucket of poi
26、nters to file records, each record having search-key value Ki. Only need bucket structure if search-key does not form a primary key.nIf Li, Lj are leaf nodes and i k.2.If such a value exists, assume it is Kj. Then follow Pi to the child node3.Otherwise k Km1, where there are m pointers in the node.
27、Then follow Pm to the child node.2.If the node reached by following the pointer above is not a leaf node, repeat step 1 on the node3.Else we have reached a leaf node. 1. If for some i, key Ki = k follow pointer Pi to the desired record or bucket. 2.Else no record with search-key value k exists.Silbe
28、rschatz, Korth and Sudarshan12.25Database System Concepts - 5th Edition, Aug 12, 2005.nIn processing a query, a path is traversed in the tree from the root to some leaf node.nIf there are K search-key values in the file, the path is no longer than logn/2(K).nA node is generally the same size as a di
29、sk block, typically 4 kilobytes, and n is typically around 100 (40 bytes per index entry).nWith 1 million search key values and n = 100, at most log50(1,000,000) = 4 nodes are accessed in a lookup.nContrast this with a balanced binary free with 1 million search key values around 20 nodes are accesse
30、d in a lookuplabove difference is significant since every node access may need a disk I/O, costing around 20 milliseconds!Silberschatz, Korth and Sudarshan12.26Database System Concepts - 5th Edition, Aug 12, 2005.nFind the leaf node in which the search-key value would appearnIf the search-key value
31、is already there in the leaf node, record is added to file and if necessary a pointer is inserted into the bucket.nIf the search-key value is not there, then add the record to the main file and create a bucket if necessary. Then:lIf there is room in the leaf node, insert (key-value, pointer) pair in
32、 the leaf nodelOtherwise, split the node (along with the new (key-value, pointer) entry) as discussed in the next slide.Silberschatz, Korth and Sudarshan12.27Database System Concepts - 5th Edition, Aug 12, 2005.nSplitting a node:ltake the n(search-key value, pointer) pairs (including the one being i
33、nserted) in sorted order. Place the first n/2 in the original node, and the rest in a new node.llet the new node be p, and let k be the least key value in p. Insert (k,p) in the parent of the node being split. If the parent is full, split it and propagate the split further up.nThe splitting of nodes
34、 proceeds upwards till a node that is not full is found. In the worst case the root node may be split increasing the height of the tree by 1. Result of splitting node containing Brighton and Downtown on inserting ClearviewSilberschatz, Korth and Sudarshan12.28Database System Concepts - 5th Edition,
35、Aug 12, 2005.B+-Tree before and after insertion of “Clearview”Silberschatz, Korth and Sudarshan12.29Database System Concepts - 5th Edition, Aug 12, 2005.nRead pseudocode in book!Silberschatz, Korth and Sudarshan12.30Database System Concepts - 5th Edition, Aug 12, 2005.nFind the record to be deleted,
36、 and remove it from the main file and from the bucket (if present)nRemove (search-key value, pointer) from the leaf node if there is no bucket or if the bucket has become emptynIf the node has too few entries due to the removal, and the entries in the node and a sibling fit into a single node, then
37、lInsert all the search-key values in the two nodes into a single node (the one on the left), and delete the other node.lDelete the pair (Ki1, Pi), where Pi is the pointer to the deleted node, from its parent, recursively using the above procedure.Silberschatz, Korth and Sudarshan12.31Database System
38、 Concepts - 5th Edition, Aug 12, 2005.nOtherwise, if the node has too few entries due to the removal, and the entries in the node and a sibling fit into a single node, but the sibling is full before merging thenlRedistribute the pointers between the node and a sibling such that both have more than t
39、he minimum number of entries.lUpdate the corresponding search-key value in the parent of the node.nThe node deletions may cascade upwards till a node which has n/2 or more pointers is found. If the root node has only one pointer after deletion, it is deleted and the sole child becomes the root. Silb
40、erschatz, Korth and Sudarshan12.32Database System Concepts - 5th Edition, Aug 12, 2005.nThe removal of the leaf node containing “Downtown” did not result in its parent having too little pointers. So the cascaded deletions stopped with the deleted leaf nodes parent.Before and after deleting “Downtown
41、”Silberschatz, Korth and Sudarshan12.33Database System Concepts - 5th Edition, Aug 12, 2005.nNode with “Perryridge” becomes underfull (actually empty, in this special case) and merged with its sibling.nAs a result “Perryridge” nodes parent became underfull, and was merged with its sibling (and an en
42、try was deleted from their parent)nRoot node then had only one child, and was deleted and its child became the new root nodeDeletion of “Perryridge” from result of previous exampleSilberschatz, Korth and Sudarshan12.34Database System Concepts - 5th Edition, Aug 12, 2005.nParent of leaf containing Pe
43、rryridge became underfull, and borrowed a pointer from its left siblingnSearch-key value in the parents parent changes as a resultBefore and after deletion of “Perryridge” from earlier exampleSilberschatz, Korth and Sudarshan12.35Database System Concepts - 5th Edition, Aug 12, 2005.nA bucket is a un
44、it of storage containing one or more records (a bucket is typically a disk block). nIn a hash file organization we obtain the bucket of a record directly from its search-key value using a hash function.nHash function h is a function from the set of all search-key values K to the set of all bucket ad
45、dresses B.nHash function is used to locate records for access, insertion as well as deletion.nRecords with different search-key values may be mapped to the same bucket; thus entire bucket has to be searched sequentially to locate a record. Silberschatz, Korth and Sudarshan12.36Database System Concep
46、ts - 5th Edition, Aug 12, 2005.nThere are 10 buckets,nThe binary representation of the ith character is assumed to be the integer i.nThe hash function returns the sum of the binary representations of the characters modulo 10lE.g. h(Perryridge) = 5 h(Round Hill) = 3 h(Brighton) = 3Hash file organizat
47、ion of account file, using branch_name as key (See figure in next slide.)Silberschatz, Korth and Sudarshan12.37Database System Concepts - 5th Edition, Aug 12, 2005.Hash file organization of account file, using branch_name as key (see previous slide for details).Silberschatz, Korth and Sudarshan12.38
48、Database System Concepts - 5th Edition, Aug 12, 2005.nWorst hash function maps all search-key values to the same bucket; this makes access time proportional to the number of search-key values in the file.nAn ideal hash function is uniform, i.e., each bucket is assigned the same number of search-key
49、values from the set of all possible values.nIdeal hash function is random, so each bucket will have the same number of records assigned to it irrespective of the actual distribution of search-key values in the file.nTypical hash functions perform computation on the internal binary representation of
50、the search-key. l For example, for a string search-key, the binary representations of all the characters in the string could be added and the sum modulo the number of buckets could be returned. .Silberschatz, Korth and Sudarshan12.39Database System Concepts - 5th Edition, Aug 12, 2005.nBucket overfl
51、ow can occur because of lInsufficient buckets lSkew in distribution of records. This can occur due to two reasons:4multiple records have same search-key value4chosen hash function produces non-uniform distribution of key valuesnAlthough the probability of bucket overflow can be reduced, it cannot be
52、 eliminated; it is handled by using overflow buckets.Silberschatz, Korth and Sudarshan12.40Database System Concepts - 5th Edition, Aug 12, 2005.nOverflow chaining the overflow buckets of a given bucket are chained together in a linked list.nAbove scheme is called closed hashing. lAn alternative, cal
53、led open hashing, which does not use overflow buckets, is not suitable for database applications.Silberschatz, Korth and Sudarshan12.41Database System Concepts - 5th Edition, Aug 12, 2005.nHashing can be used not only for file organization, but also for index-structure creation. nA hash index organi
54、zes the search keys, with their associated record pointers, into a hash file structure.nStrictly speaking, hash indices are always secondary indices lif the file itself is organized using hashing, a separate primary hash index on it using the same search-key is unnecessary. lHowever, we use the term
55、 hash index to refer to both secondary index structures and hash organized files. Silberschatz, Korth and Sudarshan12.42Database System Concepts - 5th Edition, Aug 12, 2005.Silberschatz, Korth and Sudarshan12.43Database System Concepts - 5th Edition, Aug 12, 2005.nIn static hashing, function h maps
56、search-key values to a fixed set of B of bucket addresses.lDatabases grow with time. If initial number of buckets is too small, performance will degrade due to too much overflows.lIf file size at some point in the future is anticipated and number of buckets allocated accordingly, significant amount
57、of space will be wasted initially.lIf database shrinks, again space will be wasted.lOne option is periodic re-organization of the file with a new hash function, but it is very expensive.nThese problems can be avoided by using techniques that allow the number of buckets to be modified dynamically. Si
58、lberschatz, Korth and Sudarshan12.44Database System Concepts - 5th Edition, Aug 12, 2005.nCreate an indexcreate index on ()E.g.: create index b-index on branch(branch_name)nUse create unique index to indirectly specify and enforce the condition that the search key is a candidate key is a candidate k
59、ey.lNot really required if SQL unique integrity constraint is supportednTo drop an index drop index Database System Concepts, 5th Ed.Silberschatz, Korth and SudarshanSee www.db- for conditions on re-use Silberschatz, Korth and Sudarshan12.46Database System Concepts - 5th Edition, Aug 12, 2005.nHash
60、values are split into segments that depend on each attribute of the search-key.(A1, A2, . . . , An) for n attribute search-keynExample: n = 2, for customer, search-key being (customer-street, customer-city)search-key valuehash value(Main, Harrison)101 111(Main, Brooklyn)101 001(Park, Palo Alto)010 0
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 二零二五年度科技產(chǎn)品銷售提成及創(chuàng)新激勵(lì)協(xié)議
- 二零二五年度金融機(jī)構(gòu)資金結(jié)算服務(wù)協(xié)議
- 二零二五年度山坪塘承包合同履行中的合同糾紛解決
- 二零二五年度終止雙方在線教育平臺(tái)合作協(xié)議
- 二零二五年度海底油氣管道水平定向鉆施工合作協(xié)議
- 二零二五年度全球市場(chǎng)傭金分成合作協(xié)議
- 2、2024廣西專業(yè)技術(shù)人員繼續(xù)教育公需科目參考答案(97分)
- 2025年合作貨運(yùn)從業(yè)資格證科目一考試答案
- 預(yù)制裝配式檢查井施工工法
- 公司領(lǐng)導(dǎo)發(fā)言稿范文
- 社會(huì)階層與教育選擇行為分析-深度研究
- 2025年內(nèi)蒙古呼和浩特市屬國(guó)企業(yè)紀(jì)檢監(jiān)察機(jī)構(gòu)招聘工作人員80人高頻重點(diǎn)模擬試卷提升(共500題附帶答案詳解)
- 社會(huì)工作行政(第三版)課件匯 時(shí)立榮 第6-11章 項(xiàng)目管理- 社會(huì)工作行政的挑戰(zhàn)、變革與數(shù)字化發(fā)展
- 全過程工程咨詢文件管理標(biāo)準(zhǔn)
- 模特?cái)z影及肖像使用合同協(xié)議范本
- 2025年湘潭醫(yī)衛(wèi)職業(yè)技術(shù)學(xué)院高職單招職業(yè)適應(yīng)性測(cè)試近5年??及鎱⒖碱}庫(kù)含答案解析
- 《預(yù)制高強(qiáng)混凝土風(fēng)電塔筒生產(chǎn)技術(shù)規(guī)程》文本附編制說明
- 2025福建福州地鐵集團(tuán)限公司運(yùn)營(yíng)分公司校園招聘高頻重點(diǎn)提升(共500題)附帶答案詳解
- 兒童睡眠障礙治療
- 四川省建筑行業(yè)調(diào)研報(bào)告
- 北京市豐臺(tái)區(qū)2024-2025學(xué)年高三上學(xué)期期末英語(yǔ)試題
評(píng)論
0/150
提交評(píng)論