
















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

















Unary Relational Operations: SELECT and PROJECT
Relational Algebra Operations from Set Theory
Binary Relational Operations: JOIN and DIVISION
Query Trees
Unary operator (one relation as operand)
Returns subset of the tuples from a relation that satisfies a selection condition: 𝜎<𝑠𝑒𝑙𝑒𝑐𝑡𝑖𝑜𝑛 𝑐𝑜𝑛𝑑𝑖𝑡𝑖𝑜𝑛> 𝑅 where
Applied independently to each individual tuple t in operand
Example:
𝜎 (^) 𝐷𝑛𝑜= 4 AND 𝑆𝑎𝑙𝑎𝑟𝑦> 2500 OR (𝐷𝑛𝑜= 5 AND 𝑆𝑎𝑙𝑎𝑟𝑦> 30000 ) EMPLOYEE
Do not confuse this with SQL’s SELECT statement!
Correspondence
Employee
FROM Employee WHERE JobType = 'Faculty';
ID Name S Dept JobType 12 Chen F CS Faculty 13 Wang M MATH Secretary 14 Lin F CS Technician 15 Liu M ECE Faculty
Unary operator (one relation as operand)
Keeps specified attributes and discards the others:
𝜋<𝑎𝑡𝑡𝑟𝑖𝑏𝑢𝑡𝑒 𝑙𝑖𝑠𝑡> 𝑅
Duplicate elimination
Example:
𝜋𝐹𝑛𝑎𝑚𝑒,𝐿𝑛𝑎𝑚𝑒,𝐴𝑑𝑑𝑟𝑒𝑠𝑠,𝑆𝑎𝑙𝑎𝑟𝑦 EMPLOYEE
Correspondence
Employee
SELECT DISTINCT Name, S, Department FROM Employee WHERE JobType = 'Faculty';
ID Name S Dept JobType 12 Chen F CS Faculty 13 Wang M MATH Secretary 14 Lin F CS Technician 15 Liu M ECE Faculty
Sometimes easier to write expressions a piece at a time
Consider in-line expression:
𝜋Fname,Lname,Salary 𝜎Dno= 5 (EMPLOYEE)
Equivalent sequence of operations:
DEP5_EMPS ← 𝜎Dno= 5 EMPLOYEE RESULT ← 𝜋Fname,Lname,Salary DEP5_EMPS
Binary operator
aka CARTESIAN PRODUCT or CROSS JOIN
R × S
Relations do not have to be union compatible
Often followed by a selection that matches values of attributes
What if both operands have an attribute with the same name?
Course dept cnum instructor term CS 338 Jones Spring CS 330 Smith Winter STATS 330 Wong Winter
TA name major Ashley CS Lee STATS
Course TA dept cnum instructor term name major CS 338 Jones Spring Ashley CS CS 330 Smith Winter Ashley CS STATS 330 Wong Winter Ashley CS CS 338 Jones Spring Lee STATS CS 330 Smith Winter Lee STATS STATS 330 Wong Winter Lee STATS
Unary RENAME operator
Example: pairing upper year students with freshmen
𝜌Mentor(senior,class) 𝜎year> 2 Student × 𝜎year= 1 Student
Student name year Ashley 4 Lee 3 Dana 1 Jo 1 Jaden 2 Billie 3
Examples:
Join selectivity
Common case (as in examples above): equijoin
Course dept cnum instructor term CS 338 Jones Spring CS 330 Smith Winter STATS 330 Wong Winter
TA name major Ashley CS Lee STATS
Course ⋈dept=major TA dept cnum instructor term name major CS 338 Jones Spring Ashley CS CS 330 Smith Winter Ashley CS STATS 330 Wong Winter Lee STATS
Very common case
Binary operator
R ÷ S
Used to answer questions involving all
“Inverse” of cross product
Works enum pnum E35 P E45 P E35 P E52 P E52 P E45 P E35 P
Critical pnum P P
Works ÷ Critical enum E E
( Works ÷ Critical ) × Critical enum pnum E45 P E45 P E35 P E35 P
Select 𝜎<𝑠𝑒𝑙𝑒𝑐𝑡𝑖𝑜𝑛 𝑐𝑜𝑛𝑑𝑖𝑡𝑖𝑜𝑛> 𝑅
Project 𝜋<𝑎𝑡𝑡𝑟𝑖𝑏𝑢𝑡𝑒 𝑙𝑖𝑠𝑡> 𝑅
Rename 𝜌<𝑛𝑒𝑤 𝑠𝑐ℎ𝑒𝑚𝑎> 𝑅
Union 𝑅 ∪ 𝑆
Intersection 𝑅 ∩ 𝑆
Difference 𝑅 − 𝑆
Cross product 𝑅 × 𝑆
Natural join 𝑅 ⋈ 𝑆
Division 𝑅 ÷ 𝑆