790 likes | 1.21k Views
Indexing. Indexing. Index ? What is it ?. Indexing. Index ? What is it ? A database index is a persistent memory data structure that improves efficiency of data lookup to rows of a table by a keyed access method. Indexing. Why do we need it ?. Indexing. Why do we need it ?
E N D
Indexing • Index ? What is it ?
Indexing • Index ? What is it ? A database index is a persistent memory data structure that improves efficiency of data lookup to rows of a table by a keyed access method
Indexing • Why do we need it ?
Indexing • Why do we need it ? The objective of indexing in database systems is to improve performance of query processing
Indexing • Does it have any impact on the other database operations ?
Indexing • Does it have any impact on the other database operations ? YES !!!
Indexing • Does it have any impact on the other database operations ? YES !!! Indexing decreases (!!!) performance of insert update and delete operations
Indexing • Does it have any impact on the other database operations ? YES !!! Indexing decreases (!!!) performance of insert update and delete operations Poorly designed indexing schema maydecrease performance of query processing
Indexing • Sequential search vs. index based search
Indexing • Sequential search vs. index based search disk storage Supplier ...
Indexing • Sequential search vs. index based search disk blocks disk storage Supplier ...
Indexing • Sequential search vs. index based search disk blocks disk storage Supplier ... rows (tuples)
Indexing • Sequential search vs. index based search All rows such that city = ‘Sydney’ Supplier ...
Indexing • Sequential search vs. index based search All rows such that city = ‘Sydney’ Supplier ... SELECT * FROM Supplier\ WHERE city = ‘Sydney’
Indexing • Sequential search vs. index based search All rows such that city = ‘Sydney’ Supplier ... SELECT * FROM Supplier\ WHERE city = ‘Sydney’ To find all suppliers from Sydney we have to read entire table - all data blocks !
Indexing • Sequential search vs. index based search Index on attribute city All rows such that city = ‘Sydney’ Supplier ... SELECT * FROM Supplier\ WHERE city = ‘Sydney’
Indexing • Sequential search vs. index based search Index on attribute city All rows such that city = ‘Sydney’ ‘Sydney’ Supplier ... SELECT * FROM Supplier\ WHERE city = ‘Sydney’
Indexing • Sequential search vs. index based search Index on attribute city All rows such that city = ‘Sydney’ ‘Sydney’ Supplier ... SELECT * FROM Supplier\ WHERE city = ‘Sydney’ To find all suppliers from Sydney we have to read 4 data blocks + index data blocks (<4)
Indexing • Syntax
Indexing • Syntax CREATE INDEX empx ON Supplier( city );
Indexing • Syntax CREATE INDEX empx ON Supplier( city ); index name
Indexing • Syntax CREATE INDEX empx ON Supplier( city ); index name relational table name
Indexing • Syntax CREATE INDEX empx ON Supplier( city ); index name relational table name attribute name(s)
Indexing • Index selection problem
Indexing • Index selection problem Find a smallest set of indexed attributes that maximises the search benefits and minimises the costs of insert, update, delete operations
Indexing • “ To index or not to index ? That’s the question ! ”
Indexing • “ To index or not to index ? That’s the question ! ” • Indexing an attribute which is NOT USED in WHERE clauses entails overhead and yields no benefits
Indexing • “ To index or not to index ? That’s the question ! ” • Indexing an attribute which is NOT USED in WHERE clauses entails overhead and yields no benefits • Indexing an attribute which is frequently updated may cause huge time overhead
Indexing • “ To index or not to index ? That’s the question ! ” • Indexing an attribute which is NOT USED in WHERE clauses entails overhead and yields no benefits • Indexing an attribute which is frequently updated may cause huge time overhead • Indexes on small tables can do more harm than good
Indexing • “ To index or not to index ? That’s the question ! ” • Indexing an attribute which has low selectivityis a bad idea
“ To index or not to index ? That’s the question ! ” • Indexing an attribute which has low selectivityis a bad idea Selectivity of attribute A = total number of values in the domain of A total number of rows
Indexing • Implementation of indexes
Indexing • Implementation of indexes • B-Tree based
Indexing • Implementation of indexes • B-Tree based • Hash based
Indexing • Few interesting facts
Indexing • Few interesting facts • All primary keys are automatically indexed
Indexing • Few interesting facts • All primary keys are automatically indexed • Height of B-Tree index is not larger than 4
Indexing • Few interesting facts • All primary keys are automatically indexed • Height of B-Tree index is not larger than 4 • Implementation of hash-based index needs NO persistent storage
Indexing • Few interesting facts • All primary keys are automatically indexed • Height of B-Tree index is not larger than 4 • Implementation of hash-based index needs NO persistent storage • Hash-based index is better than B-tree based index if all (majority) of index keys are know in advance
Indexing • Non-clustered vs. clustered indexes
Indexing • Non-clustered vs. clustered indexes non-clustered B-tree index . . . . . .
Indexing • Non-clustered vs. clustered indexes clustered B-tree index non-clustered B-tree index . . . . . . ..... . . . . . .
Indexing • Non-clustered vs. clustered indexes Index on attribute city All rows such that city = ‘Sydney’ ‘Sydney’ Supplier ... SELECT * FROM Supplier\ WHERE city = ‘Sydney’ To find all suppliers from Sydney we have to read 2 data blocks + index data blocks (<4)
Clustering • Cluster ? What is it ?
Clustering • Cluster ? What is it ? A cluster is a group of tables that share the same data blocks because they share common columns and are often used together
Clustering • Why do we need it ?
Clustering • Why do we need it ? The objective of clustering in database systems is to improve performance of query processing and to remove redundant data
Clustering • Does it have any impact on the other database operations ?
Clustering • Does it have any impact on the other database operations ? YES !!!