1 Chapter 7 Optimizing the Optimizer. 2 The Oracle Optimizer is… About query optimization Is a sophisticated set of algorithms Choosing the fastest approach.

Slides:



Advertisements
Similar presentations
Tuning: overview Rewrite SQL (Leccotech)Leccotech Create Index Redefine Main memory structures (SGA in Oracle) Change the Block Size Materialized Views,
Advertisements

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.
1 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.
SQL Performance 2011/12 Joe Chang, SolidQ
Paper by: A. Balmin, T. Eliaz, J. Hornibrook, L. Lim, G. M. Lohman, D. Simmen, M. Wang, C. Zhang Slides and Presentation By: Justin Weaver.
CS263 Lecture 19 Query Optimisation.  Motivation for Query Optimisation  Phases of Query Processing  Query Trees  RA Transformation Rules  Heuristic.
David Konopnicki Choosing Access Path ä The basic methods. ä The access paths and when they are available. ä How the optimizer chooses among the.
1 The Optimizer How ORACLE optimizes SQL statements David Konopnicky 1997, Revised by Mordo Shalom 2004.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 11 Database Performance Tuning and Query Optimization.
Query Optimization. General Overview Relational model - SQL  Formal & commercial query languages Functional Dependencies Normalization Physical Design.
1 Copyright © 2011, Oracle and/or its affiliates. All rights reserved. Understanding Optimizer Statistics.
©Silberschatz, Korth and Sudarshan14.1Database System Concepts 3 rd Edition Chapter 14: Query Optimization Overview Catalog Information for Cost Estimation.
Oracle 10g Database Administrator: Implementation and Administration
Chapter 9 Overview  Reasons to monitor SQL Server  Performance Monitoring and Tuning  Tools for Monitoring SQL Server  Common Monitoring and Tuning.
Executing Explain Plans and Explaining Execution Plans Craig Martin 01/20/2011.
12 Copyright © 2007, Oracle. All rights reserved. Database Maintenance.
Database Systems: Design, Implementation, and Management Tenth Edition Chapter 11 Database Performance Tuning and Query Optimization.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Database Performance Tuning and Query Optimization.
Oracle Database Administration Lecture 6 Indexes, Optimizer, Hints.
DBSQL 14-1 Copyright © Genetic Computer School 2009 Chapter 14 Microsoft SQL Server.
Access Path Selection in a Relational Database Management System Selinger et al.
Database Management 9. course. Execution of queries.
The Self-Managing Database: Guided Application and SQL Tuning Mohamed Ziauddin Consulting Member of Technical Staff Oracle Corporation Session id:
RBO RIP George Lumpkin Director Product Management Oracle Corporation Session id:
Academic Year 2014 Spring. MODULE CC3005NI: Advanced Database Systems “QUERY OPTIMIZATION” Academic Year 2014 Spring.
1 What’s Up with dbms_stats? Terry Sutton Database Specialists, Inc.
1 Chapter 14 DML Tuning. 2 DML Performance Fundamentals DML Performance is affected by: – Efficiency of WHERE clause – Amount of index maintenance – Referential.
Oracle9i Performance Tuning Chapter 12 Tuning Tools.
Database Design and Management CPTG /23/2015Chapter 12 of 38 Functions of a Database Store data Store data School: student records, class schedules,
1 Chapter 10 Joins and Subqueries. 2 Joins & Subqueries Joins – Methods to combine data from multiple tables – Optimizer information can be limited based.
8 1 Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
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.
Commercial RDBMSs Access and Oracle. Access DBMS Architchecture  Can be used as a standalone system on a single PC: -JET Engine -Microsoft Data Engine.
1 Chapter 13 Parallel SQL. 2 Understanding Parallel SQL Enables a SQL statement to be: – Split into multiple threads – Each thread processed simultaneously.
Chapter 4 Logical & Physical Database Design
Chapter 5 Index and Clustering
Query Optimization CMPE 226 Database Systems By, Arjun Gangisetty
1 Copyright © 2005, Oracle. All rights reserved. Following a Tuning Methodology.
IMS 4212: Database Implementation 1 Dr. Lawrence West, Management Dept., University of Central Florida Physical Database Implementation—Topics.
1 Chapter 9 Tuning Table Access. 2 Overview Improve performance of access to single table Explain access methods – Full Table Scan – Index – Partition-level.
DB Tuning : Chapter 10. Optimizer Center for E-Business Technology Seoul National University Seoul, Korea 이상근 Intelligent Database Systems Lab School of.
Sorting and Joining.
Query Processing – Implementing Set Operations and Joins Chap. 19.
1 Chapter 8 Execution Plan Management. 2 Overview of Execution Plan Management Review techniques to – override optimizer – Improve optimizer’s decisions.
8 Copyright © 2005, Oracle. All rights reserved. Gathering Statistics.
SQL Server Statistics DEMO SQL Server Statistics SREENI JULAKANTI,MCTS.MCITP,MCP. SQL SERVER Database Administration.
SQL Server Statistics DEMO SQL Server Statistics SREENI JULAKANTI,MCTS.MCITP SQL SERVER Database Administration.
Diving into Query Execution Plans ED POLLACK AUTOTASK CORPORATION DATABASE OPTIMIZATION ENGINEER.
3 Copyright © 2006, Oracle. All rights reserved. Designing and Developing for Performance.
11 Copyright © 2009, Oracle. All rights reserved. Enhancing ETL Performance.
Tuning Oracle SQL The Basics of Efficient SQL Common Sense Indexing
Chiu Luk CS257 Database Systems Principles Spring 2009
SQL Server Statistics and its relationship with Query Optimizer
Query Optimization Techniques
SQL Tuning.
EVOLUTION OF THE ORACLE OPTIMIZER THINKING
Database Systems: Design, Implementation, and Management Tenth Edition
Database Performance Tuning &
Query Tuning without Production Data
Database Performance Tuning and Query Optimization
Chapter 15 QUERY EXECUTION.
Cardinality Estimator 2014/2016
Statistics: What are they and How do I use them
Practical Database Design and Tuning
Chapter 11 Database Performance Tuning and Query Optimization
Introduction to the Optimizer
Presentation transcript:

1 Chapter 7 Optimizing the Optimizer

2 The Oracle Optimizer is… About query optimization Is a sophisticated set of algorithms Choosing the fastest approach (hopefully) Cost-based determinations, including – Time estimates for retrieval – Estimated CPU time – Does not include network components

3 OPTIMIZER_GOAL parameter Controls how the optimizer calculates cost ALL_ROWS – minimizes cost of processing all rows – Favors full table scans FIRST_ROWS_N – minimizes cost of processing first N rows – Favors index usage RULE – Obsolete but can be invoked with RULE hint

4 Query Transformation Oracle can transform a query into a logically equivalent statement Types of transformations include: – View Merging – Taking view and merging into a SQL statement – Star – Used for star schemas – Join elimination – eliminates unnecessary joins – Join factorization – used with UNION operations – Antijoin and semijoin – Converts MINUS and INTERSECT

5 Basis of Cost Calculations The amount of data accessed Estimated data in memory Estimate of physical IO operations Estimate of CPU-related operations – Sorting – Hashing Relative speed of IO and compute operations

6 Inputs into Cost Calculations Object statistics – metadata about the tables Histograms – data distribution statistics Database parameters – data block, memory, and other process configuration parameters System statistics – physical hardware configuration Bind Variable Peeking - Using actual value of variable to help determine execution plan

7 Database Parameters Influences optimizer decisions Some key parameters affecting optimization: – DB_FILE_MULTIBLOCK_READ_COUNT – how many blocks read in single IO operation – OPTIMIZER_INDEX_CACHING & OPTIMIZER_INDEX_COST_ADJ – affects how optimizer thinks about indexes – OPTIMIZER_FEATURES_ENABLE – tells optimizer what Oracle version to base decisions – Parallel_threads_per_cpu – affects how prominent parallelism can be – Many memory (SGA/PGA based) parameters – See pp

8 System Statistics View these in SYS.AUX_STATS$ view Statistics on physical system configuration Types include: – Nonworkload statistics – collect in absence of database load / use – Workload statistics – collect during typical database activity Workload statistics more reflective of actual hardware configuration

9 Collecting Statistics Automatic Statistics Gathering – Automated as of Oracle 10g – Many configurable parameters – Can configure within manually or within Enterprise Manager Stale Statistics – Means Oracle keeps DML activity to determine when statistics become stale – STATISTICS_LEVEL must be set to use – View information in ALL_TAB_MODIFICATIONS view – Can configure the threshold of what is regarded as “stale”

10 Collecting Statistics (cont.) Manual Statistics Gathering – Usually necessary on some objects to keep current as is needed – Used to fine-tune statistics collection – Used to collect on SYSTEM objects not gather automatically – Used to create “extended statistics” Dynamic Sampling – Done by Oracle on-the-fly at execution time – Done when certain objects have no statistics – Oracle may determine doing this may reduce execution time – Determined by OPTIMIZER_DYNAMIC_SAMPLING parameter

11 Using DBMS_STATS Oracle provided PL/SQL Package Collects and manages optimizer statistics – For a table – For a schema – For objects with “stale” statistics – Used to create histograms – Used to transfer statistics from another database – See pp for procedures and parameters

12 Using DBMS_STATS (cont.) Defaults can be set via the following procedures – SET_GLOBAL_PREFS – SET_DATABASE_PREFS – SET_SCHEMA_PREFS – SET_TABLE_PREFS Configurable parameters: – CASCADE – DEGREE – ESTIMATE_PERCENT – METHOD_OPT – GRANULARITY – See p. 202 for others

13 Histograms and METHOD_OPT Histograms – Increase accuracy of of cost calculations – Increase overhead of collecting statistics – Worthwhile for Columns with irregular data distribution Columns involved with WHERE or JOIN expressions METHOD_OPT affects how histograms are created – Default is FOR ALL COLUMNS SIZE AUTO – leaves decision to Oracle to choose columns on which to create histograms – Based on cardinality – Based on presence of filters dependent on the data – Set METHOD_OPT manually when appropriate if knowledge of column data makeup is known

14 Extended Statistics Stored in ALL_TAB_COL_STATISTICS Two types – Multicolumn – Expression-based Multicolumn Extended Statistics – Calculates selectivity of multicolumn expressions – Example 50% of customers are men 10% of customers are from Australia Optimizer conclusion: 5% of customers are Australian men

15 Extended Statistics Expression Extended Statistics – Optimizer gathers statistics on an expression to help determine query cost – Take the query: SELECT COUNT(*), SUM(amount_sold) FROM SALES WHERE sale_category (amount_sold) = 1; – By gathering statistics on the expression in above query, optimizer will likely more accurately determine cost of query BEGIN DBMS_STATS.gather_table_stats (ownname=>USER,tabname=>’SALES’,method_opt=> ‘FOR ALL COLUMNS FOR COLUMNS (sale_category(amount_sold))’); END

16 More on DBMS_STATS Can perform other operations, such as – Locking statistics (LOCK_SCHEMA_STATS) – Collect system statistics (GATHER_SYSTEM_STATS) – Move statistics from one database to another Popular to simulate production statistics in a development environment – Manipulate object statistics Modifying statistics based on actual data Good if forecasting data changes