CS 4432lecture #71 CS4432: Database Systems II Lecture #7 Professor Elke A. Rundensteiner
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
CS 4432lecture #73 Topics Sequential Files (chap. 4.1) Secondary Indexes (chap 4.2)
CS 4432lecture #74 Sequential File
CS 4432lecture #75 Sequential File Dense Index Every Record is in Index.
CS 4432lecture #76 Sequential File Sparse Index Only first Record per block in Index.
CS 4432lecture #77 Sequential File Sparse 2nd level
CS 4432lecture #78 NOTE: FILE or INDEX may be layed out on disk as either a contiguous or a block- chained strategy
CS 4432lecture #79 Question: Can we (do we want to) build a dense, 2nd level index for a dense index? Sequential File nd level? st level?
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)
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
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)
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
CS 4432lecture #714 Next: Duplicate keys Deletion/Insertion Secondary indexes
CS 4432lecture #715 Duplicate keys
CS 4432lecture # Dense index, one way to implement? Duplicate keys
CS 4432lecture # Dense index, better way? Duplicate keys
CS 4432lecture # Sparse index, one way? Duplicate keys careful if looking for 20 or 30!
CS 4432lecture # Sparse index, another way? Duplicate keys – place first new key from block should this be 40?
CS 4432lecture #720 Duplicate values, primary index Index may point to first instance of each value only File Index Summary a a a b
CS 4432lecture #721 Next: Duplicate keys Deletion/Insertion Secondary indexes
CS 4432lecture #722 Deletion from sparse index
CS 4432lecture #723 Deletion from sparse index – delete record 40
CS 4432lecture #724 Deletion from sparse index – delete record 30 40
CS 4432lecture #725 Deletion from sparse index – delete records 30 &
CS 4432lecture #726 Deletion from dense index
CS 4432lecture #727 Deletion from dense index – delete record 30 40
CS 4432lecture #728 Insertion, sparse index case
CS 4432lecture #729 Insertion, sparse index case – insert record our lucky day! we have free space where we need it!
CS 4432lecture #730 Insertion, sparse index case – insert record Illustrated: Immediate reorganization Variation: – insert new block (chained file) – update index
CS 4432lecture #731 Insertion, sparse index case – insert record overflow blocks (reorganize later...)
CS 4432lecture #732 Insertion, dense index case Similar Often more expensive...
CS 4432lecture #733 Next: Duplicate keys Deletion/Insertion Secondary indexes
CS 4432lecture #734 Secondary indexes Sequence field Can I make a Sparse Index?
CS 4432lecture #735 Secondary indexes Sequence field Sparse index does not make sense!
CS 4432lecture #736 Secondary indexes Sequence field Dense index sparse high level
CS 4432lecture #737 With secondary indexes: Lowest level is dense Other levels are sparse Also: Pointers are record pointers (not block pointers; not computed)
CS 4432lecture #738 Duplicate values & secondary indexes
CS 4432lecture #739 Duplicate values & secondary indexes one option... Problem: excess overhead! disk space search time
CS 4432lecture #740 Duplicate values & secondary indexes another option Problem: variable size records in index!
CS 4432lecture #741 Duplicate values & secondary indexes Another idea : Chain records with same key? Problems: Need to add fields to records Need to follow chain to know records
CS 4432lecture #742 Summary : Conventional Indexes –Basic Ideas: sparse, dense, multi-level… –Duplicate Keys –Deletion/Insertion –Secondary indexes