0% found this document useful (0 votes)
7 views21 pages

DEC - Indexing

The document discusses database indexing, including what it is, why it is used, how to use indexes, when to use and not use indexes, and tips for optimizing indexing. Indexing can vastly reduce query times by sorting data in a tree structure and using pointers instead of storing data. Every table should be indexed on its primary key as a clustered index and can have multiple non-clustered indexes. Small tables and operations involving many updates or inserts may not benefit from indexing.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views21 pages

DEC - Indexing

The document discusses database indexing, including what it is, why it is used, how to use indexes, when to use and not use indexes, and tips for optimizing indexing. Indexing can vastly reduce query times by sorting data in a tree structure and using pointers instead of storing data. Every table should be indexed on its primary key as a clustered index and can have multiple non-clustered indexes. Small tables and operations involving many updates or inserts may not benefit from indexing.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

DEC Training

Database Indexing
Outline
● What & Why is indexing?

● How to use index?

● When & When not to use?

● Optimize Indexing
What is indexing?
What is indexing?

An index is a structure that holds the field the index is sorting and a pointer from each record to their
corresponding record in the original table where the data is actually stored.
What is indexing?
B-Tree

● Is a “self-balancing tree data structure”


● Creates a tree-like structure that sorts data for quick searching.
Why is indexing?
What is indexing?
What is indexing?
● Created when the table is created.
● Are the unique index per table
● Use the primary key sorted in ascending order

● Point to memory addresses instead of storing data


themselves
● You can create many non-clustered indexes
What is indexing?
How to use index?
Using indexes for INSERT, UPDATE, DELETE ?
When to use an index?

● Frequent querying

● Sorting and ordering

● Filtering and conditional statements

● Full-Text Searching

● Large Dataset
When not to use an index?

● Small tables

● Large batch updates or insert operations

● Used on columns that contain a high number of NULL values


Database Indexing Summary
● Indexing can vastly reduce the time of queries

● Every table with a primary key has one clustered index

● Every table can have many non-clustered indexes to aid in querying

● Non-clustered indexes hold pointers back to the main table

● Not every database will benefit from indexing

● Not every index will increase the query speed for the database
Database Indexing Summary

Create index by “employee_id”

Create index by “employee_id” and “subsidiary_id”

THE ORDER DOES MATTER


Slow Index
Tips for SQL
Tips for SQL
Tips for SQL
● Avoid too many JOINs

● Avoid using SELECT DISTINCT

● Use TOP to sample query results

● Avoid using multiple OR in the FILTER predicate

● BETWEEN is better than IN

● Running in off-peak hours


THANKS FOR LISTENING

You might also like