Xtreme SQL Tuning: The Tuning Limbo Iggy Fernandez Database Specialists, Inc. www.dbspecialists.com TCOUG Fall Meeting 2008.

Slides:



Advertisements
Similar presentations
Youre Smarter than a Database Overcoming the optimizers bad cardinality estimates.
Advertisements

Tuning Oracle SQL The Basics of Efficient SQLThe Basics of Efficient SQL Common Sense Indexing The Optimizer –Making SQL Efficient Finding Problem Queries.
Tuning: overview Rewrite SQL (Leccotech)Leccotech Create Index Redefine Main memory structures (SGA in Oracle) Change the Block Size Materialized Views,
Introduction to SQL Tuning Brown Bag Three essential concepts.
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.
M ODULE 4 D ATABASE T UNING Section 3 Application Performance 1 ITEC 450 Fall 2012.
Overview of performance tuning strategies Oracle Performance Tuning Allan Young June 2008.
CS 540 Database Management Systems
Finding the Performance Bottlenecks in Your Application Ian Jones and Roger Schrag Database Specialists, Inc. IOUG-A Live! 1999 Paper.
Agenda Overview of the optimizer How SQL is executed Identifying statements that need tuning Explain Plan Modifying the plan.
Virtual techdays INDIA │ 9-11 February 2011 SQL 2008 Query Tuning Praveen Srivatsa │ Principal SME – StudyDesk91 │ Director, AsthraSoft Consulting │ Microsoft.
Query Optimization 3 Cost Estimation R&G, Chapters 12, 13, 14 Lecture 15.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 11 Database Performance Tuning and Query Optimization.
Oracle 10g Database Administrator: Implementation and Administration Chapter 14 Proactive Maintenance.
1 How to improve SQL Performance with new Health Check Tool? Carlos Sierra Consulting Technical Advisor © 2012 Oracle Corporation – Proprietary and Confidential.
Optimization Exercises. Question 1 How do you think the following query should be computed? What indexes would you suggest to use? SELECT E.ename, D.mgr.
Chapter 9 Overview  Reasons to monitor SQL Server  Performance Monitoring and Tuning  Tools for Monitoring SQL Server  Common Monitoring and Tuning.
Module 8: Monitoring SQL Server for Performance. Overview Why to Monitor SQL Server Performance Monitoring and Tuning Tools for Monitoring SQL Server.
SQL Tuning Ohio Oracle User’s Group October 2002 © Copyright, Kris T. Mason, 2002.
Introduction and simple using of Oracle Logistics Information System Yaxian Yao
® Enterprise Manager/Management Packs Conference Call Phone Number: 1(888) Pass Code: CYBER.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Database Performance Tuning and Query Optimization.
Lecture 8 Index Organized Tables Clusters Index compression
Oracle Database Administration Lecture 6 Indexes, Optimizer, Hints.
1 Robert Wijnbelt Health Check your Database A Performance Tuning Methodology.
Improving Efficiency of I/O Bound Systems More Memory, Better Caching Newer and Faster Disk Drives Set Object Access (SETOBJACC) Reorganize (RGZPFM) w/
Oracle9i Performance Tuning Chapter 1 Performance Tuning Overview.
Deadlocks For $1000: Let’s Play Jeopardy! Iggy Fernandez Database Specialists, Inc. TCOUG Fall Meeting 2008.
The Self-Managing Database: Guided Application and SQL Tuning Mohamed Ziauddin Consulting Member of Technical Staff Oracle Corporation Session id:
1 RAC Internals Julian Dyke Independent Consultant Web Version juliandyke.com © 2007 Julian Dyke.
Michał Kwiatek – CERN /IT-DES Performance Optimization and Tuning 1 Data Management and Database Technologies Performance Optimization and Tuning Avoid.
Oracle Tuning Considerations. Agenda Why Tune ? Why Tune ? Ways to Improve Performance Ways to Improve Performance Hardware Hardware Software Software.
Oracle Tuning Ashok Kapur Hawkeye Technology, Inc.
1 What’s Up with dbms_stats? Terry Sutton Database Specialists, Inc.
Basic Optimization DB Workshop for LHC online/offline developers CERN January
11-1 Improve response time of interactive programs. Improve batch throughput. To ensure scalability of applications load vs. performance. Reduce system.
1 All Powder Board and Ski Oracle 9i Workbook Chapter 9: Database Administration Jerry Post Copyright © 2003.
© 2008 Quest Software, Inc. ALL RIGHTS RESERVED. Perfmon and Profiler 101.
Star Transformations Tony Hasler, UKOUG Birmingham 2012 Tony Hasler, Anvil Computer Services Ltd.
Mark Inman U.S. Navy (Naval Sea Logistics Center) Session #213 Analytic SQL for Beginners.
By Shanna Epstein IS 257 September 16, Cnet.com Provides information, tools, and advice to help customers decide what to buy and how to get the.
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.
1 Oracle Enterprise Manager Slides from Dominic Gélinas CIS
Module 4 Database SQL Tuning Section 3 Application Performance.
Indexes and Views Unit 7.
University of Sunderland COM 220 Lecture Ten Slide 1 Database Performance.
Chapter 5 Index and Clustering
Tracing Individual Users in Connection-pooled Environments with Oracle 10g Terry Sutton Database Specialists, Inc.
10g Tuning Highlights Presenter JEREMY SCHNEIDER Senior Consultant, ITC Technology Services.
Indexes- What?  Optional structures associated with tables  Provides a quick access path to table data  You can create indexes on one or more columns.
1 Chapter 9 Tuning Table Access. 2 Overview Improve performance of access to single table Explain access methods – Full Table Scan – Index – Partition-level.
Database Performance Eric Grancher - Nilo Segura Oracle Support Team IT/DES.
Ad Hoc User or Application Cost-based Data Dictionary Statistics Rule-based Execution Plan Asks the question: All people and their grades in a list giving.
Copyright © 2009 Rolta International, Inc., All Rights Reserved Michael R. Messina, Management Consultant Rolta-TUSC, Oracle Open World 2009 (60 min) ID#:
Oracle9i Developer: PL/SQL Programming Chapter 11 Performance Tuning.
8 Copyright © 2005, Oracle. All rights reserved. Gathering Statistics.
Copyright Sammamish Software Services All rights reserved. 1 Prog 140  SQL Server Performance Monitoring and Tuning.
Scott Fallen Sales Engineer, SQL Sentry Blog: scottfallen.blogspot.com.
LAB: Web-scale Data Management on a Cloud Lab 11. Query Execution Plan 2011/05/27.
Diving into Query Execution Plans ED POLLACK AUTOTASK CORPORATION DATABASE OPTIMIZATION ENGINEER.
SQL Advanced Monitoring Using DMV, Extended Events and Service Broker Javier Villegas – DBA | MCP | MCTS.
1 Copyright © 2005, Oracle. All rights reserved. Oracle Database Administration: Overview.
Tuning Oracle SQL The Basics of Efficient SQL Common Sense Indexing
Data, Space and Transaction Processing
Index An index is a performance-tuning method of allowing faster retrieval of records. An index creates an entry for each value that appears in the indexed.
EXPLAIN and AUTOTRACE.
What’s Up with dbms_stats?
Recommending Materialized Views and Indexes with the IBM DB2 Design Advisor (Automating Physical Database Design) Jarek Gryz.
Performance Tuning ETL Process
Presentation transcript:

Xtreme SQL Tuning: The Tuning Limbo Iggy Fernandez Database Specialists, Inc. TCOUG Fall Meeting 2008

2 Speaker Qualifications  Oracle DBA at Database Specialists  Editor of the Journal of the Northern California Oracle Users Group  Author of Beginning Oracle Database 11g Administration

3 Definition of SQL Efficiency  Amount of computing resources used in producing the output  Elapsed time is not a good proxy  Logical reads is a good proxy

4 Identifying Inefficient SQL Statements  Enterprise Manager, SQL Developer, Toad  Tracing sessions –dbms_monitor.session_trace_enable –dbms_monitor.session_trace_disable  Statspack reports  Diagnostic Pack –AWR –ADDM

5 Causes of Inefficient SQL  Optimizer limitations  Many ways to write a query  Failure to use advanced features –Analytic Functions  Ad-hoc queries  Poor logical and physical database design  Inadequate database maintenance

6 Other Performance Inhibitors  Hardware limitations  Mixed workloads  Contention

7 Ways to Improve SQL— Physical Database Design  Indexes –B-tree indexes –Reverse key indexes –Function-based indexes –Indexes on virtual columns –Bitmap indexes  Clusters  IOTs  Partitioning

8 Ways To Improve SQL— Hints  LEADING  ORDERED  INDEX  FULL  NO_MERGE  USE_NL, USE_HASH, USE_MERGE

9 Ways To Improve SQL— Statistics  ENABLE_JOB, DISABLE_JOB, START_JOB  GATHER_*_STATS  DELETE_*_STATS  EXPORT_*_STATS  IMPORT_*_STATS  RESTORE_*_STATS  LOCK_*_STATS  SET_*_PREFS

10 Statistics— Quotable Quotes “It astonishes me how many shops prohibit any unapproved production changes and yet re- analyze schema stats weekly. Evidently, they do not understand that the purpose of schema re- analysis is to change their production SQL execution plans, and they act surprised when performance changes!” —Don Burleson

11 Statistics— Quotable Quotes “I have advised many customers to stop analyzing, thereby creating a more stable environment overnight.” —Mogens Norgaard in the NoCOUG Journal

12 Statistics —Quotable Quotes “Oh, and by the way, could you please stop gathering statistics constantly? I don’t know much about databases, but I do think I know the following: small tables tend to stay small, large tables tend to stay large, unique indexes have a tendency to stay unique, and non-unique indexes often stay non-unique.” —Dave Ensor as remembered by Mogens Norgaard and quoted in the NoCOUG Journal

13 Statistics—Quotable Quotes “Monitor the changes in execution plans and/or performance for the individual SQL statements … and perhaps as a consequence re-gather stats. That way, you’d leave stuff alone that works very well, thank you, and you’d put your efforts into exactly the things that have become worse.” —Mogens Norgaard, in the NoCOUG Journal

14 Statistics —Quotable Quotes “It is my firm belief that most scheduled statistics- gathering jobs do not cause much harm only because (most) changes in the statistics were insignificant as far as the optimizer is concerned—meaning that it was an exercise in futility.” —Wolfgang Breitling in the NoCOUG Journal

15 Statistics —Quotable Quotes “There are some statistics about your data that can be left unchanged for a long time, possibly forever; there are some statistics that need to be changed periodically; and there are some statistics that need to be changed constantly. … The biggest problem is that you need to understand the data.” —Jonathan Lewis in the NoCOUG Journal

16 Tuning By Example CREATE TABLE my_tables AS SELECT dba_tables.* FROM dba_tables; CREATE TABLE my_indexes AS SELECT dba_indexes.* FROM dba_tables, dba_indexes WHERE dba_tables.owner = dba_indexes.table_owner AND dba_tables.table_name = dba_indexes.table_name;

17 Tables Which Have a Bitmap Index EXEC :index_type := 'BITMAP'; SELECT DISTINCT my_tables.owner, my_tables.table_name, my_tables.tablespace_name FROM my_tables, my_indexes WHERE my_tables.owner = my_indexes.table_owner AND my_tables.table_name = my_indexes.table_name AND my_indexes.index_type = :index_type;

18 Autotrace ALTER SYSTEM FLUSH SHARED_POOL; ALTER SYSTEM FLUSH BUFFER_CACHE; Statistics recursive calls 0 db block gets 498 consistent gets 137 physical reads 0 redo size 645 bytes sent via SQL*Net to client 381 bytes received via SQL*Net from client 2 SQL*Net roundtrips to/from client 37 sorts (memory) 0 sorts (disk) 5 rows processed

19 Autotrace ALTER SYSTEM FLUSH BUFFER_CACHE; Statistics recursive calls 0 db block gets 108 consistent gets 104 physical reads 0 redo size 645 bytes sent via SQL*Net to client 381 bytes received via SQL*Net from client 2 SQL*Net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 5 rows processed

20 Baseline Statistics recursive calls 0 db block gets 108 consistent gets 0 physical reads 0 redo size 645 bytes sent via SQL*Net to client 381 bytes received via SQL*Net from client 2 SQL*Net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 5 rows processed

21 Execution Plan I | Operation | Name | Buffers | | HASH UNIQUE | | 108 | | HASH JOIN | | 108 | | TABLE ACCESS FULL| MY_INDEXES | 58 | | TABLE ACCESS FULL| MY_TABLES | 50 |

22 Constraints ALTER TABLE my_tables ADD (CONSTRAINT my_tables_pk PRIMARY KEY (owner, table_name)); ALTER TABLE my_indexes ADD (CONSTRAINT my_indexes_pk PRIMARY KEY (owner, index_name)); ALTER TABLE my_indexes ADD (CONSTRAINT my_indexes_fk1 FOREIGN KEY (table_owner, table_name) REFERENCES my_tables);

23 Indexes CREATE INDEX my_indexes_i1 ON my_indexes (index_type); CREATE INDEX my_indexes_fk1 ON my_indexes (table_owner, table_name);

24 Statistics EXEC DBMS_STATS.gather_table_stats(ownname=>'IFERNANDEZ',tabname=>'MY_TABLES'); EXEC DBMS_STATS.gather_table_stats(ownname=>'IFERNANDEZ',tabname=>'MY_INDEXES'); EXEC DBMS_STATS.gather_index_stats(ownname=>'IFERNANDEZ',indname=>'MY_TABLES_PK'); EXEC DBMS_STATS.gather_index_stats(ownname=>'IFERNANDEZ',indname=>'MY_INDEXES_I1'); EXEC DBMS_STATS.gather_index_stats(ownname=>'IFERNANDEZ',indname=>'MY_INDEXES_FK1');

25 Execution Plan II | Operation | Name | Buffers | | HASH UNIQUE | | 55 | | HASH JOIN | | 55 | | TABLE ACCESS BY INDEX ROWID| MY_INDEXES | 5 | | INDEX RANGE SCAN | MY_INDEXES_I1 | 2 | | TABLE ACCESS FULL | MY_TABLES | 50 |

26 SQL Access Advisor VARIABLE tuning_task VARCHAR2(32); EXEC :tuning_task := dbms_sqltune.create_tuning_task (sql_id => '&sqlID'); EXEC dbms_sqltune.execute_tuning_task(task_name => :tuning_task); SELECT DBMS_SQLTUNE.report_tuning_task (:tuning_task) AS recommendations FROM DUAL;

27 Recommendations The execution plan of this statement can be improved by creating one or more indices. Recommendation (estimated benefit: 100%) Consider running the Access Advisor to improve the physical schema design or creating the recommended index. create index IFERNANDEZ.IDX$$_ on IFERNANDEZ.MY_TABLES('OWNER', 'TABLE_NAME','TABLESPACE_NAME');

28 Hints EXEC :index_type := 'BITMAP'; SELECT /*+ INDEX(MY_INDEXES (INDEX_TYPE)) INDEX(MY_TABLES (OWNER TABLE_NAME)) LEADING(MY_INDEXES MY_TABLES) USE_NL(MY_TABLES) */ DISTINCT my_tables.owner, my_tables.table_name, my_tables.tablespace_name FROM my_tables, my_indexes WHERE my_tables.owner = my_indexes.table_owner AND my_tables.table_name = my_indexes.table_name AND my_indexes.index_type = :index_type;

29 Execution Plan III | Operation | Name | Buffers | | HASH UNIQUE | | 37 | | NESTED LOOPS | | 37 | | TABLE ACCESS BY INDEX ROWID| MY_INDEXES | 5 | | INDEX RANGE SCAN | MY_INDEXES_I1 | 2 | | TABLE ACCESS BY INDEX ROWID| MY_TABLES | 32 | | INDEX UNIQUE SCAN | MY_TABLES_PK | 17 |

30 Cluster CREATE CLUSTER my_cluster (index_type VARCHAR2(27)) SIZE 8192 HASHKEYS 5;

31 Materialized View CREATE MATERIALIZED VIEW LOG ON my_tables WITH ROWID; CREATE MATERIALIZED VIEW LOG ON my_indexes WITH ROWID; CREATE MATERIALIZED VIEW my_mv CLUSTER my_cluster (index_type) REFRESH FAST ON COMMIT ENABLE QUERY REWRITE AS SELECT t.ROWID AS table_rowid, t.owner AS table_owner, t.table_name, t.tablespace_name, i.ROWID AS index_rowid, i.index_type FROM my_tables t, my_indexes i WHERE t.owner = i.table_owner AND t.table_name = i.table_name;

32 Execution Plan IV | Operation | Name | Buffers | | HASH UNIQUE | | 1 | | TABLE ACCESS HASH| MY_MV | 1 |

33 Result Cache SELECT /*+ RESULT_CACHE */ DISTINCT my_tables.owner, my_tables.table_name, my_tables.tablespace_name FROM my_tables, my_indexes WHERE my_tables.owner = my_indexes.table_owner AND my_tables.table_name = my_indexes.table_name AND my_indexes.index_type = :index_type;

34 Execution Plan V | Operation | Name | | SELECT STATEMENT | | | RESULT CACHE | afscr8p240b168b5az0dkd4k65 | | HASH UNIQUE | | | TABLE ACCESS HASH| MY_MV |

35 White Paper  Contains all of the material we discussed today and more  Code samples are easier to read  Easier to cut and paste the code for testing on your system  Download:

36 Contact Information Iggy Fernandez Database Specialists, Inc. 388 Market Street, Suite 400 San Francisco, CA Tel: Ext Web:

37 There’s No Substitute For Experience  Proven track record with emerging to Fortune 500 clients since  Services and support plans tailored to your business needs and budget.  Team of recognized industry experts and thought leaders. Database Specialists helps you increase uptime, improve performance, minimize risk, and reduce costs

38 About Database Specialists  Database Specialists, Inc. provides Oracle database consulting in Solaris, Linux, HP-UX, AIX, and Windows environments.  Our DBA Pro offering and Database Rx™ tools provide remote database support and 24/7 coverage at an attractive price point.  We specialize in short term projects including upgrades, performance tuning and health checks.  Our Oracle DBAs each have a minimum of 10 years of Oracle experience with a focus on Oracle technology, mission-critical production support and RAC environments.  Database Specialists is US-based. Database Specialists helps you increase uptime, improve performance, minimize risk, and reduce costs

Xtreme SQL Tuning: The Tuning Limbo Iggy Fernandez Database Specialists, Inc. TCOUG Fall Meeting 2008