SlideShare a Scribd company logo
4 June 2008 MythBusters - performance tuning 102 Paul Guerin Bachelor of Engineering (Computer) Oracle DBA Certified Professional DBA 10+ years Employers: Origin Energy, Bluescope Steel, BHP Billiton
Why is application performance important? Directly: End users not waiting as long for data retrieval. More productive use of time while in the office. Increased likelyhood of meeting a tight deadline – especially if technical issues arise. Less frustration that may lead to comments along the line of “This system is xxxx!!!” Greater job satisfaction in current role? Indirectly: Improves employee performance. Increased value to the organisation. Less employee churn? faster application performance = increased user satisfaction
Topics Fundamentals + Cost Based Optimiser Column constraints + indexes SQL tuning + subqueries Non-SQL performance issues, including undo storage Processing: serial + parallel Data migrations
Fundamentals of application performance Minimise the database workload Minimise logical I/O (which in turn reduces physical I/O). Minimise unnecessary sorting. Minimise the result set. Balance the database workload Execute jobs outside normal business hours (including materialised views). Parallelise the database workload Not an option where high concurrency exists.
Cost Based Optimiser The Cost Based Optimiser (CBO) is a program in the database that predicts the cost of various execution plans and selects the one with the lowest estimated. Estimated cost = logical I/O + physical I/O + external database I/O Note: Cost is in terms of database blocks, not rows. To help predict the lowest cost execution plan, the CBO needs to refer to: Statistics for the table, columns, indexes, and system. Any constraints on the table columns. Rewriting the SQL influences the prediction that the CBO makes.
Cost Based Optimiser statistics Myth: Old statistics always lead to poor performance. Fact - Old statistics often remain accurate. Fact – A single insert usually makes the statistics obsolete, so most all database statistics are obsolete anyway. Myth: Recent statistics always lead to improved performance. Fact - New statistics are often not more accurate than the old ones if an insert has just taken place.
Cost Based Optimiser statistics Myth: Gathering CBO stats after each DML statement is the best practice. Myth: Taking statistics can’t hurt. Fact – Cached cursors are invalidated and must be validated again before reuse.  Increased overhead. Fact – Increased contention for the same object blocks.  Increased latching. Fact - Most of the time recent statistics don’t change the execution plan. Fact - Gathering statistics can become more CPU intensive than the actual SQL statement. Fact - Oracle does not automatically gather statistics for the reasons above. Increased overhead and latching leads to higher contention for CPU time.
Cost Based Optimiser statistics Myth: Poor performance always caused by the database. Fact – Network issues can be the cause (e.g. PSPD migration to new host)
Column constraints Column constraints are used to enforce data integrity. Some column constraints are associated with: an index. e.g primary key, unique key. another table. e.g. foreign key. Creating column constraints alone can result in reduced logical I/O and data sorting  - resulting in better performance. However the sole presence of column constraints may not result in satisfactory performance. The creation of additional indexes may be necessary.
Indexes If column constraints alone do not result in satisfactory performance then create an index on the: Foreign key column: important if deleting or updating the primary key of the parent table. Predicate of a WHERE clause. ORDER BY or GROUP BY clause providing the index is in the same sort order. MIN() or MAX() function: index can be asc or desc (key can be anywhere in concatenated index). Single column index ideally for predicates separated by OR operators. Concatenated column index ideally for predicates separated by AND operators. Myth: An index access is always faster than a full-table scan. Fact - For large result sets a full-table scan is often faster. Fact - A table that features a poor clustering factor with respect to its indexes will perform better with a full-table scan.
SQL tuning tips Beware of statements that implicitly sort: DISTINCT, GROUP BY (<=9i), UNION (prefer UNION ALL) Use ROWNUM to retrieve only the top rows of a sort: SELECT * FROM (SELECT … FROM … ORDER BY …) WHERE rownum<=5; Write SQL that may be able to use an index: =, >, <, LIKE, IN Trailing wildcard character (%). Conditions that compare columns with constants. Rewrite SQL that will never be able to use an index: Functions, including implicit type conversions. Leading wildcard character (%). NULL, NOT, <>, !=, ||. Use >-9.99*POWER(10,125) instead of IS NOT NULL. Myth: Tuning an SQL statement only benefits that statement. Fact – All statements that execute concurrently also benefit due to less CPU contention.
SQL tuning tips – EXISTS or IN subqueries A subquery (i.e. semi-join) returns one row in the first table for which at least one match is found, whereas an inner-join returns every match between tables. Many different types of subqueries: Correlated (IN, EXISTS):  A correlated subquery is where the inner query references a column in the outer query. The inner query is evaluated for each row processed in the outer query. e.g. SELECT * FROM hr.dept WHERE EXISTS ( SELECT NULL FROM hr.employees WHERE employees.department_id = dept.deptno ); Uncorrelated (IN, EXISTS): e.g. SELECT * FROM hr.dept WHERE deptno IN ( SELECT department_id FROM hr.employees ); General guidelines for EXISTS and IN subqueries: Choose an IN where the inner query is more selective. Choose an EXISTS where outer query is more selective.
SQL tuning tips – joins or subqueries The CBO will automatically attempt to unnest a correlated or uncorrelated subquery into a join if it thinks indexes will improve efficiency. Every subquery can be rewritten as a join. Not necessarily every join can be rewritten as a subquery. General guidelines for joins and subqueries: Use a subquery when no columns from the subquery table(s) are referenced. Use a join when you need to return columns from more than one table.
SQL tuning tips – multitable transactions Specify WITH CHECK OPTION to indicate that Oracle prohibits any changes to the table or view that would produce rows that are not included in the subquery. UPDATE/DELETE/INSERT INTO (select … from …  with check option ) VALUES (…); Use the MERGE statement to select rows from one table for update or insertion into another table. The decision whether to update or insert into the target table is based on a condition in the ON clause. MERGE INTO <table1> USING <select from table2 subquery> ON <join condition for table1 and table2> WHEN MATCHED THEN <update clause>   WHEN NOT MATCHED THEN <insert clause>;
Non-SQL performance issues There are a number of other performance inhibitors not related to the SQL statement: Hardware performance: e.g. CPU speed on one host may be slower than another. Non-cached data (performance is faster after the first execution) restart of database. small data buffer cache. e.g. execution plan cost is not proportional to elapsed time. Database parameter differences between environments. Undo storage: killing a session reads rollback information. data consistency.
Non-SQL performance issues Row locks (lock on a row in a table). Memory latching (lock on a block in memory). more overhead -> more CPU utilisation. Object inefficiency: non-deallocation of extents, index inefficiency. Sort spills over from memory to disk: Global Memory Bound will vary if other sessions are sorting/hashing. Temporary tablespace may need to extend. CPU contention between environments on the same host:  riskr, ntst, ntsd, ndr, gtsd, gtst, gtsu, gtsx, ntsrt, ntsrx, ntsm Forced redo logging to nullify the Append hint on inserting. e.g. NTS, not NTSRP.
Non-SQL performance issues - UNDO Every time data is changed a representation of the old data is stored in the UNDO tablespace (also referred to as rollback). Allows concurrency: reads don’t block writes, writes don’t block reads.  Overhead required to reconstruct data to the past. Once the transaction is committed the representation of the old data is disregarded. If the transaction is explicitly or implicitly rolledback (killed or deadlocked) then the UNDO tablespace is read to reconstruct the old data. A long running transaction (e.g. large query, refresh of materialised view) requires lots of UNDO space. The UNDO functionality is unique to the Oracle database
Processing Serial processing (default mode) One serial process accessing a single object at a time.  No contention for the same data. No blocking occurs because no session references the same data at the same time.  Regarded as best practice – focus on performing efficiently via SQL tuning.
Processing Serial processing (default mode) One serial process accessing a single object at a time.  No contention for the same data. No blocking occurs because no session references the same data at the same time.  Regarded as best practice – focus on performing efficiently via SQL tuning. Parallel processing Multiple parallel processes accessing a single object.  No contention for the same data because the work is divided among the processes. Parallel processing is not suitable for high concurrency applications. e.g. NETSDEV No blocking occurs because each parallel process references different data at the same time.
Processing Serial processing (default mode) One serial process accessing a single object at a time.  No contention for the same data. No blocking occurs because no session references the same data at the same time.  Regarded as best practice – focus on performing efficiently via SQL tuning. Parallel processing Multiple parallel processes accessing a single object.  No contention for the same data because the work is divided among the processes. Parallel processing is not suitable for high concurrency applications. e.g. NETSDEV No blocking occurs because each parallel process references different data at the same time. Multi-session serial processing via the application Attempt to simulate parallel processing using serial processes.  Used instead of SQL tuning? Each session needs data consistent to when execution started.  More overhead. Blocking occurs because each session attempts to reference the same data at the same time.  Therefore latch contention occurs = more overhead = more CPU utilisation. Regarded as not best practice but acceptable for one-off and incidental processing.
Processing Myth: High CPU utilisation always means lots of real work is being performed. Fact - Maybe, but more likely high CPU indicates high overhead due to spinning on a latch. Fact - Latch spinning results due to contention between sessions for the same block from an object. e.g. index root node.
Data migrations Distributed database links: Smaller the data size the better (but without metadata). Can’t make the data consistent to the time required (unless read-only). e.g. To obtain all the data at midday, start the migration before this time, but the consistency is from the start time.
Data migrations Distributed database links: Smaller the data size the better (but without metadata). Can’t make the data consistent to the time required (unless read-only). e.g. To obtain all the data at midday, start the migration before this time, but the consistency is from the start time. Export and import utilities: Smaller the data size the better (with or without metadata). Can’t make the data consistent to the time required (unless read-only).
Data migrations Distributed database links: Smaller the data size the better (but without metadata). Can’t make the data consistent to the time required (unless read-only). e.g. To obtain all the data at midday, start the migration before this time, but the consistency is from the start time. Export and import utilities: Smaller the data size the better (with or without metadata). Can’t make the data consistent to the time required (unless read-only). RMAN duplicates: Small or large data sizes with metadata. Data consistent from a desired time – doesn’t need to be read-only. e.g. month-end snapshot. Example All the data may be required at mid-day today, but could be consistent from mid-day, yesterday, or last week. The production data is still available for reading and writing.
Use column constraints. e.g. primary key, foreign key, not null, etc. Statistics are not the “silver bullet” for all performance problems. Prefer to process jobs serially for the same table. Consult the DBAs Summary:
Analytic functions? Partitions and pruning? More fundamental SQL tuning? More subqueries? Using export & import utilities? Target a smaller audience? Currently accepting requests Possible topics for future forums:

More Related Content

PPTX
Oracle DB Performance Tuning Tips
PDF
MySQL Query And Index Tuning
PPT
Top 10 Oracle SQL tuning tips
PPTX
New T-SQL Features in SQL Server 2012
PPTX
TSQL in SQL Server 2012
PDF
Advanced MySQL Query Optimizations
PPTX
Oracle SQL Tuning for Day-to-Day Data Warehouse Support
PPTX
Stored procedure tunning
Oracle DB Performance Tuning Tips
MySQL Query And Index Tuning
Top 10 Oracle SQL tuning tips
New T-SQL Features in SQL Server 2012
TSQL in SQL Server 2012
Advanced MySQL Query Optimizations
Oracle SQL Tuning for Day-to-Day Data Warehouse Support
Stored procedure tunning

What's hot (20)

PPTX
MySQL Replication Evolution -- Confoo Montreal 2017
PDF
MySQL Indexing : Improving Query Performance Using Index (Covering Index)
ODP
SQL Tunning
PPTX
Query Optimization in SQL Server
PPTX
PHP UK 2020 Tutorial: MySQL Indexes, Histograms And other ways To Speed Up Yo...
ODP
Oracle SQL Advanced
PPTX
Confoo 2021 - MySQL Indexes & Histograms
PPT
Oracle Course
PPTX
Getting to know oracle database objects iot, mviews, clusters and more…
PDF
An Approach to Sql tuning - Part 1
PDF
Using T-SQL
PPTX
Query parameterization
PDF
How to Fine-Tune Performance Using Amazon Redshift
PPTX
PyCon DE 2013 - Table Partitioning with Django
PPTX
Sql killedserver
PDF
MySQL Optimizer Cost Model
PPTX
Oracle Data Redaction - UKOUG - TECH14
PPTX
Oracle Data Redaction
PPTX
Oracle Database 12c - Data Redaction
PPT
Mysql Indexing
MySQL Replication Evolution -- Confoo Montreal 2017
MySQL Indexing : Improving Query Performance Using Index (Covering Index)
SQL Tunning
Query Optimization in SQL Server
PHP UK 2020 Tutorial: MySQL Indexes, Histograms And other ways To Speed Up Yo...
Oracle SQL Advanced
Confoo 2021 - MySQL Indexes & Histograms
Oracle Course
Getting to know oracle database objects iot, mviews, clusters and more…
An Approach to Sql tuning - Part 1
Using T-SQL
Query parameterization
How to Fine-Tune Performance Using Amazon Redshift
PyCon DE 2013 - Table Partitioning with Django
Sql killedserver
MySQL Optimizer Cost Model
Oracle Data Redaction - UKOUG - TECH14
Oracle Data Redaction
Oracle Database 12c - Data Redaction
Mysql Indexing
Ad

Viewers also liked (8)

PPT
SQL Optimization With Trace Data And Dbms Xplan V6
PPT
Cost Based Optimizer - Part 1 of 2
PDF
Performance tuning a quick intoduction
PDF
New Tuning Features in Oracle 11g - How to make your database as boring as po...
PPTX
Introduction to oracle optimizer
PDF
Explaining the explain_plan
PDF
Indexes: The neglected performance all rounder
PDF
Oracle Rac Performance Tunning Tips&Tricks
SQL Optimization With Trace Data And Dbms Xplan V6
Cost Based Optimizer - Part 1 of 2
Performance tuning a quick intoduction
New Tuning Features in Oracle 11g - How to make your database as boring as po...
Introduction to oracle optimizer
Explaining the explain_plan
Indexes: The neglected performance all rounder
Oracle Rac Performance Tunning Tips&Tricks
Ad

Similar to Myth busters - performance tuning 102 2008 (20)

PPT
Myth busters - performance tuning 101 2007
PPTX
Database Performance Tuning
PPTX
Top 10 tips for Oracle performance
PDF
Query Tuning for Database Pros & Developers
PPTX
Oracle sql high performance tuning
PDF
Tips for Database Performance
PPTX
Oracle database performance tuning
PDF
SQL Database Performance Tuning for Developers
PPT
Indexing Strategies
PDF
White Paper for OMG! Identifying and Refactoring Common SQL...
PDF
NOCOUG_201311_Fine_Tuning_Execution_Plans.pdf
TXT
Oracle sql tuning
PPTX
SQL Server 2012 Best Practices
PPTX
Oracle Database Performance Tuning Basics
PPTX
It Depends
PDF
Developer day v2
ODP
Performance tuning
PPT
PDF
Database and application performance vivek sharma
PPTX
Oracle performance tuning for java developers
Myth busters - performance tuning 101 2007
Database Performance Tuning
Top 10 tips for Oracle performance
Query Tuning for Database Pros & Developers
Oracle sql high performance tuning
Tips for Database Performance
Oracle database performance tuning
SQL Database Performance Tuning for Developers
Indexing Strategies
White Paper for OMG! Identifying and Refactoring Common SQL...
NOCOUG_201311_Fine_Tuning_Execution_Plans.pdf
Oracle sql tuning
SQL Server 2012 Best Practices
Oracle Database Performance Tuning Basics
It Depends
Developer day v2
Performance tuning
Database and application performance vivek sharma
Oracle performance tuning for java developers

More from paulguerin (6)

PPTX
In Sync11 Presentation The Biggest Loser
PPT
Automation system performance myths
PPT
Sydney Oracle Meetup - indexes
PPT
Sydney Oracle Meetup - execution plans
PPT
Sydney Oracle Meetup - access paths
PPT
Myth busters - performance tuning 103 2008
In Sync11 Presentation The Biggest Loser
Automation system performance myths
Sydney Oracle Meetup - indexes
Sydney Oracle Meetup - execution plans
Sydney Oracle Meetup - access paths
Myth busters - performance tuning 103 2008

Recently uploaded (20)

PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Electronic commerce courselecture one. Pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf
PDF
Approach and Philosophy of On baking technology
PPTX
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Advanced Soft Computing BINUS July 2025.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
KodekX | Application Modernization Development
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
DOCX
The AUB Centre for AI in Media Proposal.docx
20250228 LYD VKU AI Blended-Learning.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Electronic commerce courselecture one. Pdf
Empathic Computing: Creating Shared Understanding
Chapter 3 Spatial Domain Image Processing.pdf
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf
Approach and Philosophy of On baking technology
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Advanced methodologies resolving dimensionality complications for autism neur...
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Advanced Soft Computing BINUS July 2025.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
KodekX | Application Modernization Development
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
The AUB Centre for AI in Media Proposal.docx

Myth busters - performance tuning 102 2008

  • 1. 4 June 2008 MythBusters - performance tuning 102 Paul Guerin Bachelor of Engineering (Computer) Oracle DBA Certified Professional DBA 10+ years Employers: Origin Energy, Bluescope Steel, BHP Billiton
  • 2. Why is application performance important? Directly: End users not waiting as long for data retrieval. More productive use of time while in the office. Increased likelyhood of meeting a tight deadline – especially if technical issues arise. Less frustration that may lead to comments along the line of “This system is xxxx!!!” Greater job satisfaction in current role? Indirectly: Improves employee performance. Increased value to the organisation. Less employee churn? faster application performance = increased user satisfaction
  • 3. Topics Fundamentals + Cost Based Optimiser Column constraints + indexes SQL tuning + subqueries Non-SQL performance issues, including undo storage Processing: serial + parallel Data migrations
  • 4. Fundamentals of application performance Minimise the database workload Minimise logical I/O (which in turn reduces physical I/O). Minimise unnecessary sorting. Minimise the result set. Balance the database workload Execute jobs outside normal business hours (including materialised views). Parallelise the database workload Not an option where high concurrency exists.
  • 5. Cost Based Optimiser The Cost Based Optimiser (CBO) is a program in the database that predicts the cost of various execution plans and selects the one with the lowest estimated. Estimated cost = logical I/O + physical I/O + external database I/O Note: Cost is in terms of database blocks, not rows. To help predict the lowest cost execution plan, the CBO needs to refer to: Statistics for the table, columns, indexes, and system. Any constraints on the table columns. Rewriting the SQL influences the prediction that the CBO makes.
  • 6. Cost Based Optimiser statistics Myth: Old statistics always lead to poor performance. Fact - Old statistics often remain accurate. Fact – A single insert usually makes the statistics obsolete, so most all database statistics are obsolete anyway. Myth: Recent statistics always lead to improved performance. Fact - New statistics are often not more accurate than the old ones if an insert has just taken place.
  • 7. Cost Based Optimiser statistics Myth: Gathering CBO stats after each DML statement is the best practice. Myth: Taking statistics can’t hurt. Fact – Cached cursors are invalidated and must be validated again before reuse. Increased overhead. Fact – Increased contention for the same object blocks. Increased latching. Fact - Most of the time recent statistics don’t change the execution plan. Fact - Gathering statistics can become more CPU intensive than the actual SQL statement. Fact - Oracle does not automatically gather statistics for the reasons above. Increased overhead and latching leads to higher contention for CPU time.
  • 8. Cost Based Optimiser statistics Myth: Poor performance always caused by the database. Fact – Network issues can be the cause (e.g. PSPD migration to new host)
  • 9. Column constraints Column constraints are used to enforce data integrity. Some column constraints are associated with: an index. e.g primary key, unique key. another table. e.g. foreign key. Creating column constraints alone can result in reduced logical I/O and data sorting - resulting in better performance. However the sole presence of column constraints may not result in satisfactory performance. The creation of additional indexes may be necessary.
  • 10. Indexes If column constraints alone do not result in satisfactory performance then create an index on the: Foreign key column: important if deleting or updating the primary key of the parent table. Predicate of a WHERE clause. ORDER BY or GROUP BY clause providing the index is in the same sort order. MIN() or MAX() function: index can be asc or desc (key can be anywhere in concatenated index). Single column index ideally for predicates separated by OR operators. Concatenated column index ideally for predicates separated by AND operators. Myth: An index access is always faster than a full-table scan. Fact - For large result sets a full-table scan is often faster. Fact - A table that features a poor clustering factor with respect to its indexes will perform better with a full-table scan.
  • 11. SQL tuning tips Beware of statements that implicitly sort: DISTINCT, GROUP BY (<=9i), UNION (prefer UNION ALL) Use ROWNUM to retrieve only the top rows of a sort: SELECT * FROM (SELECT … FROM … ORDER BY …) WHERE rownum<=5; Write SQL that may be able to use an index: =, >, <, LIKE, IN Trailing wildcard character (%). Conditions that compare columns with constants. Rewrite SQL that will never be able to use an index: Functions, including implicit type conversions. Leading wildcard character (%). NULL, NOT, <>, !=, ||. Use >-9.99*POWER(10,125) instead of IS NOT NULL. Myth: Tuning an SQL statement only benefits that statement. Fact – All statements that execute concurrently also benefit due to less CPU contention.
  • 12. SQL tuning tips – EXISTS or IN subqueries A subquery (i.e. semi-join) returns one row in the first table for which at least one match is found, whereas an inner-join returns every match between tables. Many different types of subqueries: Correlated (IN, EXISTS): A correlated subquery is where the inner query references a column in the outer query. The inner query is evaluated for each row processed in the outer query. e.g. SELECT * FROM hr.dept WHERE EXISTS ( SELECT NULL FROM hr.employees WHERE employees.department_id = dept.deptno ); Uncorrelated (IN, EXISTS): e.g. SELECT * FROM hr.dept WHERE deptno IN ( SELECT department_id FROM hr.employees ); General guidelines for EXISTS and IN subqueries: Choose an IN where the inner query is more selective. Choose an EXISTS where outer query is more selective.
  • 13. SQL tuning tips – joins or subqueries The CBO will automatically attempt to unnest a correlated or uncorrelated subquery into a join if it thinks indexes will improve efficiency. Every subquery can be rewritten as a join. Not necessarily every join can be rewritten as a subquery. General guidelines for joins and subqueries: Use a subquery when no columns from the subquery table(s) are referenced. Use a join when you need to return columns from more than one table.
  • 14. SQL tuning tips – multitable transactions Specify WITH CHECK OPTION to indicate that Oracle prohibits any changes to the table or view that would produce rows that are not included in the subquery. UPDATE/DELETE/INSERT INTO (select … from … with check option ) VALUES (…); Use the MERGE statement to select rows from one table for update or insertion into another table. The decision whether to update or insert into the target table is based on a condition in the ON clause. MERGE INTO <table1> USING <select from table2 subquery> ON <join condition for table1 and table2> WHEN MATCHED THEN <update clause> WHEN NOT MATCHED THEN <insert clause>;
  • 15. Non-SQL performance issues There are a number of other performance inhibitors not related to the SQL statement: Hardware performance: e.g. CPU speed on one host may be slower than another. Non-cached data (performance is faster after the first execution) restart of database. small data buffer cache. e.g. execution plan cost is not proportional to elapsed time. Database parameter differences between environments. Undo storage: killing a session reads rollback information. data consistency.
  • 16. Non-SQL performance issues Row locks (lock on a row in a table). Memory latching (lock on a block in memory). more overhead -> more CPU utilisation. Object inefficiency: non-deallocation of extents, index inefficiency. Sort spills over from memory to disk: Global Memory Bound will vary if other sessions are sorting/hashing. Temporary tablespace may need to extend. CPU contention between environments on the same host: riskr, ntst, ntsd, ndr, gtsd, gtst, gtsu, gtsx, ntsrt, ntsrx, ntsm Forced redo logging to nullify the Append hint on inserting. e.g. NTS, not NTSRP.
  • 17. Non-SQL performance issues - UNDO Every time data is changed a representation of the old data is stored in the UNDO tablespace (also referred to as rollback). Allows concurrency: reads don’t block writes, writes don’t block reads. Overhead required to reconstruct data to the past. Once the transaction is committed the representation of the old data is disregarded. If the transaction is explicitly or implicitly rolledback (killed or deadlocked) then the UNDO tablespace is read to reconstruct the old data. A long running transaction (e.g. large query, refresh of materialised view) requires lots of UNDO space. The UNDO functionality is unique to the Oracle database
  • 18. Processing Serial processing (default mode) One serial process accessing a single object at a time. No contention for the same data. No blocking occurs because no session references the same data at the same time. Regarded as best practice – focus on performing efficiently via SQL tuning.
  • 19. Processing Serial processing (default mode) One serial process accessing a single object at a time. No contention for the same data. No blocking occurs because no session references the same data at the same time. Regarded as best practice – focus on performing efficiently via SQL tuning. Parallel processing Multiple parallel processes accessing a single object. No contention for the same data because the work is divided among the processes. Parallel processing is not suitable for high concurrency applications. e.g. NETSDEV No blocking occurs because each parallel process references different data at the same time.
  • 20. Processing Serial processing (default mode) One serial process accessing a single object at a time. No contention for the same data. No blocking occurs because no session references the same data at the same time. Regarded as best practice – focus on performing efficiently via SQL tuning. Parallel processing Multiple parallel processes accessing a single object. No contention for the same data because the work is divided among the processes. Parallel processing is not suitable for high concurrency applications. e.g. NETSDEV No blocking occurs because each parallel process references different data at the same time. Multi-session serial processing via the application Attempt to simulate parallel processing using serial processes. Used instead of SQL tuning? Each session needs data consistent to when execution started. More overhead. Blocking occurs because each session attempts to reference the same data at the same time. Therefore latch contention occurs = more overhead = more CPU utilisation. Regarded as not best practice but acceptable for one-off and incidental processing.
  • 21. Processing Myth: High CPU utilisation always means lots of real work is being performed. Fact - Maybe, but more likely high CPU indicates high overhead due to spinning on a latch. Fact - Latch spinning results due to contention between sessions for the same block from an object. e.g. index root node.
  • 22. Data migrations Distributed database links: Smaller the data size the better (but without metadata). Can’t make the data consistent to the time required (unless read-only). e.g. To obtain all the data at midday, start the migration before this time, but the consistency is from the start time.
  • 23. Data migrations Distributed database links: Smaller the data size the better (but without metadata). Can’t make the data consistent to the time required (unless read-only). e.g. To obtain all the data at midday, start the migration before this time, but the consistency is from the start time. Export and import utilities: Smaller the data size the better (with or without metadata). Can’t make the data consistent to the time required (unless read-only).
  • 24. Data migrations Distributed database links: Smaller the data size the better (but without metadata). Can’t make the data consistent to the time required (unless read-only). e.g. To obtain all the data at midday, start the migration before this time, but the consistency is from the start time. Export and import utilities: Smaller the data size the better (with or without metadata). Can’t make the data consistent to the time required (unless read-only). RMAN duplicates: Small or large data sizes with metadata. Data consistent from a desired time – doesn’t need to be read-only. e.g. month-end snapshot. Example All the data may be required at mid-day today, but could be consistent from mid-day, yesterday, or last week. The production data is still available for reading and writing.
  • 25. Use column constraints. e.g. primary key, foreign key, not null, etc. Statistics are not the “silver bullet” for all performance problems. Prefer to process jobs serially for the same table. Consult the DBAs Summary:
  • 26. Analytic functions? Partitions and pruning? More fundamental SQL tuning? More subqueries? Using export & import utilities? Target a smaller audience? Currently accepting requests Possible topics for future forums: