Subtask 10.2.1
Run the following JOIN of two tables which has two restrictions.
Examine the output
– is this what you expect? Prefix the query with “EXPLAIN EXTENDED”
and review
the output.
SQL
EXPLAIN EXTENDED
SELECT * FROM Orders NATURAL JOIN Order_Details WHERE
QuotedPrice > 1000 AND OrderDate BETWEEN '2012-10-01'
AND '2012-10-31';
Examine the query plan output with the help of the column
explanations given above.
Describe in your own words how the DBMS is fetching the rows. For
each table, does
it look through the data rows or access them through an index? How
does this
influence the number of rows examined? According to the output,
which table was
accessed first? Why do you think the DBMS decided to access this
table first instead
of the other one (both have restrictions)?
If you need to find out which columns are accessed through an
index, run
SHOW indexes in Order_Details;
Document your findings and upload them.
Here we have used NATURAL JOIN which will works only when both
table(Orders and Order_Details) has least one common attribute with
same name.For example if the both table has order_id has
common column then sql first generates the same column once then
join the matching attributes where the values of attributes in both
the relations are same.
Naturally the sql hits the first table(Orders) which mentioned in
query then compare its value with common attributes(highly detect
the primay key or foreign key)and composed of comparing
order_id from both the two tables.
And so output for given sql doesn't have all the attributes to join with common order_id because there are two where condition which commonly applied in both tables that QuotedPrice should be greater than 1000 and also OrderDate should be between '2012-10-01 and '2012-10-31'.
Get Answers For Free
Most questions answered within 1 hours.