DBMS
DBMS
Note: The above figure is now called Figure 15.3 (continued) in Edition 4
Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 15-23
Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Algorithms for SELECT and JOIN Operations
(14)
Implementing the JOIN Operation (cont.):
Factors affecting JOIN performance
– Available buffer space
Example:
For every project located in ‘Stafford’, retrieve the project number,
the controlling department number and the department manager’s
last name, address and birthdate.
Relation algebra:
PNUMBER, DNUM, LNAME, ADDRESS, BDATE (((PLOCATION=‘STAFFORD’(PROJECT))
DNUM=DNUMBER (DEPARTMENT)) MGRSSN=SSN (EMPLOYEE))
SQL query:
Q2: SELECT P.NUMBER,P.DNUM,E.LNAME, E.ADDRESS, E.BDATE
FROM PROJECT AS P,DEPARTMENT AS D, EMPLOYEE AS E
WHERE P.DNUM=D.DNUMBER AND D.MGRSSN=E.SSN AND
P.PLOCATION=‘STAFFORD’;
Note: The above figure is now called Figure 15.4 (continued) in Edition 4
Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 15-43
Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Using Heuristics in Query Optimization (6)
Heuristic Optimization of Query Trees:
The same query could correspond to many different relational
algebra expressions — and hence many different query trees.
Example:
Q: SELECT LNAME
FROM EMPLOYEE, WORKS_ON, PROJECT
WHERE PNAME = ‘AQUARIUS’ AND PNMUBER=PNO
AND ESSN=SSN AND BDATE > ‘1957-12-31’;
Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 15-44
Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Using Heuristics in Query Optimization (7)
Issues
– Cost function
– Number of execution strategies to be considered
Left-deep tree: a binary tree where the right child of each non-
leaf node is always a base relation.
– Amenable to pipelining
– Could utilize any access paths on the base relation (the right child)
when executing the join.