David Konopnicki -1997 1 Choosing Access Path ä The basic methods. ä The access paths and when they are available. ä How the optimizer chooses among the.

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

Presented By Akin S Walter-Johnson Ms Principal PeerLabs, Inc
Introduction to SQL Tuning Brown Bag Three essential concepts.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
1 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.
Chapter 15 Algorithms for Query Processing and Optimization Copyright © 2004 Pearson Education, Inc.
Query Optimization CS634 Lecture 12, Mar 12, 2014 Slides based on “Database Management Systems” 3 rd ed, Ramakrishnan and Gehrke.
Query Evaluation. An SQL query and its RA equiv. Employees (sin INT, ename VARCHAR(20), rating INT, age REAL) Maintenances (sin INT, planeId INT, day.
Module 14: Analyzing Queries. Overview Queries That Use the AND Operator the OR Operator Join Operations.
1 King Saud University College of Computer & Information Sciences IS 335 Database Management System Lecture 6 Query Processing and Optimization (Practice)
Agenda Overview of the optimizer How SQL is executed Identifying statements that need tuning Explain Plan Modifying the plan.
CS263 Lecture 19 Query Optimisation.  Motivation for Query Optimisation  Phases of Query Processing  Query Trees  RA Transformation Rules  Heuristic.
1 Query Optimization. 2 Why Optimize? Given a query of size n and a database of size m, how big can the output of applying the query to the database be?
Access Path Selection in a RDBMS Shahram Ghandeharizadeh Computer Science Department University of Southern California.
1 The Optimizer How ORACLE optimizes SQL statements David Konopnicky 1997, Revised by Mordo Shalom 2004.
ACS-4902 Ron McFadyen Chapter 15 Algorithms for Query Processing and Optimization.
Query Processing & Optimization
Chapter 19 Query Processing and Optimization
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.
Access Path Selection in a Relation Database Management System (summarized in section 2)
AN INTRODUCTION TO EXECUTION PLAN OF QUERIES These slides have been adapted from a presentation originally made by ORACLE. The full set of original slides.
SQL's Data Definition Language (DDL) – View, Sequence, Index.
Relational Database Performance CSCI 6442 Copyright 2013, David C. Roberts, all rights reserved.
Lecture 8 Index Organized Tables Clusters Index compression
Oracle Data Block Oracle Concepts Manual. Oracle Rows Oracle Concepts Manual.
Oracle Database Administration Lecture 6 Indexes, Optimizer, Hints.
Database Management 9. course. Execution of queries.
4-1 Copyright  Oracle Corporation, All rights reserved. Displaying Data from Multiple Tables.
Ashwani Roy Understanding Graphical Execution Plans Level 200.
CS 338Query Evaluation7-1 Query Evaluation Lecture Topics Query interpretation Basic operations Costs of basic operations Examples Textbook Chapter 12.
CPSC 404, Laks V.S. Lakshmanan1 Evaluation of Relational Operations: Other Operations Chapter 14 Ramakrishnan & Gehrke (Sections ; )
1 Information Retrieval and Use (IRU) CE An Introduction To SQL Part 1.
Joins & Sub-queries. Oracle recognizes that you may want data that resides in multiple tables drawn together in some meaningful way. One of the most important.
SELECT Statements Lecture Notes Sree Nilakanta Fall 2010 (rev)
1 Chapter 10 Joins and Subqueries. 2 Joins & Subqueries Joins – Methods to combine data from multiple tables – Optimizer information can be limited based.
Module 4 Database SQL Tuning Section 3 Application Performance.
11-1 Copyright  Oracle Corporation, All rights reserved. What Are Constraints? Constraints enforce rules at the table level. Constraints prevent.
Indexes and Views Unit 7.
University of Sunderland COM 220 Lecture Ten Slide 1 Database Performance.
SQL/Lesson 7/Slide 1 of 32 Implementing Indexes Objectives In this lesson, you will learn to: * Create a clustered index * Create a nonclustered index.
Managing Schema Objects
Chapter 5 Index and Clustering
9-1 © Prentice Hall, 2007 Topic 9: Physical Database Design Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph S. Valacich,
Advance Database Systems Query Optimization Ch 15 Department of Computer Science The University of Lahore.
1 B + -Trees: Search  If there are n search-key values in the file,  the path is no longer than  log  f/2  (n)  (worst case).
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.
David Konopnicki –1997, Rev. MS Optimizing Join Statements To choose an execution plan for a join statement, the optimizer must choose: ä Access.
Query Processing – Implementing Set Operations and Joins Chap. 19.
11-1 © Prentice Hall, 2004 Chapter 11: Physical Database Design Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph S. Valacich,
Query Optimization Cases. D. ChristozovINF 280 DB Systems Query Optimization: Cases 2 Executable Block 1 Algorithm using Indices (if available) Temporary.
1 Indexes ► Sort data logically to improve the speed of searching and sorting operations. ► Provide rapid retrieval of specified rows from the table without.
8 Copyright © 2005, Oracle. All rights reserved. Gathering Statistics.
LAB: Web-scale Data Management on a Cloud Lab 11. Query Execution Plan 2011/05/27.
SQL IMPLEMENTATION & ADMINISTRATION Indexing & Views.
How is data stored? ● Table and index Data are stored in blocks(aka Page). ● All IO is done at least one block at a time. ● Typical block size is 8Kb.
Subqueries Schedule: Timing Topic 25 minutes Lecture
Choosing Access Path The basic methods.
Query Processing and Optimization
Interpreting Execution Plans
COST ESTIMATION FOR THE RELATIONAL ALGEBRA OPERATIONS MIT 813 GROUP 15 PRESENTATION.
Chapter 15 QUERY EXECUTION.
Database Management Systems (CS 564)
JULIE McLAIN-HARPER LINKEDIN: JM HARPER
Advance Database Systems
Subqueries Schedule: Timing Topic 25 minutes Lecture
Evaluation of Relational Operations: Other Techniques
Introduction to the Optimizer
Subqueries Schedule: Timing Topic 25 minutes Lecture
Presentation transcript:

David Konopnicki Choosing Access Path ä The basic methods. ä The access paths and when they are available. ä How the optimizer chooses among the access paths.

David Konopnicki Access Methods ä Full Table Scans ä Read each row and determine of it satisfies the statement’s WHERE clause. ä Implemented very efficiently using multi-block reads. ä Each data block is read only once. ä Table Access by ROWID: fastest way.

David Konopnicki Indexes, Clusters and Hash Clusters ä Indexes are created on one or more columns of a table. Very useful for range conditions. They are independent of the table. ä Clusters are an optional method for storing the table. Clusters group together tables because they share columns and often used together. ä The related columns in a cluster is the Cluster key (always indexed)

David Konopnicki Example: Cluster Indexed

David Konopnicki Hash Clusters ä Organization like simple clusters but... ä A row is stored in a hash cluster based on the result of applying a hash function to the row’s cluster key value. ä All rows with the same key value are stored together on the disk.

David Konopnicki Example: Hash Cluster

David Konopnicki Access Methods (cont...) ä Cluster Scans: ä Retrieves all the rows that have the same cluster key value. ä ORACLE first obtains the ROWID of one of the selected rows by scanning the cluster index. ä ORACLE then locates the rows based on this ROWID.

David Konopnicki Access Methods (Cont...) ä Hash Scans: ä ORACLE first obtains the hash value by applying the hash function. ä ORACLE then scans the data blocks containing rows with that hash value.

David Konopnicki Access Methods ä Index Scans: ä ORACLE searches the index for the indexed column values accessed by the statement. ä If the statement accesses only columns of the index, ORACLE reads the values only from the index. ä In the other case, ORACLE uses the ROWID found in the index to read the specific row from the table.

David Konopnicki Index Scan (cont...) ä An index scan can be one of these types: ä Unique: a unique scan of the index returns only a single ROWID. ä Range: A range scan can return more than one ROWID.

David Konopnicki The Rank of the access paths

David Konopnicki Single Row By ROWID ä If the Where Clause identifies the ROWID ä Example: SELECT * FROM emp WHERE ROWID=‘00000DC ’

David Konopnicki Single Row by Cluster Join ä For statements that join tables stored in the same cluster if: ä the statement equates every column of the cluster in each table. ä there is a condition that guarantees that only one row will be returned.

David Konopnicki Example SELECT * FROM emp,dept WHERE emp.deptno =dept.deptno AND emp.empno=7800

David Konopnicki Single Row by Hash Cluster Key with Unique or Primary Key ä The WHERE clause uses all columns of a hash cluster key with equality conditions. ä The statement is guaranteed to return only one row because the columns of the cluster key makes also a primary or unique key.

David Konopnicki Example SELECT * FROM orders WHERE orderno =

David Konopnicki Single Row by Unique or Primary key ä The WHERE clause uses all the columns of a unique or primary key in equality condition. ä ORACLE uses the index of the key to find the ROWID and then accesses the row in the table.

David Konopnicki Example SELECT * FROM emp WHERE empno=7800

David Konopnicki Clustered Join ä The statement joins tables stored in the same cluster, that is the WHERE clause equates the columns of the cluster columns in the two tables. ä To execute the statement, ORACLE performs a nested loop operation.

David Konopnicki Example SELECT * FROM emp,dept WHERE emp.deptno = dept.deptno

David Konopnicki Hash Cluster Key ä The WHERE clause uses all the columns of the hash key in equality conditions. ä ORACLE calculates the hash value and then performs a hash scan. SELECT * FROM line_items WHERE deptno=

David Konopnicki Indexed Cluster Key ä ORACLE searches the cluster index to find the ROWID. ä ORACLE then scans the rows with the same cluster key using this ROWID. SELECT * FROM emp WHERE deptno = 10

David Konopnicki Composite Index ä All the columns of the index are in the WHERE clause in equality conditions. ä ORACLE scans the index for the ROWIDs and then accesses the table SELECT * FROM emp WHERE job=‘CLERK’ AND deptno=30

David Konopnicki Single Column indexes SELECT * FROM emp WHERE job=‘CLERK’ ä ORACLE can merge indexes if the query conditions uses columns of many single column indexes

David Konopnicki Bounded Range Search on Indexed Columns ä The conditions uses either a single-column index or the leading portion of a composite index: column = expr column >[=] expr AND column [=] expr AND column <[=] expr column BETWEEN expr AND expr column LIKE ‘c%’ ä ORACLE performs a range scan on the index and then accesses the table by ROWID.

David Konopnicki Unbounded Range Search on Indexed Columns column >[=] expr column <[=] expr

David Konopnicki Sort Merge Join ä Join on non-clustered columns.

David Konopnicki Max or Min of Indexed Column SELECT MAX(sal) FROM emp ä ORACLE performs a range scan on the index

David Konopnicki ORDER BY on indexed column SELECT * FROM emp ORDER BY empno

David Konopnicki Full Table Scan ä For any SQL statement. ä Remark: You cannot use a index if you have column1 (>| =| | =|<=) column2 column IS NULL column IS NOT NULL column NOT IN column != column LIKE column1 and column2 are in the same table.

David Konopnicki Cost-Based Optimization To choose among the available access paths, the optimizer considers these factors: ä Selectivity of the query. (big % : Full scan, small %: index scan).  DB_FILE_MULTIBLOCK_READ_COUNT (high: Full scan, small: index scan)

David Konopnicki Example ä If ename is a unique or primary key, the optimizer determines that this query is highly selective and that it must use the index. ä If ename is not a key, the optimizer uses the following statistical values: USER_TAB_COLUMNS.NUM_DISTINCT USER_TABLES.NUM_ROWS By assuming that the ename values are uniformly distributed, the optimizer can evaluate the selectivity SELECT * FROM emp WHERE ename = ‘JACKSON’

David Konopnicki Example  To estimate the selectivity of this query, the optimizer uses the boundary value of 7500 the statistics HIGH_VALUE and LOW_VALUE in the USER_TAB_COLUMNS stats table. It assumes that the values are evenly distributed in the range to estimate the selectivity of the condition. SELECT * FROM emp WHERE empno < 7500

David Konopnicki Example  The value of the bind variable :e1 is unknown at optimization time, therefore the optimizer heuristically guesses 25% of selectivity. SELECT * FROM emp WHERE empno < :e1

David Konopnicki Example ä Let S1 be the selectivity of the condition empno >= ä Let S2 be the selectivity of the condition empno <= ä The optimizer estimates the selectivity of the statement as: S = ABS(S1+S2-1) SELECT *FROM emp WHERE empno BETWEEN 7500 AND 7800 :e1 :e2 S2 = 25% S1 = 25% S = ABS( ) = 50 %