SlideShare une entreprise Scribd logo
1  sur  19
Carlos Oliveira / May 31, 2012
Agenda
 Oracle Database Overview
         Introduction
         What isSQL & PL/SQL
         Performance X Organization
         What is an Access Plan
         Access Plan
         Rules
         Cost
         Our Environment Parameters
         How to use Cost
         Improve Performance in SQL*Plus
         POC
         Training & Reference
         Questions
Introduction
I am a forward-looking Information Systems Architect with a
solid Oracle DBA background comprising the daily
infrastructure tasks of the DBA, several projects as a Data
Modeler, and performance management projects.

I Started on the mainframe business, and soon had a deep dive
in application development for Oracle databases. After
acquiring an Oracle certification, I worked on performance
enhancement for applications using Oracle databases, and later
worked several years as an infrastructure DBA, later I worked
on data modeling projects and more recently a performance
management project, on both application and database layers.
“The limits of my language
mean the limits of my world.”



Ludwig Wittgenstein
What is SQL & PL/SQL
•SQL - Is a data oriented language for selecting and manipulating sets of
data.
•It has to be parsed and transformed by the database into an execution plan
of how to access the data
•The execution plan can be different due to environment changes

•PL/SQL is a procedural language to create applications.
•It is already a series of statements and commands to be executed by the
database
•The program flow doesn't change, no matter the changes in the
environment.
Performance X Organization
         PERFORMANCE                      ORGANIZATION
SQL      •Faster access to data           •Easier to understand the access plan
         •Faster retrieval of data        •Easier to maintain the query
PL/SQL   •Faster execution of the program •Easier to read the code
         •Less memory used                •Easier to maintain the program
What is an Access Plan
It is created by Oracle optimizer for SELECT, UPDATE, INSERT, and DELETE statements.
A statement's execution plan is the sequence of operations Oracle performs to run the statement.

The row source tree is the core of the execution plan. It shows the following information:
•An ordering of the tables referenced by the statement
•An access method for each table mentioned in the statement
•A join method for tables affected by join operations in the statement
•Data operations like filter, sort, or aggregation

In addition to the row source tree, the plan table contains information about the following:
•Optimization, such as the cost and cardinality of each operation
•Partitioning, such as the set of accessed partitions
•Parallel execution, such as the distribution method of join inputs

The ACCESS PLAN results let you determine whether the optimizer selects a particular execution
plan, such as, nested loops join. It also helps you to understand the optimizer decisions, such as why the
optimizer chose a nested loops join instead of a hash join, and lets you understand the performance of a
query.
Access Plan
SELECT e.employee_id, j.job_title, e.salary, d.department_name
    FROM employees e, jobs j, departments d
    WHERE e.employee_id < 103
       AND e.job_id = j.job_id
       AND e.department_id = d.department_id;

-----------------------------------------------------------------------------------
| Id | Operation                      | Name         | Rows | Bytes | Cost (%CPU)|
-----------------------------------------------------------------------------------
|   0 | SELECT STATEMENT              |              |     3 |   189 |    10 (10)|
|   1 | NESTED LOOPS                  |              |     3 |   189 |    10 (10)|
|   2 |   NESTED LOOPS                |              |     3 |   141 |     7 (15)|
|* 3 |     TABLE ACCESS FULL          | EMPLOYEES    |     3 |    60 |     4 (25)|
|   4 |    TABLE ACCESS BY INDEX ROWID| JOBS         |    19 |   513 |     2 (50)|
|* 5 |      INDEX UNIQUE SCAN         | JOB_ID_PK    |     1 |       |            |
|   6 |   TABLE ACCESS BY INDEX ROWID | DEPARTMENTS |     27 |   432 |     2 (50)|
|* 7 |     INDEX UNIQUE SCAN          | DEPT_ID_PK   |     1 |       |            |
-----------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------
   3 - filter("E"."EMPLOYEE_ID"<103)
   5 - access("E"."JOB_ID"="J"."JOB_ID")
   7 - access("E"."DEPARTMENT_ID"="D"."DEPARTMENT_ID")
Access Plan
What Influences the Access Plan
COST
Different Costs
     Data volume and statistics
     Bind variable types
RULE
•Order of the tables in the FROM clause
•Order of the join conditions in the WHERE/JOIN clause
•Collected Statistics
•Rules

GENERAL
•Different Schemas/Databases/Users
•Schema changes (usually changes in indexes) between the two operations.
•Initialization parameters - set globally or at session level
•Hints
•Indexed Columns inhibitors (+0 or ||'' )
Rules
•RBO Path 1: Single Row by Rowid
•RBO Path 2: Single Row by Cluster Join
•RBO Path 3: Single Row by Hash Cluster Key with Unique or Primary Key
•RBO Path 4: Single Row by Unique or Primary Key
•RBO Path 5: Clustered Join
•RBO Path 6: Hash Cluster Key
•RBO Path 7: Indexed Cluster Key
•RBO Path 8: Composite Index
•RBO Path 9: Single-Column Indexes
•RBO Path 10: Bounded Range Search on Indexed Columns
•RBO Path 11: Unbounded Range Search on Indexed Columns
•RBO Path 12: Sort Merge Join
•RBO Path 13: MAX or MIN of Indexed Column
•RBO Path 14: ORDER BY on Indexed Column
•RBO Path 15: Full Table Scan
Cost
 Query Transformer
 Four different query transformation techniques:
 •View Merging
 •Predicate Pushing
 •Subquery Unnesting
 •Query Rewrite with Materialized Views

 Estimator
 Three different types of measures:
 •Selectivity
 •Cardinality
 •Cost

 Plan Generator
Sample Environment Parameters
 Database Version = 9.2.0.8.0

 Compatible = 9.2.0.0.0

 Optimizer Features Enable = 9.2.0

 Optimizer Mode = CHOOSE

 Database Triggers => No (on_logon)
How to use Cost
•Gather index Statistics
BEGIN                                                                   •Set for session in SQL*PLUS
    SYS.DBMS_STATS.GATHER_INDEX_STATS (                                 ALTER SESSION SET OPTIMIZER_MODE=ALL_ROWS;
     OwnName         => ‘HR'
     ,IndName    => 'IDX_JOB_3'                                         •Use Hint /*+ ALL_ROWS */
    ,Estimate_Percent => NULL                                           Remove indexed columns inhibitors (+0 or ||'' )
    ,Degree      => NULL
    ,No_Invalidate    => FALSE);                                        SELECT /*+ ALL_ROWS */ column1, column2, ...
END;
/


                                                                        •Show Access Plan & Statistics in SQL*PLUS
•Set for session in a program                                           SET AUTOTRACE ON EXPLAIN STATISTICS;
BEGIN
    EXECUTE_IMMEDIATE(‘ALTER SESSION SET OPTIMIZER_MODE = ALL_ROWS’);   •Study the Access Plan
END;
/
Improve Performance in SQL*Plus
SYSTEM Variables Influencing SQL*Plus Performance
SET ARRAYSIZE
Sets the number of rows, called a batch, that SQL*Plus will fetch from the database at one time. Valid values are 1 to 5000. A large value increases the
efficiency of queries and subqueries that fetch many rows, but requires more memory. Values over approximately 100 provide little added performance.
ARRAYSIZE has no effect on the results of SQL*Plus operations other than increasing efficiency.
SET DEFINE OFF
Controls whether SQL*Plus parses scripts for substitution variables. If DEFINE is OFF, SQL*Plus does not parse scripts for substitution variables. If your
script does not use substitution variables, setting DEFINE OFF may result in some performance gains.
SET FLUSH OFF
Controls when output is sent to the user's display device. OFF allows the host operating system to buffer output which may improve performance by
reducing the amount of program input and output.
Use OFF only when you run a script that does not require user interaction and whose output you do not need to see until the script finishes running.
SET SERVEROUTPUT
Controls whether SQL*Plus checks for and displays DBMS output. If SERVEROUTPUT is OFF, SQL*Plus does not check for DBMS output and does not
display output after applicable SQL or PL/SQL statements. Suppressing this output checking and display may result in performance gains.
SET TRIMOUT ON
Determines whether SQL*Plus allows trailing blanks at the end of each displayed line. ON removes blanks at the end of each line, which may improve
performance especially when you access SQL*Plus from a slow communications device. TRIMOUT ON does not affect spooled output.
SET TRIMSPOOL ON
Determines whether SQL*Plus allows trailing blanks at the end of each spooled line. ON removes blanks at the end of each line, which may improve
performance especially when you access SQL*Plus from a slow communications device. TRIMSPOOL ON does not affect terminal output.
Improve Performance in SQL*Plus
•Improve performance and control in SQL*Plus
ALTER SESSION SET optimizer_mode=ALL_ROWS;
SET DEFINE OFF
SET FLUSH OFF
SET SERVEROUTPUT OFF
SET TRIMOUT ON
SET TRIMSPOOL ON
-- ARRAYSIZE DEFAULT = 15
SET ARRAYSIZE 5000
SET TIMI ON;


PROMPT SETA DBMS_APPLICATION_INFO.SET_MODULE
BEGIN
    DBMS_APPLICATION_INFO.SET_MODULE(‘XXXXXXXXX','');
END;
/
POC
WITHOUT PERFORMANCE PARAMETERS                 USING PERFORMANCE PARAMETERS
dbtest> SET PAGESIZE 9999                  dbtest> SET PAGESIZE 9999
dbtest> SET TIMI ON;                       dbtest> --Improve performance and control in SQL*Plus
dbtest> SELECT USERNAME FROM DBA_USERS;    dbtest> ALTER SESSION SET optimizer_mode=ALL_ROWS;
USERNAME                                   Session altered.
------------------------------             Elapsed: 00:00:00.48
...                                        dbtest> SET DEFINE OFF
...                                        dbtest> SET FLUSH OFF
...                                        dbtest> SET SERVEROUTPUT OFF
                                           dbtest> SET TRIMOUT ON
41632 rows selected.                       dbtest> SET TRIMSPOOL ON
Elapsed: 00:22:28.75                       dbtest> SET ARRAYSIZE 5000
dbtest> SPOOL OFF;                         dbtest> SET TIMI ON;
                                           dbtest> PROMPT SETA DBMS_APPLICATION_INFO.SET_MODULE
                                           SETA DBMS_APPLICATION_INFO.SET_MODULE
                                           dbtest> BEGIN
                                             2      DBMS_APPLICATION_INFO.SET_MODULE('XXXXXXXXX','');
                                             3 END;
                                             4 /
                                           PL/SQL procedure successfully completed.
                                           Elapsed: 00:00:00.48
                                           dbtest> SELECT USERNAME FROM DBA_USERS;

                                           USERNAME
                                           ------------------------------
                                           ....
                                           ....
                                           41632 rows selected.

                                           Elapsed: 00:00:27.07
                                           dbtest> SPOOL OFF;
Training & Reference
Resources at Oracle Website
•Performance Tuning Guide and Reference
http://docs.oracle.com/cd/B10500_01/server.920/a96533/toc.htm

•SQL Reference
http://docs.oracle.com/cd/B10500_01/server.920/a96540/toc.htm

•PL/SQL User's Guide and Reference
http://docs.oracle.com/cd/B10500_01/appdev.920/a96624/toc.htm
Thank you




Carlos Oliveira / May 31, 2012

Contenu connexe

Tendances

SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?Andrej Pashchenko
 
Optimizing MySQL Queries
Optimizing MySQL QueriesOptimizing MySQL Queries
Optimizing MySQL QueriesAchievers Tech
 
Oracle Database In-Memory and the Query Optimizer
Oracle Database In-Memory and the Query OptimizerOracle Database In-Memory and the Query Optimizer
Oracle Database In-Memory and the Query OptimizerChristian Antognini
 
Flashback - The Time Machine..
Flashback - The Time Machine..Flashback - The Time Machine..
Flashback - The Time Machine..Navneet Upneja
 
Oracle database performance tuning
Oracle database performance tuningOracle database performance tuning
Oracle database performance tuningYogiji Creations
 
Oracle-L11 using Oracle flashback technology-Mazenet solution
Oracle-L11 using  Oracle flashback technology-Mazenet solutionOracle-L11 using  Oracle flashback technology-Mazenet solution
Oracle-L11 using Oracle flashback technology-Mazenet solutionMazenetsolution
 
12c Database new features
12c Database new features12c Database new features
12c Database new featuresSandeep Redkar
 
MERGE SQL Statement: Lesser Known Facets
MERGE SQL Statement: Lesser Known FacetsMERGE SQL Statement: Lesser Known Facets
MERGE SQL Statement: Lesser Known FacetsAndrej Pashchenko
 
How to analyze and tune sql queries for better performance percona15
How to analyze and tune sql queries for better performance percona15How to analyze and tune sql queries for better performance percona15
How to analyze and tune sql queries for better performance percona15oysteing
 
DB2 LUW Access Plan Stability
DB2 LUW Access Plan StabilityDB2 LUW Access Plan Stability
DB2 LUW Access Plan Stabilitydmcmichael
 
2011 Collaborate IOUG Presentation
2011 Collaborate IOUG Presentation2011 Collaborate IOUG Presentation
2011 Collaborate IOUG PresentationBiju Thomas
 
Oracle flashback
Oracle flashbackOracle flashback
Oracle flashbackCambodia
 
Oracle Diagnostics : Joins - 1
Oracle Diagnostics : Joins - 1Oracle Diagnostics : Joins - 1
Oracle Diagnostics : Joins - 1Hemant K Chitale
 
Indexes: Structure, Splits and Free Space Management Internals
Indexes: Structure, Splits and Free Space Management InternalsIndexes: Structure, Splits and Free Space Management Internals
Indexes: Structure, Splits and Free Space Management InternalsChristian Antognini
 
Properly Use Parallel DML for ETL
Properly Use Parallel DML for ETLProperly Use Parallel DML for ETL
Properly Use Parallel DML for ETLAndrej Pashchenko
 
Oracle Database Performance Tuning Basics
Oracle Database Performance Tuning BasicsOracle Database Performance Tuning Basics
Oracle Database Performance Tuning Basicsnitin anjankar
 
Advanced functions in PL SQL
Advanced functions in PL SQLAdvanced functions in PL SQL
Advanced functions in PL SQLHosein Zare
 

Tendances (20)

SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?
 
Optimizing MySQL Queries
Optimizing MySQL QueriesOptimizing MySQL Queries
Optimizing MySQL Queries
 
Oracle Database In-Memory and the Query Optimizer
Oracle Database In-Memory and the Query OptimizerOracle Database In-Memory and the Query Optimizer
Oracle Database In-Memory and the Query Optimizer
 
Flashback - The Time Machine..
Flashback - The Time Machine..Flashback - The Time Machine..
Flashback - The Time Machine..
 
Oracle database performance tuning
Oracle database performance tuningOracle database performance tuning
Oracle database performance tuning
 
Oracle-L11 using Oracle flashback technology-Mazenet solution
Oracle-L11 using  Oracle flashback technology-Mazenet solutionOracle-L11 using  Oracle flashback technology-Mazenet solution
Oracle-L11 using Oracle flashback technology-Mazenet solution
 
Explain that explain
Explain that explainExplain that explain
Explain that explain
 
Oracle 12c SPM
Oracle 12c SPMOracle 12c SPM
Oracle 12c SPM
 
12c Database new features
12c Database new features12c Database new features
12c Database new features
 
MERGE SQL Statement: Lesser Known Facets
MERGE SQL Statement: Lesser Known FacetsMERGE SQL Statement: Lesser Known Facets
MERGE SQL Statement: Lesser Known Facets
 
Oracle SQL Tuning
Oracle SQL TuningOracle SQL Tuning
Oracle SQL Tuning
 
How to analyze and tune sql queries for better performance percona15
How to analyze and tune sql queries for better performance percona15How to analyze and tune sql queries for better performance percona15
How to analyze and tune sql queries for better performance percona15
 
DB2 LUW Access Plan Stability
DB2 LUW Access Plan StabilityDB2 LUW Access Plan Stability
DB2 LUW Access Plan Stability
 
2011 Collaborate IOUG Presentation
2011 Collaborate IOUG Presentation2011 Collaborate IOUG Presentation
2011 Collaborate IOUG Presentation
 
Oracle flashback
Oracle flashbackOracle flashback
Oracle flashback
 
Oracle Diagnostics : Joins - 1
Oracle Diagnostics : Joins - 1Oracle Diagnostics : Joins - 1
Oracle Diagnostics : Joins - 1
 
Indexes: Structure, Splits and Free Space Management Internals
Indexes: Structure, Splits and Free Space Management InternalsIndexes: Structure, Splits and Free Space Management Internals
Indexes: Structure, Splits and Free Space Management Internals
 
Properly Use Parallel DML for ETL
Properly Use Parallel DML for ETLProperly Use Parallel DML for ETL
Properly Use Parallel DML for ETL
 
Oracle Database Performance Tuning Basics
Oracle Database Performance Tuning BasicsOracle Database Performance Tuning Basics
Oracle Database Performance Tuning Basics
 
Advanced functions in PL SQL
Advanced functions in PL SQLAdvanced functions in PL SQL
Advanced functions in PL SQL
 

En vedette

Le Top 10 des Best Practices pour SQL Server
Le Top 10 des Best Practices pour SQL ServerLe Top 10 des Best Practices pour SQL Server
Le Top 10 des Best Practices pour SQL ServerMicrosoft Technet France
 
Challenger Banks in Europe: Challenge Accepted
Challenger Banks in Europe: Challenge AcceptedChallenger Banks in Europe: Challenge Accepted
Challenger Banks in Europe: Challenge AcceptedFrontline Ventures
 
Social Network Analysis & an Introduction to Tools
Social Network Analysis & an Introduction to ToolsSocial Network Analysis & an Introduction to Tools
Social Network Analysis & an Introduction to ToolsPatti Anklam
 
The Buyer's Journey - by Chris Lema
The Buyer's Journey - by Chris LemaThe Buyer's Journey - by Chris Lema
The Buyer's Journey - by Chris LemaChris Lema
 

En vedette (7)

Le Top 10 des Best Practices pour SQL Server
Le Top 10 des Best Practices pour SQL ServerLe Top 10 des Best Practices pour SQL Server
Le Top 10 des Best Practices pour SQL Server
 
KM 101
KM 101KM 101
KM 101
 
Challenger Banks in Europe: Challenge Accepted
Challenger Banks in Europe: Challenge AcceptedChallenger Banks in Europe: Challenge Accepted
Challenger Banks in Europe: Challenge Accepted
 
SQL Server 2012 Best Practices
SQL Server 2012 Best PracticesSQL Server 2012 Best Practices
SQL Server 2012 Best Practices
 
The Irish Tech Startup Guide
The Irish Tech Startup GuideThe Irish Tech Startup Guide
The Irish Tech Startup Guide
 
Social Network Analysis & an Introduction to Tools
Social Network Analysis & an Introduction to ToolsSocial Network Analysis & an Introduction to Tools
Social Network Analysis & an Introduction to Tools
 
The Buyer's Journey - by Chris Lema
The Buyer's Journey - by Chris LemaThe Buyer's Journey - by Chris Lema
The Buyer's Journey - by Chris Lema
 

Similaire à Sql and PL/SQL Best Practices I

Presentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12cPresentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12cRonald Francisco Vargas Quesada
 
NOCOUG_201311_Fine_Tuning_Execution_Plans.pdf
NOCOUG_201311_Fine_Tuning_Execution_Plans.pdfNOCOUG_201311_Fine_Tuning_Execution_Plans.pdf
NOCOUG_201311_Fine_Tuning_Execution_Plans.pdfcookie1969
 
Top 10 tips for Oracle performance
Top 10 tips for Oracle performanceTop 10 tips for Oracle performance
Top 10 tips for Oracle performanceGuy Harrison
 
05_DP_300T00A_Optimize.pptx
05_DP_300T00A_Optimize.pptx05_DP_300T00A_Optimize.pptx
05_DP_300T00A_Optimize.pptxKareemBullard1
 
Oracle Query Optimizer - An Introduction
Oracle Query Optimizer - An IntroductionOracle Query Optimizer - An Introduction
Oracle Query Optimizer - An Introductionadryanbub
 
Explain the explain_plan
Explain the explain_planExplain the explain_plan
Explain the explain_planMaria Colgan
 
Beginners guide to_optimizer
Beginners guide to_optimizerBeginners guide to_optimizer
Beginners guide to_optimizerMaria Colgan
 
Evolution of Performance Management: Oracle 12c adaptive optimizations - ukou...
Evolution of Performance Management: Oracle 12c adaptive optimizations - ukou...Evolution of Performance Management: Oracle 12c adaptive optimizations - ukou...
Evolution of Performance Management: Oracle 12c adaptive optimizations - ukou...Nelson Calero
 
Presentation interpreting execution plans for sql statements
Presentation    interpreting execution plans for sql statementsPresentation    interpreting execution plans for sql statements
Presentation interpreting execution plans for sql statementsxKinAnx
 
Query Optimization with MySQL 5.6: Old and New Tricks
Query Optimization with MySQL 5.6: Old and New TricksQuery Optimization with MySQL 5.6: Old and New Tricks
Query Optimization with MySQL 5.6: Old and New TricksMYXPLAIN
 
Tony jambu (obscure) tools of the trade for tuning oracle sq ls
Tony jambu   (obscure) tools of the trade for tuning oracle sq lsTony jambu   (obscure) tools of the trade for tuning oracle sq ls
Tony jambu (obscure) tools of the trade for tuning oracle sq lsInSync Conference
 
Tony Jambu (obscure) tools of the trade for tuning oracle sq ls
Tony Jambu   (obscure) tools of the trade for tuning oracle sq lsTony Jambu   (obscure) tools of the trade for tuning oracle sq ls
Tony Jambu (obscure) tools of the trade for tuning oracle sq lsInSync Conference
 
My Experience Using Oracle SQL Plan Baselines 11g/12c
My Experience Using Oracle SQL Plan Baselines 11g/12cMy Experience Using Oracle SQL Plan Baselines 11g/12c
My Experience Using Oracle SQL Plan Baselines 11g/12cNelson Calero
 
Web Cloud Computing SQL Server - Ferrara University
Web Cloud Computing SQL Server  -  Ferrara UniversityWeb Cloud Computing SQL Server  -  Ferrara University
Web Cloud Computing SQL Server - Ferrara Universityantimo musone
 
D73549GC10_06.pptx
D73549GC10_06.pptxD73549GC10_06.pptx
D73549GC10_06.pptxVLQuyNhn
 
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...Alex Zaballa
 
Understanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
Understanding Query Optimization with ‘regular’ and ‘Exadata’ OracleUnderstanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
Understanding Query Optimization with ‘regular’ and ‘Exadata’ OracleGuatemala User Group
 
MySQL sys schema deep dive
MySQL sys schema deep diveMySQL sys schema deep dive
MySQL sys schema deep diveMark Leith
 

Similaire à Sql and PL/SQL Best Practices I (20)

Presentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12cPresentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12c
 
NOCOUG_201311_Fine_Tuning_Execution_Plans.pdf
NOCOUG_201311_Fine_Tuning_Execution_Plans.pdfNOCOUG_201311_Fine_Tuning_Execution_Plans.pdf
NOCOUG_201311_Fine_Tuning_Execution_Plans.pdf
 
Top 10 tips for Oracle performance
Top 10 tips for Oracle performanceTop 10 tips for Oracle performance
Top 10 tips for Oracle performance
 
05_DP_300T00A_Optimize.pptx
05_DP_300T00A_Optimize.pptx05_DP_300T00A_Optimize.pptx
05_DP_300T00A_Optimize.pptx
 
Oracle Query Optimizer - An Introduction
Oracle Query Optimizer - An IntroductionOracle Query Optimizer - An Introduction
Oracle Query Optimizer - An Introduction
 
Explain the explain_plan
Explain the explain_planExplain the explain_plan
Explain the explain_plan
 
Beginners guide to_optimizer
Beginners guide to_optimizerBeginners guide to_optimizer
Beginners guide to_optimizer
 
Evolution of Performance Management: Oracle 12c adaptive optimizations - ukou...
Evolution of Performance Management: Oracle 12c adaptive optimizations - ukou...Evolution of Performance Management: Oracle 12c adaptive optimizations - ukou...
Evolution of Performance Management: Oracle 12c adaptive optimizations - ukou...
 
Presentation interpreting execution plans for sql statements
Presentation    interpreting execution plans for sql statementsPresentation    interpreting execution plans for sql statements
Presentation interpreting execution plans for sql statements
 
Query Optimization with MySQL 5.6: Old and New Tricks
Query Optimization with MySQL 5.6: Old and New TricksQuery Optimization with MySQL 5.6: Old and New Tricks
Query Optimization with MySQL 5.6: Old and New Tricks
 
Tony jambu (obscure) tools of the trade for tuning oracle sq ls
Tony jambu   (obscure) tools of the trade for tuning oracle sq lsTony jambu   (obscure) tools of the trade for tuning oracle sq ls
Tony jambu (obscure) tools of the trade for tuning oracle sq ls
 
Tony Jambu (obscure) tools of the trade for tuning oracle sq ls
Tony Jambu   (obscure) tools of the trade for tuning oracle sq lsTony Jambu   (obscure) tools of the trade for tuning oracle sq ls
Tony Jambu (obscure) tools of the trade for tuning oracle sq ls
 
SQL Tunning
SQL TunningSQL Tunning
SQL Tunning
 
My Experience Using Oracle SQL Plan Baselines 11g/12c
My Experience Using Oracle SQL Plan Baselines 11g/12cMy Experience Using Oracle SQL Plan Baselines 11g/12c
My Experience Using Oracle SQL Plan Baselines 11g/12c
 
Web Cloud Computing SQL Server - Ferrara University
Web Cloud Computing SQL Server  -  Ferrara UniversityWeb Cloud Computing SQL Server  -  Ferrara University
Web Cloud Computing SQL Server - Ferrara University
 
D73549GC10_06.pptx
D73549GC10_06.pptxD73549GC10_06.pptx
D73549GC10_06.pptx
 
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...
 
Understanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
Understanding Query Optimization with ‘regular’ and ‘Exadata’ OracleUnderstanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
Understanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
 
Stored procedure with cursor
Stored procedure with cursorStored procedure with cursor
Stored procedure with cursor
 
MySQL sys schema deep dive
MySQL sys schema deep diveMySQL sys schema deep dive
MySQL sys schema deep dive
 

Dernier

Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 

Dernier (20)

Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 

Sql and PL/SQL Best Practices I

  • 1. Carlos Oliveira / May 31, 2012
  • 2. Agenda  Oracle Database Overview  Introduction  What isSQL & PL/SQL  Performance X Organization  What is an Access Plan  Access Plan  Rules  Cost  Our Environment Parameters  How to use Cost  Improve Performance in SQL*Plus  POC  Training & Reference  Questions
  • 3. Introduction I am a forward-looking Information Systems Architect with a solid Oracle DBA background comprising the daily infrastructure tasks of the DBA, several projects as a Data Modeler, and performance management projects. I Started on the mainframe business, and soon had a deep dive in application development for Oracle databases. After acquiring an Oracle certification, I worked on performance enhancement for applications using Oracle databases, and later worked several years as an infrastructure DBA, later I worked on data modeling projects and more recently a performance management project, on both application and database layers.
  • 4. “The limits of my language mean the limits of my world.” Ludwig Wittgenstein
  • 5. What is SQL & PL/SQL •SQL - Is a data oriented language for selecting and manipulating sets of data. •It has to be parsed and transformed by the database into an execution plan of how to access the data •The execution plan can be different due to environment changes •PL/SQL is a procedural language to create applications. •It is already a series of statements and commands to be executed by the database •The program flow doesn't change, no matter the changes in the environment.
  • 6. Performance X Organization PERFORMANCE ORGANIZATION SQL •Faster access to data •Easier to understand the access plan •Faster retrieval of data •Easier to maintain the query PL/SQL •Faster execution of the program •Easier to read the code •Less memory used •Easier to maintain the program
  • 7. What is an Access Plan It is created by Oracle optimizer for SELECT, UPDATE, INSERT, and DELETE statements. A statement's execution plan is the sequence of operations Oracle performs to run the statement. The row source tree is the core of the execution plan. It shows the following information: •An ordering of the tables referenced by the statement •An access method for each table mentioned in the statement •A join method for tables affected by join operations in the statement •Data operations like filter, sort, or aggregation In addition to the row source tree, the plan table contains information about the following: •Optimization, such as the cost and cardinality of each operation •Partitioning, such as the set of accessed partitions •Parallel execution, such as the distribution method of join inputs The ACCESS PLAN results let you determine whether the optimizer selects a particular execution plan, such as, nested loops join. It also helps you to understand the optimizer decisions, such as why the optimizer chose a nested loops join instead of a hash join, and lets you understand the performance of a query.
  • 8. Access Plan SELECT e.employee_id, j.job_title, e.salary, d.department_name FROM employees e, jobs j, departments d WHERE e.employee_id < 103 AND e.job_id = j.job_id AND e.department_id = d.department_id; ----------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| ----------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 3 | 189 | 10 (10)| | 1 | NESTED LOOPS | | 3 | 189 | 10 (10)| | 2 | NESTED LOOPS | | 3 | 141 | 7 (15)| |* 3 | TABLE ACCESS FULL | EMPLOYEES | 3 | 60 | 4 (25)| | 4 | TABLE ACCESS BY INDEX ROWID| JOBS | 19 | 513 | 2 (50)| |* 5 | INDEX UNIQUE SCAN | JOB_ID_PK | 1 | | | | 6 | TABLE ACCESS BY INDEX ROWID | DEPARTMENTS | 27 | 432 | 2 (50)| |* 7 | INDEX UNIQUE SCAN | DEPT_ID_PK | 1 | | | ----------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 3 - filter("E"."EMPLOYEE_ID"<103) 5 - access("E"."JOB_ID"="J"."JOB_ID") 7 - access("E"."DEPARTMENT_ID"="D"."DEPARTMENT_ID")
  • 10. What Influences the Access Plan COST Different Costs Data volume and statistics Bind variable types RULE •Order of the tables in the FROM clause •Order of the join conditions in the WHERE/JOIN clause •Collected Statistics •Rules GENERAL •Different Schemas/Databases/Users •Schema changes (usually changes in indexes) between the two operations. •Initialization parameters - set globally or at session level •Hints •Indexed Columns inhibitors (+0 or ||'' )
  • 11. Rules •RBO Path 1: Single Row by Rowid •RBO Path 2: Single Row by Cluster Join •RBO Path 3: Single Row by Hash Cluster Key with Unique or Primary Key •RBO Path 4: Single Row by Unique or Primary Key •RBO Path 5: Clustered Join •RBO Path 6: Hash Cluster Key •RBO Path 7: Indexed Cluster Key •RBO Path 8: Composite Index •RBO Path 9: Single-Column Indexes •RBO Path 10: Bounded Range Search on Indexed Columns •RBO Path 11: Unbounded Range Search on Indexed Columns •RBO Path 12: Sort Merge Join •RBO Path 13: MAX or MIN of Indexed Column •RBO Path 14: ORDER BY on Indexed Column •RBO Path 15: Full Table Scan
  • 12. Cost Query Transformer Four different query transformation techniques: •View Merging •Predicate Pushing •Subquery Unnesting •Query Rewrite with Materialized Views Estimator Three different types of measures: •Selectivity •Cardinality •Cost Plan Generator
  • 13. Sample Environment Parameters Database Version = 9.2.0.8.0 Compatible = 9.2.0.0.0 Optimizer Features Enable = 9.2.0 Optimizer Mode = CHOOSE Database Triggers => No (on_logon)
  • 14. How to use Cost •Gather index Statistics BEGIN •Set for session in SQL*PLUS SYS.DBMS_STATS.GATHER_INDEX_STATS ( ALTER SESSION SET OPTIMIZER_MODE=ALL_ROWS; OwnName => ‘HR' ,IndName => 'IDX_JOB_3' •Use Hint /*+ ALL_ROWS */ ,Estimate_Percent => NULL Remove indexed columns inhibitors (+0 or ||'' ) ,Degree => NULL ,No_Invalidate => FALSE); SELECT /*+ ALL_ROWS */ column1, column2, ... END; / •Show Access Plan & Statistics in SQL*PLUS •Set for session in a program SET AUTOTRACE ON EXPLAIN STATISTICS; BEGIN EXECUTE_IMMEDIATE(‘ALTER SESSION SET OPTIMIZER_MODE = ALL_ROWS’); •Study the Access Plan END; /
  • 15. Improve Performance in SQL*Plus SYSTEM Variables Influencing SQL*Plus Performance SET ARRAYSIZE Sets the number of rows, called a batch, that SQL*Plus will fetch from the database at one time. Valid values are 1 to 5000. A large value increases the efficiency of queries and subqueries that fetch many rows, but requires more memory. Values over approximately 100 provide little added performance. ARRAYSIZE has no effect on the results of SQL*Plus operations other than increasing efficiency. SET DEFINE OFF Controls whether SQL*Plus parses scripts for substitution variables. If DEFINE is OFF, SQL*Plus does not parse scripts for substitution variables. If your script does not use substitution variables, setting DEFINE OFF may result in some performance gains. SET FLUSH OFF Controls when output is sent to the user's display device. OFF allows the host operating system to buffer output which may improve performance by reducing the amount of program input and output. Use OFF only when you run a script that does not require user interaction and whose output you do not need to see until the script finishes running. SET SERVEROUTPUT Controls whether SQL*Plus checks for and displays DBMS output. If SERVEROUTPUT is OFF, SQL*Plus does not check for DBMS output and does not display output after applicable SQL or PL/SQL statements. Suppressing this output checking and display may result in performance gains. SET TRIMOUT ON Determines whether SQL*Plus allows trailing blanks at the end of each displayed line. ON removes blanks at the end of each line, which may improve performance especially when you access SQL*Plus from a slow communications device. TRIMOUT ON does not affect spooled output. SET TRIMSPOOL ON Determines whether SQL*Plus allows trailing blanks at the end of each spooled line. ON removes blanks at the end of each line, which may improve performance especially when you access SQL*Plus from a slow communications device. TRIMSPOOL ON does not affect terminal output.
  • 16. Improve Performance in SQL*Plus •Improve performance and control in SQL*Plus ALTER SESSION SET optimizer_mode=ALL_ROWS; SET DEFINE OFF SET FLUSH OFF SET SERVEROUTPUT OFF SET TRIMOUT ON SET TRIMSPOOL ON -- ARRAYSIZE DEFAULT = 15 SET ARRAYSIZE 5000 SET TIMI ON; PROMPT SETA DBMS_APPLICATION_INFO.SET_MODULE BEGIN DBMS_APPLICATION_INFO.SET_MODULE(‘XXXXXXXXX',''); END; /
  • 17. POC WITHOUT PERFORMANCE PARAMETERS USING PERFORMANCE PARAMETERS dbtest> SET PAGESIZE 9999 dbtest> SET PAGESIZE 9999 dbtest> SET TIMI ON; dbtest> --Improve performance and control in SQL*Plus dbtest> SELECT USERNAME FROM DBA_USERS; dbtest> ALTER SESSION SET optimizer_mode=ALL_ROWS; USERNAME Session altered. ------------------------------ Elapsed: 00:00:00.48 ... dbtest> SET DEFINE OFF ... dbtest> SET FLUSH OFF ... dbtest> SET SERVEROUTPUT OFF dbtest> SET TRIMOUT ON 41632 rows selected. dbtest> SET TRIMSPOOL ON Elapsed: 00:22:28.75 dbtest> SET ARRAYSIZE 5000 dbtest> SPOOL OFF; dbtest> SET TIMI ON; dbtest> PROMPT SETA DBMS_APPLICATION_INFO.SET_MODULE SETA DBMS_APPLICATION_INFO.SET_MODULE dbtest> BEGIN 2 DBMS_APPLICATION_INFO.SET_MODULE('XXXXXXXXX',''); 3 END; 4 / PL/SQL procedure successfully completed. Elapsed: 00:00:00.48 dbtest> SELECT USERNAME FROM DBA_USERS; USERNAME ------------------------------ .... .... 41632 rows selected. Elapsed: 00:00:27.07 dbtest> SPOOL OFF;
  • 18. Training & Reference Resources at Oracle Website •Performance Tuning Guide and Reference http://docs.oracle.com/cd/B10500_01/server.920/a96533/toc.htm •SQL Reference http://docs.oracle.com/cd/B10500_01/server.920/a96540/toc.htm •PL/SQL User's Guide and Reference http://docs.oracle.com/cd/B10500_01/appdev.920/a96624/toc.htm
  • 19. Thank you Carlos Oliveira / May 31, 2012