SlideShare a Scribd company logo
Chapter 6
Index Structures
2
Chapter 6: Objectives
 Types of Single-level Ordered Indexes
 Primary Indexes
 Clustering Indexes
 Secondary Indexes
 Multilevel Indexes
 Dynamic Multilevel Indexes Using B-Trees
and B+-Trees
 Indexes on Multiple Keys
Ritu CHaturvedi
Figures adapted from Fundamentals of Database
Systems By Elmasri and Navathe
3
File Structures
 Disk Storage Devices
 Files of Records
 Operations on Files
 Unordered Files
 Ordered Files
 Hashed Files
Ritu CHaturvedi
Figures adapted from Fundamentals of Database
Systems By Elmasri and Navathe
4
Indexes as Access Paths
 A single-level index is an auxiliary file that makes it
more efficient to search for a record in the data
file.
 The index is usually specified on one field of the
file (although it could be specified on several
fields)
 One form of an index is a file of entries <field
value, pointer to record>, which is ordered by
field value
 The index is called an access path on the field.
Ritu CHaturvedi
Figures adapted from Fundamentals of Database
Systems By Elmasri and Navathe
5
Indexes as Access Paths (contd.)
 The index file usually occupies considerably less
disk blocks than the data file because its entries
are much smaller
 A binary search on the index yields a pointer to
the file record
 Indexes can also be characterized as dense or
sparse.
 A dense index has an index entry for every search
key value (and hence every record) in the data file.
 A sparse (or nondense) index, on the other hand,
has index entries for only some of the search values
Ritu CHaturvedi
Figures adapted from Fundamentals of Database
Systems By Elmasri and Navathe
6
Example: Given the following data file:
EMPLOYEE(NAME, SSN, ADDRESS, JOB, SAL, ... )
Suppose that:
record size R=150 bytes
block size B=512 bytes
r=30000 records
Then, we get:
blocking factor Bfr= B div R= 512 div 150= 3 records/block
number of file blocks b= (r/Bfr)= (30000/3)= 10000 blocks
For an index on the SSN field, assume the field size VSSN=9 bytes,
assume the record pointer size PR=7 bytes. Then:
index entry size RI=(VSSN+ PR)=(9+7)=16 bytes
index blocking factor BfrI= B div RI= 512 div 16= 32 entries/block
number of index blocks b= (r/ BfrI)= (30000/32)= 938 blocks
binary search needs log2bI= log2938= 10 block accesses
This is compared to an average linear search cost of:
(b/2)= 30000/2= 15000 block accesses
If the file records are ordered, the binary search cost would be:
log2b= log230000= 15 block accesses
Indexes as Access Paths (contd.)
Ritu CHaturvedi
Figures adapted from Fundamentals of Database
Systems By Elmasri and Navathe
7
Types of Single-Level Indexes
 Primary Index
 Defined on an ordered data file
 The data file is ordered on a key field
 Includes one index entry for each block in the data file; the
index entry has the key field value for the first record in the
block, which is called the block anchor
 A similar scheme can use the last record in a block.
 A primary index is a nondense (sparse) index, since it
includes an entry for each disk block of the data file and the
keys of its anchor record rather than for every search value.
Ritu CHaturvedi
Figures adapted from Fundamentals of Database
Systems By Elmasri and Navathe
8
FIGURE 4.1
Primary
index on the
ordering key
field of the
file shown in
Figure 13.7.
Ritu CHaturvedi
Figures adapted from Fundamentals of Database
Systems By Elmasri and Navathe
9
Types of Single-Level Indexes
 Clustering Index
 Defined on an ordered data file
 The data file is ordered on a non-key field unlike primary
index, which requires that the ordering field of the data file
have a distinct value for each record.
 Includes one index entry for each distinct value of the field;
the index entry points to the first data block that contains
records with that field value.
 It is another example of nondense index where Insertion and
Deletion is relatively straightforward with a clustering index.
Ritu CHaturvedi
Figures adapted from Fundamentals of Database
Systems By Elmasri and Navathe
10
FIGURE 4.2
A clustering index
on the DEPTNUMBER
ordering nonkey field
of an
EMPLOYEE file.
Ritu CHaturvedi
Figures adapted from Fundamentals of Database
Systems By Elmasri and Navathe
11
FIGURE 4.3
Clustering index
with a separate block
cluster for each
group of records that
share the same value
for the clustering
field.
Ritu CHaturvedi
Figures adapted from Fundamentals of Database
Systems By Elmasri and Navathe
12
Types of Single-Level Indexes
 Secondary Index
 A secondary index provides a secondary means of accessing a file for
which some primary access already exists.
 The secondary index may be on a field which is a candidate key and
has a unique value in every record, or a nonkey with duplicate values.
 The index is an ordered file with two fields.
 The first field is of the same data type as some nonordering
field of the data file that is an indexing field.
 The second field is either a block pointer or a record pointer.
There can be many secondary indexes (and hence, indexing
fields) for the same file.
 Includes one entry for each record in the data file; hence, it is a
dense index
Ritu CHaturvedi
Figures adapted from Fundamentals of Database
Systems By Elmasri and Navathe
13
FIGURE 4.4
A dense
secondary index
(with block
pointers) on a
nonordering key
field of a file.
Ritu CHaturvedi
Figures adapted from Fundamentals of Database
Systems By Elmasri and Navathe
14
FIGURE 4.5
A secondary index (with recored pointers) on a nonkey field implemented
using one level of indirection so that index entries are of fixed length and
have unique field values.
Ritu CHaturvedi
Figures adapted from Fundamentals of Database
Systems By Elmasri and Navathe
15
Ritu CHaturvedi
Figures adapted from Fundamentals of Database
Systems By Elmasri and Navathe
16
Multi-Level Indexes
 Because a single-level index is an ordered file, we can create a
primary index to the index itself ; in this case, the original index
file is called the first-level index and the index to the index is
called the second-level index.
 We can repeat the process, creating a third, fourth, ..., top level
until all entries of the top level fit in one disk block
 A multi-level index can be created for any type of first-level
index (primary, secondary, clustering) as long as the first-level
index consists of more than one disk block
Ritu CHaturvedi
Figures adapted from Fundamentals of Database
Systems By Elmasri and Navathe
17
FIGURE 4.6
A two-level
primary index
resembling
ISAM (Indexed
Sequential
Access Method)
organization.
Ritu CHaturvedi
Figures adapted from Fundamentals of Database
Systems By Elmasri and Navathe
18
Multi-Level Indexes
 Such a multi-level index is a form of search tree ;
however, insertion and deletion of new index entries is
a severe problem because every level of the index is an
ordered file.
Ritu CHaturvedi
Figures adapted from Fundamentals of Database
Systems By Elmasri and Navathe
19
FIGURE 4.8
A node in a search tree with pointers to subtrees
below it.
Ritu CHaturvedi
Figures adapted from Fundamentals of Database
Systems By Elmasri and Navathe
20
FIGURE 4.9
A search tree of order p = 3.
Ritu CHaturvedi
Figures adapted from Fundamentals of Database
Systems By Elmasri and Navathe
21
Dynamic Multilevel Indexes Using B-
Trees and B+-Trees
 Because of the insertion and deletion problem, most multi-level
indexes use B-tree or B+-tree data structures, which leave space
in each tree node (disk block) to allow for new index entries
 These data structures are variations of search trees that allow
efficient insertion and deletion of new search values.
 In B-Tree and B+-Tree data structures, each node corresponds to
a disk block
 Each node is kept between half-full and completely full
Ritu CHaturvedi
Figures adapted from Fundamentals of Database
Systems By Elmasri and Navathe
22
Dynamic Multilevel Indexes Using B-
Trees and B+-Trees (contd.)
 An insertion into a node that is not full is quite efficient; if a
node is full the insertion causes a split into two nodes
 Splitting may propagate to other tree levels
 A deletion is quite efficient if a node does not become less than
half full
 If a deletion causes a node to become less than half full, it must
be merged with neighboring nodes
Ritu CHaturvedi
Figures adapted from Fundamentals of Database
Systems By Elmasri and Navathe
23
Difference between B-tree and B+-tree
 In a B-tree, pointers to data records exist at all levels of the tree
 In a B+-tree, all pointers to data records exists at the leaf-level
nodes
 A B+-tree can have less levels (or higher capacity of search
values) than the corresponding B-tree
Ritu CHaturvedi
Figures adapted from Fundamentals of Database
Systems By Elmasri and Navathe
24
FIGURE 4.10
B-tree structures. (a) A node in a B-tree with q – 1 search
values. (b) A B-tree of order p = 3. The values were
inserted in the order 8, 5, 1, 7, 3, 12, 9, 6.
Ritu CHaturvedi
Figures adapted from Fundamentals of Database
Systems By Elmasri and Navathe
25
FIGURE 4.11
The nodes of a B+-tree. (a) Internal node of a B+-tree with q –1 search
values. (b) Leaf node of a B+-tree with q – 1 search values and q – 1 data
pointers.
Ritu CHaturvedi
Figures adapted from Fundamentals of Database
Systems By Elmasri and Navathe
26
Choose file organizations and indexes
Determine optimal file organizations to store
the base tables, and the indexes required to
achieve acceptable performance.
 Consists of the following steps:
 Step 1 Analyze transactions
 Step 2 Choose file organizations
 Step 3 Choose indexes
Ritu CHaturvedi
Figures adapted from Fundamentals of Database
Systems By Elmasri and Navathe
27
Analyze transactions
To understand functionality of the transactions
and to analyze the important ones.
Identify performance criteria, such as:
 transactions that run frequently and will have a
significant impact on performance;
 transactions that are critical to the business;
 times during the day/week when there will be a
high demand made on the database (called the
peak load).
Ritu CHaturvedi
Figures adapted from Fundamentals of Database
Systems By Elmasri and Navathe
28
Analyze transactions
 Use this information to identify the parts of the
database that may cause performance
problems.
 Often not possible to analyze all expected
transactions, so investigate most ‘important’
ones.
Ritu CHaturvedi
Figures adapted from Fundamentals of Database
Systems By Elmasri and Navathe
29
Choose file organizations
To determine an efficient file organization for
each base table.
 File organizations include Heap, Hash, Indexed
Sequential Access Method (ISAM), B+-Tree, and
Clusters.
 Some DBMSs (particularly PC-based DBMS) have
fixed file organization that you cannot alter.
Ritu CHaturvedi
Figures adapted from Fundamentals of Database
Systems By Elmasri and Navathe
30
Choose indexes
Determine whether adding indexes will
improve the performance of the system.
 One approach is to keep records unordered and create
as many secondary indexes as necessary.
Ritu CHaturvedi
Figures adapted from Fundamentals of Database
Systems By Elmasri and Navathe
31
Choose indexes
 Or could order records in table by specifying a primary
or clustering index.
 In this case, choose the column for ordering or
clustering the records as:
 column that is used most often for join operations - this
makes join operation more efficient, or
 column that is used most often to access the records in a
table in order of that column.
Ritu CHaturvedi
Figures adapted from Fundamentals of Database
Systems By Elmasri and Navathe
32
Choose indexes
 If ordering column chosen is key of table, index will be
a primary index; otherwise, index will be a clustering
index.
 Each table can only have either a primary index or a
clustering index.
 Secondary indexes provide additional keys for a base
table that can be used to retrieve data more efficiently.
Ritu CHaturvedi
Figures adapted from Fundamentals of Database
Systems By Elmasri and Navathe
33
Choose indexes – Guidelines for
choosing ‘wish-list’
(1) Do not index small tables.
(2) Add secondary index to any column that is heavily
used as a secondary key.
(3) Add secondary index to a FK if it is frequently
accessed.
(4) Add secondary index on columns that are involved in:
selection or join criteria; ORDER BY; GROUP BY;
and other operations involving sorting (such as UNION
or DISTINCT).
Ritu CHaturvedi
Figures adapted from Fundamentals of Database
Systems By Elmasri and Navathe
34
Choose indexes – Guidelines for
choosing ‘wish-list’
(5) Add secondary index on columns involved in built-in
functions.
(6) Add secondary index on columns that could result in
an index-only plan.
(7) Avoid indexing an column or table that is frequently
updated.
(8) Avoid indexing an column if the query will retrieve a
significant proportion of the records in the table.
(9) Avoid indexing columns that consist of long character
strings.
Ritu CHaturvedi
Figures adapted from Fundamentals of Database
Systems By Elmasri and Navathe

More Related Content

PPTX
Adbms 22 dynamic multi level index using b and b+ tree
Vaibhav Khanna
 
PPTX
Indexing structure for files
Zainab Almugbel
 
PDF
indexingstructureforfiles-160728120658.pdf
FraolUmeta
 
PPT
Chapter14.ppt
DeepChakraborty39
 
PPT
Ardbms
guestcc2d29
 
PDF
indexing and hashing
University of Potsdam
 
PPTX
Chapter17.pptx data base management sysytetem
syedalishahid6
 
PPTX
DB LECTURE 4 INDEXINGS PPT NOTES.pptx
grahamoyigo19
 
Adbms 22 dynamic multi level index using b and b+ tree
Vaibhav Khanna
 
Indexing structure for files
Zainab Almugbel
 
indexingstructureforfiles-160728120658.pdf
FraolUmeta
 
Chapter14.ppt
DeepChakraborty39
 
Ardbms
guestcc2d29
 
indexing and hashing
University of Potsdam
 
Chapter17.pptx data base management sysytetem
syedalishahid6
 
DB LECTURE 4 INDEXINGS PPT NOTES.pptx
grahamoyigo19
 

Similar to 11885558.ppt (20)

PPTX
Index Structures.pptx
MBablu1
 
PPTX
index examples.pptx
shazasowiss
 
PPTX
index examples.pptx
shazasowiss
 
PDF
DBMS 8 | Memory Hierarchy and Indexing
Mohammad Imam Hossain
 
PPTX
DBMS-Unit5-PPT.pptx important for revision
yuvivarmaa
 
PPTX
Database Management System-Module-IV(part-1).pptx
AiswaryaMohan31
 
PPTX
Indexing1.pptxnnnnñnnnnnnnnnnnnnnnnnnnnnn
228w1a1292
 
PDF
DOC-20240804-WA0006..pdforaclesqlindexing
storage2ndyr
 
PPT
Free video lectures for b.tech
Edhole.com
 
PPTX
File Organization, Indexing and Hashing.pptx
niqqaanonymous211
 
PPT
File organization 1
Rupali Rana
 
PPTX
File Organization in database management.pptx
ubaidullah75790
 
PPTX
files,indexing,hashing,linear and non linear hashing
Rohit Kumar
 
PDF
Indexing Structures in Database Management system.pdf
Christalin Nelson
 
PPT
File organization techniques
Meghlal Khan
 
PPT
3620121datastructures.ppt
SheejamolMathew
 
PPT
Data Indexing Presentation-My.pptppt.ppt
sdsm2
 
PPT
Storage struct
durgaprasad1407
 
PPTX
Lec 1 indexing and hashing
Md. Mashiur Rahman
 
PDF
Access Methods - Lecture 9 - Introduction to Databases (1007156ANR)
Beat Signer
 
Index Structures.pptx
MBablu1
 
index examples.pptx
shazasowiss
 
index examples.pptx
shazasowiss
 
DBMS 8 | Memory Hierarchy and Indexing
Mohammad Imam Hossain
 
DBMS-Unit5-PPT.pptx important for revision
yuvivarmaa
 
Database Management System-Module-IV(part-1).pptx
AiswaryaMohan31
 
Indexing1.pptxnnnnñnnnnnnnnnnnnnnnnnnnnnn
228w1a1292
 
DOC-20240804-WA0006..pdforaclesqlindexing
storage2ndyr
 
Free video lectures for b.tech
Edhole.com
 
File Organization, Indexing and Hashing.pptx
niqqaanonymous211
 
File organization 1
Rupali Rana
 
File Organization in database management.pptx
ubaidullah75790
 
files,indexing,hashing,linear and non linear hashing
Rohit Kumar
 
Indexing Structures in Database Management system.pdf
Christalin Nelson
 
File organization techniques
Meghlal Khan
 
3620121datastructures.ppt
SheejamolMathew
 
Data Indexing Presentation-My.pptppt.ppt
sdsm2
 
Storage struct
durgaprasad1407
 
Lec 1 indexing and hashing
Md. Mashiur Rahman
 
Access Methods - Lecture 9 - Introduction to Databases (1007156ANR)
Beat Signer
 
Ad

More from KalsoomTahir2 (20)

PDF
005813616.pdf
KalsoomTahir2
 
PDF
009576860.pdf
KalsoomTahir2
 
PDF
005813185.pdf
KalsoomTahir2
 
PDF
HASH FUNCTIONS.pdf
KalsoomTahir2
 
PPTX
6. McCall's Model.pptx
KalsoomTahir2
 
PPT
ch02-Database System Concepts and Architecture.ppt
KalsoomTahir2
 
PPT
9223301.ppt
KalsoomTahir2
 
PPT
Indexing.ppt
KalsoomTahir2
 
PPT
chap05-info366.ppt
KalsoomTahir2
 
PPT
1650607.ppt
KalsoomTahir2
 
PDF
005281271.pdf
KalsoomTahir2
 
PPT
soa_and_jra.ppt
KalsoomTahir2
 
PPT
ERP_Up_Down.ppt
KalsoomTahir2
 
PPT
Topic1CourseIntroduction.ppt
KalsoomTahir2
 
PPT
Lecture 19 - Dynamic Web - JAVA - Part 1.ppt
KalsoomTahir2
 
PPT
CommercialSystemsBahman.ppt
KalsoomTahir2
 
PPT
EJBDetailsFeb25.ppt
KalsoomTahir2
 
PPT
jan28EAI.ppt
KalsoomTahir2
 
PDF
005428052.pdf
KalsoomTahir2
 
PPT
jini-1.ppt
KalsoomTahir2
 
005813616.pdf
KalsoomTahir2
 
009576860.pdf
KalsoomTahir2
 
005813185.pdf
KalsoomTahir2
 
HASH FUNCTIONS.pdf
KalsoomTahir2
 
6. McCall's Model.pptx
KalsoomTahir2
 
ch02-Database System Concepts and Architecture.ppt
KalsoomTahir2
 
9223301.ppt
KalsoomTahir2
 
Indexing.ppt
KalsoomTahir2
 
chap05-info366.ppt
KalsoomTahir2
 
1650607.ppt
KalsoomTahir2
 
005281271.pdf
KalsoomTahir2
 
soa_and_jra.ppt
KalsoomTahir2
 
ERP_Up_Down.ppt
KalsoomTahir2
 
Topic1CourseIntroduction.ppt
KalsoomTahir2
 
Lecture 19 - Dynamic Web - JAVA - Part 1.ppt
KalsoomTahir2
 
CommercialSystemsBahman.ppt
KalsoomTahir2
 
EJBDetailsFeb25.ppt
KalsoomTahir2
 
jan28EAI.ppt
KalsoomTahir2
 
005428052.pdf
KalsoomTahir2
 
jini-1.ppt
KalsoomTahir2
 
Ad

Recently uploaded (20)

PPTX
How to Track Skills & Contracts Using Odoo 18 Employee
Celine George
 
PPTX
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
A Smarter Way to Think About Choosing a College
Cyndy McDonald
 
PDF
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
PPTX
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
PPTX
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
PPTX
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
PPTX
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
PDF
Virat Kohli- the Pride of Indian cricket
kushpar147
 
DOCX
Modul Ajar Deep Learning Bahasa Inggris Kelas 11 Terbaru 2025
wahyurestu63
 
PDF
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
PPTX
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 
PPTX
CDH. pptx
AneetaSharma15
 
DOCX
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
PPTX
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
PPTX
PROTIEN ENERGY MALNUTRITION: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
PPTX
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
PDF
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 
How to Track Skills & Contracts Using Odoo 18 Employee
Celine George
 
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
A Smarter Way to Think About Choosing a College
Cyndy McDonald
 
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
Virat Kohli- the Pride of Indian cricket
kushpar147
 
Modul Ajar Deep Learning Bahasa Inggris Kelas 11 Terbaru 2025
wahyurestu63
 
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 
CDH. pptx
AneetaSharma15
 
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
PROTIEN ENERGY MALNUTRITION: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 

11885558.ppt

  • 2. 2 Chapter 6: Objectives  Types of Single-level Ordered Indexes  Primary Indexes  Clustering Indexes  Secondary Indexes  Multilevel Indexes  Dynamic Multilevel Indexes Using B-Trees and B+-Trees  Indexes on Multiple Keys Ritu CHaturvedi Figures adapted from Fundamentals of Database Systems By Elmasri and Navathe
  • 3. 3 File Structures  Disk Storage Devices  Files of Records  Operations on Files  Unordered Files  Ordered Files  Hashed Files Ritu CHaturvedi Figures adapted from Fundamentals of Database Systems By Elmasri and Navathe
  • 4. 4 Indexes as Access Paths  A single-level index is an auxiliary file that makes it more efficient to search for a record in the data file.  The index is usually specified on one field of the file (although it could be specified on several fields)  One form of an index is a file of entries <field value, pointer to record>, which is ordered by field value  The index is called an access path on the field. Ritu CHaturvedi Figures adapted from Fundamentals of Database Systems By Elmasri and Navathe
  • 5. 5 Indexes as Access Paths (contd.)  The index file usually occupies considerably less disk blocks than the data file because its entries are much smaller  A binary search on the index yields a pointer to the file record  Indexes can also be characterized as dense or sparse.  A dense index has an index entry for every search key value (and hence every record) in the data file.  A sparse (or nondense) index, on the other hand, has index entries for only some of the search values Ritu CHaturvedi Figures adapted from Fundamentals of Database Systems By Elmasri and Navathe
  • 6. 6 Example: Given the following data file: EMPLOYEE(NAME, SSN, ADDRESS, JOB, SAL, ... ) Suppose that: record size R=150 bytes block size B=512 bytes r=30000 records Then, we get: blocking factor Bfr= B div R= 512 div 150= 3 records/block number of file blocks b= (r/Bfr)= (30000/3)= 10000 blocks For an index on the SSN field, assume the field size VSSN=9 bytes, assume the record pointer size PR=7 bytes. Then: index entry size RI=(VSSN+ PR)=(9+7)=16 bytes index blocking factor BfrI= B div RI= 512 div 16= 32 entries/block number of index blocks b= (r/ BfrI)= (30000/32)= 938 blocks binary search needs log2bI= log2938= 10 block accesses This is compared to an average linear search cost of: (b/2)= 30000/2= 15000 block accesses If the file records are ordered, the binary search cost would be: log2b= log230000= 15 block accesses Indexes as Access Paths (contd.) Ritu CHaturvedi Figures adapted from Fundamentals of Database Systems By Elmasri and Navathe
  • 7. 7 Types of Single-Level Indexes  Primary Index  Defined on an ordered data file  The data file is ordered on a key field  Includes one index entry for each block in the data file; the index entry has the key field value for the first record in the block, which is called the block anchor  A similar scheme can use the last record in a block.  A primary index is a nondense (sparse) index, since it includes an entry for each disk block of the data file and the keys of its anchor record rather than for every search value. Ritu CHaturvedi Figures adapted from Fundamentals of Database Systems By Elmasri and Navathe
  • 8. 8 FIGURE 4.1 Primary index on the ordering key field of the file shown in Figure 13.7. Ritu CHaturvedi Figures adapted from Fundamentals of Database Systems By Elmasri and Navathe
  • 9. 9 Types of Single-Level Indexes  Clustering Index  Defined on an ordered data file  The data file is ordered on a non-key field unlike primary index, which requires that the ordering field of the data file have a distinct value for each record.  Includes one index entry for each distinct value of the field; the index entry points to the first data block that contains records with that field value.  It is another example of nondense index where Insertion and Deletion is relatively straightforward with a clustering index. Ritu CHaturvedi Figures adapted from Fundamentals of Database Systems By Elmasri and Navathe
  • 10. 10 FIGURE 4.2 A clustering index on the DEPTNUMBER ordering nonkey field of an EMPLOYEE file. Ritu CHaturvedi Figures adapted from Fundamentals of Database Systems By Elmasri and Navathe
  • 11. 11 FIGURE 4.3 Clustering index with a separate block cluster for each group of records that share the same value for the clustering field. Ritu CHaturvedi Figures adapted from Fundamentals of Database Systems By Elmasri and Navathe
  • 12. 12 Types of Single-Level Indexes  Secondary Index  A secondary index provides a secondary means of accessing a file for which some primary access already exists.  The secondary index may be on a field which is a candidate key and has a unique value in every record, or a nonkey with duplicate values.  The index is an ordered file with two fields.  The first field is of the same data type as some nonordering field of the data file that is an indexing field.  The second field is either a block pointer or a record pointer. There can be many secondary indexes (and hence, indexing fields) for the same file.  Includes one entry for each record in the data file; hence, it is a dense index Ritu CHaturvedi Figures adapted from Fundamentals of Database Systems By Elmasri and Navathe
  • 13. 13 FIGURE 4.4 A dense secondary index (with block pointers) on a nonordering key field of a file. Ritu CHaturvedi Figures adapted from Fundamentals of Database Systems By Elmasri and Navathe
  • 14. 14 FIGURE 4.5 A secondary index (with recored pointers) on a nonkey field implemented using one level of indirection so that index entries are of fixed length and have unique field values. Ritu CHaturvedi Figures adapted from Fundamentals of Database Systems By Elmasri and Navathe
  • 15. 15 Ritu CHaturvedi Figures adapted from Fundamentals of Database Systems By Elmasri and Navathe
  • 16. 16 Multi-Level Indexes  Because a single-level index is an ordered file, we can create a primary index to the index itself ; in this case, the original index file is called the first-level index and the index to the index is called the second-level index.  We can repeat the process, creating a third, fourth, ..., top level until all entries of the top level fit in one disk block  A multi-level index can be created for any type of first-level index (primary, secondary, clustering) as long as the first-level index consists of more than one disk block Ritu CHaturvedi Figures adapted from Fundamentals of Database Systems By Elmasri and Navathe
  • 17. 17 FIGURE 4.6 A two-level primary index resembling ISAM (Indexed Sequential Access Method) organization. Ritu CHaturvedi Figures adapted from Fundamentals of Database Systems By Elmasri and Navathe
  • 18. 18 Multi-Level Indexes  Such a multi-level index is a form of search tree ; however, insertion and deletion of new index entries is a severe problem because every level of the index is an ordered file. Ritu CHaturvedi Figures adapted from Fundamentals of Database Systems By Elmasri and Navathe
  • 19. 19 FIGURE 4.8 A node in a search tree with pointers to subtrees below it. Ritu CHaturvedi Figures adapted from Fundamentals of Database Systems By Elmasri and Navathe
  • 20. 20 FIGURE 4.9 A search tree of order p = 3. Ritu CHaturvedi Figures adapted from Fundamentals of Database Systems By Elmasri and Navathe
  • 21. 21 Dynamic Multilevel Indexes Using B- Trees and B+-Trees  Because of the insertion and deletion problem, most multi-level indexes use B-tree or B+-tree data structures, which leave space in each tree node (disk block) to allow for new index entries  These data structures are variations of search trees that allow efficient insertion and deletion of new search values.  In B-Tree and B+-Tree data structures, each node corresponds to a disk block  Each node is kept between half-full and completely full Ritu CHaturvedi Figures adapted from Fundamentals of Database Systems By Elmasri and Navathe
  • 22. 22 Dynamic Multilevel Indexes Using B- Trees and B+-Trees (contd.)  An insertion into a node that is not full is quite efficient; if a node is full the insertion causes a split into two nodes  Splitting may propagate to other tree levels  A deletion is quite efficient if a node does not become less than half full  If a deletion causes a node to become less than half full, it must be merged with neighboring nodes Ritu CHaturvedi Figures adapted from Fundamentals of Database Systems By Elmasri and Navathe
  • 23. 23 Difference between B-tree and B+-tree  In a B-tree, pointers to data records exist at all levels of the tree  In a B+-tree, all pointers to data records exists at the leaf-level nodes  A B+-tree can have less levels (or higher capacity of search values) than the corresponding B-tree Ritu CHaturvedi Figures adapted from Fundamentals of Database Systems By Elmasri and Navathe
  • 24. 24 FIGURE 4.10 B-tree structures. (a) A node in a B-tree with q – 1 search values. (b) A B-tree of order p = 3. The values were inserted in the order 8, 5, 1, 7, 3, 12, 9, 6. Ritu CHaturvedi Figures adapted from Fundamentals of Database Systems By Elmasri and Navathe
  • 25. 25 FIGURE 4.11 The nodes of a B+-tree. (a) Internal node of a B+-tree with q –1 search values. (b) Leaf node of a B+-tree with q – 1 search values and q – 1 data pointers. Ritu CHaturvedi Figures adapted from Fundamentals of Database Systems By Elmasri and Navathe
  • 26. 26 Choose file organizations and indexes Determine optimal file organizations to store the base tables, and the indexes required to achieve acceptable performance.  Consists of the following steps:  Step 1 Analyze transactions  Step 2 Choose file organizations  Step 3 Choose indexes Ritu CHaturvedi Figures adapted from Fundamentals of Database Systems By Elmasri and Navathe
  • 27. 27 Analyze transactions To understand functionality of the transactions and to analyze the important ones. Identify performance criteria, such as:  transactions that run frequently and will have a significant impact on performance;  transactions that are critical to the business;  times during the day/week when there will be a high demand made on the database (called the peak load). Ritu CHaturvedi Figures adapted from Fundamentals of Database Systems By Elmasri and Navathe
  • 28. 28 Analyze transactions  Use this information to identify the parts of the database that may cause performance problems.  Often not possible to analyze all expected transactions, so investigate most ‘important’ ones. Ritu CHaturvedi Figures adapted from Fundamentals of Database Systems By Elmasri and Navathe
  • 29. 29 Choose file organizations To determine an efficient file organization for each base table.  File organizations include Heap, Hash, Indexed Sequential Access Method (ISAM), B+-Tree, and Clusters.  Some DBMSs (particularly PC-based DBMS) have fixed file organization that you cannot alter. Ritu CHaturvedi Figures adapted from Fundamentals of Database Systems By Elmasri and Navathe
  • 30. 30 Choose indexes Determine whether adding indexes will improve the performance of the system.  One approach is to keep records unordered and create as many secondary indexes as necessary. Ritu CHaturvedi Figures adapted from Fundamentals of Database Systems By Elmasri and Navathe
  • 31. 31 Choose indexes  Or could order records in table by specifying a primary or clustering index.  In this case, choose the column for ordering or clustering the records as:  column that is used most often for join operations - this makes join operation more efficient, or  column that is used most often to access the records in a table in order of that column. Ritu CHaturvedi Figures adapted from Fundamentals of Database Systems By Elmasri and Navathe
  • 32. 32 Choose indexes  If ordering column chosen is key of table, index will be a primary index; otherwise, index will be a clustering index.  Each table can only have either a primary index or a clustering index.  Secondary indexes provide additional keys for a base table that can be used to retrieve data more efficiently. Ritu CHaturvedi Figures adapted from Fundamentals of Database Systems By Elmasri and Navathe
  • 33. 33 Choose indexes – Guidelines for choosing ‘wish-list’ (1) Do not index small tables. (2) Add secondary index to any column that is heavily used as a secondary key. (3) Add secondary index to a FK if it is frequently accessed. (4) Add secondary index on columns that are involved in: selection or join criteria; ORDER BY; GROUP BY; and other operations involving sorting (such as UNION or DISTINCT). Ritu CHaturvedi Figures adapted from Fundamentals of Database Systems By Elmasri and Navathe
  • 34. 34 Choose indexes – Guidelines for choosing ‘wish-list’ (5) Add secondary index on columns involved in built-in functions. (6) Add secondary index on columns that could result in an index-only plan. (7) Avoid indexing an column or table that is frequently updated. (8) Avoid indexing an column if the query will retrieve a significant proportion of the records in the table. (9) Avoid indexing columns that consist of long character strings. Ritu CHaturvedi Figures adapted from Fundamentals of Database Systems By Elmasri and Navathe

Editor's Notes