Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 14- 1 Index Index field = one of the columns/attributes in a table.

Similar presentations


Presentation on theme: "Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 14- 1 Index Index field = one of the columns/attributes in a table."— Presentation transcript:

1 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 14- 1 Index Index field = one of the columns/attributes in a table Index = file or other structure containing an entry for each value of the index field pointers to records or disk blocks containing particular values of the index field. Values in the index are ordered for rapid search. Small size and ordering of the index permit rapid searches.

2 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 14- 2 Types of Index Primary index An index of an "ordering key field", i.e., the records in the main file/table are physically maintained in order by index field. Not common for database tables (rows are not ordered) Secondary index An index on a field which is a "nonordering field" Many secondary indexes may be built for one table or file.

3 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 14- 3 Secondary Indexes -- for candidate/secondary key One entry in index for each record of table "Dense" index Entry: Key and Pointer Ordering of index permits binary search in O(lg n) search for 1 in 1,000,000 values in 20 lookups or fewer c.f., linear search requiring 500,000 lookups on average.

4 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 14- 4 Pointers are to blocks of 4 records each

5 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 14- 5 Secondary indexes -- for non-key fields The index entry points to a second level: A block of entries pointing to occurrences of the field value in the table being indexed

6 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 14- 6 Index on non-key field points to a block of record pointers identifying qualifying records

7 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 14- 7 Indexing with B+ Search Trees Each internal node in the tree has a set number of key values and pointers (p) to subtrees Keys are kept in order within internal nodes Subtrees to the left are for values <= Key (1) Subtrees to the right are for values > Key (p-1) Subtrees in the middle are for values > the key to the left, and values <= the key to the right Each leaf node has pointers for up to p data records Keys within leaf nodes are kept in order The number of entries in an internal node is the "fanout" of the tree Seach speed will be O(log fo n)

8 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 14- 8

9 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 14- 9 Root originally a leaf node: Note: all key values must appear in leaf nodes Insert order: 8, 5, 1, 7, 3, 12, 9, 6

10 Let's index our class by Last Name The names: Moon Patel Kotak Green Yu Liang Leaf node for B+ tree with fanout of 3: n = 3 Ptr 1Ptr 2Ptr 3 Key 1Key 2

11 Add Moon p Moon p p Insert Patel p Moon p Patel p Insert Kotak p Moon p p p Kotak p Moon pp Patel p p

12 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 14- 12 Primary index on an ordering field (name)

13 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 14- 13 Mulit-level indexing The first level index can be considered an ordered file with a distinct value for each entry Apply a second level index This is a primary index to the first level index Apply a third level index to the second level, etc. IBM's ISAM structure is an example, but one in which the file itself is in physical order by key value.

14 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 14- 14


Download ppt "Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 14- 1 Index Index field = one of the columns/attributes in a table."

Similar presentations


Ads by Google