Query Tuning. overview Use of Views CREATE VIEW techlocation AS SELECT ssnum, tech.dept, location FROM employee, tech WHERE employee.dept = tech.dept;

Slides:



Advertisements
Similar presentations
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
Advertisements

AOBD07/08H. Galhardas Query Tuning. H. Galhardas AOBD07/08 Query Tuning SELECT s.RESTAURANT_NAME, t.TABLE_SEATING, to_char(t.DATE_TIME,'Dy, Mon FMDD')
Data Warehouse Tuning. 7 - Datawarehouse2 Datawarehouse Tuning Aggregate (strategic) targeting: –Aggregates flow up from a wide selection of data, and.
Database Systems: A Practical Approach to Design, Implementation and Management International Computer Science S. Carolyn Begg, Thomas Connolly Lecture.
A Guide to Oracle9i1 Advanced Forms Builder Topics Chapter 10.
1 Physical Database Design and Tuning Module 5, Lecture 3.
March 2010ACS-4904 Ron McFadyen1 Aggregate management References: Lawrence Corr Aggregate improvement
Physical Database Monitoring and Tuning the Operational System.
H.Lu/HKUST L05: Query Processing & Tuning Queries  Query Processing -- Principles  Tuning Queries.
Tuning Relational Systems I. Schema design  Trade-offs among normalization, denormalization, clustering, aggregate materialization, vertical partitioning,
A Guide to Oracle9i1 Advanced SQL And PL/SQL Topics Chapter 9.
Chapter 17 Methodology – Physical Database Design for Relational Databases Transparencies © Pearson Education Limited 1995, 2005.
Team Dosen UMN Physical DB Design Connolly Book Chapter 18.
Cloud Computing Lecture Column Store – alternative organization for big relational data.
Week 6 Lecture Normalization
Practical Database Design and Tuning. Outline  Practical Database Design and Tuning Physical Database Design in Relational Databases An Overview of Database.
IT The Relational DBMS Section 06. Relational Database Theory Physical Database Design.
Context Tailoring the DBMS –To support particular applications Beyond alphanumerical data Beyond retrieve + process –To support particular hardware New.
Lecture 9 Methodology – Physical Database Design for Relational Databases.
PowerPoint Presentation for Dennis & Haley Wixom, Systems Analysis and Design, 2 nd Edition Copyright 2003 © John Wiley & Sons, Inc. All rights reserved.
Physical Database Design & Performance. Optimizing for Query Performance For DBs with high retrieval traffic as compared to maintenance traffic, optimizing.
Physical Database Design Chapter 6. Physical Design and implementation 1.Translate global logical data model for target DBMS  1.1Design base relations.
1 Implementation of Relational Operators. 2 Steps of processing a high-level query Parser Query Optimizer StatisticsCost Model QEPParsed Query Database.
Chapter 16 Methodology – Physical Database Design for Relational Databases.
Querying Large Databases Rukmini Kaushik. Purpose Research for efficient algorithms and software architectures of query engines.
DAY 12: DATABASE CONCEPT Tazin Afrin September 26,
H. Pang / NUS Principles of Query Processing Pang Hwee Hwa School of Computing, NUS CS5226 Week 5.
Chapter 16 Practical Database Design and Tuning Copyright © 2004 Pearson Education, Inc.
© Pearson Education Limited, Chapter 13 Physical Database Design – Step 4 (Choose File Organizations and Indexes) Transparencies.
10/10/2012ISC239 Isabelle Bichindaritz1 Physical Database Design.
Physical Database Design Transparencies. ©Pearson Education 2009 Chapter 11 - Objectives Purpose of physical database design. How to map the logical database.
Module 4 Designing and Implementing Views. Module Overview Introduction to Views Creating and Managing Views Performance Considerations for Views.
Methodology – Physical Database Design for Relational Databases.
Principles of Query Processing. Application Programmer (e.g., business analyst, Data architect) Sophisticated Application Programmer (e.g., SAP admin)
Index Tuning Conventional index. Overview.
ADVANCED TOPICS IN RELATIONAL DATABASES Spring 2011 Instructor: Hassan Khosravi.
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.
Query Tuning. Types of Nested Queries Uncorrelated subqueries with aggregates in the nested query SELECT ssnum FROM employee WHERE salary > (select avg(salary)
Lec 7 Practical Database Design and Tuning Copyright © 2004 Pearson Education, Inc.
Chapter 4 Logical & Physical Database Design
Chapter 5 : Integrity And Security  Domain Constraints  Referential Integrity  Security  Triggers  Authorization  Authorization in SQL  Views 
Infrastructure for Data Warehouses. Basics Of Data Access Data Store Machine Memory Buffer Memory Cache Data Store Buffer Bus Structure.
Chapter 5 Index and Clustering
Session id: Darrell Hilliard Senior Delivery Manager Oracle University Oracle Corporation.

1 Chapter 4. Tuning a Relational Database System May 2002 Prof. Sang Ho Lee School of Computing, Soongsil University
SQL IMPLEMENTATION & ADMINISTRATION Indexing & Views.
1 CS122A: Introduction to Data Management Lecture #15: Physical DB Design Instructor: Chen Li.
Practical Database Design and Tuning
Rya Query Inference.
Indexes By Adrienne Watt.
CS 540 Database Management Systems
Understanding Indexes in KB_SQL March 2001
Methodology – Physical Database Design for Relational Databases
Physical Database Design for Relational Databases Step 3 – Step 8
國立臺北科技大學 課程:資料庫系統 fall Chapter 18
File organization and Indexing
Practical Database Design and Tuning
Transactions, Locking and Query Optimisation
Systems Analysis and Design
Tuning Queries from (E&N)
Sunil Agarwal | Principal Program Manager
Index Tuning Additional knowledge.
The Relational Database Model
Creating and Managing Database Tables
Views 1.
Database Management System
PURCHASE MANAGEMNET.
Query Tuning.
Index Structures Chapter 13 of GUW September 16, 2019
Presentation transcript:

Query Tuning

overview

Use of Views CREATE VIEW techlocation AS SELECT ssnum, tech.dept, location FROM employee, tech WHERE employee.dept = tech.dept; SELECT location FROM techlocation WHERE ssnum = ; Optimizers expand views when identifying the query blocks to be optimized. The selection from techlocation is expanded into a join: SELECT location FROM employee, tech WHERE employee.dept = tech.dept AND ssnum = ;

Avoid Views with unnecessary Joins Join with Techdept unnecessarily CREATE VIEW Techlocation AS SELECT ssnum, Techdept.dept, location FROM Employee, Techdept WHERE Employee.dept = Techdept.dept SELECT dept FROM Techlocation WHERE ssnum = 4444 SELECT dept FROM Employee WHERE ssnum = 4444

Some Idiosyncrasies OR may stop the index being used –break the query and use UNION Order of tables may affect join implementation

Performance Impact of the Query Rewritings Running Example Employees Students 10 tech

Aggregate Maintenance Materialize an aggregate if needed “frequently” The accounting department of a convenience store chain issues queries every twenty minutes to obtain: –The total dollar amount on order from a particular vendor –The total dollar amount on order by a particular store outlet. Original Schema: Ordernum(ordernum, itemnum, quantity, purchaser, vendor) Item(itemnum, price) Ordernum and Item have a clustering index on itemnum The total dollar queries are expensive. Can you see why?

Aggregate Maintenance Add: –VendorOutstanding(vendor, amount), where amount is the dollar value of goods on order to the vendor, with a clustering index on vendor –StoreOutstanding(purchase r, amount), where amount is the dollar value of goods on order by the purchaser store, with a clustering index on purchaser. Each update to order causes an update to these two redundant tables (triggers can be used to implement this explicitely, materialized views make these updates implicit) Trade-off between update overhead and loopup speed-up.

Materialized Views in Oracle9i Oracle9i supports materialized views: CREATE MATERIALIZED VIEW VendorOutstanding BUILD IMMEDIATE REFRESH COMPLETE ENABLE QUERY REWRITE AS SELECT orders.vendor, sum(orders.quantity*item.price) FROM orders,item WHERE orders.itemnum = item.itemnum group by orders.vendor; Some Options: –BUILD immediate/deferred –REFRESH complete/fast –ENABLE QUERY REWRITE Key characteristics: –Transparent aggregate maintenance –Transparent expansion performed by the optimizer based on cost. It is the optimizer and not the programmer that performs query rewriting

Aggregate Maintenance Use trigger to update create trigger updateVendorOutstanding on orders for insert as update vendorOutstanding set amount = (select vendorOutstanding.amount+sum(inserted.quantity*item.price) from inserted,item where inserted.itemnum = item.itemnum ) where vendor = (select vendor from inserted) ;

Aggregate Maintenance SQLServer on Windows2000 accounting department schema and queries orders, 1000 items Using triggers for view maintenance On this experiment, the trade-off is largely in favor of aggregate maintenance

summary