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



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

In this session, we use the table ZZTELE with approx. 115,000 records for the examples. The primary key is defined on the columns NAME,VORNAME,STR

Elena Baralis, Silvia Chiusano Politecnico di Torino. Pag. 1. Physical Design. Phases of database design. Physical design: Inputs.

Maximizing Materialized Views

Chapter 9 Joining Data from Multiple Tables. Oracle 10g: SQL

SQL Tuning Proven Methodologies

Lab # 5. Retreiving Data from Multiple Tables. Eng. Alaa O Shama

Anatomy of a SQL Tuning Session

Database CIS 340. lab#6. I.Arwa Najdi

Oracle 10g PL/SQL Training

Database Programming with PL/SQL: Learning Objectives

VARRAY AND NESTED TABLE

Join Example. Join Example Cart Prod Comprehensive Consulting Solutions, Inc.All rights reserved.

Oracle Database 12c: Introduction to SQL Ed 1.1

Displaying Data from Multiple Tables. Chapter 4

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

Handling Exceptions. Schedule: Timing Topic 45 minutes Lecture 20 minutes Practice 65 minutes Total

Aggregating Data Using Group Functions

Guide to SQL Programming: SQL:1999 and Oracle Rdb V7.1

ICAB4136B Use structured query language to create database structures and manipulate data

SQL. Short introduction

D61830GC30. MySQL for Developers. Summary. Introduction. Prerequisites. At Course completion After completing this course, students will be able to:

Teradata Utilities Class Outline

Useful Business Analytics SQL operators and more Ajaykumar Gupte IBM

Programming with SQL

Oracle. Brief Course Content This course can be done in modular form as per the detail below. ORA-1 Oracle Database 10g: SQL 4 Weeks 4000/-

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

Query Optimization in Oracle Database10g Release 2. An Oracle White Paper June 2005

Oracle Database: SQL and PL/SQL Fundamentals NEW

RDBMS Using Oracle. Lecture Week 7 Introduction to Oracle 9i SQL Last Lecture. kamran.munir@gmail.com. Joining Tables

Introduction to SQL Tuning. 1. Introduction to SQL Tuning SkillBuilders, Inc. SKILLBUILDERS

Instant SQL Programming

Oracle EXAM - 1Z Oracle Database 11g Release 2: SQL Tuning. Buy Full Product.

1Z0-117 Oracle Database 11g Release 2: SQL Tuning. Oracle

Top 25+ DB2 SQL Tuning Tips for Developers. Presented by Tony Andrews, Themis Inc.

ORACLE 9I / 10G / 11G / PL/SQL COURSE CONTENT

MySQL for Beginners Ed 3

CSI 2132 Lab 3. Outline 09/02/2012. More on SQL. Destroying and Altering Relations. Exercise: DROP TABLE ALTER TABLE SELECT

Using TimesTen between your Application and Oracle. between your Application and Oracle. DOAG Conference 2011

Oracle/SQL Tutorial 1

Performance Tuning for the Teradata Database

Oracle Database: SQL and PL/SQL Fundamentals

Data warehousing in Oracle. SQL extensions for data warehouse analysis. Available OLAP functions. Physical aggregation example

Oracle SQL. Course Summary. Duration. Objectives

SQL Query Evaluation. Winter Lecture 23

Subqueries Chapter 6

Handling Exceptions. Copyright 2006, Oracle. All rights reserved. Oracle Database 10g: PL/SQL Fundamentals 8-1

SQL Query Performance Tuning: Tips and Best Practices

SQL, the underestimated Big Data technology

Displaying Data from Multiple Tables

Using SQL Queries to Insert, Update, Delete, and View Data: Joining Multiple Tables. Lesson C Objectives. Joining Multiple Tables

Duration Vendor Audience 5 Days Oracle End Users, Developers, Technical Consultants and Support Staff

Oracle Database 11 g Performance Tuning. Recipes. Sam R. Alapati Darl Kuhn Bill Padfield. Apress*

Querying Microsoft SQL Server

Objectives. Oracle SQL and SQL*PLus. Database Objects. What is a Sequence?

Best Practices for DB2 on z/os Performance

Fallacies of the Cost Based Optimizer

DB2 Developers Guide to Optimum SQL Performance

P_Id LastName FirstName Address City 1 Kumari Mounitha VPura Bangalore 2 Kumar Pranav Yelhanka Bangalore 3 Gubbi Sharan Hebbal Tumkur

Writing Control Structures

2015 OSIsoft TechCon. Optimizing SQL Queries for Performance using PI OLEDB Enterprise

University of Massachusetts Amherst Department of Computer Science Prof. Yanlei Diao

Using the SQL Procedure

Oracle Database: SQL and PL/SQL Fundamentals

Programming Database lectures for mathema

Execution plans and tools

Big Data, Fast Processing Speeds Kevin McGowan SAS Solutions on Demand, Cary NC

Handling Exceptions. Schedule: Timing Topic. 45 minutes Lecture 20 minutes Practice 65 minutes Total

Oracle Database 11g SQL

Topics Advanced PL/SQL, Integration with PROIV SuperLayer and use within Glovia

Duration Vendor Audience 5 Days Oracle Developers, Technical Consultants, Database Administrators and System Analysts

Consulting. Personal Attention, Expert Assistance

Course ID#: W 35 Hrs. Course Content

Oracle Database: Develop PL/SQL Program Units

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

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Relational Algebra. Query Languages Review. Operators. Select (σ), Project (π), Union ( ), Difference (-), Join: Natural (*) and Theta ( )

Querying Microsoft SQL Server 20461C; 5 days

SQL Server Query Tuning

Oracle Database Security

IBM DB Introduction to SQL and database objects Hands-on Lab. Information Management Cloud Computing Center of Competence.

Partitioning under the hood in MySQL 5.5

Query tuning by eliminating throwaway

Chapter 1 Overview of the SQL Procedure

Course 20461C: Querying Microsoft SQL Server Duration: 35 hours

Querying Microsoft SQL Server Course M Day(s) 30:00 Hours

SQL - QUICK GUIDE. Allows users to access data in relational database management systems.

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

Execution Plans: The Secret to Query Tuning Success. MagicPASS January 2015

Oracle Database 11g: SQL Tuning Workshop Release 2

Oracle Database: Introduction to SQL

Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification

Displaying Data from Multiple Tables

Introducing Microsoft SQL Server 2012 Getting Started with SQL Server Management Studio

Financial Data Access with SQL, Excel & VBA

14 Triggers / Embedded SQL

Outline. SAS-seminar Proc SQL, the pass-through facility. What is SQL? What is a database? What is Proc SQL? What is SQL and what is a database

Transcription:

Politecnico di Torino Database Management System Oracle Hints Data Base and Data Mining Group of Politecnico di Torino Tania Cerquitelli Computer Engineering, 2014-2015, 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 Management System 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 plus 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 Management System 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 Management System 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 Management System 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 Management System 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 Management System 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 Management System 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 Management System 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 Management System 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 jobs is suggested Database Management System 11 Oracle Hints 6