Download presentation
Presentation is loading. Please wait.
1
Database Management System
Lecture - 37 © Virtual University of Pakistan
2
© Virtual University of Pakistan
Introduction Any subset of the fields of a relation can be the search key for an index on the relation. Search key is not the same as key (e.g. doesn’t have to be unique ID). © Virtual University of Pakistan
3
© Virtual University of Pakistan
Introduction An index contains a collection of data entries, and supports efficient retrieval of all records with a given search key value k. © Virtual University of Pakistan
4
© Virtual University of Pakistan
Introduction Typically, index also contains auxiliary information that directs searches to the desired data entries © Virtual University of Pakistan
5
© Virtual University of Pakistan
Introduction Can have multiple (different) indexes per file. e.g. file sorted by stid, with a hash index on cgpa and a B+tree index on stname. © Virtual University of Pakistan
6
© Virtual University of Pakistan
Introduction Indexes on primary key and on attribute(s) in the unique constraint are automatically created We can still create more © Virtual University of Pakistan
7
© Virtual University of Pakistan
Index Classification What selections does it support? Representation of data entries in index what kind of info is the index actually storing? © Virtual University of Pakistan
8
© Virtual University of Pakistan
Index Classification 3 alternatives here Clustered vs. Un-clustered Indexes Single Key vs. Composite Indexes Tree-based, inverted files, pointers © Virtual University of Pakistan
9
© Virtual University of Pakistan
Creating Index CREATE [ UNIQUE ] [ CLUSTERED | NONCLUSTERED ] INDEX index_name ON { table | view } ( column [ ASC | DESC ] [ ,...n ] ) © Virtual University of Pakistan
10
© Virtual University of Pakistan
Create Index Example CREATE UNIQUE INDEX pr_prName ON program(prName) © Virtual University of Pakistan
11
© Virtual University of Pakistan
Create Index Example Can also be created on composite attributes CREATE UNIQUE INDEX St_Name ON Student(stName ASC, stFName DESC) © Virtual University of Pakistan
12
© Virtual University of Pakistan
Properties of Indexes Indexes can be defined even when there is no data in the table Existing values are checked on execution of this command © Virtual University of Pakistan
13
© Virtual University of Pakistan
Properties of Indexes Support selections of form field <operator> constant Support equality selections Either “tree” or “hash” indexes help here. © Virtual University of Pakistan
14
© Virtual University of Pakistan
Properties of Indexes Support Range selections (operator is one among <, >, <=, >=, BETWEEN) “Hash” indexes don’t work for these © Virtual University of Pakistan
15
© Virtual University of Pakistan
Secondary Key Index Users often need to access data on the basis of non-key or non-unique attribute; secondary key Like student name, program name, students enrolled in a particular program © Virtual University of Pakistan
16
© Virtual University of Pakistan
Secondary Key Index Records are stored on the basis of key attribute; three possibilities Sequential search Sorted on the basis of name Sort for command execution Problematic © Virtual University of Pakistan
17
© Virtual University of Pakistan
Secondary Key Index Index on secondary key is solution Data remains in original order, however secondary key index maintains ordered sequence of records, and provides direct access © Virtual University of Pakistan
18
© Virtual University of Pakistan
Secondary Key Index Three implementation approaches Inverted files or inversions Linked lists B+ Trees © Virtual University of Pakistan
19
Database Management System
Lecture - 37 © Virtual University of Pakistan
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.