SlideShare una empresa de Scribd logo
1 de 6
Descargar para leer sin conexión
Healthy Code May 201420
Article
INDEX!=
Healthy CodeMay 2014 21
= FASTER ACCESS
Ankit Kumar Katiyar & N.S.Sekar
O
ne of the frequently encountered solutions
that application developers are offered, while
dealing with performance issues with the
oracle database is: “create an index on that column”.
This may enhance the performance in some cases if
you know your index well enough. However this can
actually degrade or not have any significant impact
on the SQL performance in the application at all.
Therefore it’s important to be aware of the behavior
of index if you want to leverage its true potential. We
have identified a bunch of issues while working with
index in Oracle and discussed them in this article.
Here’s a list of concerns raised by developers and our
response to them.
Concern #1:
I have created an appropriate index on particular
column. But why is the query engine not picking up
the index?
This may happen due to bad or incomplete statistics.
In the absence of statistics, the optimizer (Cost based
optimization) may choose a full table scan (FTS) as
compared to indexed access.
Recommendations:
Prior to testing queries, just make sure you re-analyze
the table and index with dbms_stats. This provides
the optimizer with good metadata.
You can use the following queries to check the last
analyzed status.
You can use the following queries to execute the dms_
stats procedure to analyze objects.
Concern #2:
I have created an appropriate index on a particular
column and I have also verified the earlier step
discussed in Concern#1. I still see that oracle is not
using that index.
This may happen if the number of rows in that table
is less or your query is returning almost all the data
in a table.
Recommendations:
If table is small that it can be read in a single I/O call,
then a full table scan of table might be cheaper than
an index range scan. Single I/O call can be defined by
Healthy Code May 201422
DB_FILE_MULTIBLOCK_READ_COUNT parameter
and value defined by blocks.
If your query is returning the majority of the data in a
table, then a full table scan is probably going to be the
most efficient way to access the table and optimizer
may choose to decide that it would be more efficient
not to use the index.
Concern #3:
I have created proper B-Tree Index on the particular
column and have also analyzed the table and index.
I still don’t find oracle using that index.
Oracle B-TREE Indexes can surely help in improving
the query performance provided there is optimal
selectivity on that column. The ratio of the number
of distinct values in the indexed column/columns
to the number of records in the table represents the
selectivity of an index. Ideal selectivity is 1 in case of
primary key and unique key.
While optimizing, oracle takes a decision of choosing
an index based on I/O. As discussed earlier, if the
query is returning the majority of the data in a table,
then a full table scan is probably going to be the most
efficient way to access the table.
Recommendations:
We should create indexes on tables that are
often queried for less than 15% of the table’s rows.
This value may be higher in situations where all
data can be retrieved from an index, or where the
indexed columns can be used for joining to other
tables.
Please check if you have right index on that
column. In other words, in oracle while standard
B-tree indexes are most effective for columns
containing a high number of different values
(good selectivity), bitmapped indexes are most
appropriate for columns with a limited number
(poor selectivity) of possible values.
In general, B-tree indices are good for OLTP
and Bitmapped indices are good for OLAP systems.
Factor in your usage, prior to creating the index.
Concern #4:
I have a query
Healthy CodeMay 2014 23
The query engine is still not using the index.
If you are using the SQL “like” clause then it can
be tricky because the wildcard “%” operator can
invalidate the index.
Recommendations:
STRING% will do INDEX RANGE SCAN
data because optimizer knows where the string
gets started.
% STRING will do the INDEX FULL table
because LIKE expression that starts with a
wildcard.
%STRING% will perform the FULL table scan
because optimizer doesn’t know from which letter
the String get started.
Concern #5:
I have a query,
I also have a proper index on id column. Why is the
query engine still not using the index?
If you have got a WHERE clause which contains
something like “id is null” then query engine will
always perform the full-table scan because NULL
values cannot be indexed. If you have no choice, but to
have this condition in your query, consider replacing
it with a NVL function.
Recommendations:
If you have a null in your where clause you may
have to keep the following in mind:
When you have “IS NOT NULL” type
WHERE clause will use an index
When you have “IS NULL” type WHERE
doesn’t use an index
Concern #6:
I have a query,
I have proper index on name column then why is the
query engine not utilizing an index?
Healthy Code May 201424
Even though the name column has an index, the upper
functions will invalidate the index and WHERE clause
predicates might invoke FTS (unnecessary I/O).
Recommendations:
In such cases, use Function-Based index on that
column. Function-Based indexes give the ability to
index computed columns and use theses indexes in a
query as shown here.
Concern #7:
I have created a Function-based index on a table
column, yet when I check my execution plan, the
optimizer ignores the Function-based index?
Typically, function-based indexes or any index
are ignored when analyze the index has not been
performed.
Recommendations:
After creating a function-based index, don’t forget to
re-gather table statistics and get extended statistics on
the function.
Concern #8:
I have a query,
I have a proper index on these columns but no use
of the index.
This may happen if you are performing mathematical
operations on the indexed column then oracle will
invalidate the index and will go for the full table scan.
Concern #9:
I have a following query
In this case name column is indexed but oracle is not
using an index. Why?
When an indexed column appears on both sides of an
operator, the index for that column is disabled.
Recommendations:
You can rewrite the above-mentioned query as
Concern #10:
I have following query
Inspite of having a proper index on these columns
why doesn’t oracle use it?
If we use the NOT EXISTS then nested index scans
will be used in the sub query for each row in the
DEPARTMENT table. The only records that will be
returned from DEPARTMENT are those that return
no rows from the sub query, and no full table scans
are performed by the sub query.
Recommendations:
The following query statement is more efficient.
department.department_id=employee.
department_id)
Concern #11:
In my query, I have an index on a DATE column
but oracle is not using index if I fetch results using
JDBC driver?
This might happen due to data type conversion
between Date and TimeStamp. Developers, typically
use the setTimestamp method in order to set time.
When this is done, the index on the DATE column
will not be used. This is because, oracle internally
converts/casts datatypes (of date to timestamp) .
Recommendations:
You can address this problem with the following:
Healthy CodeMay 2014 25
Concern #12:
In spite of having index on “first_name” and “last_
name” columns the query
“
takes much longer than expected.
The use of ‘OR’ statements confuses the optimizer
(Cost Based Optimizer). It will rarely choose to use an
index on column referenced using an OR statement.
Recommendations:
You can work around this issue by using UNION
ALL as shown here.
Concern #13:
I have created composite index on the column but
how does it work with my query?
A composite index contains more than one key
column. Composite indexes can provide additional
advantages over single column indexes. Consider
creating a composite index on columns that are
frequently used together in WHERE clause conditions
combined with AND operators, especially if their
combined selectivity is better than the selectivity
of either column individually. Even If you do not
include the first column of a concatenated index in the
WHERE clause of your statement then also Index Skip
Scanning will be used.
Summary
This article was just a brief overview at database
indexing with some light on b-tree index, bitmap
indexes, function-based indexes, and composite
indexes. Index efficiency is hard and finding
appropriate index even harder. We hope that these
tips when used appropriately may help you debug
performance issues, even after you have created the
index on the relevant columns.
In general, when things are really slow due to a SQL
statement, in your application, use the EXPLAIN
PLAN to look at the execution plan of the statement.
Following this, make the changes in your SQL based
on cost estimation.
Remember that “FULL TABLE SCANS ARE NOT
ALWAYS BAD” and “SQL INDEX != FASTER
ACCESS” in all scenarios.
Happy indexing!!!
Ankit Kumar is currently serving Successfactors
(SAP Cloud) as a Principal Engineer. His work is
with the Employee Central (EC) product wherein
his main focus is to make EC world’s most high-
performing, scalable, and blazing fast cloud
platform. Prior to this, he worked with Oracle
as a technology lead and Hewlett Packard (HP)
as a software analyst. He holds a patent and
disclosure in database and network technologies,
respectively.
NS Sekar
Sekar is Vice President of Engineering at Success
Factors. He has previously worked as Director
at Yahoo and Informatica. He is a seasoned tech-
nology and product development executive with
experience in building and scaling distributed en-
gineering and product teams from multiple ear-
ly-stage startups to the next level. His expertise
includes Data Integration, Data Quality, Web Ana-
lytics, Internet Platforms, and SaaS
Ankit Kumar

Más contenido relacionado

La actualidad más candente

Excel.fns frmls
Excel.fns frmlsExcel.fns frmls
Excel.fns frmlsrowenick
 
Elementary Data Analysis with MS Excel_Day-4
Elementary Data Analysis with MS Excel_Day-4Elementary Data Analysis with MS Excel_Day-4
Elementary Data Analysis with MS Excel_Day-4Redwan Ferdous
 
User hook implemantation sample example
User hook implemantation  sample exampleUser hook implemantation  sample example
User hook implemantation sample exampleAshish Harbhajanka
 
Using Excel Functions
Using Excel FunctionsUsing Excel Functions
Using Excel FunctionsGautam Gupta
 
10 Excel Formulas that will help you in any Job
10 Excel Formulas that will help you in any Job10 Excel Formulas that will help you in any Job
10 Excel Formulas that will help you in any JobHitesh Biyani
 
Excel Master Class
Excel Master ClassExcel Master Class
Excel Master Classbwymer
 
Understanding excel’s error values
Understanding excel’s error valuesUnderstanding excel’s error values
Understanding excel’s error valuesVijay Perepa
 

La actualidad más candente (13)

Excel.fns frmls
Excel.fns frmlsExcel.fns frmls
Excel.fns frmls
 
Elementary Data Analysis with MS Excel_Day-4
Elementary Data Analysis with MS Excel_Day-4Elementary Data Analysis with MS Excel_Day-4
Elementary Data Analysis with MS Excel_Day-4
 
Excel 2007 Unit B
Excel 2007 Unit BExcel 2007 Unit B
Excel 2007 Unit B
 
Django orm-tips
Django orm-tipsDjango orm-tips
Django orm-tips
 
Sql Server 2014 Course Content
Sql Server 2014 Course ContentSql Server 2014 Course Content
Sql Server 2014 Course Content
 
Excel 2007 Unit B
Excel 2007 Unit BExcel 2007 Unit B
Excel 2007 Unit B
 
Oracle SQL Part 2
Oracle SQL Part 2Oracle SQL Part 2
Oracle SQL Part 2
 
User hook implemantation sample example
User hook implemantation  sample exampleUser hook implemantation  sample example
User hook implemantation sample example
 
Module08
Module08Module08
Module08
 
Using Excel Functions
Using Excel FunctionsUsing Excel Functions
Using Excel Functions
 
10 Excel Formulas that will help you in any Job
10 Excel Formulas that will help you in any Job10 Excel Formulas that will help you in any Job
10 Excel Formulas that will help you in any Job
 
Excel Master Class
Excel Master ClassExcel Master Class
Excel Master Class
 
Understanding excel’s error values
Understanding excel’s error valuesUnderstanding excel’s error values
Understanding excel’s error values
 

Destacado

Database Architecture & Scaling Strategies, in the Cloud & on the Rack
Database Architecture & Scaling Strategies, in the Cloud & on the Rack Database Architecture & Scaling Strategies, in the Cloud & on the Rack
Database Architecture & Scaling Strategies, in the Cloud & on the Rack Clustrix
 
Why Traditional Databases Fail so Miserably to Scale with E-Commerce Site Growth
Why Traditional Databases Fail so Miserably to Scale with E-Commerce Site GrowthWhy Traditional Databases Fail so Miserably to Scale with E-Commerce Site Growth
Why Traditional Databases Fail so Miserably to Scale with E-Commerce Site GrowthClustrix
 
Clustrix Database Percona Ruby on Rails benchmark
Clustrix Database Percona Ruby on Rails benchmarkClustrix Database Percona Ruby on Rails benchmark
Clustrix Database Percona Ruby on Rails benchmarkClustrix
 
E-Commerce Success is a Balancing Act. Ensure Success with ClustrixDB.
E-Commerce Success is a Balancing Act. Ensure Success with ClustrixDB.E-Commerce Success is a Balancing Act. Ensure Success with ClustrixDB.
E-Commerce Success is a Balancing Act. Ensure Success with ClustrixDB.Clustrix
 
Moving an E-commerce Site to AWS. A Case Study
Moving an  E-commerce Site to AWS. A Case StudyMoving an  E-commerce Site to AWS. A Case Study
Moving an E-commerce Site to AWS. A Case StudyClustrix
 
ClustrixDB 7.5 Announcement
ClustrixDB 7.5 AnnouncementClustrixDB 7.5 Announcement
ClustrixDB 7.5 AnnouncementClustrix
 
Clustrix Database Overview
Clustrix Database OverviewClustrix Database Overview
Clustrix Database OverviewClustrix
 
Achieve new levels of performance for Magento e-commerce sites.
Achieve new levels of performance for Magento e-commerce sites.Achieve new levels of performance for Magento e-commerce sites.
Achieve new levels of performance for Magento e-commerce sites.Clustrix
 
Scaling Techniques to Increase Magento Capacity
Scaling Techniques to Increase Magento CapacityScaling Techniques to Increase Magento Capacity
Scaling Techniques to Increase Magento CapacityClustrix
 
Database index by Reema Gajjar
Database index by Reema GajjarDatabase index by Reema Gajjar
Database index by Reema GajjarReema Gajjar
 
Database index
Database indexDatabase index
Database indexRiteshkiit
 
Presto: Distributed sql query engine
Presto: Distributed sql query engine Presto: Distributed sql query engine
Presto: Distributed sql query engine kiran palaka
 
Data indexing presentation
Data indexing presentationData indexing presentation
Data indexing presentationgmbmanikandan
 
Introduction to InfluxDB, an Open Source Distributed Time Series Database by ...
Introduction to InfluxDB, an Open Source Distributed Time Series Database by ...Introduction to InfluxDB, an Open Source Distributed Time Series Database by ...
Introduction to InfluxDB, an Open Source Distributed Time Series Database by ...Hakka Labs
 
Scaling Pinterest
Scaling PinterestScaling Pinterest
Scaling PinterestC4Media
 

Destacado (18)

Database Architecture & Scaling Strategies, in the Cloud & on the Rack
Database Architecture & Scaling Strategies, in the Cloud & on the Rack Database Architecture & Scaling Strategies, in the Cloud & on the Rack
Database Architecture & Scaling Strategies, in the Cloud & on the Rack
 
Datadog at NYCBUG
Datadog at NYCBUGDatadog at NYCBUG
Datadog at NYCBUG
 
Why Traditional Databases Fail so Miserably to Scale with E-Commerce Site Growth
Why Traditional Databases Fail so Miserably to Scale with E-Commerce Site GrowthWhy Traditional Databases Fail so Miserably to Scale with E-Commerce Site Growth
Why Traditional Databases Fail so Miserably to Scale with E-Commerce Site Growth
 
Clustrix Database Percona Ruby on Rails benchmark
Clustrix Database Percona Ruby on Rails benchmarkClustrix Database Percona Ruby on Rails benchmark
Clustrix Database Percona Ruby on Rails benchmark
 
E-Commerce Success is a Balancing Act. Ensure Success with ClustrixDB.
E-Commerce Success is a Balancing Act. Ensure Success with ClustrixDB.E-Commerce Success is a Balancing Act. Ensure Success with ClustrixDB.
E-Commerce Success is a Balancing Act. Ensure Success with ClustrixDB.
 
Moving an E-commerce Site to AWS. A Case Study
Moving an  E-commerce Site to AWS. A Case StudyMoving an  E-commerce Site to AWS. A Case Study
Moving an E-commerce Site to AWS. A Case Study
 
ClustrixDB 7.5 Announcement
ClustrixDB 7.5 AnnouncementClustrixDB 7.5 Announcement
ClustrixDB 7.5 Announcement
 
Clustrix Database Overview
Clustrix Database OverviewClustrix Database Overview
Clustrix Database Overview
 
Achieve new levels of performance for Magento e-commerce sites.
Achieve new levels of performance for Magento e-commerce sites.Achieve new levels of performance for Magento e-commerce sites.
Achieve new levels of performance for Magento e-commerce sites.
 
Scaling Techniques to Increase Magento Capacity
Scaling Techniques to Increase Magento CapacityScaling Techniques to Increase Magento Capacity
Scaling Techniques to Increase Magento Capacity
 
Database index by Reema Gajjar
Database index by Reema GajjarDatabase index by Reema Gajjar
Database index by Reema Gajjar
 
Clusterix at VDS 2016
Clusterix at VDS 2016Clusterix at VDS 2016
Clusterix at VDS 2016
 
Database index
Database indexDatabase index
Database index
 
Presto: Distributed sql query engine
Presto: Distributed sql query engine Presto: Distributed sql query engine
Presto: Distributed sql query engine
 
Data indexing presentation
Data indexing presentationData indexing presentation
Data indexing presentation
 
Introduction to InfluxDB, an Open Source Distributed Time Series Database by ...
Introduction to InfluxDB, an Open Source Distributed Time Series Database by ...Introduction to InfluxDB, an Open Source Distributed Time Series Database by ...
Introduction to InfluxDB, an Open Source Distributed Time Series Database by ...
 
Scaling Pinterest
Scaling PinterestScaling Pinterest
Scaling Pinterest
 
Scalability Design Principles - Internal Session
Scalability Design Principles - Internal SessionScalability Design Principles - Internal Session
Scalability Design Principles - Internal Session
 

Similar a Db performance optimization with indexing

Filtered Indexes In Sql 2008
Filtered Indexes In Sql 2008Filtered Indexes In Sql 2008
Filtered Indexes In Sql 2008wharrislv
 
dotnetMALAGA - Sql query tuning guidelines
dotnetMALAGA - Sql query tuning guidelinesdotnetMALAGA - Sql query tuning guidelines
dotnetMALAGA - Sql query tuning guidelinesJavier García Magna
 
Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09guest9d79e073
 
Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09Mark Ginnebaugh
 
Application sql issues_and_tuning
Application sql issues_and_tuningApplication sql issues_and_tuning
Application sql issues_and_tuningAnil Pandey
 
Oracle Sql Tuning
Oracle Sql TuningOracle Sql Tuning
Oracle Sql TuningChris Adkin
 
Optimized cluster index generation
Optimized cluster index generationOptimized cluster index generation
Optimized cluster index generationRutvik Pensionwar
 
Db2 sql tuning and bmc catalog manager
Db2 sql tuning and bmc catalog manager Db2 sql tuning and bmc catalog manager
Db2 sql tuning and bmc catalog manager Krishan Singh
 
Query Optimization in SQL Server
Query Optimization in SQL ServerQuery Optimization in SQL Server
Query Optimization in SQL ServerRajesh Gunasundaram
 
8 i index_tables
8 i index_tables8 i index_tables
8 i index_tablesAnil Pandey
 
Oracle DB Performance Tuning Tips
Oracle DB Performance Tuning TipsOracle DB Performance Tuning Tips
Oracle DB Performance Tuning TipsAsanka Dilruk
 
Advanced MySQL Query Optimizations
Advanced MySQL Query OptimizationsAdvanced MySQL Query Optimizations
Advanced MySQL Query OptimizationsDave Stokes
 
Guide To Mastering The MySQL Query Execution Plan
Guide To Mastering The MySQL Query Execution PlanGuide To Mastering The MySQL Query Execution Plan
Guide To Mastering The MySQL Query Execution PlanOptimiz DBA
 
Sql scripting sorcerypaper
Sql scripting sorcerypaperSql scripting sorcerypaper
Sql scripting sorcerypaperoracle documents
 
PHP UK 2020 Tutorial: MySQL Indexes, Histograms And other ways To Speed Up Yo...
PHP UK 2020 Tutorial: MySQL Indexes, Histograms And other ways To Speed Up Yo...PHP UK 2020 Tutorial: MySQL Indexes, Histograms And other ways To Speed Up Yo...
PHP UK 2020 Tutorial: MySQL Indexes, Histograms And other ways To Speed Up Yo...Dave Stokes
 
Myth busters - performance tuning 102 2008
Myth busters - performance tuning 102 2008Myth busters - performance tuning 102 2008
Myth busters - performance tuning 102 2008paulguerin
 
How to Think Like the SQL Server Engine
How to Think Like the SQL Server EngineHow to Think Like the SQL Server Engine
How to Think Like the SQL Server EngineBrent Ozar
 
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-dbuncleRhyme
 
SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343
SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343
SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343Edgar Alejandro Villegas
 

Similar a Db performance optimization with indexing (20)

Filtered Indexes In Sql 2008
Filtered Indexes In Sql 2008Filtered Indexes In Sql 2008
Filtered Indexes In Sql 2008
 
dotnetMALAGA - Sql query tuning guidelines
dotnetMALAGA - Sql query tuning guidelinesdotnetMALAGA - Sql query tuning guidelines
dotnetMALAGA - Sql query tuning guidelines
 
Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09
 
Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09
 
Application sql issues_and_tuning
Application sql issues_and_tuningApplication sql issues_and_tuning
Application sql issues_and_tuning
 
Oracle Sql Tuning
Oracle Sql TuningOracle Sql Tuning
Oracle Sql Tuning
 
Optimized cluster index generation
Optimized cluster index generationOptimized cluster index generation
Optimized cluster index generation
 
Db2 sql tuning and bmc catalog manager
Db2 sql tuning and bmc catalog manager Db2 sql tuning and bmc catalog manager
Db2 sql tuning and bmc catalog manager
 
Teradata sql-tuning-top-10
Teradata sql-tuning-top-10Teradata sql-tuning-top-10
Teradata sql-tuning-top-10
 
Query Optimization in SQL Server
Query Optimization in SQL ServerQuery Optimization in SQL Server
Query Optimization in SQL Server
 
8 i index_tables
8 i index_tables8 i index_tables
8 i index_tables
 
Oracle DB Performance Tuning Tips
Oracle DB Performance Tuning TipsOracle DB Performance Tuning Tips
Oracle DB Performance Tuning Tips
 
Advanced MySQL Query Optimizations
Advanced MySQL Query OptimizationsAdvanced MySQL Query Optimizations
Advanced MySQL Query Optimizations
 
Guide To Mastering The MySQL Query Execution Plan
Guide To Mastering The MySQL Query Execution PlanGuide To Mastering The MySQL Query Execution Plan
Guide To Mastering The MySQL Query Execution Plan
 
Sql scripting sorcerypaper
Sql scripting sorcerypaperSql scripting sorcerypaper
Sql scripting sorcerypaper
 
PHP UK 2020 Tutorial: MySQL Indexes, Histograms And other ways To Speed Up Yo...
PHP UK 2020 Tutorial: MySQL Indexes, Histograms And other ways To Speed Up Yo...PHP UK 2020 Tutorial: MySQL Indexes, Histograms And other ways To Speed Up Yo...
PHP UK 2020 Tutorial: MySQL Indexes, Histograms And other ways To Speed Up Yo...
 
Myth busters - performance tuning 102 2008
Myth busters - performance tuning 102 2008Myth busters - performance tuning 102 2008
Myth busters - performance tuning 102 2008
 
How to Think Like the SQL Server Engine
How to Think Like the SQL Server EngineHow to Think Like the SQL Server Engine
How to Think Like the SQL Server Engine
 
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 – The Natural Language for Analysis - Oracle - Whitepaper - 2431343
SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343
SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343
 

Más de Rajeev Kumar

Más de Rajeev Kumar (9)

Javasession10
Javasession10Javasession10
Javasession10
 
Jms intro
Jms introJms intro
Jms intro
 
Javasession8
Javasession8Javasession8
Javasession8
 
Javasession6
Javasession6Javasession6
Javasession6
 
Javasession7
Javasession7Javasession7
Javasession7
 
Javasession5
Javasession5Javasession5
Javasession5
 
Javasession4
Javasession4Javasession4
Javasession4
 
Java session 3
Java session 3Java session 3
Java session 3
 
Java session2
Java session2Java session2
Java session2
 

Último

Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.MateoGardella
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 

Último (20)

Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 

Db performance optimization with indexing

  • 1. Healthy Code May 201420 Article INDEX!=
  • 2. Healthy CodeMay 2014 21 = FASTER ACCESS Ankit Kumar Katiyar & N.S.Sekar O ne of the frequently encountered solutions that application developers are offered, while dealing with performance issues with the oracle database is: “create an index on that column”. This may enhance the performance in some cases if you know your index well enough. However this can actually degrade or not have any significant impact on the SQL performance in the application at all. Therefore it’s important to be aware of the behavior of index if you want to leverage its true potential. We have identified a bunch of issues while working with index in Oracle and discussed them in this article. Here’s a list of concerns raised by developers and our response to them. Concern #1: I have created an appropriate index on particular column. But why is the query engine not picking up the index? This may happen due to bad or incomplete statistics. In the absence of statistics, the optimizer (Cost based optimization) may choose a full table scan (FTS) as compared to indexed access. Recommendations: Prior to testing queries, just make sure you re-analyze the table and index with dbms_stats. This provides the optimizer with good metadata. You can use the following queries to check the last analyzed status. You can use the following queries to execute the dms_ stats procedure to analyze objects. Concern #2: I have created an appropriate index on a particular column and I have also verified the earlier step discussed in Concern#1. I still see that oracle is not using that index. This may happen if the number of rows in that table is less or your query is returning almost all the data in a table. Recommendations: If table is small that it can be read in a single I/O call, then a full table scan of table might be cheaper than an index range scan. Single I/O call can be defined by
  • 3. Healthy Code May 201422 DB_FILE_MULTIBLOCK_READ_COUNT parameter and value defined by blocks. If your query is returning the majority of the data in a table, then a full table scan is probably going to be the most efficient way to access the table and optimizer may choose to decide that it would be more efficient not to use the index. Concern #3: I have created proper B-Tree Index on the particular column and have also analyzed the table and index. I still don’t find oracle using that index. Oracle B-TREE Indexes can surely help in improving the query performance provided there is optimal selectivity on that column. The ratio of the number of distinct values in the indexed column/columns to the number of records in the table represents the selectivity of an index. Ideal selectivity is 1 in case of primary key and unique key. While optimizing, oracle takes a decision of choosing an index based on I/O. As discussed earlier, if the query is returning the majority of the data in a table, then a full table scan is probably going to be the most efficient way to access the table. Recommendations: We should create indexes on tables that are often queried for less than 15% of the table’s rows. This value may be higher in situations where all data can be retrieved from an index, or where the indexed columns can be used for joining to other tables. Please check if you have right index on that column. In other words, in oracle while standard B-tree indexes are most effective for columns containing a high number of different values (good selectivity), bitmapped indexes are most appropriate for columns with a limited number (poor selectivity) of possible values. In general, B-tree indices are good for OLTP and Bitmapped indices are good for OLAP systems. Factor in your usage, prior to creating the index. Concern #4: I have a query
  • 4. Healthy CodeMay 2014 23 The query engine is still not using the index. If you are using the SQL “like” clause then it can be tricky because the wildcard “%” operator can invalidate the index. Recommendations: STRING% will do INDEX RANGE SCAN data because optimizer knows where the string gets started. % STRING will do the INDEX FULL table because LIKE expression that starts with a wildcard. %STRING% will perform the FULL table scan because optimizer doesn’t know from which letter the String get started. Concern #5: I have a query, I also have a proper index on id column. Why is the query engine still not using the index? If you have got a WHERE clause which contains something like “id is null” then query engine will always perform the full-table scan because NULL values cannot be indexed. If you have no choice, but to have this condition in your query, consider replacing it with a NVL function. Recommendations: If you have a null in your where clause you may have to keep the following in mind: When you have “IS NOT NULL” type WHERE clause will use an index When you have “IS NULL” type WHERE doesn’t use an index Concern #6: I have a query, I have proper index on name column then why is the query engine not utilizing an index?
  • 5. Healthy Code May 201424 Even though the name column has an index, the upper functions will invalidate the index and WHERE clause predicates might invoke FTS (unnecessary I/O). Recommendations: In such cases, use Function-Based index on that column. Function-Based indexes give the ability to index computed columns and use theses indexes in a query as shown here. Concern #7: I have created a Function-based index on a table column, yet when I check my execution plan, the optimizer ignores the Function-based index? Typically, function-based indexes or any index are ignored when analyze the index has not been performed. Recommendations: After creating a function-based index, don’t forget to re-gather table statistics and get extended statistics on the function. Concern #8: I have a query, I have a proper index on these columns but no use of the index. This may happen if you are performing mathematical operations on the indexed column then oracle will invalidate the index and will go for the full table scan. Concern #9: I have a following query In this case name column is indexed but oracle is not using an index. Why? When an indexed column appears on both sides of an operator, the index for that column is disabled. Recommendations: You can rewrite the above-mentioned query as Concern #10: I have following query Inspite of having a proper index on these columns why doesn’t oracle use it? If we use the NOT EXISTS then nested index scans will be used in the sub query for each row in the DEPARTMENT table. The only records that will be returned from DEPARTMENT are those that return no rows from the sub query, and no full table scans are performed by the sub query. Recommendations: The following query statement is more efficient. department.department_id=employee. department_id) Concern #11: In my query, I have an index on a DATE column but oracle is not using index if I fetch results using JDBC driver? This might happen due to data type conversion between Date and TimeStamp. Developers, typically use the setTimestamp method in order to set time. When this is done, the index on the DATE column will not be used. This is because, oracle internally converts/casts datatypes (of date to timestamp) . Recommendations: You can address this problem with the following:
  • 6. Healthy CodeMay 2014 25 Concern #12: In spite of having index on “first_name” and “last_ name” columns the query “ takes much longer than expected. The use of ‘OR’ statements confuses the optimizer (Cost Based Optimizer). It will rarely choose to use an index on column referenced using an OR statement. Recommendations: You can work around this issue by using UNION ALL as shown here. Concern #13: I have created composite index on the column but how does it work with my query? A composite index contains more than one key column. Composite indexes can provide additional advantages over single column indexes. Consider creating a composite index on columns that are frequently used together in WHERE clause conditions combined with AND operators, especially if their combined selectivity is better than the selectivity of either column individually. Even If you do not include the first column of a concatenated index in the WHERE clause of your statement then also Index Skip Scanning will be used. Summary This article was just a brief overview at database indexing with some light on b-tree index, bitmap indexes, function-based indexes, and composite indexes. Index efficiency is hard and finding appropriate index even harder. We hope that these tips when used appropriately may help you debug performance issues, even after you have created the index on the relevant columns. In general, when things are really slow due to a SQL statement, in your application, use the EXPLAIN PLAN to look at the execution plan of the statement. Following this, make the changes in your SQL based on cost estimation. Remember that “FULL TABLE SCANS ARE NOT ALWAYS BAD” and “SQL INDEX != FASTER ACCESS” in all scenarios. Happy indexing!!! Ankit Kumar is currently serving Successfactors (SAP Cloud) as a Principal Engineer. His work is with the Employee Central (EC) product wherein his main focus is to make EC world’s most high- performing, scalable, and blazing fast cloud platform. Prior to this, he worked with Oracle as a technology lead and Hewlett Packard (HP) as a software analyst. He holds a patent and disclosure in database and network technologies, respectively. NS Sekar Sekar is Vice President of Engineering at Success Factors. He has previously worked as Director at Yahoo and Informatica. He is a seasoned tech- nology and product development executive with experience in building and scaling distributed en- gineering and product teams from multiple ear- ly-stage startups to the next level. His expertise includes Data Integration, Data Quality, Web Ana- lytics, Internet Platforms, and SaaS Ankit Kumar