Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 4432lecture #71 CS4432: Database Systems II Lecture #7 Professor Elke A. Rundensteiner.

Similar presentations


Presentation on theme: "CS 4432lecture #71 CS4432: Database Systems II Lecture #7 Professor Elke A. Rundensteiner."— Presentation transcript:

1 CS 4432lecture #71 CS4432: Database Systems II Lecture #7 Professor Elke A. Rundensteiner

2 CS 4432lecture #72 Indexing : helps to retrieve data quicker for certain queries value= 1,000,000 Select * FROM Emp WHERE salary = 1,000,000; Chapter 4 (chapter 13 in ‘complete book’)  value record

3 CS 4432lecture #73 Topics Sequential Files (chap. 4.1) Secondary Indexes (chap 4.2)

4 CS 4432lecture #74 Sequential File 20 10 40 30 60 50 80 70 100 90

5 CS 4432lecture #75 Sequential File 20 10 40 30 60 50 80 70 100 90 Dense Index 10 20 30 40 50 60 70 80 90 100 110 120 Every Record is in Index.

6 CS 4432lecture #76 Sequential File 20 10 40 30 60 50 80 70 100 90 Sparse Index 10 30 50 70 90 110 130 150 170 190 210 230 Only first Record per block in Index.

7 CS 4432lecture #77 Sequential File 20 10 40 30 60 50 80 70 100 90 Sparse 2nd level 10 30 50 70 90 110 130 150 170 190 210 230 10 90 170 250 330 410 490 570

8 CS 4432lecture #78 NOTE: FILE or INDEX may be layed out on disk as either a contiguous or a block- chained strategy

9 CS 4432lecture #79 Question: Can we (do we want to) build a dense, 2nd level index for a dense index? Sequential File 20 10 40 30 60 50 80 70 100 90 2nd level? 10 30 50 70 90 110 130 150 170 190 210 230 10 90 170 250 330 410 490 570 1st level?

10 CS 4432lecture #710 Notes on pointers: (1)Block pointer (sparse index) can be smaller than record pointer BP RP (2) If file is contiguous, then we can omit pointers (i.e., compute them)

11 CS 4432lecture #711 K1 K3 K4 K2 R1R2R3R4 say: 1024 B per block if we want K3 block: get it at offset (3-1)1024 = 2048 bytes

12 CS 4432lecture #712 Sparse vs. Dense Tradeoff Sparse: Less index space per record can keep more of index in memory (Later: sparse better for insertions) Dense: Can tell if any record exists without accessing file (Later: dense needed for secondary indexes)

13 CS 4432lecture #713 Terms Index sequential file Search key (  primary key) Primary index (on Sequencing field) Secondary index Dense index (all Search Key values in) Sparse index Multi-level index

14 CS 4432lecture #714 Next: Duplicate keys Deletion/Insertion Secondary indexes

15 CS 4432lecture #715 Duplicate keys 10 20 10 30 20 30 45 40

16 CS 4432lecture #716 10 20 10 30 20 30 45 40 10 20 10 30 20 30 45 40 10 20 30 10 20 30 Dense index, one way to implement? Duplicate keys

17 CS 4432lecture #717 10 20 10 30 20 30 45 40 Dense index, better way? 10 20 30 40 Duplicate keys

18 CS 4432lecture #718 10 20 10 30 20 30 45 40 10 20 30 Sparse index, one way? Duplicate keys careful if looking for 20 or 30!

19 CS 4432lecture #719 10 20 10 30 20 30 45 40 10 20 30 Sparse index, another way? Duplicate keys – place first new key from block should this be 40?

20 CS 4432lecture #720 Duplicate values, primary index Index may point to first instance of each value only File Index Summary a a a b 

21 CS 4432lecture #721 Next: Duplicate keys Deletion/Insertion Secondary indexes

22 CS 4432lecture #722 Deletion from sparse index 20 10 40 30 60 50 80 70 10 30 50 70 90 110 130 150

23 CS 4432lecture #723 Deletion from sparse index 20 10 40 30 60 50 80 70 10 30 50 70 90 110 130 150 – delete record 40

24 CS 4432lecture #724 Deletion from sparse index 20 10 40 30 60 50 80 70 10 30 50 70 90 110 130 150 – delete record 30 40

25 CS 4432lecture #725 Deletion from sparse index 20 10 40 30 60 50 80 70 10 30 50 70 90 110 130 150 – delete records 30 & 40 50 70

26 CS 4432lecture #726 Deletion from dense index 20 10 40 30 60 50 80 70 10 20 30 40 50 60 70 80

27 CS 4432lecture #727 Deletion from dense index 20 10 40 30 60 50 80 70 10 20 30 40 50 60 70 80 – delete record 30 40

28 CS 4432lecture #728 Insertion, sparse index case 20 1030 50 4060 10 30 40 60

29 CS 4432lecture #729 Insertion, sparse index case 20 1030 50 4060 10 30 40 60 – insert record 34 34 our lucky day! we have free space where we need it!

30 CS 4432lecture #730 Insertion, sparse index case 20 1030 50 4060 10 30 40 60 – insert record 15 15 20 30 20 Illustrated: Immediate reorganization Variation: – insert new block (chained file) – update index

31 CS 4432lecture #731 Insertion, sparse index case 20 1030 50 4060 10 30 40 60 – insert record 25 25 overflow blocks (reorganize later...)

32 CS 4432lecture #732 Insertion, dense index case Similar Often more expensive...

33 CS 4432lecture #733 Next: Duplicate keys Deletion/Insertion Secondary indexes

34 CS 4432lecture #734 Secondary indexes Sequence field 50 30 70 20 40 80 10 100 60 90 Can I make a Sparse Index?

35 CS 4432lecture #735 Secondary indexes Sequence field 50 30 70 20 40 80 10 100 60 90 Sparse index 30 20 80 100 90... does not make sense!

36 CS 4432lecture #736 Secondary indexes Sequence field 50 30 70 20 40 80 10 100 60 90 Dense index 10 20 30 40 50 60 70... 10 50 90... sparse high level

37 CS 4432lecture #737 With secondary indexes: Lowest level is dense Other levels are sparse Also: Pointers are record pointers (not block pointers; not computed)

38 CS 4432lecture #738 Duplicate values & secondary indexes 10 20 40 20 40 10 40 10 40 30

39 CS 4432lecture #739 Duplicate values & secondary indexes 10 20 40 20 40 10 40 10 40 30 10 20 30 40... one option... Problem: excess overhead! disk space search time

40 CS 4432lecture #740 Duplicate values & secondary indexes 10 20 40 20 40 10 40 10 40 30 10 another option... 403020 Problem: variable size records in index!

41 CS 4432lecture #741 Duplicate values & secondary indexes 10 20 40 20 40 10 40 10 40 30 10 20 30 40 50 60... Another idea : Chain records with same key? Problems: Need to add fields to records Need to follow chain to know records

42 CS 4432lecture #742 Summary : Conventional Indexes –Basic Ideas: sparse, dense, multi-level… –Duplicate Keys –Deletion/Insertion –Secondary indexes


Download ppt "CS 4432lecture #71 CS4432: Database Systems II Lecture #7 Professor Elke A. Rundensteiner."

Similar presentations


Ads by Google