5. Query Processing and Optimization
5. Query Processing and Optimization
■ Query optimization:
■ The process of choosing a suitable execution
strategy for processing a query.
■ Two internal representations of a query:
■ Query Tree
■ Query Graph
■ Examples:
■ (OP1): σ SSN='123456789' (EMPLOYEE)
■ (OP2): σ DNUMBER>5(DEPARTMENT)
■ (OP3): σ DNO=5(EMPLOYEE)
■ (OP4): σ DNO=5 AND SALARY>30000 AND SEX=F(EMPLOYEE)
■ (OP5): σ ESSN=123456789 AND PNO=10(WORKS_ON)
■ Example:
■ For a 2-way join, combine the 2 selections on the
input and one projection on the output with the
Join.
■ Dynamic generation of code to allow for multiple
operations to be pipelined.
■ Results of a select operation are fed in a
"Pipeline" to the join algorithm.
■ Also known as stream-based processing.
■ 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’;
■ Other transformations
■ Issues
■ Cost function
■ Number of execution strategies to be considered