Copyright © 200\8 Quest Software High Performance PL/SQL Guy Harrison Chief Architect, Database Solutions.

Slides:



Advertisements
Similar presentations
PL/SQL : Stop making the same performance mistakes
Advertisements

Tuning Oracle SQL The Basics of Efficient SQLThe Basics of Efficient SQL Common Sense Indexing The Optimizer –Making SQL Efficient Finding Problem Queries.
Copyright © SoftTree Technologies, Inc. DB Tuning Expert.
Chapter 9. Performance Management Enterprise wide endeavor Research and ascertain all performance problems – not just DBMS Five factors influence DB performance.
13 Copyright © 2005, Oracle. All rights reserved. Monitoring and Improving Performance.
Module 13: Performance Tuning. Overview Performance tuning methodologies Instance level Database level Application level Overview of tools and techniques.
Overview of performance tuning strategies Oracle Performance Tuning Allan Young June 2008.
Part IV: Memory Management
1 Optimizing compilers Managing Cache Bercovici Sivan.
Finding the Performance Bottlenecks in Your Application Ian Jones and Roger Schrag Database Specialists, Inc. IOUG-A Live! 1999 Paper.
Clarity Educational Community Clarity Educational Community Creating and Tuning SQL Queries that Engage Users.
Communicating with the Outside. Hardware [Processor(s), Disk(s), Memory] Operating System Concurrency ControlRecovery Storage Subsystem Indexes Query.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 11 Database Performance Tuning and Query Optimization.
Module 8: Monitoring SQL Server for Performance. Overview Why to Monitor SQL Server Performance Monitoring and Tuning Tools for Monitoring SQL Server.
1 Tuning PL/SQL procedures using DBMS_PROFILER 20-August 2009 Tim Gorman Evergreen Database Technologies, Inc. Northern California Oracle.
PL/SQL Bulk Collections in Oracle 9i and 10g Kent Crotty Burleson Consulting October 13, 2006.
ORACLE ONLINE TRAINING Contact our Support Team : SOFTNSOL India: Skype id : softnsoltrainings id:
Database Systems: Design, Implementation, and Management Tenth Edition Chapter 11 Database Performance Tuning and Query Optimization.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Database Performance Tuning and Query Optimization.
SAGE Computing Services Customised Oracle Training Workshops and Consulting Are you making the most of PL/SQL? Hints and tricks and things you may have.
Operator Precedence First the contents of all parentheses are evaluated beginning with the innermost set of parenthesis. Second all multiplications, divisions,
A Metadata Based Approach For Supporting Subsetting Queries Over Parallel HDF5 Datasets Vignesh Santhanagopalan Graduate Student Department Of CSE.
1 Robert Wijnbelt Health Check your Database A Performance Tuning Methodology.
Physical Database Design & Performance. Optimizing for Query Performance For DBs with high retrieval traffic as compared to maintenance traffic, optimizing.
Module 7 Reading SQL Server® 2008 R2 Execution Plans.
© Dennis Shasha, Philippe Bonnet – 2013 Communicating with the Outside.
Improving Efficiency of I/O Bound Systems More Memory, Better Caching Newer and Faster Disk Drives Set Object Access (SETOBJACC) Reorganize (RGZPFM) w/
Ashwani Roy Understanding Graphical Execution Plans Level 200.
Chapter 12 Recursion, Complexity, and Searching and Sorting
1 Names, Scopes and Bindings Aaron Bloomfield CS 415 Fall
1 Optimizing Your ColdFusion Applications for Oracle Justin Fidler, CNA, CPS, CCFD Chief Technology Officer Bantu, Inc. 8 May 2001.
From Zero to Hero : Using an assortment of caching techniques to improve performance of SQL containing PL/SQL calls. Tim Hall.
Oracle PL/SQL Practices. Critical elements of PL/SQL Best Practices Build your development toolbox Unit test PL/SQL programs Optimize SQL in PL/SQL programs.
Views In some cases, it is not desirable for all users to see the entire logical model (that is, all the actual relations stored in the database.) In some.
Improving Database Performance Derrick Rapley
1 Chapter 10 Joins and Subqueries. 2 Joins & Subqueries Joins – Methods to combine data from multiple tables – Optimizer information can be limited based.
8 1 Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 3 Handling Data in PL/SQL Blocks.
1 Chapter 13 Parallel SQL. 2 Understanding Parallel SQL Enables a SQL statement to be: – Split into multiple threads – Each thread processed simultaneously.
Dynamic SQL. 2 home back first prev next last What Will I Learn? Recall the stages through which all SQL statements pass Describe the reasons for using.
Oracle10g Developer: PL/SQL Programming1 Objectives SQL queries within PL/SQL Host or bind variables The %TYPE attribute Include queries and control structures.
1 Copyright © 2005, Oracle. All rights reserved. Following a Tuning Methodology.
1 Chapter 9 Tuning Table Access. 2 Overview Improve performance of access to single table Explain access methods – Full Table Scan – Index – Partition-level.
Text TCS INTERNAL Oracle PL/SQL – Introduction. TCS INTERNAL PL SQL Introduction PLSQL means Procedural Language extension of SQL. PLSQL is a database.
Oracle9i Developer: PL/SQL Programming Chapter 11 Performance Tuning.
Database Systems, 8 th Edition SQL Performance Tuning Evaluated from client perspective –Most current relational DBMSs perform automatic query optimization.
5 Copyright © 2007, Oracle. All rights reserved. Implementing the Performance Improvements.
Scott Fallen Sales Engineer, SQL Sentry Blog: scottfallen.blogspot.com.
Dynamic SQL Writing Efficient Queries on the Fly ED POLLACK AUTOTASK CORPORATION DATABASE OPTIMIZATION ENGINEER.
Diving into Query Execution Plans ED POLLACK AUTOTASK CORPORATION DATABASE OPTIMIZATION ENGINEER.
3 Copyright © 2006, Oracle. All rights reserved. Designing and Developing for Performance.
SQL IMPLEMENTATION & ADMINISTRATION Indexing & Views.
Tuning Oracle SQL The Basics of Efficient SQL Common Sense Indexing
Designing High Performance BIRT Reports
Chapter 2: Computer-System Structures(Hardware)
Query Optimization Techniques
SQL Trace and TKPROF.
Troubleshooting SQL Server When You Cannot Access The Machine
Database Performance Tuning &
Database Performance Tuning and Query Optimization
Query Optimization Techniques
Top Tips for Better TSQL Stored Procedures
Chapter 8 Advanced SQL.
Chapter 11 Database Performance Tuning and Query Optimization
MATERI PL/SQL Procedures Functions Packages Database Triggers
Diving into Query Execution Plans
Query Optimization Techniques
Performance Tuning ETL Process
Presentation transcript:

Copyright © 200\8 Quest Software High Performance PL/SQL Guy Harrison Chief Architect, Database Solutions

PL/SQL top tips 1.Optimize network traffic 2.Array processing 3.Set PLSQL_OPTIMIZE_LEVEL 4.Loop processing 5.Recursion 6.NoCopy 7.Associative arrays 8.Bind variables in NDS 9.Number crunching 10.Using the profiler 11.G

Tip 0: It’s usually the SQL Most PL/SQL routines spend most of their time executing SELECT statements and DML Tune these first: –Identify proportion of time spent in SQL (profiler, V$SQL) –Use SQL Trace+ tkprof or the profiler to identify top SQL SQL tuning is a big topic but: –Look at statistics collection policies In development AND in production –Consider adequacy of indexing –Learn hints –Exploit 10g/11g tuning facilities (if licensed) –Don’t issue SQL when you don’t need to

PLSQL_OPTIMIZE_LEVEL Introduced in 10g Controls transparent optimization of PL/SQL code similar to reorganizing code –Level 0: No optimization –Level 1: Minor optimizations, not much reorganization –Level 2: (the default) Significant reorganization including loop optimizations and automatic bulk collect –Level 3: (11g only) Further optimizations, notably automatic in-lining of subroutines

Motivations for stored procedures Historically: –Security –Client-Server division of labour –Separation of business logic –Manageability –Portability ? –Network overhead –Divide and conquer complex SQL Today –Middle tier provides most of these –Network traffic is perhaps the strongest remaining motivation

Optimizing network traffic PL/SQL routines most massively outperform other languages when network round trips are significant.

Network traffic Routines that process large numbers of rows and return simple aggregates are also candidates for a stored procedure approach

Stored procedure alternative

Network traffic example

Array processing Considered bad: Excessive loop iterations Increases logical reads (rows in the same block fetched separately)

Array processing Considered better: Selects all data in a single operation Large result sets might take longer as memory grows Other concurrent sessions may have limited memory for sorts, etc. Out of memory errors are possible

Array processing Considered best: Never more that p_array_size elements in collection Best throughput, acceptable memory utilization

Array processing (plsql_optimize_level=1) No bulk collect Bulk collect without LIMIT

Bulk Collect and PLSQL_OPTIMIZE_LEVEL PLSQL_OPTIMIZE_LEVEL>1 causes transparent BULK COLLECT LIMIT 100 This means that FOR loops can actually be more efficient that unlimited BULK COLLECT! ******************************************************************************** SQL ID : 6z2hybgm1ahkh SELECT /*+ cache(t) */ PK, DATA FROM BULK_COLLECT_TAB call count cpu elapsed disk query current rows Parse Execute Fetch total Misses in library cache during parse: 1 Optimizer mode: ALL_ROWS Parsing user id: 88 (recursive depth: 1)

Reduce unnecessary Looping Unnecessary loop iterations burn CPU

Remove loop Invariant terms Any term in a loop that does not vary should be extracted from the loop PLSQL_OPTIMIZE_LEVEL>1 does this automatically

Loop invariant terms relocated

Loop invariant performance improvements

Recursive routines Recursive routines often offer elegant solutions. However, deep recursion is memory-intensive and usually not scalable

Recursion memory overhead

NOCOPY The NOCOPY clause causes a parameter to be passed “by reference” rather than “by value” Without NOCOPY, a copy of each parameter variable is created within the subroutine This is particularly expensive when collections are passed as parameters

NoCopy performance gains 4,000 row, 10 column “table”; 4000 lookups:

Associative arrays Traditionally, sequential scans of PLSQL tables are used for caching database table data:

Associative arrays Associative arrays allow for faster and simpler lookups:

Associative array performance 10,000 random customer lookups with 55,000 customers

Bind variables in Dynamic SQL Using bind variables allows sharable SQL, reduces parse overhead and minimizes latch contention Unlike other languages, PL/SQL uses bind variables transparently However, dynamic SQL makes it easy to “forget”

Using bind variables

Bind variable performance 10,000 calls like this:

Number crunching Until recently, it’s been hard to determine how much time is spent in PLSQL code, vs time in SQL inside PLSQL:

Java for computation? Your results will vary

Why Native didn’t work well for me… I need a routine with no SQL and no built in functions!

The profiler DBMS_PROFILER is the best way to find PL/SQL “hot spots”:

Toad profiler support

Hierarchical profiler $ plshprof -output hprof demo1.trc

Plshprof output

DBMS_HPROF tables

Toad Hierarchical profiler

11g and other stuff 11g Native compilation 11g In-lining Data types (SIMPLE_INTEGER) IF and CASE ordering SQL tuning (duh!) PLSQL Function cache

Function cache example Suits deterministic but expensive functions Expensive table lookups on non-volatile tables

100 executions, random date ranges 1-30 days:

Thank You – Q&A