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

  Implement in access database using check and unique

These comprise NOT NULL, CHECK, UNIQUE, REFERENTIAL INTEGRITY, and PRIMARY KEY constraints. Are these constraints which we are talking about easy to implement in Access Database?

  Write set of relational schemas-identify primary-foreign key

Sketch an E-R diagram which reflects the above reuirements. Write a set of relational schemas and identify primary and foreign keys. Try not to include redundant schemas.

  Draw an e-r diagram

Draw an E-R Diagram and draw an E-R Diagram for Student Information System.

  Write the functional dependencies in the table

Write the functional dependencies in the table which concerns invoicing (an application Premiere Products is considering adding to its database), subject to the specified conditions.

  Find the names of employees with the highest salary

Find all department(s) with at least two employees of different names and find the department(s) with the most people and find the names of employee(s) with the highest salary.

  Optimistic concurrency control sets few locks on the data

Optimistic concurrency control sets few locks on the data in the database, lowering the isolation level that you use in an application. This allows more applications to run concurrently and potentially increases the throughput of the applications. Th..

  Case - max in the state department

Construct a diagram using Rationale to map the arguments about a moral claim that you have identified in the article/case study and write an essay, which maps closely to the Rationale diagram that you constructed.

  Create a decision table that describes movement of inventory

Name four attributes that you can use to define a data flow in the grocery inventory information system.

  Advantage storing metadata in tables

What advantage is there in storing metadata in tables? Is Microsoft Access a DBMS? Why or why not? List the several consequences of a poorly designed database.

  Make a spreadsheet to compare e-commerce sites

create a spreadsheet to compare the three identified e-commerce hosting sites and the e-commerce hosting site that you find • prepare a PowerPoint presentation that represents the presentation you would give to management explaining your selection..

  Explain class diagram

Explain Class diagram. Outline the main steps in developing a class diagram for a Use Case(UC).

  Objectivesto analyse and comprehend a provided er diagram

objectivesto analyse and comprehend a provided er diagram and database schemato implement a database based on the

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