You are on page 1of 15

8/11/2017 SQL Indexes | Performance Tuning | Normal Index | Unique Index | Bitmap Index | Global Index | Local Index

SQL WORLD
GET YOUR SQL QUERY FAST AND FURIOUS..

ABOUT US COMPLEX SQL QUERIES EXAMPLES CONTACT US HOME

MICROSOFT SQL MYSQL OBIEE ORACLE POSTGRESQL SIEBEL UNIX

SQL Indexes | Performance


SEARCH YOUR TOPIC HERE

Tuning | Normal Index | SEARCH

Unique Index | Bitmap


Index | Global Index | Local CATEGORIES

Index BI Tutorials

SQL Complex Queries


February 9, 2017 admin SQL Performance Tuning, SQL
Tutorials 25 SQL Di erence Between

SQL Interview Questions

SQL Interview Questions For


Freshers

SQL Joins

SQL Performance Tuning

SQL Tutorials

Unix Tutorials

RECENT POSTS

SQL Indexes: OBIEE RPD | OBIEE Repository


Development | RPD
In most of SQL projects the data is in millions and billions. Because of
Development in OBIEE | Starting
huge volume of the data performance of SQL statement degrades.So
with RPD
there are lot of di erent ways to improve the performance of
application,performance of reports or performance of SQL query.So OBIEE Architecture | OBIEE
most of people prefer SQL Indexes to improve the performance of Components | Oracle Business

http://www.complexsql.com/indexing-in-sql/ 1/15
8/11/2017 SQL Indexes | Performance Tuning | Normal Index | Unique Index | Bitmap Index | Global Index | Local Index

the query.Indexing sometimes improve the performance but make Intelligence Architecture
sure that the table is not inserting or updating the data while you are
Features of OBIEE | Advantages
running the query.
Of OBIEE | How to Log in in
OBIEE?
CLICK HERE TO GET BASIC IDEA OF PERFORMANCE TUNING
Database Schema used in OBIEE
De nition Of Index: | Star Schema | Snow ake
schema

Data Modeling in OBIEE | Fact


and Dimension Modeling |
Aggregate table with Example |
Fact with Example | Dimensions
with Example

Data warehouse Concept |


OBIEE as Data warehouse | What
SQL Indexes are nothing but optional structure associated with the is Data warehouse? | Data
table which may or may not improve the performance of Query warehouse vs transactional
System | Types of Data
In simple words suppose we want to search the topic in to Warehouse System | OLAP VS
OLTP
book we go to index page of that book and search the topic
which we want.Just like that to search the values from the table What is Business Intelligence
when indexing is there you need notuse the full table scan. (BI)?

vi Editor | vi Editor with its


SQL Indexes are nothing but way of reducing the cost of the options | how to use vi Editor |
query.More the cost of the query less the performance of the Step by Step Learning of vi Editor
query.The main task of query tuner is to reduce the cost of the query | ftp Commands
using indexing,Reduce the Full table scans,reduce the time to fetch
the records from the query. Chmod command in unix | Unix
File Permissions | chmod with
There are following types of SQL Indexes: examples | Chwn command |
Chgrp command | UNMASK
1.Normal index
Sed Command in Unix with
examples | Stream Editor in Unix
2.Unique Index
| Pipe Command with Examples

3.Bit Map Index | Head and Tail command with


examples
4.Composite Index Grep Command in unix | Grep
Command with Examples | Grep
5.B-Tree Index(Oracle considered Normal indexes as B-Tree Indexes)
Command with Options | Search
String in Unix File | Practical
6.Function Based Index
Examples of Grep command |

http://www.complexsql.com/indexing-in-sql/ 2/15
8/11/2017 SQL Indexes | Performance Tuning | Normal Index | Unique Index | Bitmap Index | Global Index | Local Index

7.Clustered Index fgrep command with example |


egrep command with example
8.Non-Clustered Index.
Process Commands in Unix |

In this article i will give brief introduction about Normal index,Bit map Unix Filter commands | Touch

index and unique index which are most widely used indexes to tune command with example | ps

the Query performance. command with examples | Kill


command with examples
CLICK HERE TO GET INTERVIEW QUSTIONS ON PERFORMANCE Filter Commands in Unix | Sort
TUNING.. command with Example | Uniq
Command with Example | Date
Normal Indexes:
Command with Example

To create normal index you must have CREATE ANY INDEX Filter Commands in Unix | Cut
privilege.After that you can create index on the table.Before creating command with Example | Paste
these indexes you need to go to table and check the cost of the Command With Example |
table.If you are using SQL developer editor you will get query cost by Translate (tr) Command with
pressing F10 key else you are using the direct statement Explain Example
Plan before SQL Query.After checking the cost of query user needs to
File Commands with Examples |
check whether any indexes are there on the table or
WC command with Example | CP
not.ALL_INDEXES is the system table which gives user the
Command with Example | CMP
information about the indexes on the table.If Indexing is not there on
Command with Example | LS
table level you can do the indexing on column of the table.
command with Example | RM
command with Example
Syntax of Normal Index:
Unix Directory Commands |
Create index Index_name on Table_Name(Column_Name); Create Directory in Unix | Mkdir
Command with Example | PWD
Example: command with example | Rmdir
command to remove directory |
Create index NI_EMP_NAME on EMP(NAME); Cd command to change directory

Create le in unix using multiple


Unique Index: ways | Cat Command with
examples | Touch command
To create unique index you must have CREATE ANY INDEX with examples | Di erence
privilege.Here the concept is bit di erent.User needs to check the between Cat and Touch | Unix
values of the table to create unique index.If table contains uniquely Commands to create le | Create
identi ed values in speci ed column then you should use unique le using Vi editor
index.Especially while creating the table if we specify the primary key
then unique index is automatically created on that column.But for Basic Unix Commands |

Unique key constaint columns you separately need to do Frequently Used Unix

indexing.Kindly make sure that Unique key indexes created on the Commands | Unix Commands

columns which has unique values only. with Examples | Useful Unix
Commands

http://www.complexsql.com/indexing-in-sql/ 3/15
8/11/2017 SQL Indexes | Performance Tuning | Normal Index | Unique Index | Bitmap Index | Global Index | Local Index

Syntax for Unique Index: Oracle Partitioning | Table


Partitioning in Oracle |
Create Unique index Index_name on Table_name(Unique column Partitioning in SQL | How
name); Partitioning helps improving
Performance | Table Partitioning
Example: with Examples | Partitioning on
existing table
CREATE UNIQUE INDEX UI1_EMP on EMP(EMP_ID); Database Normalization
Examples | Normalization in
CLICK HERE TO GET INFORMATION ON OPTIMIZER Database with Examples |
Database Normalization with
Bit-Map Index: Real Life Examples | Designing
Normalized Database
If Table contains the distinct values which are not more than 20
distinct values then user should go for Bit map indexes.User should Interview Questions for HCL |
avoid the indexing on each and every row and do the indexing only SQL Interview Questions for HCL
on distinct records of the table column.You should able to check | Interview Questions Asked in
drastic change in query cost after changing the normal index to Bit HCL | HCL Interview Questions |
map index.The bit map indexes are very much useful in dataware 20 Most Important SQL Interview
housing where there are low level of concurrent transactions.Bit map Questions for HCL
index stores row_id as associated key value with bitmap and did the
Operators in SQL | SQL
indexing only distinct values.Means If in 1 million records only 20
Operators | Arithmetic
distinct values are there so Bitmap index only stores 20 values as
Operators | Logical Operators |
bitmap and fetches the records from that 20 values only.
Comparison Operators |
Negation Operators | Operators
Syntax: in SQL with Examples

Interview Questions for TCS |


Create bitmap index Index_name on Table_name(Columns which
SQL Interview Questions for TCS
have distinct values);
| Interview Questions Asked in
TCS | TCS Interview Questions
Example:
Pivot in SQL with Example | Pivot
CREATE BITMAP index BM_DEPT_NAME on Clause | Pivot and unpivot in SQL
DEPT(Department_name); | Pivot in Oracle | SQL Pivot with
Real Life Example
Example/Real Life Scenario: Di erence between Truncate and
Delete, Drop in SQL | Truncate
Suppose There are 2 tables which has milions of records.We Delete and Drop Commands in
need to improve the performance of Query.Now It is taking 4 SQL | SQL Di erence between
mins to fetch 1 million Records. Truncate,Delete and Drop
Commands | Real Life Examples
Step 1: of Truncate Delete and Drop
Command
http://www.complexsql.com/indexing-in-sql/ 4/15
8/11/2017 SQL Indexes | Performance Tuning | Normal Index | Unique Index | Bitmap Index | Global Index | Local Index

Explain Planselect * from DEPT d,EMP e where d.DEPTNO= e.deptno; SUBSCRIBE TO BLOG VIA
EMAIL
Output:
Enter your email address to
Cost of DEPT Table-20000 table is Full Scanned subscribe to this blog and receive
noti cations of new posts by
Cost of EMP tabe-20000-table is Full Scanned
email.
Join 55 other subscribers
Step 2:
Email Address

Check whether there are SQL Indexes on table columns: SUBSCRIBE

Select * from ALL_INDEXES where Table name in (EMP,DEPT);

Output:

No indexes found.

Step 3:

Check description of the table and check whether the normal index
where the Unique index and where bitmap indexes are applicable.

Step 4:

Creation of normal index on EMP table name column.

Create index NI_EMP_NAME on EMP(NAME);

Step 5:

EMP_ID has unique values so kindly create UNIQUE INDEX ON that


column.DEPTNO has also unique values so for DEPTNO column we
need to create unique index.

CREATE UNIQUE INDEX UI1_EMP on EMP(EMP_ID);

CREATE UNIQUE INDEX UI2_DEPT on DEPT(DEPTNO);

Step 6:

Check for Distinct values.So Department_name has 20 distinct


departments so on Department_name column create Bit-map index.

CREATE BITMAP index BM_DEPT_NAME on DEPT(Department_name);

http://www.complexsql.com/indexing-in-sql/ 5/15
8/11/2017 SQL Indexes | Performance Tuning | Normal Index | Unique Index | Bitmap Index | Global Index | Local Index

Step 7:

Check the cost of Query

Explain Planselect * from DEPT d,EMP e where d.DEPTNO= e.deptno;

Output:

Emp Table :-> 20 Fast Unique Scan

DEPT Table:-> 10 Bit-map Scan

and Results will come in 10 Seconds..Hope everyone get idea about


basic indexing and how it is been used in real life scenarios.

Composite Index:

When 2 or more columns in single table are related which each other
and used in where condition of select statement then user should
create composite index on the columns which are created.If all
columns selected by in query are in composite index then oracle will
return the values from the index without accessing the table.

Composite indexes should be avoided as they are large in size

Example:

Select e.Emp_name,d.Dept_name

from Employee e ,Deartment d

where e.Empno=d.empno

and e.Deptno=d.Deptno;

Suppose we want to do indexing on Employee and Department


table.Here in above example Empno and Deptno are related to each
other.So we can create index on Employee_Num and
Department_Num

Create index CI_ENO_DEPTNO on Employee(Empno,Deptno);

CLICK HERE TO GET INFORMATION ABOUT JOINS IN SQL..

http://www.complexsql.com/indexing-in-sql/ 6/15
8/11/2017 SQL Indexes | Performance Tuning | Normal Index | Unique Index | Bitmap Index | Global Index | Local Index

Function Based Indexes:

Function based indexes allows us to index on the functional columns


so that oracle engine will take the index and improves the
performance of the query. As per requirements we are using lot of
SQL functions to fetch the results.Function based indexs gives ability
to index the computed columns.Function based indexes are easy to
implement and it also provides immediate value.These indexes
speeds up the application without changing application code or
query.

Syntax:

Create index indexname on


tablename(Function_name(column_name));

Example:

Create index FI_Employee on Employee(trunc(Hire_date));

Clustered Indexes:

1.The clustered indexes are indexes which are physically stored in


order means it stores in ascending or descending order in Database.

2.Clustered indexes are created one for each table.

3.When primary key is created then clustered index has been


automatically created in the table.

4.If table is under heavy data modi cations the clustered indexes are
preferable to use.

Non Clustered Indexes:

1.The clustered indexes are used for searching purpose as we can


create clustered indexes where primary is is de ned.But Non
clustered indexes are indexes which will be created on the multiple
joining conditions,multiple lters used in query.

2.We can create 0 to 249 clustered indexes on single table.

3.Foreign keys should be non clustered.When user wants to retrieve


heavy data from elds other than primary key the non clustered

http://www.complexsql.com/indexing-in-sql/ 7/15
8/11/2017 SQL Indexes | Performance Tuning | Normal Index | Unique Index | Bitmap Index | Global Index | Local Index

indexes are useful.

I have explained the Basic concept of SQL Indexes here.In upcoming


articles i will explain how the indexing works in detailed description
with Example.Please comment if you want copy of this article or if
you have any questions.Hope you like article of SQL Indexes.

What is mean by Global and Local Index?

When there is partition on the table and we need to apply the


indexes on that table then we need to use global indexes or local
indexes.When table is partitioned then we need to use global or local
parameters/keywords in DDL of create index statement.

Global Index:

Usually when you create index on the table has indexed but when
you are using partitioned table we need to change the syntax of the
create index and need to use the Global index for one to many
relationship.Global index is one to many relationships which allows
index partition to map to many table partitions.The global index can
be partitioned by range or hash method and it can be de nd on any
kind of partitioned or non partitioned table.

Syntax:

Create index Indexname

On tablename(Column name)

GLOBAL

(PARTITION Partition_name values(value_of_partition),

PARTITION Partition_name values(value_of_partition),

PARTITION Partition_name values(value_of_partition),

PARTITION Partition_other values(value_of_partition));

Example:

Create indexEmployee_GI

http://www.complexsql.com/indexing-in-sql/ 8/15
8/11/2017 SQL Indexes | Performance Tuning | Normal Index | Unique Index | Bitmap Index | Global Index | Local Index

On tablename(Employee_num)

GLOBAL

(PARTITION Employee_1 values(1),

PARTITION Employee_2 values(2),

PARTITION Employee_3 values(3),

PARTITION Employee_other values(default));

LOCAL INDEX:

Local indexes are indexes where there is one to one mapping


between index partition and table partition.These indexes are
basically used to improve the performance of partitioned tables.Local
indexes directly uses divide and conquer approach to generate the
Fast and best execution plan of SQL Query.

Syntax:

Create index indexname

on table_name(Column_name)

LOCAL

(Partition Partition_name1,

Partition Partition_name2.

);

Hope you will get brief idea about indexing.If you like this article dont
forget to comment in comment section.

CLICK HERE TO GET 20 TCS Interview Questions

HOME

Like 139

Share this:

http://www.complexsql.com/indexing-in-sql/ 9/15
8/11/2017 SQL Indexes | Performance Tuning | Normal Index | Unique Index | Bitmap Index | Global Index | Local Index

139

Related

SQL Optimization SQL Interview Parser and


interview questions Questions for Tech Optimizer in SQL
| Performance Mahindra | |Execution Plan in
Tuning Interview Important SQL SQL | SQL
Questions | 20 Interview Questions Performance Tuning
Interview Questions for Tech Mahindra | |Di erence
of SQL Performance Tech Mahindra Between Rule Based
March 1, 2017 Interview Questions and Cost Based
In "SQL Interview and answers Optimizer
Questions" February 26, 2017 February 24, 2017
In "SQL Interview In "SQL
Questions" Performance
Tuning"

PREVIOUS NEXT
SQL Set Operators| SQL Statements |
Intersect and Minus SQL Select
in SQL | Real Life Statement | Step-
Scenarios | by-step Execution of
Di erence Between Select Statement |
Intersect and Minus Data Query
| Real Life Examples Language
of Intersect and
Minus

14 COMMENTS

priyanka
FEBRUARY 9, 2017 AT 2:02 PM

Thanks for Posting..


I have a doubt should we create indexes to each and every column of
the tables in order to improve the performance ?

REPLY

admin
FEBRUARY 9, 2017 AT 3:46 PM

http://www.complexsql.com/indexing-in-sql/ 10/15
8/11/2017 SQL Indexes | Performance Tuning | Normal Index | Unique Index | Bitmap Index | Global Index | Local Index

No Priyanka..You need to select the columns which are used as


lters in the query to do indexingMeans if you need to tune
following query
select * from Employee e and dept d where e.emp_id=d.emp_id;

then you only need to create index on column named Emp_id


not on all columnsin the table..
Hope you will get the idea about indexing..If any other
issues..Kindly post

REPLY

priyanka
FEBRUARY 9, 2017 AT 2:20 PM

The Explain Plan [Query] which you have described here I am not
able to Query in SQL Server 2008 R2 Server.

REPLY

admin
FEBRUARY 9, 2017 AT 3:49 PM

If you are working on SQL server you will not get your query plan
using Explain command.You need to use CTL + M command to
get your query plan.You can use SQL server pro ler to analyse
the query also..
Thanks for posting..If other information needed i will help u

REPLY

priyanka
FEBRUARY 17, 2017 AT 10:23 AM

Thank you for clarifying


Could you post an article on how to analyse the T-sql query
and what should we do to increase the performance of the
query.

REPLY

http://www.complexsql.com/indexing-in-sql/ 11/15
8/11/2017 SQL Indexes | Performance Tuning | Normal Index | Unique Index | Bitmap Index | Global Index | Local Index

admin
FEBRUARY 17, 2017 AT 4:37 PM

Sure priyanka..I will write article on it

REPLY

Prashanta Hegde
FEBRUARY 21, 2017 AT 10:30 AM

Hi Sir,
Thank you so much I have read 2-3 articles. Very well explained.

Thanks,
Prashanth

REPLY

admin
FEBRUARY 21, 2017 AT 4:51 PM

Thanks prashanthI will write more and more articles on


complexsqlsThanks for motivation

REPLY

Hanuman
FEBRUARY 28, 2017 AT 7:20 AM

where is explanation of other indexes

REPLY

admin
FEBRUARY 28, 2017 AT 2:58 PM

I covered only basics in this article..I will write on Advanced


indexing soon..Thanks for suggestions

REPLY
http://www.complexsql.com/indexing-in-sql/ 12/15
8/11/2017 SQL Indexes | Performance Tuning | Normal Index | Unique Index | Bitmap Index | Global Index | Local Index
REPLY

Saket Parab
APRIL 7, 2017 AT 4:27 AM

In the non clustered index part, you have stated: We can create 0 to
249 clustered indexes on single table, it should be Non-Clustered
and not clustered Index, as only one clustered index is allowed per
table.

REPLY

admin
APRIL 9, 2017 AT 4:17 AM

Thanks for extra information sanket

REPLY

Chin
APRIL 22, 2017 AT 12:32 PM

Good day very cool website!! Man .. Beautiful .. Wonderful .. Ill


bookmark your web site and take the feeds additionallyIm glad to
search out numerous useful information right here in the post, wed
like develop more strategies on this regard, thank you for sharing. . . .
..

REPLY

admin
APRIL 24, 2017 AT 3:27 PM

Thanks Chin

REPLY

11 TRACKBACKS / PINGBACKS

http://www.complexsql.com/indexing-in-sql/ 13/15
8/11/2017 SQL Indexes | Performance Tuning | Normal Index | Unique Index | Bitmap Index | Global Index | Local Index

Parser and Optimizer in SQL |Execution Plan in SQL | SQL


Performance Tuning |Di erence Between Rule Based and Cost Based
Optimizer

SQL Interview Questions for Tech Mahindra | Important SQL


Interview Questions

Interview Questions on SQL Performance | SQL Performance


Tuning Questions | 20 Interview Questions of SQL Performance

Basics of SQL Performance Tuning | Performance Tuning for SQL


| How to improve Query Performance?

Interview Questions For Oracle | SQL interview Questions

SQL Interview Questions for Freshers | Freshers Interview


Questions in SQL | SQL Basic interview questions | 20 Most
important SQL Questions | SQL Questions with Answers | SQL
Questions Asked in Interview

Interview Questions for HCL | SQL Interview Questions for HCL |


Interview Questions Asked in HCL | HCL Interview Questions | 20
Most Important SQL Interview Questions for HCL

Oracle Partitioning | Table Partitioning in Oracle | Partitioning in


SQL | How Partitioning helps improving Performance | Table
Partitioning with Examples | Partitioning on existing table

SQL Constraints | Constraints in SQL | Primary Key in SQL |


Foreign Key in SQL | Check Constraints in SQL | Null Value

Oracle System tables | Find Table | Find Constraint | Find User |


Find Index | Oracle system tables list | Important Oracle System
Tables | Useful Oracle System tables

OBIEE

Leave a Reply
Your email address will not be published.

http://www.complexsql.com/indexing-in-sql/ 14/15
8/11/2017 SQL Indexes | Performance Tuning | Normal Index | Unique Index | Bitmap Index | Global Index | Local Index

Comment

Name *

Email *

Website

POST COMMENT

Notify me of follow-up comments by email.

Notify me of new posts by email.

Copyright 2017 | WordPress Theme by MH Themes

http://www.complexsql.com/indexing-in-sql/ 15/15

You might also like