SlideShare una empresa de Scribd logo
1 de 24
Performance Tuning
By
Ami Bhatt
What is performance Tuning?
Performance tuning is the improvement of
system performance. This is typically a
computer systems. The motivation for such
activity is called a performance problem, which
can be real or anticipated. Most systems will
respond to increased load with some degree of
decreasing performance.
Scope
●
SQL Tuning – Responsibility of the Developer
● Database Tuning – Responsibility of the
Database Administrator
●
●
System Tuning – Responsibility of the
System Administrator
●
● Network Tuning – Responsibility of the
Network / LAN / WAN Administrator.
SQL Tuning
1. Identifying high load or top SQL statements that
are responsible for a large share of the application
workload and system resources, by reviewing past
SQL execution history available in the system.
2. Verifying that the execution plans produced by the
query optimizer for these statements perform
reasonably.
3. Implementing corrective actions to generate
better execution plans for poorly performing SQL
statements.
Goals For Tuning
● Reduce the Workload
●
This can be achieved by modifying the query and by
generating better execution plan.
●
Balance the Workload
● Systems often tend to have peak usage in the daytime
when real users are connected to the system, and low
usage in the nighttime. If you can schedule noncritical
reports and batch jobs to run in the nighttime and reduce
their concurrency during day time, then the database frees
up resources for the more critical programs in the day.
● Parallelize the Workload
When Oracle runs SQL statements in parallel, multiple
processes work together simultaneously to run a single SQL
statement.
Identifying High-Load SQL
● Is the problem specific to a single program
(or small number of programs)?
● Is the problem generic over the application?
Problem is specific to a single
program
Query for displaying sessions, session state
and events
select sid, decode(state, 'WAITING','Waiting','Working')
state from v$session where username = 'ARUP';
SID STATE
——— ——————
2832 Working
3346 Waiting
Getting the SQL
select sql_id from v$session
where sid = 3089;
SQL_ID
—————————————————
g0uubmuvk4uax
select sql_fulltext
from v$sql
where sql_id = 'g0uubmuvk4uax';
SQL_FULLTEXT
—————————————————
update t1 set col2 = 'y' where col1 = 1
S
Problem is generic over the
application
SQL*Trace/Oracle Trace/Database Trace
Alter session set sql_trace = true
In PL*SQL
execute immediate 'Alter session set sql_trace = true';
●
It will generate TK*Prof
TK*ProfTK*Prof
TK*Prof is an Oracle tool used to display the statistics
generated during a trace. When an Oracle session is traced (by
SQL*Trace, Oracle Trace, or Database Trace), a trace file is
generated. This trace file is barely human-readable; TK*Prof
collates and formats the data into a more meaningful form.
Location of TK*Prof
SELECT value
FROM sys.v_$parameter
WHERE name = 'user_dump_dest'
Running TK*Prof
tkprof trace_file output_file
[ explain=userid/password@database ]
TK*Prof output
-High volume Sql, Low volume Sql,Execution Plan
Show the TK*Prof output to the DBA to see if the database can
be tuned
Quick Tips for Oracle SQL Query WritingQuick Tips for Oracle SQL Query Writing
Use of EXISTS versus IN for Subqueries
Example 1: Using IN - Selective Filters in the
Subquery
SELECT e.employee_id, e.first_name, e.last_name, e.salary
FROM employees e
WHERE EXISTS (SELECT 1
FROM orders o
WHERE e.employee_id = o.sales_rep_id
AND o.customer_id = 144);
Rewritting USING IN:
SELECT /* IN example */
e.employee_id, e.first_name, e.last_name, e.salary
FROM employees e
WHERE e.employee_id IN (SELECT o.sales_rep_id /* Note 4 */
FROM orders o
WHERE o.customer_id = 144); /* Note 3 */
Quick Tips for Oracle SQL Query WritingQuick Tips for Oracle SQL Query Writing
Example 2: Using IN - Selective Predicate in the
Parent
SELECT /* IN example */
e.employee_id, e.first_name, e.last_name, e.department_id,
e.salary
FROM employees e
WHERE e.department_id = 80
AND e.job_id = 'SA_REP'
AND e.employee_id IN (SELECT o.sales_rep_id FROM orders o);
Rewritting USING EXISTS:
SELECT /* EXISTS example */
e.employee_id, e.first_name, e.last_name, e.salary
FROM employees e
WHERE e.department_id = 80
AND e.job_id = 'SA_REP'
AND EXISTS (SELECT 1
FROM orders o
WHERE e.employee_id = o.sales_rep_id);
Quick Tips for Oracle SQL Query WritingQuick Tips for Oracle SQL Query Writing
Do use temp tables to improve cursor performance
●
Cursors not only suffer from speed problems, which in itself can
be an issue with many operations, but they can also cause your
operation to block other operations for a lot longer than is
necessary. This greatly decreases concurrency in your system.
● We may be able to get away from cursor-induced performance
issues by doing the cursor operations against a temp table
instead.For Example,
●
A cursor that goes through a table and updates a couple of
columns based on some comparison results. Instead of doing the
comparison against the live table, you may be able to put that
data into a temp table and do the comparison against that
instead. Then you have a single UPDATE statement against the live
table that’s much smaller and holds locks only for a short time.
Quick Tips for Oracle SQL Query WritingQuick Tips for Oracle SQL Query Writing
Don’t nest views
When you have views that call views that call
views that call views. This is called nesting views
and it can cause severe performance issues,
particularly in two ways. First, you will very likely
have much more data coming back than you need.
Second, the query optimizer will give up and return a
bad query plan.
Quick Tips for Oracle SQL Query WritingQuick Tips for Oracle SQL Query Writing
Don’t do large ops on many tables in the
same batch
●
A delete routine that ran several times a day was deleting
data out of 14 tables in an explicit transaction. Handling
all 14 tables in one transaction meant that the locks were
held on every single table until all of the deletes were
finished. The solution was to break up each table's deletes
into separate transactions so that each delete transaction
held locks on only one table. This freed up the other
tables and reduced the blocking and allowed other
operations to continue working. You always want to split
up large transactions like this into separate smaller ones
to prevent blocking.
Quick Tips for Oracle SQL Query WritingQuick Tips for Oracle SQL Query Writing
Don't use triggers
● Whatever it is you want them to do will be done in
the same transaction as the original operation. If
you write a trigger to insert data into another table
when you update a row in the Orders table, the lock
will be held on both tables until the trigger is done.
If you need to insert data into another table after
the update, then put the update and the insert into
a stored procedure and do them in separate
transactions.
Quick Tips for Oracle SQL Query WritingQuick Tips for Oracle SQL Query Writing
Don’t count all rows if you only need to see
if data exists
To check for the existence of that data:
(SELECT COUNT(*) into v_cnt FROM table_name;
If v_cnt > 0
BEGIN
<Do something>
END
/
It’s completely unnecessary.
If EXISTS (SELECT 1 FROM table_name)
BEGIN
<Do something>
END
Quick Tips for Oracle SQL Query WritingQuick Tips for Oracle SQL Query Writing
Try to use UNION ALL in place of UNION
The UNION ALL statement is faster than UNION, because
UNION ALL statement does not consider duplicate s, and
UNION statement does look for duplicates in a table while
selection of rows, whether or not they exist.
Original query:
SELECT cust_id FROM SH.sales
UNION
SELECT cust_id FROM customers;
Improved query:
SELECT cust_id FROM SH.sales
UNION ALL
SELECT cust_id FROM customers;
Quick Tips for Oracle SQL Query WritingQuick Tips for Oracle SQL Query Writing
Use Column Names Instead of * in a SELECT
Statement
If you are selecting only a few columns from a table there is
no need to use SELECT *. Though this is easier to write, it
will cost more time for the database to complete the query.
By selecting only the columns you need, you are reducing
the size of the result table, reducing the network traffic and
also in turn boosting the overall performance of the query.
Original query:
SELECT * FROM SH.Sales;
Improved query:
SELECT s.prod_id FROM SH.sales s;
Quick Tips for Oracle SQL Query WritingQuick Tips for Oracle SQL Query Writing
Avoid including a HAVING clause in SELECT
statements
The HAVING clause is used to filter the rows after all the
rows are selected and it is used like a filter. It is quite
useless in a SELECT statement. It works by going through
the final result table of the query parsing out the rows that
don’t meet the HAVING condition.
Original query:
SELECT s.cust_id,count(s.cust_id) FROM SH.sales s
GROUP BY s.cust_id
HAVING s.cust_id != '1660' AND s.cust_id != '2';
Improved query:
SELECT s.cust_id,count(cust_id) FROM SH.sales s
WHERE s.cust_id != '1660'
AND s.cust_id !='2'
GROUP BY s.cust_id;
Quick Tips for Oracle SQL Query WritingQuick Tips for Oracle SQL Query Writing
Use EXISTS instead of DISTINCT when using
table joins that involves tables having one-to-
many relationships
The DISTINCT keyword works by selecting all the columns
in the table then parses out any duplicates.Instead, if you
use sub query with the EXISTS keyword, you can avoid
having to return an entire table.
Original query:
SELECT DISTINCT c.country_id, c.country_name
FROM SH.countries c,SH.customers e
WHERE e.country_id = c.country_id;
Improved query:
SELECT c.country_id, c.country_name
FROM SH.countries c
WHERE EXISTS (SELECT 'X' FROM SH.customers e
WHERE e.country_id = c.country_id);
Quick Tips for Oracle SQL Query WritingQuick Tips for Oracle SQL Query Writing
Remove any redundant mathematics
There will be times where you will be performing
mathematics within an SQL statement. They can be a drag
on the performance if written improperly. For each time the
query finds a row it will recalculate the math. So eliminating
any unnecessary math in the statement will make it perform
faster.
Original query:
SELECT *
FROM SH.sales s
WHERE s.cust_id + 10000 < 35000;
Improved query:
SELECT *
FROM SH.sales s
WHERE s.cust_id < 25000;
References:
https://docs.oracle.com/
http://www.dataintegration.ninja
http://www.orafaq.com
http://nikunjthaker.blogspot.in/
http://www.infoworld.com
http://stackoverflow.com/questions/64193
12/
Performance tuning

Más contenido relacionado

La actualidad más candente

Avoiding cursors with sql server 2005 tech republic
Avoiding cursors with sql server 2005   tech republicAvoiding cursors with sql server 2005   tech republic
Avoiding cursors with sql server 2005 tech republic
Kaing Menglieng
 
Myth busters - performance tuning 102 2008
Myth busters - performance tuning 102 2008Myth busters - performance tuning 102 2008
Myth busters - performance tuning 102 2008
paulguerin
 
Oracle Course
Oracle CourseOracle Course
Oracle Course
rspaike
 
View, Store Procedure & Function and Trigger in MySQL - Thaipt
View, Store Procedure & Function and Trigger in MySQL - ThaiptView, Store Procedure & Function and Trigger in MySQL - Thaipt
View, Store Procedure & Function and Trigger in MySQL - Thaipt
Framgia Vietnam
 

La actualidad más candente (20)

Oracle SQL Advanced
Oracle SQL AdvancedOracle SQL Advanced
Oracle SQL Advanced
 
An Approach to Sql tuning - Part 1
An Approach to Sql tuning - Part 1An Approach to Sql tuning - Part 1
An Approach to Sql tuning - Part 1
 
Oracle Database 12c - Data Redaction
Oracle Database 12c - Data RedactionOracle Database 12c - Data Redaction
Oracle Database 12c - Data Redaction
 
Oracle Data Redaction
Oracle Data RedactionOracle Data Redaction
Oracle Data Redaction
 
Oracle Data Redaction
Oracle Data RedactionOracle Data Redaction
Oracle Data Redaction
 
Avoiding cursors with sql server 2005 tech republic
Avoiding cursors with sql server 2005   tech republicAvoiding cursors with sql server 2005   tech republic
Avoiding cursors with sql server 2005 tech republic
 
Myth busters - performance tuning 102 2008
Myth busters - performance tuning 102 2008Myth busters - performance tuning 102 2008
Myth busters - performance tuning 102 2008
 
Using AWR for SQL Analysis
Using AWR for SQL AnalysisUsing AWR for SQL Analysis
Using AWR for SQL Analysis
 
Oraclesql
OraclesqlOraclesql
Oraclesql
 
Awr report error
Awr report errorAwr report error
Awr report error
 
Oracle views
Oracle viewsOracle views
Oracle views
 
A New View of Database Views
A New View of Database ViewsA New View of Database Views
A New View of Database Views
 
Oracle Course
Oracle CourseOracle Course
Oracle Course
 
Controlling execution plans 2014
Controlling execution plans   2014Controlling execution plans   2014
Controlling execution plans 2014
 
View, Store Procedure & Function and Trigger in MySQL - Thaipt
View, Store Procedure & Function and Trigger in MySQL - ThaiptView, Store Procedure & Function and Trigger in MySQL - Thaipt
View, Store Procedure & Function and Trigger in MySQL - Thaipt
 
Less08 Schema
Less08 SchemaLess08 Schema
Less08 Schema
 
MySql Triggers Tutorial - The Webs Academy
MySql Triggers Tutorial - The Webs AcademyMySql Triggers Tutorial - The Webs Academy
MySql Triggers Tutorial - The Webs Academy
 
Introduction to triggers
Introduction to triggersIntroduction to triggers
Introduction to triggers
 
DBA Commands and Concepts That Every Developer Should Know - Part 2
DBA Commands and Concepts That Every Developer Should Know - Part 2DBA Commands and Concepts That Every Developer Should Know - Part 2
DBA Commands and Concepts That Every Developer Should Know - Part 2
 
SQL subquery
SQL subquerySQL subquery
SQL subquery
 

Destacado

RÁ D I O S I E M E N S S R T I F
RÁ D I O  S I E M E N S  S R T  I FRÁ D I O  S I E M E N S  S R T  I F
RÁ D I O S I E M E N S S R T I F
Fxx
 

Destacado (20)

Carolannduffy revision power point
Carolannduffy revision power pointCarolannduffy revision power point
Carolannduffy revision power point
 
Smc050 - Crowdfunding, meer dan geld alleen
Smc050 - Crowdfunding, meer dan geld alleenSmc050 - Crowdfunding, meer dan geld alleen
Smc050 - Crowdfunding, meer dan geld alleen
 
Innovation, apps and the monetization hexagon, UX Sofia 2014
Innovation, apps and the monetization hexagon, UX Sofia 2014Innovation, apps and the monetization hexagon, UX Sofia 2014
Innovation, apps and the monetization hexagon, UX Sofia 2014
 
Linked inwhitepa
Linked inwhitepaLinked inwhitepa
Linked inwhitepa
 
Spanish omelette
Spanish omeletteSpanish omelette
Spanish omelette
 
Describing the Elephant: UX Cambridge 2014
Describing the Elephant: UX Cambridge 2014Describing the Elephant: UX Cambridge 2014
Describing the Elephant: UX Cambridge 2014
 
Crowdfunding - meer dan geld alleen - STIMA
Crowdfunding  - meer dan geld alleen - STIMACrowdfunding  - meer dan geld alleen - STIMA
Crowdfunding - meer dan geld alleen - STIMA
 
Midokura OpenStack Meetup Taipei
Midokura OpenStack Meetup TaipeiMidokura OpenStack Meetup Taipei
Midokura OpenStack Meetup Taipei
 
Crowdfunding in de Zorg - Verschillende vormen en tips en trucs
Crowdfunding in de Zorg - Verschillende vormen en tips en trucsCrowdfunding in de Zorg - Verschillende vormen en tips en trucs
Crowdfunding in de Zorg - Verschillende vormen en tips en trucs
 
Using New media to create a band of youth social journalists
Using New media to create a band of youth social journalistsUsing New media to create a band of youth social journalists
Using New media to create a band of youth social journalists
 
A messaging app for teams.... who think differently
A messaging app for teams.... who think differentlyA messaging app for teams.... who think differently
A messaging app for teams.... who think differently
 
Social Media in Crisis Management: ISCRAM Summer School 2011
Social Media in Crisis Management: ISCRAM Summer School 2011Social Media in Crisis Management: ISCRAM Summer School 2011
Social Media in Crisis Management: ISCRAM Summer School 2011
 
Anne PitN
Anne PitNAnne PitN
Anne PitN
 
RÁ D I O S I E M E N S S R T I F
RÁ D I O  S I E M E N S  S R T  I FRÁ D I O  S I E M E N S  S R T  I F
RÁ D I O S I E M E N S S R T I F
 
County Party Organizing
County Party OrganizingCounty Party Organizing
County Party Organizing
 
INSME - Crowdfunding webinar
INSME - Crowdfunding webinarINSME - Crowdfunding webinar
INSME - Crowdfunding webinar
 
Photoshopadas
PhotoshopadasPhotoshopadas
Photoshopadas
 
Startups in Vietnam
Startups in VietnamStartups in Vietnam
Startups in Vietnam
 
Smc040 - crowdfunding meer dan geld alleen
Smc040 - crowdfunding meer dan geld alleenSmc040 - crowdfunding meer dan geld alleen
Smc040 - crowdfunding meer dan geld alleen
 
อีเลิร์นนิ่งสำหรับผู้บริหารโรงเรียนสังกัด กทม.
อีเลิร์นนิ่งสำหรับผู้บริหารโรงเรียนสังกัด กทม.อีเลิร์นนิ่งสำหรับผู้บริหารโรงเรียนสังกัด กทม.
อีเลิร์นนิ่งสำหรับผู้บริหารโรงเรียนสังกัด กทม.
 

Similar a Performance tuning

Building scalable application with sql server
Building scalable application with sql serverBuilding scalable application with sql server
Building scalable application with sql server
Chris Adkin
 

Similar a Performance tuning (20)

Oracle Sql Tuning
Oracle Sql TuningOracle Sql Tuning
Oracle Sql Tuning
 
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
 
Sql and PL/SQL Best Practices I
Sql and PL/SQL Best Practices ISql and PL/SQL Best Practices I
Sql and PL/SQL Best Practices I
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAsOracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAs
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c  - New Features for Developers and DBAsOracle Database 12c  - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAs
 
SQL Server Performance Tuning with DMVs
SQL Server Performance Tuning with DMVsSQL Server Performance Tuning with DMVs
SQL Server Performance Tuning with DMVs
 
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
 
Oracle SQL Tuning
Oracle SQL TuningOracle SQL Tuning
Oracle SQL Tuning
 
Sql scripting sorcerypaper
Sql scripting sorcerypaperSql scripting sorcerypaper
Sql scripting sorcerypaper
 
Teradata sql-tuning-top-10
Teradata sql-tuning-top-10Teradata sql-tuning-top-10
Teradata sql-tuning-top-10
 
Introduction to mysql part 3
Introduction to mysql part 3Introduction to mysql part 3
Introduction to mysql part 3
 
Building scalable application with sql server
Building scalable application with sql serverBuilding scalable application with sql server
Building scalable application with sql server
 
Oracle SQL Basics
Oracle SQL BasicsOracle SQL Basics
Oracle SQL Basics
 
DBA Commands and Concepts That Every Developer Should Know - Part 2
DBA Commands and Concepts That Every Developer Should Know - Part 2DBA Commands and Concepts That Every Developer Should Know - Part 2
DBA Commands and Concepts That Every Developer Should Know - Part 2
 
Top 10 Oracle SQL tuning tips
Top 10 Oracle SQL tuning tipsTop 10 Oracle SQL tuning tips
Top 10 Oracle SQL tuning tips
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
 
Stored procedure tunning
Stored procedure tunningStored procedure tunning
Stored procedure tunning
 
Sherlock holmes for dba’s
Sherlock holmes for dba’sSherlock holmes for dba’s
Sherlock holmes for dba’s
 
05_DP_300T00A_Optimize.pptx
05_DP_300T00A_Optimize.pptx05_DP_300T00A_Optimize.pptx
05_DP_300T00A_Optimize.pptx
 

Último

Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Krashi Coaching
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Último (20)

Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 

Performance tuning

  • 2. What is performance Tuning? Performance tuning is the improvement of system performance. This is typically a computer systems. The motivation for such activity is called a performance problem, which can be real or anticipated. Most systems will respond to increased load with some degree of decreasing performance.
  • 3. Scope ● SQL Tuning – Responsibility of the Developer ● Database Tuning – Responsibility of the Database Administrator ● ● System Tuning – Responsibility of the System Administrator ● ● Network Tuning – Responsibility of the Network / LAN / WAN Administrator.
  • 4. SQL Tuning 1. Identifying high load or top SQL statements that are responsible for a large share of the application workload and system resources, by reviewing past SQL execution history available in the system. 2. Verifying that the execution plans produced by the query optimizer for these statements perform reasonably. 3. Implementing corrective actions to generate better execution plans for poorly performing SQL statements.
  • 5. Goals For Tuning ● Reduce the Workload ● This can be achieved by modifying the query and by generating better execution plan. ● Balance the Workload ● Systems often tend to have peak usage in the daytime when real users are connected to the system, and low usage in the nighttime. If you can schedule noncritical reports and batch jobs to run in the nighttime and reduce their concurrency during day time, then the database frees up resources for the more critical programs in the day. ● Parallelize the Workload When Oracle runs SQL statements in parallel, multiple processes work together simultaneously to run a single SQL statement.
  • 6. Identifying High-Load SQL ● Is the problem specific to a single program (or small number of programs)? ● Is the problem generic over the application?
  • 7. Problem is specific to a single program Query for displaying sessions, session state and events select sid, decode(state, 'WAITING','Waiting','Working') state from v$session where username = 'ARUP'; SID STATE ——— —————— 2832 Working 3346 Waiting
  • 8. Getting the SQL select sql_id from v$session where sid = 3089; SQL_ID ————————————————— g0uubmuvk4uax select sql_fulltext from v$sql where sql_id = 'g0uubmuvk4uax'; SQL_FULLTEXT ————————————————— update t1 set col2 = 'y' where col1 = 1
  • 9. S Problem is generic over the application SQL*Trace/Oracle Trace/Database Trace Alter session set sql_trace = true In PL*SQL execute immediate 'Alter session set sql_trace = true'; ● It will generate TK*Prof
  • 10. TK*ProfTK*Prof TK*Prof is an Oracle tool used to display the statistics generated during a trace. When an Oracle session is traced (by SQL*Trace, Oracle Trace, or Database Trace), a trace file is generated. This trace file is barely human-readable; TK*Prof collates and formats the data into a more meaningful form. Location of TK*Prof SELECT value FROM sys.v_$parameter WHERE name = 'user_dump_dest' Running TK*Prof tkprof trace_file output_file [ explain=userid/password@database ] TK*Prof output -High volume Sql, Low volume Sql,Execution Plan Show the TK*Prof output to the DBA to see if the database can be tuned
  • 11. Quick Tips for Oracle SQL Query WritingQuick Tips for Oracle SQL Query Writing Use of EXISTS versus IN for Subqueries Example 1: Using IN - Selective Filters in the Subquery SELECT e.employee_id, e.first_name, e.last_name, e.salary FROM employees e WHERE EXISTS (SELECT 1 FROM orders o WHERE e.employee_id = o.sales_rep_id AND o.customer_id = 144); Rewritting USING IN: SELECT /* IN example */ e.employee_id, e.first_name, e.last_name, e.salary FROM employees e WHERE e.employee_id IN (SELECT o.sales_rep_id /* Note 4 */ FROM orders o WHERE o.customer_id = 144); /* Note 3 */
  • 12. Quick Tips for Oracle SQL Query WritingQuick Tips for Oracle SQL Query Writing Example 2: Using IN - Selective Predicate in the Parent SELECT /* IN example */ e.employee_id, e.first_name, e.last_name, e.department_id, e.salary FROM employees e WHERE e.department_id = 80 AND e.job_id = 'SA_REP' AND e.employee_id IN (SELECT o.sales_rep_id FROM orders o); Rewritting USING EXISTS: SELECT /* EXISTS example */ e.employee_id, e.first_name, e.last_name, e.salary FROM employees e WHERE e.department_id = 80 AND e.job_id = 'SA_REP' AND EXISTS (SELECT 1 FROM orders o WHERE e.employee_id = o.sales_rep_id);
  • 13. Quick Tips for Oracle SQL Query WritingQuick Tips for Oracle SQL Query Writing Do use temp tables to improve cursor performance ● Cursors not only suffer from speed problems, which in itself can be an issue with many operations, but they can also cause your operation to block other operations for a lot longer than is necessary. This greatly decreases concurrency in your system. ● We may be able to get away from cursor-induced performance issues by doing the cursor operations against a temp table instead.For Example, ● A cursor that goes through a table and updates a couple of columns based on some comparison results. Instead of doing the comparison against the live table, you may be able to put that data into a temp table and do the comparison against that instead. Then you have a single UPDATE statement against the live table that’s much smaller and holds locks only for a short time.
  • 14. Quick Tips for Oracle SQL Query WritingQuick Tips for Oracle SQL Query Writing Don’t nest views When you have views that call views that call views that call views. This is called nesting views and it can cause severe performance issues, particularly in two ways. First, you will very likely have much more data coming back than you need. Second, the query optimizer will give up and return a bad query plan.
  • 15. Quick Tips for Oracle SQL Query WritingQuick Tips for Oracle SQL Query Writing Don’t do large ops on many tables in the same batch ● A delete routine that ran several times a day was deleting data out of 14 tables in an explicit transaction. Handling all 14 tables in one transaction meant that the locks were held on every single table until all of the deletes were finished. The solution was to break up each table's deletes into separate transactions so that each delete transaction held locks on only one table. This freed up the other tables and reduced the blocking and allowed other operations to continue working. You always want to split up large transactions like this into separate smaller ones to prevent blocking.
  • 16. Quick Tips for Oracle SQL Query WritingQuick Tips for Oracle SQL Query Writing Don't use triggers ● Whatever it is you want them to do will be done in the same transaction as the original operation. If you write a trigger to insert data into another table when you update a row in the Orders table, the lock will be held on both tables until the trigger is done. If you need to insert data into another table after the update, then put the update and the insert into a stored procedure and do them in separate transactions.
  • 17. Quick Tips for Oracle SQL Query WritingQuick Tips for Oracle SQL Query Writing Don’t count all rows if you only need to see if data exists To check for the existence of that data: (SELECT COUNT(*) into v_cnt FROM table_name; If v_cnt > 0 BEGIN <Do something> END / It’s completely unnecessary. If EXISTS (SELECT 1 FROM table_name) BEGIN <Do something> END
  • 18. Quick Tips for Oracle SQL Query WritingQuick Tips for Oracle SQL Query Writing Try to use UNION ALL in place of UNION The UNION ALL statement is faster than UNION, because UNION ALL statement does not consider duplicate s, and UNION statement does look for duplicates in a table while selection of rows, whether or not they exist. Original query: SELECT cust_id FROM SH.sales UNION SELECT cust_id FROM customers; Improved query: SELECT cust_id FROM SH.sales UNION ALL SELECT cust_id FROM customers;
  • 19. Quick Tips for Oracle SQL Query WritingQuick Tips for Oracle SQL Query Writing Use Column Names Instead of * in a SELECT Statement If you are selecting only a few columns from a table there is no need to use SELECT *. Though this is easier to write, it will cost more time for the database to complete the query. By selecting only the columns you need, you are reducing the size of the result table, reducing the network traffic and also in turn boosting the overall performance of the query. Original query: SELECT * FROM SH.Sales; Improved query: SELECT s.prod_id FROM SH.sales s;
  • 20. Quick Tips for Oracle SQL Query WritingQuick Tips for Oracle SQL Query Writing Avoid including a HAVING clause in SELECT statements The HAVING clause is used to filter the rows after all the rows are selected and it is used like a filter. It is quite useless in a SELECT statement. It works by going through the final result table of the query parsing out the rows that don’t meet the HAVING condition. Original query: SELECT s.cust_id,count(s.cust_id) FROM SH.sales s GROUP BY s.cust_id HAVING s.cust_id != '1660' AND s.cust_id != '2'; Improved query: SELECT s.cust_id,count(cust_id) FROM SH.sales s WHERE s.cust_id != '1660' AND s.cust_id !='2' GROUP BY s.cust_id;
  • 21. Quick Tips for Oracle SQL Query WritingQuick Tips for Oracle SQL Query Writing Use EXISTS instead of DISTINCT when using table joins that involves tables having one-to- many relationships The DISTINCT keyword works by selecting all the columns in the table then parses out any duplicates.Instead, if you use sub query with the EXISTS keyword, you can avoid having to return an entire table. Original query: SELECT DISTINCT c.country_id, c.country_name FROM SH.countries c,SH.customers e WHERE e.country_id = c.country_id; Improved query: SELECT c.country_id, c.country_name FROM SH.countries c WHERE EXISTS (SELECT 'X' FROM SH.customers e WHERE e.country_id = c.country_id);
  • 22. Quick Tips for Oracle SQL Query WritingQuick Tips for Oracle SQL Query Writing Remove any redundant mathematics There will be times where you will be performing mathematics within an SQL statement. They can be a drag on the performance if written improperly. For each time the query finds a row it will recalculate the math. So eliminating any unnecessary math in the statement will make it perform faster. Original query: SELECT * FROM SH.sales s WHERE s.cust_id + 10000 < 35000; Improved query: SELECT * FROM SH.sales s WHERE s.cust_id < 25000;