The order in which the tables in your queries are joined

Assignment Help Database Management System
Reference no: EM13380385

The order in which the tables in your queries are joined can have an effect on the query performs. If your query is joining all the large tables first and then joins to a smaller table, then this can cause a lot of unnecessary processing. The join order in each step means that the fewest number of rows are being returned to the next step, which in turn makes query performance better. Usually DBA's will try to find the best possible access method of the tables by performing the Explainplan on the query or by verifying the optimizer statistics. They also try to optimize the SQL workload by identifying the proper indexesfields in the "Where" clause for joining the tables. Before applying WHERE clause, the DBA's will always try to provide the best suited condition in "ON" condition while performing the Join, this will filter the data and reduce the join result itself. The subsequent join conditions will be executed with filtered data which makes better performance. After that only WHERE condition will apply filter conditions.They even try to eliminate the unnecessary large full table scan.

Let us consider the below Join query. Here Explain Plan will show how the statements are executed and it also shows the number of rows performed and the cost and CPU time taken. It produces the final record set of 665 rows.

setautotracetraceonly explain

Select P.ProductID, PS.ProductID, COL.ProductID

From Customerorderitem COL

Inner Join ProductSupplier PS

On COL.ProductID = PS.ProductID

Inner Join Product P

On COL.ProductID=  P.ProductID

Execution Plan

----------------------------------------------------------

Plan hash value: 1711654722

 

--------------------------------------------------------------------------------------------

| Id  | Operation              | Name              | Rows  | Bytes | Cost (%CPU)| Time     |

--------------------------------------------------------------------------------------------

|   0 | SELECT STATEMENT       |                   |  4882 |   185K|    11  (10)| 00:00:01 |

|   1 |  NESTED LOOPS          |                   |  4882 |   185K|    11  (10)| 00:00:01 |

|*  2 |   HASH JOIN            |                   |  4882 |   123K|    11  (10)| 00:00:01 |

|   3 |    INDEX FAST FULL SCAN| PRODSUPPLPK       |   288 |  3744 |     3   (0)| 00:00:01 |

|   4 |    TABLE ACCESS FULL   | CUSTOMERORDERITEM |  4882 | 63466 |     7   (0)| 00:00:01 |

|*  5 |   INDEX UNIQUE SCAN    | PRODUCTPK         |     1 |    13 |     0   (0)| 00:00:01 |

--------------------------------------------------------------------------------------------

 

 

After modifying the Join order, executed the query with Explain Plan and it executed with little less Cost than the previous query. It even reduced the number of rows processed based on the Nested loop of table "Productsupplier" and "Product"which returned 288 rows.It also produces the final record set of 665 rows. This Join order is preferred over the first query.

 

setautotracetraceonly explain

 

Select  P.ProductID, PS.ProductID, COL.ProductID

From Customerorderitem COL

Inner Join Product P

On COL.ProductID=  P.ProductID

Inner Join ProductSupplier PS

On P.ProductID = PS.ProductID;

 

 

Execution Plan

----------------------------------------------------------

Plan hash value: 862510404

 

--------------------------------------------------------------------------------------------

| Id  | Operation              | Name              | Rows  | Bytes | Cost (%CPU)| Time     |

--------------------------------------------------------------------------------------------

|   0 | SELECT STATEMENT       |                   |  4882 |   185K|    11  (10)| 00:00:01 |

|*  1 |  HASH JOIN             |                   |  4882 |   185K|    11  (10)| 00:00:01 |

|   2 |   NESTED LOOPS         |                   |   288 |  7488 |     3   (0)| 00:00:01 |

|   3 |    INDEX FAST FULL SCAN| PRODSUPPLPK       |   288 |  3744 |     3   (0)| 00:00:01 |

|*  4 |    INDEX UNIQUE SCAN   | PRODUCTPK         |     1 |    13 |     0   (0)| 00:00:01 |

|   5 |   TABLE ACCESS FULL    | CUSTOMERORDERITEM |  4882 | 63466 |     7   (0)| 00:00:01 |

 Indexes. Consider the Global Engineering and the Retail Company databases in your answers to these questions.

a. What problems could be caused by not having appropriate indexes?

b. What problems could be cause by having too many indexes?

c. What do database statistics contribute to defining appropriate indexes?

Reference no: EM13380385

Questions Cloud

Oracle has many features for managing and tracking users we : oracle has many features for managing and tracking users. we have discussed user accounts with username password
You have been hired as the cio of a large multinational : you have been hired as the cio of a large multinational internet advertising company. the president of the company is
Crescent manufacturing inc cmi is a luxury leader in : crescent manufacturing inc. cmi is a luxury leader in crafted and customized home furnishings. the corporate
1 not having an appropriate index can cause a full table : 1. not having an appropriate index can cause a full table scan while performing the select statement by using a
The order in which the tables in your queries are joined : the order in which the tables in your queries are joined can have an effect on the query performs. if your query is
1 a table scan is reading every record from the table in a : 1. a table scan is reading every record from the table in a sequential order to find the data that a query is looking
Within this project create a package called : within this project create a package called mycompletesystem1. author a new class within your newly created package
Learning outcomes assesseda describe and discuss the : learning outcomes assesseda describe and discuss the issues involved in managing software selection. b compare
A simple database with a single table contains data : a simple database with a single table contains data concerning rental properties in australia. the table contains five

Reviews

Write a Review

Database Management System Questions & Answers

  Digitalx has been operating a chain of retail stores

digitalx has been operating a chain of retail stores selling cds dvds and games for a number of years. recently they

  Define calculations and format the table

internship at Mountain View Realty, a real estate firm that focuses in the North Utah County area. The previous intern developed a spreadsheet listing houses listed and sold during the last several months. She included addresses, location, list pr..

  Create database for easydrive school of motoring

Create mission statements and mission objectives for database systems explained in the following case study EasyDrive School of Motoring. Also in mission objectives include 10 reports that the database system must support

  Use contemporary case tools in process and data modeling

Discuss the requirements needed to build a database for the scheduling process.

  How to use spool command

How to interactively query a database by using SQL statements and SQL*PLUS commands and how to use spool command to save an interactive session within SQL*PLUS.

  What is recovering database via rollforward

What is Recovering a database via rollforward? What is aim of transaction log? What is contained in transaction log?

  Modify the no interest credit company application

Modify the No Interest Credit Company application so it executes continuously for any number of customers until a sentinel value is supplied for the account number.

  One of the needs that your client has is a databaseto

one of the needs that your client has is a database.to design a database a database planner should spend a considerable

  What are the candidate keys of r

Compute the closure sets of R - find all non-trivial dependencies and what are the candidate keys of R?

  Design database in microsoft access

Access will draw a line, called_______a, between matching fields in two tables, indicating that the tables are related. You can then select fields from either table. Access joins the tables automatically.

  Create a database.

Create a database.

  Assume that a student table in a university

Assume that a student table in a university database has an index on StudentID (the primary key). and additional indexes on Major, Age, Marital status, and HomeZipCode.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd