Module 14: Analyzing Queries. Overview Queries That Use the AND Operator the OR Operator Join Operations.

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

Chapter 4 Joining Multiple Tables
EXECUTION PLANS By Nimesh Shah, Amit Bhawnani. Outline  What is execution plan  How are execution plans created  How to get an execution plan  Graphical.
Database Management Systems 3ed, R. Ramakrishnan and Johannes Gehrke1 Evaluation of Relational Operations: Other Techniques Chapter 14, Part B.
Database Management Systems, R. Ramakrishnan and Johannes Gehrke1 Evaluation of Relational Operations: Other Techniques Chapter 12, Part B.
Chapter 11 Group Functions
CSEN 5314 Quiz What type of join is needed when you wish to include rows that do not have matching values? A. Equi-joinB. Natural join C. Outer.
1 Implementation of Relational Operations Module 5, Lecture 1.
Module 13: Optimizing Query Performance. Overview Introduction to the Query Optimizer Obtaining Execution Plan Information Using an Index to Cover a Query.
David Konopnicki Choosing Access Path ä The basic methods. ä The access paths and when they are available. ä How the optimizer chooses among the.
Virtual techdays INDIA │ 9-11 February 2011 SQL 2008 Query Tuning Praveen Srivatsa │ Principal SME – StudyDesk91 │ Director, AsthraSoft Consulting │ Microsoft.
1 Optimization - Selection. 2 The Selection Operation Table: Reserves(sid, bid, day, agent) A page (block) can hold 100 Reserves tuples There are 1,000.
Indexes Rose-Hulman Institute of Technology Curt Clifton.
Module 7: Creating and Maintaining Indexes. Overview Creating Indexes Creating Index Options Maintaining Indexes Introduction to Statistics Querying the.
1 Evaluation of Relational Operations: Other Techniques Chapter 12, Part B.
8-1 Outline  Overview of Physical Database Design  File Structures  Query Optimization  Index Selection  Additional Choices in Physical Database Design.
A Guide to MySQL 7. 2 Objectives Understand, define, and drop views Recognize the benefits of using views Use a view to update data Grant and revoke users’
1 Chapter 2 Reviewing Tables and Queries. 2 Chapter Objectives Identify the steps required to develop an Access application Specify the characteristics.
Chapter 8 Physical Database Design. McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Outline Overview of Physical Database.
Access Path Selection in a Relation Database Management System (summarized in section 2)
The query processor does what the query plan tells it to do A “good” query plan is essential for a well- performing.
Relational Database Performance CSCI 6442 Copyright 2013, David C. Roberts, all rights reserved.
Introduction to Databases Chapter 8: Improving Data Access.
Module 12: Optimizing Query Performance. Overview Introducing the Query Optimizer Tuning Performance Using SQL Utilities Using an Index to Cover a Query.
Ashwani Roy Understanding Graphical Execution Plans Level 200.
Chapter 9 Joining Data from Multiple Tables
Query Processing. Steps in Query Processing Validate and translate the query –Good syntax. –All referenced relations exist. –Translate the SQL to relational.
Relational Operator Evaluation. Overview Index Nested Loops Join If there is an index on the join column of one relation (say S), can make it the inner.
Online aggregation Joseph M. Hellerstein University of California, Berkley Peter J. Haas IBM Research Division Helen J. Wang University of California,
1 Chapter 10 Joins and Subqueries. 2 Joins & Subqueries Joins – Methods to combine data from multiple tables – Optimizer information can be limited based.
Microsoft AREC TAM Internship SQL Server Performance Tuning(I) Haijun Yang AREC SQL Support Team Feb, SQL Server 2000.
Indexes and Views Unit 7.
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.
SqlExam1Review.ppt EXAM - 1. SQL stands for -- Structured Query Language Putting a manual database on a computer ensures? Data is more current Data is.
Chapter 8 Physical Database Design. Outline Overview of Physical Database Design Inputs of Physical Database Design File Structures Query Optimization.
Chapter 5 Index and Clustering
Session 1 Module 1: Introduction to Data Integrity
Creating Indexes on Tables An index provides quick access to data in a table, based on the values in specified columns. A table can have more than one.
David Konopnicki –1997, Rev. MS Optimizing Join Statements To choose an execution plan for a join statement, the optimizer must choose: ä Access.
LINQ to DATABASE-2.  Creating the BooksDataContext  The code combines data from the three tables in the Books database and displays the relationships.
Relational Operator Evaluation. overview Projection Two steps –Remove unwanted attributes –Eliminate any duplicate tuples The expensive part is removing.
Table Structures and Indexing. The concept of indexing If you were asked to search for the name “Adam Wilbert” in a phonebook, you would go directly to.
Query Optimization Cases. D. ChristozovINF 280 DB Systems Query Optimization: Cases 2 Executable Block 1 Algorithm using Indices (if available) Temporary.
Writing Basic SQL SELECT Statements Lecture
Indexes Part 2 What type of Indexes are there? Make sure you have the pages 2 & 3 of the Lab for Indexes in front of you before playing this presentation.
Execution Plans Detail From Zero to Hero İsmail Adar.
Module 6: Creating and Maintaining Indexes. Overview Creating Indexes Understanding Index Creation Options Maintaining Indexes Introducing Statistics.
Diving into Query Execution Plans ED POLLACK AUTOTASK CORPORATION DATABASE OPTIMIZATION ENGINEER.
Views / Session 3/ 1 of 40 Session 3 Module 5: Implementing Views Module 6: Managing Views.
IFS180 Intro. to Data Management Chapter 10 - Unions.
Data Integrity & Indexes / Session 1/ 1 of 37 Session 1 Module 1: Introduction to Data Integrity Module 2: Introduction to Indexes.
SQL IMPLEMENTATION & ADMINISTRATION Indexing & Views.
Microsoft SQL Server 2005 Advanced SQL Programming and Optimization
Multiple Table Queries
Choosing Access Path The basic methods.
Module 4: Creating and Tuning Indexes
Teradata Join Processing
LESSON Database Administration Fundamentals Inserting Data.
Evaluation of Relational Operations: Other Operations
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Access: SQL Participation Project
Writing Basic SQL SELECT Statements
Query Processing CSD305 Advanced Databases.
Implementation of Relational Operations
CS222P: Principles of Data Management Notes #13 Set operations, Aggregation, Query Plans Instructor: Chen Li.
Evaluation of Relational Operations: Other Techniques
A – Pre Join Indexes.
Evaluation of Relational Operations: Other Techniques
Welcome!.
All about Indexes Gail Shaw.
Presentation transcript:

Module 14: Analyzing Queries

Overview Queries That Use the AND Operator the OR Operator Join Operations

Queries That Use the AND Operator Processing the AND Operator Returns rows that meet all conditions for every criterion specified in the WHERE clause Progressively limits the number of rows returned with each additional search condition Can use an index for each search condition of the WHERE clause Indexing Guidelines and Performance Considerations Define an index on one highly selective search criterion Evaluate performance between creating multiple, single- column indexes and creating a composite index

Queries That Use the OR Operator Processing the AND Operator Returns Rows That Meet Any of the Conditions for Every Criterion Specified in the WHERE Clause Progressively Increases the Number of Rows Returned with Each Additional Search Condition Can Use One Index or Different Indexes for Each Part of the OR Operator Always Performs a Table Scan or Clustered Index Scan If One Column Referenced in the OR Operator Does Not Have an Index or If the Index Is Not Useful Can Use Multiple Indexes

 Queries That Use Join Operations Selectivity and Density of a JOIN Clause How Joins Are Processed How Nested Loop Joins Are Processed Multimedia: How Joins Are Processed Considerations When Merge Joins Are Used How Hash Joins Are Processed

Selectivity and Density of a JOIN Clause Selectivity of a JOIN Clause Based on index density, if statistics are available Based on a number of considerations, if statistics are unavailable Density of a JOIN Clause An index with large number of duplicates has high join density A unique index has low join density Selectivity Percentage of Rows Returned

How Joins Are Processed membermember member_no … … Chen. Chen. Result Unique nonclustered index Nonclustered index chargecharge charge_no member_no … … member_no 5678 charge_no … … (13 row(s) affected USE credit SELECT m.member_no, c.charge_no, c.charge_amt, c.statement_no FROM member AS m INNER JOIN charge AS c ON m.member_no = c.member_no WHERE c.member_no = 5678 USE credit SELECT m.member_no, c.charge_no, c.charge_amt, c.statement_no FROM member AS m INNER JOIN charge AS c ON m.member_no = c.member_no WHERE c.member_no = 5678

How Nested Loop Joins Are Processed USE credit SELECT m.member_no, c.charge_no, c.charge_amt, s.statement_no FROM member AS m INNER JOIN charge AS c ON m.member_no = c.member_no INNER JOIN statement AS s ON c.member_no = s.member_no WHERE m.member_no = 5678 USE credit SELECT m.member_no, c.charge_no, c.charge_amt, s.statement_no FROM member AS m INNER JOIN charge AS c ON m.member_no = c.member_no INNER JOIN statement AS s ON c.member_no = s.member_no WHERE m.member_no = 5678 Joins the results with the qualifying rows of the charge table Retrieves qualifying rows from both tables and joins them 11 22chargecharge charge_no member_no statementstatement statement_no member_no … … membermember member_no … … Chen. Chen.

Multimedia: How Merge Joins Are Processed

Considerations When Merge Joins Are Used Requires That Joined Columns Are Sorted Evaluates Sorted Values Uses an existing index tree Leverages sort operations Performs its own sort operation Performance Considerations Usually default USE credit SELECT m.lastname, p.payment_amt FROM member AS m INNER JOIN payment AS p ON m.member_no = p.member_no WHERE p.payment_amt < 7000 AND m.firstname < 'Jak' USE credit SELECT m.lastname, p.payment_amt FROM member AS m INNER JOIN payment AS p ON m.member_no = p.member_no WHERE p.payment_amt < 7000 AND m.firstname < 'Jak'

Recommended Practices Define an Index on a Highly Selective Column Ensure That Useful Indexes Exist for All Columns Referenced in the OR Operator Minimize the Use of Hash Joins

Review Queries That Use the AND Operator the OR Operator Join Operations