Oracle Hints. Using Optimizer Hints

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

Databases IIB: DBMS-Implementation Exercise Sheet 13

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

Real-World Performance Training SQL Introduction

Objectives. After completing this lesson, you should be able to do the following:

Oracle. Exam Questions 1Z Oracle Database 11g Release 2: SQL Tuning Exam. Version:Demo

Exploring Best Practices and Guidelines for Tuning SQL Statements

Objectives. After completing this lesson, you should be able to do the following:

Interpreting Explain Plan Output. John Mullins

DRAFT SOLUTION. Query 1(a) DATABASE MANAGEMENT SYSTEMS PRACTICE 1

The use of Hints in SQL-Nested query optimization

Oracle 1Z0-054 Exam Questions and Answers (PDF) Oracle 1Z0-054 Exam Questions 1Z0-054 BrainDumps

Improving Database Performance: SQL Query Optimization

Oracle EXAM - 1Z Oracle Database 11g: Performance Tuning. Buy Full Product.

ENHANCING DATABASE PERFORMANCE

INDEX. 1 Basic SQL Statements. 2 Restricting and Sorting Data. 3 Single Row Functions. 4 Displaying data from multiple tables

Chapter 7. Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel

The use of hints in object-relational query optimization

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

@vmahawar. Agenda Topics Quiz Useful Links

D B M G. SQL language: basics. Managing tables. Creating a table Modifying table structure Deleting a table The data dictionary Data integrity

Query Processing and Query Optimization. Prof Monika Shah

Exam Actual. Higher Quality. Better Service! QUESTION & ANSWER

Semantic Errors in Database Queries

Table Joins and Indexes in SQL

Oracle DB-Tuning Essentials

SQL functions fit into two broad categories: Data definition language Data manipulation language

When should an index be used?

Physical Design. Elena Baralis, Silvia Chiusano Politecnico di Torino. Phases of database design D B M G. Database Management Systems. Pag.

PASS4TEST. IT Certification Guaranteed, The Easy Way! We offer free update service for one year

Databases - 4. Other relational operations and DDL. How to write RA expressions for dummies

MANAGING DATA(BASES) USING SQL (NON-PROCEDURAL SQL, X401.9)

KillTest *KIJGT 3WCNKV[ $GVVGT 5GTXKEG Q&A NZZV ]]] QORRZKYZ IUS =K ULLKX LXKK [VJGZK YKX\OIK LUX UTK _KGX

1. Data Definition Language.

Database Systems: Design, Implementation, and Management Tenth Edition. Chapter 7 Introduction to Structured Query Language (SQL)

NULLs & Outer Joins. Objectives of the Lecture :

Suppose we need to get/retrieve the data from multiple columns which exists in multiple tables...then we use joins..

GIFT Department of Computing Science. CS-217/224: Database Systems. Lab-5 Manual. Displaying Data from Multiple Tables - SQL Joins

Oracle Database 11gR2 Optimizer Insights

Oracle EXAM - 1Z Oracle Database SQL Expert. Buy Full Product.

Oracle9i: SQL Tuning Workshop

REPORT ON SQL TUNING USING INDEXING

Unit Assessment Guide

1z Oracle Database SQL Expert

ORACLE TRAINING CURRICULUM. Relational Databases and Relational Database Management Systems

Displaying Data from Multiple Tables. Copyright 2004, Oracle. All rights reserved.

.. Spring 2008 CSC 468: DBMS Implementation Alexander Dekhtyar..

ORACLE VIEWS ORACLE VIEWS. Techgoeasy.com

Wolfgang Breitling.

Lab # 6. Using Subqueries and Set Operators. Eng. Alaa O Shama

Querying Data with Transact SQL

Chapter 16: Advanced MySQL- Grouping Records and Joining Tables. Informatics Practices Class XII. By- Rajesh Kumar Mishra

Oracle 11g Invisible Indexes Inderpal S. Johal. Inderpal S. Johal, Data Softech Inc.

Hints (definition 1) on Hints (definition 2)

Tools and methods for optimization of databases in Oracle 10g. Part 2 Tuning of hardware, applications and SQL queries

COPYRIGHTED MATERIAL. Using SQL. The Processing Cycle for SQL Statements

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #16 Loops: Matrix Using Nested for Loop

Creating and Managing Tables Schedule: Timing Topic

Chapter # 7 Introduction to Structured Query Language (SQL) Part II

30. Structured Query Language (SQL)

1z0-047 Exam Questions Demo Oracle. Exam Questions 1z Oracle Database SQL Expert.

Chapter 9: Working With Data

What the SQL is Going On Out Here?

RDBMS Topic 4 Adv. SQL, MSBTE Questions and Answers ( 12 Marks)

Types. Inner join ( Equi Joins ) Outer(left, right, full) Cross. Prepared By : - Chintan Shah & Pankti Dharwa 2

Oracle Sql Tuning- A Framework

Data Science and Database Technology

Question No : 1 Which three possible values can be set for the TIME_ZONE session parameter by using the ALTER SESSION command? (Choose three.

COSC 304 Introduction to Database Systems SQL DDL. Dr. Ramon Lawrence University of British Columbia Okanagan

CHAPTER: 4 ADVANCE SQL: SQL PERFORMANCE TUNING (12 Marks)

THE OPTIMIZATION OF DATA ACCESS USING JOIN CLAUSE

Add Employee s Supervisor Name to a Query PROCEDURES

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

Interview Questions on DBMS and SQL [Compiled by M V Kamal, Associate Professor, CSE Dept]

Oracle. Professional. WITH Function-Based Indexes (FBIs), I was able to alter an execution. Avoid Costly Joins with FBIs Pedro Bizarro.

Detecting Logical Errors in SQL Queries

Find All Tables Containing Column With Specified Name Oracle

Tables From Existing Tables

Advance Database Systems. Joining Concepts in Advanced SQL Lecture# 4

Intermediate SQL: Aggregated Data, Joins and Set Operators

CSIT5300: Advanced Database Systems

MANAGING DATA(BASES) USING SQL (NON-PROCEDURAL SQL, X401.9)

SQL. Rodrigo García Carmona Universidad San Pablo-CEU Escuela Politécnica Superior

Table of Contents. PDF created with FinePrint pdffactory Pro trial version

Advanced Oracle Performance Troubleshooting. Query Transformations Randolf Geist

Oracle Class VII More on Exception Sequence Triggers RowID & Rownum Views

Outer Join, More on SQL Constraints

SQL Tuning via Toad Tips for Optimizing SQL Performance

Oracle 9i Application Development and Tuning

Database Foundations. 6-3 Data Definition Language (DDL) Copyright 2015, Oracle and/or its affiliates. All rights reserved.

Database Foundations. 6-9 Joining Tables Using JOIN. Copyright 2014, Oracle and/or its affiliates. All rights reserved.

Chapter 3. Introducation to Relational Database 9/2/2014 CSC4341 1

CSC Web Programming. Introduction to SQL

Query Optimization, part 2: query plans in practice

Retrieving Data Using the SQL SELECT Statement. Copyright 2004, Oracle. All rights reserved.

Oracle 1Z MySQL 5.6 Developer.

1 SQL Structured Query Language

What is SQL? Designed to retrieve data from relational databases, as well as to build and administer those databases.

Oracle Syllabus Course code-r10605 SQL

ITCertMaster. Safe, simple and fast. 100% Pass guarantee! IT Certification Guaranteed, The Easy Way!

Transcription:

Politecnico di Torino Tecnologia delle Basi di Dati Oracle Hints Computer Engineering, 2009-2010, slides by Tania Cerquitelli and Daniele Apiletti Using Optimizer Hints You can use comments in a SQL statement to pass instructions, or hints, to the Oracle Database optimizer Hints provide a mechanism to instruct the optimizer to choose a certain query execution plan based on specific criteria The optimizer uses these hints to choose an execution plan for the statement, unless some condition exists that prevents the optimizer from doing so Hints let you make decisions usually made by the optimizer you might know information about your data that the optimizer does not know Database System Technology 2 Oracle Hints 1

Specifying Hints Hints apply only to the optimization of the block of a statement in which they appear A statement block is any SELECT, UPDATE, or DELETE statement, including sub-queries The plus sign (+) causes Oracle to interpret the comment as a list of hints. The plus sign must follow immediately after the comment delimiter No space is permitted between the comment delimiter and the + sign The space between the plus sign and the hint is optional If the comment contains multiple hints, then separate the hints by at least one space Example SELECT /*+ Hint1 Hint2 Hint3 */ columnname FROM tablename WHERE conditions [ ] Database System Technology 3 Optimizer hints categories Optimizer hints are grouped into the following categories Hints for Optimization Approaches and Goals Hints for Access Paths Hints for Query Transformations Hints for Join Orders Hints for Join Operations Hints for Parallel Execution Additional Hints Database System Technology 4 Oracle Hints 2

Optimization Approaches and Goals The following hints let you choose between optimization approaches and goals ALL_ROWS optimizes a statement block with a goal of best throughput, i.e., minimum total resource consumption FIRST_ROWS(n) optimizes an individual SQL statement for fast response, choosing the plan that returns the first n rows most efficiently If a SQL statement has a hint specifying an optimization approach and goal, then the optimizer uses the specified approach regardless of the presence or absence of statistics (if absent, optimizer uses default statistical values) the OPTIMIZER_MODE initialization parameter the OPTIMIZER_MODE parameter of the ALTER SESSION statement The optimizer gives precedence to the hints for access paths or join operations, before ALL_ROWS or FIRST_ROWS(n) Database System Technology 5 Hints for Access Paths Each of the following hints instructs the optimizer to use a specific access path for a table Specifying one of these hints causes the optimizer to choose the specified access path only if the access path is available existence of an index syntactic constructs of the SQL statement You must specify the table to be accessed exactly as it appears in the statement if the statement uses an alias for the table, then use the alias rather than the table name FULL(table) INDEX(table NO_INDEX(table INDEX_COMBINE(table INDEX_FFS(table NO_INDEX_FFS(table Database System Technology 6 Oracle Hints 3

Hints for Access Paths FULL(table) full table scan on the specified table if a table alias is defined, the table must be referenced with its alias INDEX(table indexname1 indexname2 ) index scan using one or more specified indexes for the specified table does not consider a full table scan or a scan on an index not listed NO_INDEX(table indexname1 indexname2 ) avoid using one or more specified indexes for the specified table INDEX_COMBINE(table indexname1 indexname2 ) uses a bitmap access path (Boolean combination) of the specified indexes for the table INDEX_FFS(table indexname1 indexname2 ) instructs the optimizer to perform a fast full index scan rather than a full table scan NO_INDEX_FFS(table indexname1 indexname2 ) excludes a fast full index scan of the specified indexes on the specified table Database System Technology 7 Join Operations Each of the following hints instructs the optimizer to use a specific join operation for the specified tables USE_NL( table1, table2, ) NO_USE_NL ( ) USE_MERGE ( ) NO_USE_MERGE ( ) USE_HASH ( ) NO_USE_HASH ( ) Oracle uses these hints when the referenced table is forced to be the inner table of a join; the hints are ignored if the referenced table is the outer table Database System Technology 8 Oracle Hints 4

Join Orders The following hints suggest join orders ORDERED LEADING( table1 table2 ) The ORDERED hint instructs Oracle to join tables in the order in which they appear in the FROM clause The LEADING hint instructs the optimizer to use the specified set of tables as the hint parameters These hints let you choose an inner and outer table the first table is the outer table the second table is the inner table Database System Technology 9 Join Orders - Example SELECT /*+ ORDERED */ * FROM emp e, dept d WHERE d.deptno = e.deptno LEADING( e d ) 1 NESTED LOOPS 50012 3125K 168 (48) 00:00:03 2 ACCESS FULL EMP 50111 2202K 88 (4) 00:00:02 3 BY INDEX ROWID DEPT 1 19 1 (0) 00:00:01 * 4 INDEX UNIQUE SYS_... 1 0 (0) 00:00:01 Emp is the outer table Dept is the inner table SELECT /*+ ORDERED */ * LEADING( d e ) FROM dept d, emp e WHERE d.deptno = e.deptno 1 NESTED LOOPS 50012 3125K 43855 (4) 00:08:47 2 TABLE ACCESS FULL DEPT 507 9633 3 (0) 00:00:01 * 3 TABLE ACCESS FULL EMP 99 4455 86 (4) 00:00:02 Dept is the outer table Emp is the inner table Database System Technology 10 Oracle Hints 5

Example SELECT /*+ LEADING(e j) USE_NL(e j) INDEX(j empid_index) FULL(e) */ e.empid, e.name, sum(j.salary) FROM empl e, jobs j AND e.empid = j.empid GROUP BY e.empid, e.name the LEADING hint specifies the exact join order to be used the index empid_index is suggested to be used the join method USE_NL to be used on the join tables is also specified the FULL table access path to table emp is suggested Database System Technology 11 Oracle Hints 6