Ensuring Optimal Performance. Vivek Sharma. 3 rd November 2012 Sangam 2012

Similar documents
1-2 Copyright Ó Oracle Corporation, All rights reserved.

Data Organization and Processing I

Oracle Database 11gR2 Optimizer Insights

Exploring Best Practices and Guidelines for Tuning SQL Statements

IT-Tage Dezember 2016 Frankfurt am Main Maritim Hotel

Full Throttle: SQL Tuning & Ressource Consumption Appr.

Estimating Cardinality: Use of Jonathan Lewis CBO methodology

Interpreting Explain Plan Output. John Mullins

RNDr. Michal Kopecký, Ph.D. Department of Software Engineering, Faculty of Mathematics and Physics, Charles University in Prague

SQL Gone Wild: Taming Bad SQL the Easy Way (or the Hard Way) Sergey Koltakov Product Manager, Database Manageability

ORACLE 8 OBJECT ORIENTED TECHNOLOGY ORACLE SOFTWARE STRUCTURES SERVER SIDE BACKGROUND PROCESSES DATABASE SERVER AND DATABASE INSTANCE

Infrastructure at your Service. In-Memory-Pläne für den 12.2-Optimizer: Teuer oder billig?

Oracle Architectural Components

Top 5 Issues that Cannot be Resolved by DBAs (other than missed bind variables)

Oracle DB-Tuning Essentials

Tuning SQL without the Tuning Pack. John Larkin JP Morgan Chase

Eternal Story on Temporary Objects

Oracle Database 18c. Gentle introduction to Polymorphic Tables Functions with Common patterns and sample use cases

Internals of Active Dataguard. Saibabu Devabhaktuni

<Insert Picture Here> Looking at Performance - What s new in MySQL Workbench 6.2

Oracle 9i Application Development and Tuning

DumpsKing. Latest exam dumps & reliable dumps VCE & valid certification king

Creating and Managing Tables Schedule: Timing Topic

Course Contents of ORACLE 9i

Advanced Oracle SQL Tuning v3.0 by Tanel Poder

MIS NETWORK ADMINISTRATOR PROGRAM

Vijay Mahawar

Oracle Tuning. Ashok Kapur Hawkeye Technology, Inc.

EMC Unisphere for VMAX Database Storage Analyzer

Oracle Database Performance Tuning, Benchmarks & Replication

<Insert Picture Here> DBA s New Best Friend: Advanced SQL Tuning Features of Oracle Database 11g

20 Essential Oracle SQL and PL/SQL Tuning Tips. John Mullins

Scaling To Infinity: Making Star Transformations Sing. Thursday 15-November 2012 Tim Gorman

Using Oracle STATSPACK to assist with Application Performance Tuning

Copyright 2012, Oracle and/or its affiliates. All rights reserved.

Answer: Reduce the amount of work Oracle needs to do to return the desired result.

Data Warehouse Tuning. Without SQL Modification

Oracle Database 10g : Administration Workshop II (Release 2) Course 36 Contact Hours

Join Methods. Franck Pachot CERN

20761 Querying Data with Transact SQL

Oracle Database 11g: SQL Tuning Workshop. Student Guide

Oracle database overview. OpenLab Student lecture 13 July 2006 Eric Grancher

Let s Tune Oracle8 for NT

Session id: The Self-Managing Database: Guided Application and SQL Tuning

Table of Contents. Oracle SQL PL/SQL Training Courses

D B M G Data Base and Data Mining Group of Politecnico di Torino

Advanced Oracle Performance Troubleshooting. Query Transformations Randolf Geist

Effect of Stats on Two Columns Optimizer Statistics on tables and indexes are vital. Arup Nanda

Latches Demystified. What is a Latch. Longtime Oracle DBA. Arup Nanda. From Glossary in Oracle Manuals:

Query Optimizer, Who Influences & How it works ++ optimization techniques

Oracle DB-Tuning Essentials

IT Best Practices Audit TCS offers a wide range of IT Best Practices Audit content covering 15 subjects and over 2200 topics, including:

Wolfgang Breitling.

Oracle Sql Tuning- A Framework

Common Performance Monitoring Mistakes

7. Query Processing and Optimization

Optimizing Database I/O

DBPLUS Performance Monitor for Oracle

Oracle Database 11g: Administration Workshop II

Triangle SQL Server User Group Adaptive Query Processing with Azure SQL DB and SQL Server 2017

RECO CKPT SMON ARCH PMON RMAN DBWR

Resolving Latch Contention

Projects. Corporate Trainer s Profile. CMM (Capability Maturity Model) level Project Standard:- TECHNOLOGIES

Oracle Notes Part-5. Two Types of Cursor : 1)Implicit Cursor

ORACLE DATABASE 12C INTRODUCTION

Introduction. Assessment Test. Chapter 1 Introduction to Performance Tuning 1. Chapter 2 Sources of Tuning Information 33

Oracle Database 12c Performance Management and Tuning

#1290. Oracle Core: InMemory Column Performing Databases GmbH Mitterteich / Germany

Tuesday, April 6, Inside SQL Server

EMC Unisphere for VMAX Database Storage Analyzer

CONFIGURING SQL SERVER FOR PERFORMANCE LIKE A MICROSOFT CERTIFIED MASTER

Advanced indexing methods Usage and Abusage. Riyaj Shamsudeen Ora!nternals

5 Integrity Constraints and Triggers

Oracle Performance Tuning. Overview of performance tuning strategies

IT100: Oracle Administration

Course Outline: Oracle Database 11g: Administration II. Learning Method: Instructor-led Classroom Learning. Duration: 5.

Tablespace Usage By Schema In Oracle 11g Query To Check Temp

DB2 9 for z/os Selected Query Performance Enhancements

<Insert Picture Here> Exadata MAA Best Practices Series Session #4: Exadata and OLTP Applications

1 Copyright 2011, Oracle and/or its affiliates. All rights reserved.

Performance Monitoring

Oracle PL/SQL - 12c & 11g [Basic PL/SQL & Advanced PL/SQL]

Application Containers an Introduction

Oracle Database: SQL and PL/SQL Fundamentals

RAC for Beginners. Arup Nanda Longtime Oracle DBA (and a beginner, always)

Databases. Relational Model, Algebra and operations. How do we model and manipulate complex data structures inside a computer system? Until

RAC Performance Monitoring and Diagnosis using Oracle Enterprise Manager. Kai Yu Senior System Engineer Dell Oracle Solutions Engineering

Seminar: Presenter: Oracle Database Objects Internals. Oren Nakdimon.

The Oracle DBMS Architecture: A Technical Introduction

Anthony AWR report INTERPRETATION PART I

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Slide 17-1

Things to remember when working with Oracle... (for UDB specialists)

EMC Unisphere for VMAX Database Storage Analyzer

Oracle BI 11g R1: Build Repositories Course OR102; 5 Days, Instructor-led

M.C.A. (CBCS) Sem.-III Examination November-2013 CCA-3004 : Database Concepts and Tools. Faculty Code: 003 Subject Code:

Course Outline. SQL Server Performance & Tuning For Developers. Course Description: Pre-requisites: Course Content: Performance & Tuning.

Querying Microsoft SQL Server (MOC 20461C)

Oracle Login Max Length Table Name 11g Column Varchar2

Oracle Database 11g: SQL Tuning Workshop

Adaptive Cursor Sharing: An Introduction

Transcription:

Ensuring Optimal Performance Vivek Sharma 3 rd November 2012 Sangam 2012

Who am I? Around 12 Years using Oracle Products Certified DBA versions 8i Specializes in Performance Optimization COE Lead with ACS India Regular Speaker for AIOUG A Technical Hands on Consultant Email : vivek.s.sharma at oracle.com Blog : viveklsharma.wordpress.com

Scalability User Load 900 800 700 600 500 400 300 200 100 0 4 8 12 16 20 24 28 32 Resources Available Resources > Total Work Done Linear 3

Scalability User Load 900 800 700 600 500 400 300 200 100 0 Desired Problem 4 8 12 16 20 24 28 32 Resources An Example of Available Resources < Total Work Done Linear Actual 4

Why this Session? Maintain Scalability Ensure High Availability Whose Responsibility? Development DBA Production DBA Developers Co-ordination between all of these is essential to meet the Objective 5

Agenda Architecture Operating System Statistics Production Architecture (An Example) Database Design Understanding CBO Selectivity Cardinality Indexing (Careful Consideration) Why is my SQL misbehaving? Application Design Inefficient Query Power of Scalar 6

Architecture Just Enough Diagram Shared Global Area - SGA User or App Server Shared Pool Network Or Local Log Buffer LGWR Redo Logs Oracle Server Process Commits / Rollbacks DBWR Disk Reads Buffer Cache 7

Life Cycle of a Cursor Syntax / Semantics Checks N Sharable Parent Cursor Available? Store Parent Cursor in Library Cache Y Sharable Child Cursor Available? Y N Query Transformation / Execution Plans Store child Cursor in Library Cache Execute 8

Agenda Architecture Operating System Statistics Production Architecture (An Example) Database Design Understanding CBO Selectivity Cardinality Indexing (Careful Consideration) Why is my SQL misbehaving? Application Design Inefficient Query Power of Scalar 9 9

Operating System Statistics CPU CPU Utilization SYS% = Time spent executing OS system calls (like file read, file write, allocate memory, etc) USR% = Time spent executing user code IDLE% = 100% - %USER - %SYS Run queue Run Q is the number of processes that can run and are waiting for CPU Thresholds to watch: %SYS < 20% overhead Total Run Queue > Total Number of CPUs 10

Operating System Statistics Memory Page Ins / Page Outs Memory being allocated due to a Demand Small, Incremental movement of Memory to the Swap Device Health of an Operating System is Key to Production Performance / Availability 11

Agenda Architecture Operating System Statistics Production Architecture (An Example) Database Design Understanding CBO Selectivity Cardinality Indexing (Careful Consideration) Why is my SQL misbehaving? Application Design Inefficient Query Power of Scalar 12

Production Architecture An Example 6. Summary Displayed 1. Client Connects Application Server 5. Summary Fetched 2. Authenticates 3. Validated 4. Fetch Summary Oracle Database Non-Oracle Database 7. Connections established in steps 2 & 4 are then Released for other requests 13

Production Architecture An Example Response Time Client to Application Server < ms Authentication & Validation < ms Fetch Summary < 5 ms The Challenge Client to Application Server < ms Authentication & Validation < ms What if Fetch Summary takes more time? A Profound Impact on the Entire Production System 14

Agenda Architecture Operating System Statistics Production Architecture (An Example) Database Design Understanding CBO Selectivity Cardinality Indexing (Careful Consideration) Why is my SQL misbehaving? Application Design Inefficient Query Power of Scalar 15

Database Design Number of Columns Table A with 300 Columns (A1..A300) In terms of performance Is there any difference between the three queries? select A1, A8 from A where rowid= some_value ; select A1, A50 from A where rowid= some_value ; select A1, A300 from A where rowid= some_value ; Additional LIO s due to Intra-Block Chaining ib.sql 16

Database Design Column Ordering Table A with 13 Columns (A1..A13) In terms of performance Is there any difference between the two queries? select A1 from A where rowid= some_value ; select A13 from A where rowid= some_value ; Additional CPU Cycles for Column Skipping CPU Cycles for Table Column Skip 20 CPU Cycles for Scanning Table Row 130 17

Database Design Number of Columns create table cpu_test as select * from all_objects where rownum<=50; explain plan for select owner from cpu_test; #Rows 50 #Blocks 4 CPU_Cost 35986 cpu_cost = 7121.44 x #blks + (130 x #Rows) + (20 x #Rows x Col#) select distinct cpu_cost from plan_table; cpu_costing.sql 18

Database Design Number of Columns 30000 25000 20000 15000 10000 5000 0 CPU Cycles 1 4 7 10 13 16 19 22 25 28 31 34 37 40 43 46 49 1st Column 13th Column 19

Agenda Architecture Operating System Statistics Production Architecture (An Example) Database Design Understanding CBO Selectivity Cardinality Indexing (Careful Consideration) Why is my SQL misbehaving? Application Design Inefficient Query Power of Scalar 20

Cost Based Optimizer Object Statistics Query Transformation I/O v/s CPU Least Costly Plan 10g mandatory System Statistics (9i Onwards 10g mandatory) Optimizer Parameters 21

Understanding CBO Selectivity Selectivity of Predicate deptno = :b1 is 1/NDV = 1/3 = 0.333 Selectivity of Predicate (deptno = :b1 and job = :b2) = (1/3) * (1/5) =.06667 Selectivity of Predicate (deptno = :b1 or job = :b2) = (1/3)+(1/5)-(1/3)*(1/5) =.46667 DEPTNO JOB SAL 10 MANAGER 2450 10 PRESIDENT 5000 10 CLERK 1300 20 MANAGER 2975 20 ANALYST 3000 20 CLERK 1100 20 CLERK 800 20 ANALYST 3000 30 SALESMAN 1250 30 SALESMAN 1500 30 SALESMAN 1600 30 CLERK 950 30 MANAGER 2850 30 SALESMAN 1250 NDV : # of Distinct Values 22

Understanding CBO Selectivity Lower the Selectivity, better the Predicates 1/Num_Distinct v/s Density Probability theory in calculating Selectivity of Predicates p(a and B) = p(a) x p(b) p(a or B) = p(a) + p(b) p(a) x p(b) 23

Understanding CBO Cardinality Estimated Number of Rows from a Row Source Next Step to calculation of Selectivity Cardinality = Selectivity x Number of Rows Very Crucial Affects Access Path / Join Orders Improper Calculation of Cardinality is a Root Cause to many of the Query Performance Issues 24

Understanding CBO Cardinality Cardinality of Predicate deptno = :b1 is (selectivity x #Rows) = 0.333 x 14 = 4.6662 = 5 Cardinality Deptno = Estimated Actual Change 10 5 3 20 5 5 = 30 5 6 DEPTNO JOB SAL 10 MANAGER 2450 10 PRESIDENT 5000 10 CLERK 1300 20 MANAGER 2975 20 ANALYST 3000 20 CLERK 1100 20 CLERK 800 20 ANALYST 3000 30 SALESMAN 1250 30 SALESMAN 1500 30 SALESMAN 1600 30 CLERK 950 30 MANAGER 2850 30 SALESMAN 1250 NDV : # of Distinct Values 25

Agenda Architecture Operating System Statistics Production Architecture (An Example) Database Design Understanding CBO Selectivity Cardinality Indexing (Careful Consideration) Why is my SQL misbehaving? Application Design Inefficient Query Power of Scalar 26

Indexing Careful Consideration Query 1 - Where X=:b1 Query 2 Where X=:b1 and Y=:b2 There is an Index on X. Adding Column Y needs Careful Consideration cf.sql 27

Agenda Architecture Operating System Statistics Production Architecture (An Example) Database Design Understanding CBO Selectivity Cardinality Indexing (Careful Consideration) Why is my SQL misbehaving? Application Design Inefficient Query Power of Scalar 28

Why is my SQL misbehaving? Misleading Object Statistics Misleading Column Level Statistics Correlation Issues (extended_stats.sql) Non-Default Optimizer Parameters In efficient Application Queries Dynamic Sampling / Cardinality Feedback rescues to some extent cf.sql 29

Agenda Architecture Operating System Statistics Production Architecture (An Example) Database Design Understanding CBO Selectivity Cardinality Indexing (Careful Consideration) Why is my SQL misbehaving? Application Design Inefficient Query Power of Scalar 30

Application Design (Entry Screen) Mandatory Column Optional Column, Leave Blank for ALL Optional Column, Leave Blank for ALL Optional Column, Leave Blank for ALL 31

Application Design (Entry Screen) SYNONYM 32

Application Design (Inefficient Query) Select a.owner, a.object_name, b.data_object_id, a.last_ddl_time From vivek_test a, vivek_test1 b Where a.object_type = :v_object_type and and and and a.temporary = nvl(:v_temporary,a.temporary) a.owner = nvl(:v_owner,a.owner) a.last_ddl_time = nvl(:v_last_ddl_time,a.last_ddl_time) a.object_id = b.object_id; nvl_query.sql 33

Application Design (Inefficient Query) SELECT groupid,supergroupid,branchid, LOANID, NAME, AMTFIN, CLOSUREDATE, PRODUCTFLAG,BRANCHDESC,STATUS,lesseeid,AGREEMENTNO FROM( SELECT A.AGREEMENTID LOANID,A.BRANCHID,A.AMTFIN, B.BRANCHDESC, A.AGREEMENTNO, C.CUSTOMERNAME NAME, A.PRODUCTFLAG, A.STATUS, A.CLOSUREDATE, A.LESSEEID, C.GROUPID, DSUPERGROUPID FROM LAD A, NBM B, NCM C, LEM D WHERE A.BRANCHID=B.BRANCHID AND A.LESSEEID=C.CUSTOMERID AND A.EMPLOYERID=D.EMPLOYERID(+) AND (A."STATUS='A' OR A.STATUS='C')) WHERE STATUS IN (:B1) AND LOANID = :b2 ORDER BY NAME; View Unique Column Why do I need ORDER BY? 34

Application Design (Inefficient Query) ORDER BY sort SORT ressource Sort statistics Sort width: 6142 Area size: 1048576 Max Area size: 1073735680 Degree: 1 Blocks to Sort: 1 Row size: 124 Total Rows: 1 Initial runs: 1 Merge passes: 1 IO Cost / pass: 934 Total IO sort cost: 468 Total CPU sort cost: 0 Total Temp space used: 0 Best:: JoinMethod: NestedLoop Cost: 472.00 Degree: 1 Resp: 471.50 Card: 0.22 Bytes: 103 *********************** Best so far: Table#: 0 cost: 1.0000 card: 0.2222 bytes: 41 Table#: 1 cost: 2.0000 card: 0.2222 bytes: 58 Table#: 2 cost: 3.0000 card: 0.2222 bytes: 76 Table#: 3 cost: 472.0000 card: 0.2222 bytes: 103 Cost of Sorting in Serial 35

Application Design (Inefficient Query) ****** Recost for parallel table scan ******* ORDER BY sort SORT ressource Sort statistics Sort width: 6142 Area size: 1048576 Max Area size: 1073735680 Degree: 1 Blocks to Sort: 1 Row size: 124 Total Rows: 1 Initial runs: 1 Merge passes: 1 IO Cost / pass: 934 Total IO sort cost: 468 Total CPU sort cost: 0 Total Temp space used: 0 SORT response Sort statistics Sort width: 638 Area size: 22369485 Max Area size: 111847424 Degree: 192 Blocks to Sort: 1 Row size: 124 Total Rows: 1 Initial runs: 1 Merge passes: 1 IO Cost / pass: 2 Total IO sort cost: 3 Total CPU sort cost: 0 Total Temp space used: 0 Best:: JoinMethod: NestedLoop Cost: 9.00 Degree: 192 Resp: 8.33 Card: 0.22 Bytes: 103 *********************** Best so far: Table#: 0 cost: 2.0000 card: 0.2222 bytes: 41 Table#: 1 cost: 3.0000 card: 0.2222 bytes: 58 Table#: 2 cost: 4.0000 card: 0.2222 bytes: 76 Table#: 3 cost: 9.0000 card: 0.2222 bytes: 103 Cost of Sorting in Parallel is Cheaper 36

Application Design (Power of Scalar) Select fn_getbranch(branchid), column1, column2.. From emp Where deptno in (10,20); Statistics EMP 2000 Rows DEPTNO 10 Distinct Values Where Deptno in (10,20) Returns 200 Rows What would be the total no. of executions of function fn_getbranch? test_scalar.sql 37

11/12/2012 11:21:01 AM 38