DRAFT SOLUTION. Query 1(a) DATABASE MANAGEMENT SYSTEMS PRACTICE 1

Similar documents
Objectives. After completing this lesson, you should be able to do the following:

Databases - 4. Other relational operations and DDL. How to write RA expressions for dummies

Oracle Database 11g: SQL Tuning Workshop

Oracle DB-Tuning Essentials

Databases - 3. Null, Cartesian Product and Join. Null Null is a value that we use when. Something will never have a value

Databases - 3. Null, Cartesian Product and Join. Null Null is a value that we use when. Something will never have a value

Objectives. After completing this lesson, you should be able to do the following:

CS2 Current Technologies Note 1 CS2Bh

GIFT Department of Computing Science Data Selection and Filtering using the SELECT Statement

Databases IIB: DBMS-Implementation Exercise Sheet 13

QUERY OPTIMIZATION FOR DATABASE MANAGEMENT SYSTEM BY APPLYING DYNAMIC PROGRAMMING ALGORITHM

CSIT5300: Advanced Database Systems

Suppose we need to get/retrieve the data from multiple columns which exists in multiple tables...then we use joins..

Physical Design. Elena Baralis, Silvia Chiusano Politecnico di Torino. Phases of database design D B M G. Database Management Systems. Pag.

Data Science and Database Technology

Databases. Relational Model, Algebra and operations. How do we model and manipulate complex data structures inside a computer system? Until

Join Methods. Franck Pachot CERN

SQL Structured Query Language Introduction

QUERY OPTIMIZATION [CH 15]

Oracle Hints. Using Optimizer Hints

CS2 Current Technologies Lecture 3: SQL - Joins and Subqueries

5 Integrity Constraints and Triggers

RNDr. Michal Kopecký, Ph.D. Department of Software Engineering, Faculty of Mathematics and Physics, Charles University in Prague

Oracle Database 11g: SQL Tuning Workshop. Student Guide

Visit for more.

Introduction to Query Processing and Query Optimization Techniques. Copyright 2011 Ramez Elmasri and Shamkant Navathe

Querying Data with Transact SQL

ENHANCING DATABASE PERFORMANCE

Chapter 16: Advanced MySQL- Grouping Records and Joining Tables. Informatics Practices Class XII. By- Rajesh Kumar Mishra

System R Optimization (contd.)

Query optimization. Elena Baralis, Silvia Chiusano Politecnico di Torino. DBMS Architecture D B M G. Database Management Systems. Pag.

Query Optimization. Vishy Poosala Bell Labs

Interpreting Explain Plan Output. John Mullins

(Storage System) Access Methods Buffer Manager

ORACLE TRAINING CURRICULUM. Relational Databases and Relational Database Management Systems

Algorithms for Query Processing and Optimization. 0. Introduction to Query Processing (1)

Indices. We consider B-Trees only

Evaluation of Relational Operations

Question 1 (a) 10 marks

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

MANAGING DATA(BASES) USING SQL (NON-PROCEDURAL SQL, X401.9)

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

SQL. Char (30) can store ram, ramji007 or 80- b

Database System Concepts

Database Optimization

Wolfgang Breitling.

Real-World Performance Training SQL Introduction

1 SQL Structured Query Language

What happens. 376a. Database Design. Execution strategy. Query conversion. Next. Two types of techniques

Oracle SQL Tuning for Developers Workshop Student Guide - Volume I

@vmahawar. Agenda Topics Quiz Useful Links

Examples of Physical Query Plan Alternatives. Selected Material from Chapters 12, 14 and 15

1 SQL Structured Query Language

Introduction. Introduction to Oracle: SQL and PL/SQL

Chapter 3. Algorithms for Query Processing and Optimization

20 Essential Oracle SQL and PL/SQL Tuning Tips. John Mullins

Semantic Errors in Database Queries

Database Management Systems (COP 5725) Homework 3

Query Evaluation and Optimization

Oracle Database 12c: SQL Tuning for Developers

192 Chapter 14. TotalCost=3 (1, , 000) = 6, 000

Tables From Existing Tables

GIFT Department of Computing Science. CS-217/224: Database Systems. Lab-5 Manual. Displaying Data from Multiple Tables - SQL Joins

Detecting Logical Errors in SQL Queries

Hash-Based Indexing 165

And Answers In Oracle Pl Sql

Chapter 12: Query Processing

Implementation of Relational Operations

PS2 out today. Lab 2 out today. Lab 1 due today - how was it?

Chapter 13: Query Processing

Improving Database Performance: SQL Query Optimization

10. Record-Oriented DB Interface

Outline. Database Tuning. Join Strategies Running Example. Outline. Index Tuning. Nikolaus Augsten. Unit 6 WS 2014/2015

Evaluation of Relational Operations. Relational Operations

Oracle ADF 11g: New Declarative Validation, List of Values, and Search Features. Steve Muench Consulting Product Manager Oracle ADF Development Team

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

Temporal Relations 369 / 482

Database Applications (15-415)

Query Optimization Overview

Querying Data with Transact-SQL

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

! A relational algebra expression may have many equivalent. ! Cost is generally measured as total elapsed time for

Chapter 13: Query Processing Basic Steps in Query Processing

DBMS Query evaluation

Midterm 1: CS186, Spring I. Storage: Disk, Files, Buffers [11 points] cs186-

Create Rank Transformation in Informatica with example

Database implementation Further SQL

Datenbanksysteme II: Caching and File Structures. Ulf Leser

R & G Chapter 13. Implementation of single Relational Operations Choices depend on indexes, memory, stats, Joins Blocked nested loops:

Query Optimization. Schema for Examples. Motivating Example. Similar to old schema; rname added for variations. Reserves: Sailors:

The Oracle Optimizer Explain the Explain Plan O R A C L E W H I T E P A P E R A P R I L

GIFT Department of Computing Science. CS-217: Database Systems. Lab-4 Manual. Reporting Aggregated Data using Group Functions

RDBMS- Day 4. Grouped results Relational algebra Joins Sub queries. In today s session we will discuss about the concept of sub queries.

Chapter. Relational Database Concepts COPYRIGHTED MATERIAL

MySQL DML Commands - Joins and subqueries

Oracle Sql Tuning- A Framework

Advanced Databases: Parallel Databases A.Poulovassilis

1Z0-007 ineroduction to oracle9l:sql

Based on the following Table(s), Write down the queries as indicated: 1. Write an SQL query to insert a new row in table Dept with values: 4, Prog, MO

Optimizer Challenges in a Multi-Tenant World

Transcription:

DATABASE MANAGEMENT SYSTEMS PRACTICE 1 DRAFT SOLUTION Remark: Solutions in Algebra reflects the choices and the values returned by the Oracle Optimizer. Query 1(a)

The Oracle optimizer prefers to use the hash join, even if Table DEPT is relatively small, because the hash join implementation in Oracle is very efficient. Indexes on primary keys are created by default, but they are not used for table access.

Query 1(b)

Changing the optimizer goal to /*+ FIRST_ROWS(1) */ (n=1) the optimizer prefers to use nested loop (with DEPT as inner table and EMP as outer table). The inner table is accessed using unique index scan, which exploits the index on the primary key. Increasing the value of n from 1 to 3 (or more) the optimizer chooses the same plan as in best throughout configuration (hash join and table access full for both tables).

Query 2 Since the hint is to avoid using hash, the Oracle optimizer prefers to use nested loop (with DEPT inner table and EMP outer table). The inner table is accessed using unique index scan, which exploits the index on the primary key. The outer table is accessed through a full table scan. After the join operation, the Oracle optimizer performs a group by hash.

Query 3 The Oracle optimizer performs two cascaded join operations: the first one between EMP and SALGRADE, the second one between DEPT and the result of the former join. Since the hint is to avoid using hash, the Oracle optimizer prefers to use nested loop to perform the last join (with DEPT as inner table). The inner table is accessed using unique index scan, which exploits the index on the primary key. The antijoin operation is still performed using hash. Table SALGRADE, which is a relatively small table, is accessed through full table scan.

Query 4 Without indexes:

Statistics related to Table EMP columns: After creating an index on attribute Sal of Table EMP (create index EmpSalInd ON EMP(sal);) and another index on attribute Deptno of Table EMP (create index DeptnoInd ON EMP(deptno);), the two indexes are used separately (index range scan) to perform selection operations on different attributes.

To improve query performance we investigate the use of a composite index composed of two attributes. From the analysis of the height-balanced histograms for columns DEPTNO and SAL on Table EMP, it turns out that DeptNo is more selective than Sal.

Hence, the overall cost (4) achieved by creating a composite index with Deptno as first attribute (create index DeptnoSalInd ON EMP(Deptno,sal);) is lower than the one (8) achieved by combining the same attributes in the opposite order (create index SalDeptnoInd ON EMP(Sal,Deptno);).

Query 5 Without indexes: Histograms related to attribute Job of EMP:

The selectivity of the selection criterion Job = PHILOSOPHER is high. Hence, an index on attribute Job of Table EMP is deemed useful for query optimization purposes. After creating an index on Job (create index EmpJobInd ON EMP(job);) the Oracle optimizer performs an index range scan on EMP.

Creating a joint index on Job and Deptno (create index EmpJobDeptnoInd ON EMP(job,deptno);) the Oracle optimizer uses that index instead of the previous one. However, the overall query execution cost remains the same.

Query 6 Without indexes:

After creating an index on attribute Job of Table EMP (create index EmpJobInd ON EMP(job);):

The selectivity of the selection criterion Job = PHILOSOPHER is high, whereas the one of Job = ENGINEER is low. Hence, on the two instances of the same table EMP (E1 and E2) the Oracle optimizer uses different access methods, i.e., it performs a full table scan on E2 and an index scan on E1.

Query 7 Without indexes:

Height-balanced histograms on attribute Hisal of Table SALGRADE:

Creating an index on Attribute Hisal of Table SALGRADE (create index HisalInd ON SALGRADE(hisal);) the Oracle optimizer performs a fast full scan on SALGRADE. Note that in the inner query the optimizer just needs to access data in the index itself, without accessing the table. The expression LNNVL("HISAL"<>:B1) is used to also manage NULL values, because attribute HISAL is nullable.