Chapter 2
Chapter 2
By Tadesse B.
Chapter Outline
• πLname,Fname,Salary (Employee)
• Where π (Pi) is used to represent the project operation.
• If the attribute list includes only nonkey attributes or R, duplicate
tuples are likely to occur.
• But project operation removes any duplicate tuples.
• Project operation is not commutative.
05/14/25 By Tadesse B. Slide 15- 5
JOIN
• πDname,Lname,Fname(R<mgrSSN=SSN>S (Employee))
05/14/25 By Tadesse B. Slide 15- 6
Types of join operations
INNER JOIN
•Used to combine data from multiple relations so that related information can be
presented in a single table, only matching records are kept in the result.
LEFT OUTER JOIN
All rows from left side table are display
Matching value rows from right side table
Null values in place of non matching rows in other table
• What is Query?
• to ask questions, especially in order to check if something is
true(dictionary definition)
• Retrievals of records(db definition)
• Example SELECT LName, Fname FROM
EMPLOYEE
WHERE Salary > 4500
• What is Query Processing?
• The range of activities involved in extracting data from a
database.
• Includes: translation of queries, query-optimizing
transformations, evaluation of queries.
05/14/25 By Tadesse B. Slide 15- 9
Basic Steps in Query
Processing
1. Parsing and translation
2. Optimization
3. Evaluation
Optimizer
Query
Evaluation Engine Execution Plan
Output
Statistics
Data
About Data
• Query tree:
• A tree data structure that corresponds to a relational algebra
expression.
• It represents the input relations of the query as leaf nodes of the
tree, and represents the relational algebra operations as internal
nodes.
• An execution of the query tree consists of executing an internal node
operation whenever its operands are available and then replacing that
internal node by the relation that results from executing the operation.
• Query graph:
• A graph data structure that corresponds to a relational calculus
expression.
• It does not indicate an order on which operations to perform first.
• There is only a single graph corresponding to each query.
1.Portions of the file that can fit in the available buffer space
are read into the main memory
• Examples:
• (OP1): s SSN='123456789' (EMPLOYEE)
• (OP2): s DNUMBER>5(DEPARTMENT)
• (OP3): s DNO=5(EMPLOYEE)
• (OP4): s DNO=5 AND SALARY>30000 AND SEX=F(EMPLOYEE)
• (OP5): s ESSN=123456789 AND PNO=10(WORKS_ON)
Example:
Q: SELECT LNAME
FROM EMPLOYEE, WORKS_ON,
PROJECT
WHERE PNAME = ‘AQUARIUS’ AND
PNMUBER=PNO AND ESSN=SSN
AND BDATE > ‘1957-12-31’;
05/14/25 By Tadesse B. Slide 15- 39
Cont. …
05/14/25 By Tadesse B. 45
Typical stages in query
decomposition …
• Semantic Analysis:
• to reject normalized queries that are not correctly formulated or
contradictory. Incorrect if components do not contribute to generate
result.
• Contradictory if the predicate can not be satisfied by any tuple.
• for example,(gender=“m” gender= “f”) since a given book can
only be classified in either of the category at a time
• Simplification:
Detect redundant qualifications, eliminate common sub-expressions,
and transform the query to a semantically equivalent but more
easily and effectively computed form.
For example, If a user don’t have the necessary access to all of the
objects of the query , it should be rejected.
05/14/25 By Tadesse B. 46
Semantic Query Optimization
• Uses constraints specified on the database schema in order to modify
one query into another query that is more efficient to execute.