PL/SQL : Stop making the same performance mistakes

Slides:



Advertisements
Similar presentations
Analytic Functions : An Oracle Developer’s Best Friend
Advertisements

Oracle 10g & 11g for Dev Virtual Columns DML error logging
Tuning Oracle SQL The Basics of Efficient SQLThe Basics of Efficient SQL Common Sense Indexing The Optimizer –Making SQL Efficient Finding Problem Queries.
Introduction to SQL Tuning Brown Bag Three essential concepts.
Chapter 9. Performance Management Enterprise wide endeavor Research and ascertain all performance problems – not just DBMS Five factors influence DB performance.
Module 13: Performance Tuning. Overview Performance tuning methodologies Instance level Database level Application level Overview of tools and techniques.
Welcome to My Obsession
Database Performance Tuning and Query Optimization
An Overview of GoldenGate Replication Brian Keating December 31, 2009.
8 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Using Explicit Cursors.
PL/SQL.
PL/SQL User Defined Types Record and Table Please use speaker notes for additional information!
SQL Objects and PL/SQL. Who am I ?  Gary Myers  Oracle developer since 1994  Database Consultant with SMS M&T  Blogger since 2004 Now at blog.sydoracle.com.
Application Graphic design / svetagraphics.com 01 FRAMEWORK data service.
AN INTRODUCTION TO PL/SQL Mehdi Azarmi 1. Introduction PL/SQL is Oracle's procedural language extension to SQL, the non-procedural relational database.
April 14, 2004 Next Information Systems 1 Bulk Collections and Inserts in Oracle 9i & 10g Simay Alpöge Next Information Systems, Inc.
SQL*PLUS, PLSQL and SQLLDR Ali Obaidi. SQL Advantages High level – Builds on relational algebra and calculus – Powerful operations – Enables automatic.
Copyright © 200\8 Quest Software High Performance PL/SQL Guy Harrison Chief Architect, Database Solutions.
ETL - Oracle Database Features and PL/SQL Techniques Boyan Boev CNsys BGOUG
Chapter 10 Introduction to Arrays
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 11 Database Performance Tuning and Query Optimization.
Introduction to PL/SQL Lecture 0 – Self Study Akhtar Ali.
1 Chapter Overview Transferring and Transforming Data Introducing Microsoft Data Transformation Services (DTS) Transferring and Transforming Data with.
Module 5: Data Access. Overview Introduce database components involved in data access Introduce concepts of Transact -SQL and Procedural SQL as tools.
SQL Server 2005 SP2 Israeli SQL Server User Group March 2005 Ami Levin
PL/SQL Bulk Collections in Oracle 9i and 10g Kent Crotty Burleson Consulting October 13, 2006.
Clonedb: The quick and easy cloning solution you never knew you had. Tim Hall Oracle ACE Director Oracle ACE of the Year 2006.
PL / SQL P rocedural L anguage / S tructured Q uery L anguage Chapter 7 in Lab Reference.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Database Performance Tuning and Query Optimization.
IT The Relational DBMS Section 06. Relational Database Theory Physical Database Design.
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.
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.
1 Chapter 14 DML Tuning. 2 DML Performance Fundamentals DML Performance is affected by: – Efficiency of WHERE clause – Amount of index maintenance – Referential.
Oracle Data Integrator Procedures, Advanced Workflows.
6 Extraction, Transformation, and Loading (ETL) Transformation.
CIS4368: Advanced DatabaseSlide # 1 PL/SQL Dr. Peeter KirsSpring, 2003 PL/SQL.
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 8 Advanced SQL.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Oracle tuning: a tutorial Saikat Chakraborty. Introduction In this session we will try to learn how to write optimized SQL statements in Oracle 8i We.
Trigger Oracle PL/SQL. Triggers Associated with a particular table Associated with a particular table Automatically executed when a particular event occurs.
Chapter 15 Introduction to PL/SQL. Chapter Objectives  Explain the benefits of using PL/SQL blocks versus several SQL statements  Identify the sections.
PL/SQLPL/SQL Oracle11g: PL/SQL Programming Chapter 4 Cursors and Exception Handling.
ITEC 224 Database Programming PL/SQL Lab Cursors.
Chapter 16 Cursors and Exceptions. Chapter Objectives  Determine when an explicit cursor is required  Declare, open, and close an explicit cursor 
Oracle11g: PL/SQL Programming Chapter 3 Handling Data in PL/SQL Blocks.
implicit and an explicit cursor
1 Copyright © 2005, Oracle. All rights reserved. Following a Tuning Methodology.
PL/SQL programming Procedures and Cursors Lecture 1 [Part 2]
Module 11: Managing Transactions and Locks
Text TCS INTERNAL Oracle PL/SQL – Introduction. TCS INTERNAL PL SQL Introduction PLSQL means Procedural Language extension of SQL. PLSQL is a database.
Program with PL/SQL Lesson 3. Interacting with the Oracle Server.
Caching for PL/SQL Performance Tim Hall Oracle ACE Director Oracle ACE of the Year 2006 OCP DBA (7, 8, 8i, 9i, 10g, 11g) OCA.
Preface IIntroduction Course Objectives I-2 Oracle Complete Solution I-3 Course Agenda I-4 Tables Used in This Course I-5 The Order Entry Schema I-6 The.
1 Copyright © 2004, Oracle. All rights reserved. PL/SQL Programming Concepts: Review.
Tim Hall Oracle ACE Director
Pl/SQL LANGUAGE MULITPLE CHOICE QUESTION SET-3
PL/SQL.
Oracle11g: PL/SQL Programming Chapter 4 Cursors and Exception Handling.
Senior Staff Engineer, Sun Microsystems
The powerhouse PL/SQL upgrade option: Edition-Based Redefinition (EBR)
Clonedb: The quick and easy cloning solution you never knew you had.
Best Practices in PL/SQL
Advanced PL/SQL Programing
Query Optimization Techniques
Chapter 2 Handling Data in PL/SQL Blocks Oracle9i Developer:
Chapter 8 Advanced SQL.
Handling Data in PL/SQL Blocks
Query Optimization Techniques
An Overview of GoldenGate Replication
Presentation transcript:

PL/SQL : Stop making the same performance mistakes Tim Hall Oracle ACE Director Oracle ACE of the Year 2006 OakTable Network OCP DBA (7, 8, 8i, 9i, 10g, 11g) OCP Advanced PL/SQL Developer Oracle Database: SQL Certified Expert http://www.oracle-base.com Books Oracle PL/SQL Tuning Oracle Job Scheduling http://www.oracle-base.com

Stop using PL/SQL… … when you could use SQL. PL/SQL is a procedural extension to SQL, not a replacement for it. SQL is usually quicker than the PL/SQL alternative. Be an SQL expert who knows some PL/SQL, not the other way round. Learning cool stuff like Analytic Functions will help you avoid writing unnecessary PL/SQL. (setup.sql) http://www.oracle-base.com

Stop using unnecessary PL/SQL Stop using UTL_FILE to read text files if you can use external tables. (external_table.sql) Stop writing PL/SQL merges if you can use the MERGE statement. (merge.sql) Stop coding multi-table inserts manually. (multitable.sql) Stop using FORALL when you could use DML error logging (DBMS_ERRLOG) to trap failures in DML (dml_el.sql) All use DML, which is easily parallelized. http://www.oracle-base.com

Overview of the PL/SQL Engine Oracle Server PL/SQL Engine PL/SQL Block Procedural Statement Executor SQL Statement PL/SQL contains procedural and SQL code. Each type of code is processed separately. Switching between code types causes an overhead. The overhead is very noticeable during batch operations. Bulk binds minimize this overhead. http://www.oracle-base.com

Stop Avoiding Bulk-Binds (BULK COLLECT) Populate collections directly from SQL using BULK COLLECT. (bulk_collect.sql) Collections are held in memory, so watch collection sizes. (bulk_collect_limit.sql) Implicit array processing introduced in 10g. (implicit_array_processing.sql) SELECT * BULK COLLECT INTO l_tab FROM tab1; OPEN c1; LOOP FETCH c1 BULK COLLECT INTO l_tab LIMIT 1000; EXIT WHEN l_tab.count = 0; -- Process chunk. END LOOP; CLOSE c1; FOR cur_rec IN (SELECT * FROM tab1) LOOP -- Process row. END LOOP; http://www.oracle-base.com

Stop Avoiding Bulk-Binds (FORALL) Bind data in collections into DML using FORALL. (insert_forall.sql) Triggers may not work as you expect. Use INDICIES OF and VALUES OF for sparse collections. Use SQL%BULK_ROWCOUNT to return the number of rows affected by each statement. The SAVE EXCEPTIONS allows bulk operations to complete. Exceptions captured in SQL%BULK_EXCEPTIONS. FORALL i IN l_tab.FIRST .. l_tab.LAST INSERT INTO tab2 VALUES l_tab(i); http://www.oracle-base.com

Stop Using Pass-By-Value (NOCOPY) By-value: Procedure uses temporary buffer. Copies value back on successful completion. By-reference: Procedure uses original memory location directly. The NOCOPY hint allows OUT and IN OUT parameter to be passed by-reference, rather than by-value. (nocopy.sql) Beware of affect of error handling and parameter aliasing on parameter values. It’s a hint, not a directive, so it can be ignored PROCEDURE myproc (p_tab IN OUT NOCOPY CLOB) IS BEGIN -- Do something. END; http://www.oracle-base.com

Stop Using the Wrong Datatypes When you use the wrong datatypes, Oracle performs implicit conversions. Datatype conversions take/waste time. Oracle provide multiple numeric datatypes with differing performance characteristics. (numeric_types.sql) Use the appropriate datatype for the job. http://www.oracle-base.com

Quick Points Stop using index searches when you can use ROWIDs. Stop using custom code when Oracle provide built-in functions. Stop using explicit cursors. Stop avoiding instrumentation in your code. Short-Circuit Evaluations. Logic/Branching order. Stop waiting for requests to complete when you could decouple processes. http://www.oracle-base.com

The End… Questions? References: http://www.oracle-base.com Demos: http://www.oracle-base.com/workshops http://www.oracle-base.com