SlideShare ist ein Scribd-Unternehmen logo
1 von 15
DATABASE INDEX
Sql Server, Mysql, Oracle
Database Without Index
 Lets assume Sql Server, MySql and Oracle doesn’t
support Index.
 How to handle this siltation?
 Why Indexes has introduced in the database?
Benefit of In Built Index
ï‚š Data synchronization
 When data is inserted in the table, same data is also
inserted into the index.
 When data is deleted from the table same, data is also
deleted from the index.
 When data is updated in the table, same data is also
updated in the index.
How To Create Indexes?
CREATE TABLE tblEmployee(
ntEmployeeID BIGINT PRIMARY KEY,
vcEmpName VARCHAR(200),
dtDoj DATETIME,
btGender BIT,
vcSkill VARCHAR(2000),
moSalary MONEY,
ntHirarchyID BIGINT
)
Common Misconception
 Table design doesn’t decide index.
 It may help some extent .
 Primary key should be primary index (Clustered
index) of a table.
 All tables should have a clustered index on a
primary key column
Where To Start?
ï‚š OLAP (Online Analytical Processing)
ï‚š OLTP (Online Transaction Processing)
ï‚š What data is needed from a table?
ï‚š What queries are executing on a table?
How To Know What Queries Are Executing ?
ï‚š Find out all the in-lines queries.
ï‚š Find out all the queries from stored procedures
and database functions.
ï‚š Use DMVS or metadata tables to get queries.
Steps To Create Indexes
ï‚š Identify the application nature(OLAP OLTP)
ï‚š OLAP: Create index if necessary.
ï‚š OLTP: Create index if very necessary.
ï‚š OLAP + OLTP
ï‚š Sort the all queries on the base of frequency of
execution and query execution time.
Rule 1
ï‚š Create indexes on a table if the queries which fetch data
from a table have at least following clauses:
Clause Logical Processing Order
ON 1
WHERE 2
GROUP BY 3
HAVING 4
ORDER BY 5
DISTINCT 6
UNION NA
EXCEPT NA
INTERSECT NA
Rule 2
ï‚š Create index on the fields in which data are filtered only using
following operators in WHERE clause, ON clause and HAVING clause:
Operator Type
= Equality
< Range
> Range
<= Range
>= Range
IN Range
BETWEEN Range
LIKE Range
Rule 3
ï‚š Don't create indexes on the columns which are
expression in the query.
ï‚š We will discuss later how to create indexes of
such predicates.
Order of column name in an index
ï‚š Index 1:
CREATE INDEX NCI_a_b ON tblEmployee(a,b)
ï‚š Index 2:
CREATE INDEX NCI_b_a ON tblEmployee(b,a)
ï‚š Here index NCI_a_b and NCI_b_a are two totally different
indexes.
Rule 4
ï‚š Try to avoid creating single column indexes if
multi column index is possible.
ï‚š If we are creating multi column index, keep
columns order according to logical order of
processing of different clauses.
Rule 5
 Keep the all columns with equality operator first.
 One columns with range operators is allowed .
 If columns with range operator has not included
then only columns in GROUP BY Clause or ORDER
BY clause should be included.
Rule 6
ï‚š If there are two columns with equality operator
then column which has most number of distinct
values should be included first.

Weitere Àhnliche Inhalte

Was ist angesagt?

MySQL Query And Index Tuning
MySQL Query And Index TuningMySQL Query And Index Tuning
MySQL Query And Index Tuning
Manikanda kumar
 
MySQL Storage Engines
MySQL Storage EnginesMySQL Storage Engines
MySQL Storage Engines
Karthik .P.R
 

Was ist angesagt? (20)

Introduction to triggers
Introduction to triggersIntroduction to triggers
Introduction to triggers
 
Sql Server Basics
Sql Server BasicsSql Server Basics
Sql Server Basics
 
Trigger in mysql
Trigger in mysqlTrigger in mysql
Trigger in mysql
 
SQL Joins and Query Optimization
SQL Joins and Query OptimizationSQL Joins and Query Optimization
SQL Joins and Query Optimization
 
Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)
 
Joins in SQL
Joins in SQLJoins in SQL
Joins in SQL
 
MySQL Query And Index Tuning
MySQL Query And Index TuningMySQL Query And Index Tuning
MySQL Query And Index Tuning
 
Indexes in postgres
Indexes in postgresIndexes in postgres
Indexes in postgres
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
Introduction to NoSQL
Introduction to NoSQLIntroduction to NoSQL
Introduction to NoSQL
 
SQL Joins.pptx
SQL Joins.pptxSQL Joins.pptx
SQL Joins.pptx
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
 
SQL JOINS
SQL JOINSSQL JOINS
SQL JOINS
 
SQL Server Index and Partition Strategy
SQL Server Index and Partition StrategySQL Server Index and Partition Strategy
SQL Server Index and Partition Strategy
 
Query Optimization in SQL Server
Query Optimization in SQL ServerQuery Optimization in SQL Server
Query Optimization in SQL Server
 
SQL Constraints
SQL ConstraintsSQL Constraints
SQL Constraints
 
Null values, insert, delete and update in database
Null values, insert, delete and update in databaseNull values, insert, delete and update in database
Null values, insert, delete and update in database
 
MySQL INDEXES
MySQL INDEXESMySQL INDEXES
MySQL INDEXES
 
The Relational Database Model
The Relational Database ModelThe Relational Database Model
The Relational Database Model
 
MySQL Storage Engines
MySQL Storage EnginesMySQL Storage Engines
MySQL Storage Engines
 

Andere mochten auch

12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMS12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMS
koolkampus
 
CS 542 Database Index Structures
CS 542 Database Index StructuresCS 542 Database Index Structures
CS 542 Database Index Structures
J Singh
 
Less07 Users
Less07 UsersLess07 Users
Less07 Users
vivaankumar
 
Postgre sql unleashed
Postgre sql unleashedPostgre sql unleashed
Postgre sql unleashed
Marian Marinov
 
Constraints In Sql
Constraints In SqlConstraints In Sql
Constraints In Sql
Anurag
 

Andere mochten auch (20)

12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMS12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMS
 
CS 542 Database Index Structures
CS 542 Database Index StructuresCS 542 Database Index Structures
CS 542 Database Index Structures
 
Indexes
IndexesIndexes
Indexes
 
PostgreSQL: Advanced indexing
PostgreSQL: Advanced indexingPostgreSQL: Advanced indexing
PostgreSQL: Advanced indexing
 
Data indexing presentation
Data indexing presentationData indexing presentation
Data indexing presentation
 
Advanced Index, Partitioning and Compression Strategies for SQL Server
Advanced Index, Partitioning and Compression Strategies for SQL ServerAdvanced Index, Partitioning and Compression Strategies for SQL Server
Advanced Index, Partitioning and Compression Strategies for SQL Server
 
Sql index
Sql indexSql index
Sql index
 
Geek Sync | SQL Server Indexing Basics
Geek Sync | SQL Server Indexing BasicsGeek Sync | SQL Server Indexing Basics
Geek Sync | SQL Server Indexing Basics
 
Les11 Including Constraints
Les11 Including ConstraintsLes11 Including Constraints
Les11 Including Constraints
 
Indexing basics
Indexing basicsIndexing basics
Indexing basics
 
Advanced User Privileges
Advanced User PrivilegesAdvanced User Privileges
Advanced User Privileges
 
PostgreSQL Database Slides
PostgreSQL Database SlidesPostgreSQL Database Slides
PostgreSQL Database Slides
 
Less07 Users
Less07 UsersLess07 Users
Less07 Users
 
Writing optimal queries
Writing optimal queriesWriting optimal queries
Writing optimal queries
 
Postgre sql unleashed
Postgre sql unleashedPostgre sql unleashed
Postgre sql unleashed
 
Constraints In Sql
Constraints In SqlConstraints In Sql
Constraints In Sql
 
Indexing structure for files
Indexing structure for filesIndexing structure for files
Indexing structure for files
 
Columnstore indexes in sql server 2014
Columnstore indexes in sql server 2014Columnstore indexes in sql server 2014
Columnstore indexes in sql server 2014
 
User, roles and privileges
User, roles and privilegesUser, roles and privileges
User, roles and privileges
 
Data Processing Inside PostgreSQL
Data Processing Inside PostgreSQLData Processing Inside PostgreSQL
Data Processing Inside PostgreSQL
 

Ähnlich wie Database index

Module08
Module08Module08
Module08
Sridhar P
 
SQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdfSQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdf
DraguClaudiu
 
Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007
paulguerin
 
05 Create and Maintain Databases and Tables.pptx
05 Create and Maintain Databases and Tables.pptx05 Create and Maintain Databases and Tables.pptx
05 Create and Maintain Databases and Tables.pptx
MohamedNowfeek1
 
Database Architecture and Basic Concepts
Database Architecture and Basic ConceptsDatabase Architecture and Basic Concepts
Database Architecture and Basic Concepts
Tony Wong
 
02 database oprimization - improving sql performance - ent-db
02  database oprimization - improving sql performance - ent-db02  database oprimization - improving sql performance - ent-db
02 database oprimization - improving sql performance - ent-db
uncleRhyme
 
Sql server ___________session_17(indexes)
Sql server  ___________session_17(indexes)Sql server  ___________session_17(indexes)
Sql server ___________session_17(indexes)
Ehtisham Ali
 
Ms sql server ii
Ms sql server  iiMs sql server  ii
Ms sql server ii
Iblesoft
 

Ähnlich wie Database index (20)

Application sql issues_and_tuning
Application sql issues_and_tuningApplication sql issues_and_tuning
Application sql issues_and_tuning
 
MSSQL_Book.pdf
MSSQL_Book.pdfMSSQL_Book.pdf
MSSQL_Book.pdf
 
Database Application for La Salle
Database Application for La SalleDatabase Application for La Salle
Database Application for La Salle
 
Advanced MySQL Query Optimizations
Advanced MySQL Query OptimizationsAdvanced MySQL Query Optimizations
Advanced MySQL Query Optimizations
 
Module08
Module08Module08
Module08
 
Module08
Module08Module08
Module08
 
SQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdfSQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdf
 
Query parameterization
Query parameterizationQuery parameterization
Query parameterization
 
Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007
 
05 Create and Maintain Databases and Tables.pptx
05 Create and Maintain Databases and Tables.pptx05 Create and Maintain Databases and Tables.pptx
05 Create and Maintain Databases and Tables.pptx
 
Database Architecture and Basic Concepts
Database Architecture and Basic ConceptsDatabase Architecture and Basic Concepts
Database Architecture and Basic Concepts
 
Mysql Optimization
Mysql OptimizationMysql Optimization
Mysql Optimization
 
02 database oprimization - improving sql performance - ent-db
02  database oprimization - improving sql performance - ent-db02  database oprimization - improving sql performance - ent-db
02 database oprimization - improving sql performance - ent-db
 
Sql server ___________session_17(indexes)
Sql server  ___________session_17(indexes)Sql server  ___________session_17(indexes)
Sql server ___________session_17(indexes)
 
MySQL Indexing : Improving Query Performance Using Index (Covering Index)
MySQL Indexing : Improving Query Performance Using Index (Covering Index)MySQL Indexing : Improving Query Performance Using Index (Covering Index)
MySQL Indexing : Improving Query Performance Using Index (Covering Index)
 
Database Performance
Database PerformanceDatabase Performance
Database Performance
 
Steps towards of sql server developer
Steps towards of sql server developerSteps towards of sql server developer
Steps towards of sql server developer
 
MySQL Indexing
MySQL IndexingMySQL Indexing
MySQL Indexing
 
Ms sql server ii
Ms sql server  iiMs sql server  ii
Ms sql server ii
 
Interview Questions.pdf
Interview Questions.pdfInterview Questions.pdf
Interview Questions.pdf
 

Mehr von Riteshkiit (14)

Backup and restore
Backup and restoreBackup and restore
Backup and restore
 
Sql server introduction fundamental
Sql server introduction fundamentalSql server introduction fundamental
Sql server introduction fundamental
 
Index_2
Index_2Index_2
Index_2
 
Order by and join
Order by and joinOrder by and join
Order by and join
 
Sql server introduction
Sql server introductionSql server introduction
Sql server introduction
 
Database design
Database designDatabase design
Database design
 
Statistics
StatisticsStatistics
Statistics
 
Index
IndexIndex
Index
 
Addhoc query
Addhoc queryAddhoc query
Addhoc query
 
Sql server JOIN
Sql server JOINSql server JOIN
Sql server JOIN
 
Sql server 2
Sql server 2Sql server 2
Sql server 2
 
Sql query performance analysis
Sql query performance analysisSql query performance analysis
Sql query performance analysis
 
Sql query performance analysis
Sql query performance analysisSql query performance analysis
Sql query performance analysis
 
Topics
TopicsTopics
Topics
 

KĂŒrzlich hochgeladen

Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Bert Jan Schrijver
 
Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
Abortion Pills In Pretoria ](+27832195400*)[ đŸ„ Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ đŸ„ Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ đŸ„ Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ đŸ„ Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 

KĂŒrzlich hochgeladen (20)

Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
Abortion Pills In Pretoria ](+27832195400*)[ đŸ„ Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ đŸ„ Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ đŸ„ Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ đŸ„ Women's Abortion Clinic In Pre...
 
WSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AIWSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AI
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 

Database index

  • 2. Database Without Index  Lets assume Sql Server, MySql and Oracle doesn’t support Index.  How to handle this siltation?  Why Indexes has introduced in the database?
  • 3. Benefit of In Built Index ï‚š Data synchronization  When data is inserted in the table, same data is also inserted into the index.  When data is deleted from the table same, data is also deleted from the index.  When data is updated in the table, same data is also updated in the index.
  • 4. How To Create Indexes? CREATE TABLE tblEmployee( ntEmployeeID BIGINT PRIMARY KEY, vcEmpName VARCHAR(200), dtDoj DATETIME, btGender BIT, vcSkill VARCHAR(2000), moSalary MONEY, ntHirarchyID BIGINT )
  • 5. Common Misconception  Table design doesn’t decide index.  It may help some extent .  Primary key should be primary index (Clustered index) of a table.  All tables should have a clustered index on a primary key column
  • 6. Where To Start? ï‚š OLAP (Online Analytical Processing) ï‚š OLTP (Online Transaction Processing) ï‚š What data is needed from a table? ï‚š What queries are executing on a table?
  • 7. How To Know What Queries Are Executing ? ï‚š Find out all the in-lines queries. ï‚š Find out all the queries from stored procedures and database functions. ï‚š Use DMVS or metadata tables to get queries.
  • 8. Steps To Create Indexes ï‚š Identify the application nature(OLAP OLTP) ï‚š OLAP: Create index if necessary. ï‚š OLTP: Create index if very necessary. ï‚š OLAP + OLTP ï‚š Sort the all queries on the base of frequency of execution and query execution time.
  • 9. Rule 1 ï‚š Create indexes on a table if the queries which fetch data from a table have at least following clauses: Clause Logical Processing Order ON 1 WHERE 2 GROUP BY 3 HAVING 4 ORDER BY 5 DISTINCT 6 UNION NA EXCEPT NA INTERSECT NA
  • 10. Rule 2 ï‚š Create index on the fields in which data are filtered only using following operators in WHERE clause, ON clause and HAVING clause: Operator Type = Equality < Range > Range <= Range >= Range IN Range BETWEEN Range LIKE Range
  • 11. Rule 3 ï‚š Don't create indexes on the columns which are expression in the query. ï‚š We will discuss later how to create indexes of such predicates.
  • 12. Order of column name in an index ï‚š Index 1: CREATE INDEX NCI_a_b ON tblEmployee(a,b) ï‚š Index 2: CREATE INDEX NCI_b_a ON tblEmployee(b,a) ï‚š Here index NCI_a_b and NCI_b_a are two totally different indexes.
  • 13. Rule 4 ï‚š Try to avoid creating single column indexes if multi column index is possible. ï‚š If we are creating multi column index, keep columns order according to logical order of processing of different clauses.
  • 14. Rule 5  Keep the all columns with equality operator first.  One columns with range operators is allowed .  If columns with range operator has not included then only columns in GROUP BY Clause or ORDER BY clause should be included.
  • 15. Rule 6 ï‚š If there are two columns with equality operator then column which has most number of distinct values should be included first.