Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask DBMS Expert


Home >> DBMS

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?

DBMS, Programming

  • Category:- DBMS
  • Reference No.:- M9750001

Have any Question?


Related Questions in DBMS

Database and information retrieval assignment - data

Database and Information Retrieval Assignment - Data Privacy Essay Task - Write an essay (aim for 750 words) that addresses issues associated with data proivacy. Use the Australian Privacy Principles - discussed in class ...

Question lab 1 creating a database designthis assignment

Question: Lab 1: Creating a Database Design This assignment contains two (2) Sections: Database Design Diagram and Design Summary. You must submit both sections as separate files in order to complete this assignment. Not ...

Data model development and implementationpurpose of the

Data model development and implementation Purpose of the assessment (with ULO Mapping) The purpose of this assignment is to develop data models and map Database System into a standard development environment to gain unde ...

Sql injection on a searchthe way search performs its task

SQL injection on a search The way Search performs its task is by executing the following query (in a php script):          $var=stripslashes($_POST['search']);          $query = "SELECT username from lab1_login where use ...

You are in a real estate business renting apartments to

You are in a real estate business renting apartments to customers. Your job is to define an appropriate schema using SQL DDL in MySQL. The relations are Property(Id, Address, NumberOfUnits), Unit(ApartmentNumber, Propert ...

Football association of zambia faz super leaguethe faz has

Football Association of Zambia (FAZ) Super League The FAZ has recently decided to reorganise their operations to support both existing and possibly expanded league operations in Zambia and part of preparation for the 201 ...

This is a starting out with visual basic programming

This is a starting out with visual basic programming problem, meaning its a basic programming nothing advanced. Question: Add a linq statement to the combo box text-changed event to dispaly the city field of the selected ...

In this section the student is required to develop a

In this section, the student is required to develop a technical debate based on his/her understanding using available scientific literature. The answer to this question should not exceed three A4 Pages. In the traditiona ...

Databases assignment - monash library services monlib case

Databases Assignment - Monash Library Services (MonLib) Case Study TASK 1: Data Definition For this task you are required to complete the following: 1.1 - Add to your solutions script, the CREATE TABLE and CONSTRAINT def ...

Suppose that you have designed a database for morgan

Suppose that you have designed a database for Morgan Importing that has the following tables: EMPLOYEE (EmployeeID, LastName, FirstName, Department, Phone, Fax, EmailAddress) STORE (StoreName, City, Country, Phone, Fax, ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As