0% found this document useful (0 votes)
78 views29 pages

Index: Presented By-VISHAKHA CHANDRA (10030141082)

Indexes are data structures that improve the speed of operations on database tables. There are several types of indexes including clustered, non-clustered, unique, non-unique, bitmap, dense, sparse, reverse, B-tree, R-tree, and hash indexes. Indexes are used to improve performance of queries, ensure data uniqueness, and enable full-text search capabilities. While indexes improve performance, they also require additional disk space and can slow down write operations.

Uploaded by

Vishakha Chandra
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views29 pages

Index: Presented By-VISHAKHA CHANDRA (10030141082)

Indexes are data structures that improve the speed of operations on database tables. There are several types of indexes including clustered, non-clustered, unique, non-unique, bitmap, dense, sparse, reverse, B-tree, R-tree, and hash indexes. Indexes are used to improve performance of queries, ensure data uniqueness, and enable full-text search capabilities. While indexes improve performance, they also require additional disk space and can slow down write operations.

Uploaded by

Vishakha Chandra
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 29

Index

PRESENTED BY-
VISHAKHA CHANDRA(10030141082)
What is Index

A database index is a data structure that improves


the speed of operations in a table.
An index is a set of one or more keys, each key
pointing to a row in a table.
Indexes are organized versions of specific columns in
your tables.
Why is index used….

Indexes are used by the database manager to:


 Improve performance. In most cases, access to data is
faster with an index. Although an index cannot be created for a
view, an index created for the table on which a view is based
can sometimes improve the performance of operations on that
view.
 Ensure uniqueness. A table with a unique index cannot
have rows with identical keys.
Types of index

Clustered
 A clustered index is a special type of index that reorders the
way records in the table are physically stored.
 Table can have only one clustered index.
 A clustered index is analogous to a telephone directory, which
arranges data by last name.
Clustered Index
Non-clustered
 A Nonclustered index is a special type of index in which the
logical order of the index does not match the physical stored
order of the rows on the disc.
 The leaf nodes of a nonclustered index doesnot consist of the
data pages. Instead the leaf nodes contain index rows.
 Per table there can be upto 249 nonclustered indexes.
 A nonclustered index is analogous to an index in a textbook.
Types of index

Unique indexes
 Unique indexes are indexes that help maintain data
integrity by ensuring that no two rows of data in a table
have identical key values. E.g. UNIQUE and PRIMARY
key.

Non-unique indexes
 Non-unique indexes are used solely to improve query
performance by maintaining a sorted order of data values
that are used frequently.
Bi-directional indexes
 Bi-directional indexes allow scans in both the forward and
reverse directions.
 This option allows you to:
 Facilitate MIN and MAX functions
 Fetch previous keys
 Eliminate the need for the database manager to create a
temporary table for the reverse scan
 Eliminate redundant reverse order indexes
More types…

 Bitmap index
 Bitmap index is a special kind of index that stores the bulk of its data as bit
arrays(bitmaps) and answers most queries by performing bitwise logical
operations on these bitmaps.
 Bitmap indexes have traditionally been considered to work well for data such
as gender, which has a small number of distinct values, for example male and
female.
 Bitmap indexes are widely used in data warehousing environments.
Identifier Gender Female Male
1 Female 1 0
Bitmap
2 Male 0 1
3 Male 0 1
4 Unspecified 0 0
5 Female 1 0
 Dense index
 A dense index in databases is a file with pairs of keys and pointers
for every record in the data file.
 Sparse index
 A sparse index in databases is a file with pairs of keys and pointers
for every block in the data file(i.e. not all records).
 Reverse index
 A reverse key index reverses the key value before entering it in the
index.
 E.g. the value 24538 becomes 83542 in the index.
 Reverse key indexes have become particularly important in high
volume transaction processing system because they reduce
contention for index blocks.
B-Tree Indexing

B-Tree is an indexing technique most commonly


used in databases and file systems where pointers to
data are placed in a balance tree structure so that all
references to any data can be accessed in an equal
time frame.
The B-Tree has roots at the top and leaves and nodes
at the bottom.
The B-tree is a data structure designed not for use in
memory, but instead for use as a structure in hard
storage, like a disk drive.
B-Tree
R Tree Indexing

R-trees are tree data structures that are similar to


B-Tree, but are used for spatial access methods i.e.,
for indexing multi-dimensional information; for
example, the (X, Y) coordinates of geographical data.
Each node of an R-tree has a variable number of
entries. Each entry within a non-leaf nodestores two
pieces of data: a way of identifying a child node, and
the bounding boxof all entries within this child node.
Hash Indexing

Hash index uses hash function to map identifying


values, known as keys (e.g., a person's name), to
their associated values (e.g., their telephone
number).
The hash function is used to transform the key into
the index (the hash) of an array element (the slot or
bucket) where the corresponding value is to be
sought.
Advantages of Indexes

Query optimization: Indexes make search queries


much faster.
Uniqueness: Indexes like primary key index and
unique index help to avoid duplicate row data.
Text searching: Full-text indexes in MySQL
version 3.23.23, users have the opportunity to
optimize searching against even large amounts of
text located in any field indexed as such
Disadvantages Of Indexes

Take up disk space


Slow down the speed of writing queries
Indexes in MySQL

Several types of indexes in MySQL-


 "Normal" Indexes
 Unique Indexes
 Primary keys
 Full-text indexes
Normal Indexes

Normal indexes are the most basic indexes, and have no


restraints such as uniqueness. Simple index allows
duplicate values in a table.
Syntax:
 CREATE INDEX <INDEX_NAME> ON <TABLE_NAME>
(<COL_NAME>) ;
Example:
 CREATE INDEX AUTHOR_INDEX ON tutorials_tbl
(tutorial_author) ;
ALTER command to add and drop INDEX:
 ALTER TABLE tbl_name ADD INDEX index_name (column_list);
 ALTER TABLE tbl_name DROP INDEX (Index_Name);
Unique Index

A unique index means that two rows cannot have the


same index value.
Syntax:
 CREATE UNIQUE INDEX index_name ON table_name ( column1);
 You can use one or more columns to create an index
Example:
 CREATE UNIQUE INDEX AUTHOR_INDEX ON tutorials_tbl
(tutorial_author)
ALTER command to add and drop UNIQUE INDEX:
 ALTER TABLE tbl_name ADD INDEX index_name (column_list);
 ALTER TABLE tbl_name DROP INDEX (Index_Name);
Primary Keys

Primary Key works on columns which are NOT


NULL. There is only have one primary key per table.
Syntax:
 CREATE TABLE tablename ( [...], PRIMARY KEY
(columns_to_index) );
Example
 CREATE TABLE student (rollno int(20),name varchar(25),
PRIMARY KEY (rollno) );
ALTER command to add and drop UNIQUE INDEX:
 ALTER TABLE tbl_name ADD PRIMARY KEY (column_list);
 ALTER TABLE tbl_name DROP PRIMARY KEY;
Full Text Indexes

Full-text indexes are used by MySQL in full-text


searches.
Syntax:
 ALTER TABLE tbl_name ADD FULLTEXT(column1,column2,
…);
Example
 ALTER TABLE news ADD FULLTEXT(headline, story);
Once you have a FULLTEXT index, you can search it
using MATCH and AGAINST statements
Full Text IndexCont…

SELECT column1, column2 FROM tbl_name


WHERE MATCH (column1,column2) AGAINST
(‘Text');
E.g.
SELECT headline, story FROM news WHERE
MATCH (headline,story) AGAINST ('Hurricane');
Thank you….

You might also like