Relational Calculus: We Will Occasionally Use This Arrow Notation Unless There Is Danger of No Confusion
Relational Calculus: We Will Occasionally Use This Arrow Notation Unless There Is Danger of No Confusion
b • If a is true, b must be
true for the implication
T F to be true. If a is true
and b is false, the
implication evaluates to
T T F false.
a • If a is not true, we don’t
care about b, the
F T T expression is always
true.
Unsafe Queries, Expressive Power
• syntactically correct calculus queries that have an
infinite number of answers! Unsafe queries.
– e.g.,
S | S Sailors
– Solution???? Don’t do that!
• Expressive Power (Theorem due to Codd):
– every query that can be expressed in relational algebra can be
expressed as a safe query in DRC / TRC; the converse is also
true.
• Relational Completeness: Query language (e.g., SQL) can
express every query that is expressible in relational
algebra/calculus. (actually, SQL is more powerful, as we
will see…)
Summary
• The relational model has rigorously defined query
languages — simple and powerful.
• Relational algebra is more operational
– useful as internal representation for query evaluation plans.
• Relational calculus is non-operational
– users define queries in terms of what they want, not in
terms of how to compute it. (Declarative)
• Several ways of expressing a given query
– a query optimizer should choose the most efficient version.
• Algebra and safe calculus have same expressive power
– leads to the notion of relational completeness.
Midterm I - Info
• Remember - Lectures, Sections, Book & HW1
• 1 Cheat Sheet (2 sided, 8.5x11) - No electronics.
• Tues 2/21 in class
• Topics: next
Midterm I - Topics
• Ch 1 - Introduction - all sections
• Ch 3 - Relational Model - 3.1 thru 3.4
{S | SSailors
B((BBoats)
R(RReserves S.sid = R.sid
B.bid = R.bid))}
... reserved all red boats
{S | SSailors
B( (BBoats B.color = “red”)
R(RReserves S.sid = R.sid
B.bid = R.bid))}
• Find all sailors S such that for each tuple B
either it is not a tuple in Boats or there is a tuple in
Reserves showing that sailor S has reserved it.
{S | SSailors
B((BBoats) (B.color “red”)
R(RReserves S.sid = R.sid
B.bid = R.bid))}