Tuning Queries from (E&N)

Slides:



Advertisements
Similar presentations
The Basics of Efficient SQL Written for myself –Writing doesnt make you rich Proof of what works –and what doesnt Three parts: –Data Model Tuning –SQL.
Advertisements

Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
Database Tuning. Overview v After ER design, schema refinement, and the definition of views, we have the conceptual and external schemas for our database.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
Copyright © 2004 Pearson Education, Inc.. Chapter 15 Algorithms for Query Processing and Optimization.
Copyright © 2011 Ramez Elmasri and Shamkant Navathe Algorithms for SELECT and JOIN Operations (8) Implementing the JOIN Operation: Join (EQUIJOIN, NATURAL.
Copyright © 2004 Ramez Elmasri and Shamkant Navathe Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 15-1 Query Processing and.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 19 Algorithms for Query Processing and Optimization.
Chapter 15 Algorithms for Query Processing and Optimization Copyright © 2004 Pearson Education, Inc.
OUTLINE OF THE LECTURE PART I GOAL: Understand the Data Definition Statements in Fig 4.1 Step1: Columns of the Tables and Data types. Step2: Single column.
1 CSE 480: Database Systems Lecture 22: Query Optimization Reference: Read Chapter 15.6 – 15.8 of the textbook.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
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.
Manajemen Basis Data Pertemuan 7 Matakuliah: M0264/Manajemen Basis Data Tahun: 2008.
DB performance tuning using indexes Section 8.5 and Chapters 20 (Raghu)
1 Physical Database Design and Tuning Module 5, Lecture 3.
ACS-4902 Ron McFadyen Chapter 15 Algorithms for Query Processing and Optimization.
ACS-4902 Ron McFadyen Chapter 15 Algorithms for Query Processing and Optimization See Sections 15.1, 2, 3, 7.
ICS (072)Query Processing and Optimization 1 Chapter 15 Algorithms for Query Processing and Optimization ICS 424 Advanced Database Systems Dr.
Chapter 19 Query Processing and Optimization
CS346: Advanced Databases Graham Cormode Physical Database Design and Tuning.
Practical Database Design and Tuning. Outline  Practical Database Design and Tuning Physical Database Design in Relational Databases An Overview of Database.
Copyright © 2004 Ramez Elmasri and Shamkant Navathe Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 15-1 Query Processing and.
Physical Database Design & Performance. Optimizing for Query Performance For DBs with high retrieval traffic as compared to maintenance traffic, optimizing.
1 CS 430 Database Theory Winter 2005 Lecture 12: SQL DML - SELECT.
Query Optimization Arash Izadpanah. Introduction: What is Query Optimization? Query optimization is the process of selecting the most efficient query-evaluation.
Relational Algebra - Chapter (7th ed )
Query Processing and Optimization
Nested Queries (Sub-Queries). Objectives Learn how to run a query as a nested sub-query Condition on nested query Application of nested query Restriction.
Chapter 16 Practical Database Design and Tuning Copyright © 2004 Pearson Education, Inc.
Structured Query Language. Group Functions What are group functions ? Group Functions Group functions operate on sets of rows to give one result per group.
Database Management Systems. NESTING OF QUERIES  Some queries require that existing values in the database be retrieved and then used in a comparison.
Database Management COP4540, SCS, FIU Physical Database Design (2) (ch. 16 & ch. 6)
1 Notes on: Clusters Index and Cluster Creation in SQL Elisa Bertino CS Department and CERIAS Purdue University.
Structured Query Language
42 Example Join-- File Information 4 Emp( Fn Char(10), Minit Char, LN Char(20), SSN number(9), Bdate Date, Addr char(40), Sex Char, Salary Number(9,2),
Query Tuning. Types of Nested Queries Uncorrelated subqueries with aggregates in the nested query SELECT ssnum FROM employee WHERE salary > (select avg(salary)
1/18/00CSE 711 data mining1 What is SQL? Query language for structural databases (esp. RDB) Structured Query Language Originated from Sequel 2 by Chamberlin.
Lec 7 Practical Database Design and Tuning Copyright © 2004 Pearson Education, Inc.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
Advance Database Systems Query Optimization Ch 15 Department of Computer Science The University of Lahore.
Query Processing – Implementing Set Operations and Joins Chap. 19.
1 SQL: The Query Language. 2 Example Instances R1 S1 S2 v We will use these instances of the Sailors and Reserves relations in our examples. v If the.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Basic SQL تنبيه : شرائح العرض (Slides) هي وسيلة لتوضيح الدرس واداة.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 Lecture # 10 July 10,2012 More SQL: Complex Queries, Triggers,
1 CS122A: Introduction to Data Management Lecture #15: Physical DB Design Instructor: Chen Li.
Chapter (6) The Relational Algebra and Relational Calculus Objectives
Practical Database Design and Tuning
Tuning Transact-SQL Queries
CS580 Advanced Database Topics
Indexes By Adrienne Watt.
Chapter 4 Basic SQL.
6/22/2018.
CS580 Advanced Database Topics
Database Performance Tuning and Query Optimization
Examples of Physical Query Plan Alternatives
LECTURE 3: Relational Algebra
Practical Database Design and Tuning
Database Applications (15-415) DBMS Internals- Part IX Lecture 21, April 1, 2018 Mohammad Hammoud.
SQL: Structured Query Language
Relational Algebra Sample Questions.
Advance Database Systems
Chapter 11 Database Performance Tuning and Query Optimization
Physical Database Design and Tuning
SQL Grouping, Ordering & Arithmetics Presented by: Dr. Samir Tartir
SQL: Set Operations & Nested Queries. Presented by: Dr. Samir Tartir
Query Tuning.
Physical Database Design and Tuning
Presentation transcript:

Tuning Queries from (E&N) 1/14/2019 Tuning Queries from (E&N) Copyright © 2004 Pearson Education, Inc.

Tuning Queries Indications for tuning queries A query issues too many disk accesses The query plan shows that relevant indexes are not being used.

Typical instances for query tuning Many query optimizers do not use indexes in the presence of arithmetic expressions (salary/365 > 10.5) numerical comparisons of attributes of different sizes and precision, (A=B and A is of type integer, B is of type smallinteger) NULL comparisons, and sub-string comparisons. (BDate is NULL)

Typical instances for query tuning Indexes are often not used for nested queries using IN; SELECT ssn FROM employee WHERE dno IN (SELECT dnumber FROM department WHERE mgr_ssn = ‘555’);

Typical instances for query tuning Some DISTINCTs may be redundant and can be avoided without changing the result. DISTINCT often causes a sort operation and must be operated if possible Unnecessary use of temporary result tables can be avoided by collapsing multiple queries into a single query unless the temporary relation is needed for some intermediate processing.

Typical instances for query tuning In some situations involving using of correlated queries, temporaries are useful. SELECT ssn FROM employee e WHERE salary = SELECT MAX (salary) FROM employee AS m WHERE m.dno = e.dno;

Typical instances for query tuning SELECT MAX(salary) AS high_salary, dno into TEMP FROM employee GROUP BY dno; SELECT ssn FROM employee e, temp t WHERE salary=high_salary and e.dno=t.dno;

Typical instances for query tuning If multiple options for join condition are possible, choose one that uses a clustering index and avoid those that contain string comparisons.

Typical instances for query tuning The order of tables in the FROM clause may affect the join processing Some query optimizers perform worse on nested queries compared to their equivalent un-nested counterparts. Many applications are based on views that define the data of interest to those applications. Sometimes these views become an overkill.

Additional Query Tuning Guidelines A query with multiple selection conditions that are connected via OR may not be prompting the query optimizer to use any index. Such a query may be split up and expressed as a union of queries, each with a condition on an attribute that causes an index to be used.

Additional Query Tuning Guidelines Apply the following transformations NOT condition may be transformed into a positive expression. Embedded SELECT blocks may be replaced by joins. If an equality join is set up between two tables, the range predicate on the joining attribute set up in one table may be repeated for the other table WHERE conditions may be rewritten to utilize the indexes on multiple columns.