SQL Performance Tuning
SQL Performance Tuning
- Narendar V
Submitted to
4iapps.com
Agenda
SQL TUNING..………….
………………………………………………………………………………………………………... 3
WHEN TO TUNE?
………………………………………………………………………………………………………………
.4
OPTIMIZER…….….....................................................................................................
……………………….......... 6
TECHNIQUES……………………………................................................
………………………………………….………9
• When the SQL Code take so much time to retrieve data from database.
4iapps.com 4
How is an SQL Statement Processed ?
4iapps.com 5
Optimizer
4iapps.com 6
Explain and Execution Plan.
select * from
To view the Explained plan:
table(dbms_xplan.display);
• Execution Plan shows the detailed steps necessary to execute a SQL
Statement.
4iapps.com 7
Cardinality and Cost.
• Cost is the estimates amount of work the plan will do. It calculates the
usage of disk I/O , CPU,
Memory usage.
4iapps.com 8
Techniques used to optimize SQL queries.
1. SELECT Fields instead of using SELECT *.
4iapps.com 9
Index
• Index provide quick access to rows in a table.
• It increase the speed of queries.
Index Type
• B-Tree Index
I. Normal Index
II. Composite Index
III. Function-Based Index
Syntax:
create index <index_name> on <table_name> (column_name);
4iapps.com 10
How to Perform Indexing
• We can perform indexing by using an indexed column in where clause.
4iapps.com 11
Create a Composite Index.
• If the query of cost is high on a specific table and it has two or three
columns used in joins. We need to create a one composite index for those
three columns.
Syntax:
create index <index_name> on <table_name> (column1, column2,
column3, column4) nologging;
Optimizer Hints
Optimizer Hints
Optimizer Hints Optimizer Hints Types
EIPL
4iapps.com 12
View Usage
• Do not use the views out of their purpose, which means a complex view.
• Don’t join the complex view with table or another views.
• Avoid using views inside of views.
• You can create a new view and use of it.
Materialized Views
• In Oracle 12.1, you can create a materialized view as below.
Create or Replace Materialized View view_name_mv As select column
from table;
• But In 12.2, you want to create as in below document.
Create
Materialized View R12.2
4iapps.com 13
REFERENCES
https://docs.oracle.com/database/121/TGSQL/tgsql_intro.htm#TGSQL118
https://www.geeksforgeeks.org/sql-performance-tuning/
https://docs.oracle.com/en/database/oracle/oracle-database/21/tgsql/sql-tunin
g-guide.pdf
4iapps.com 14
THANK YOU
4iapps.com 15
Contact us
Sharjah
Po Box No: 42693
Hamriyah Free
Zone, Sharjah
Tel +971 52 998
9126
4iapps.com
4iapps.com 16