relational-databaserelational-algebracartesian-productcross-jointuple-relational-calculus

Please clear this confusion regarding relational algebra/tuple relational calculus


1: The explanation given for this query is "the set of all tuples t such that there exists a tuple s in the relation borrow for which the values of t and s for the cname attribute are equal, and the value of s for the amount attribute is greater than 1200". But we never mentioned to which relation t belongs. What relation is it, and why?

enter image description here

2: In the underlying image, does "AND"ing those two projections (containing attribute "CustomerID" from the "customer" relation & attribute "orderID" from the "order" relation) give the Cartesian product of these two one-column relations? enter image description here


Solution

  • 1:

    Tuple t, appearing on the left hand side, is a tuple of the answer. { t | ...t... } means "the set of every value, t say, such that ...t... is true". For each tuple value we refer to it as t and if it satisfies the condition then it goes in the answer.

    2:

    In part 1 "∧" is used for the connective AND in a predicate logic expression in a relational tuple calculus query. Here in 2 you are using it between two relation expressions as a relational algebra operator. Usually "⋈" is used for NATURAL JOIN and "⨯" is used for CARTESIAN PRODUCT (aka CROSS JOIN). Sometimes there's only a NATURAL JOIN operator and if it is used with no common attributes then its use/value is just called a Cartesian product.

    Those are two different kinds of expression. However "∧" could be used in both, although for different things. This isn't a problem because between two predicate logic expressions it's obviously AND and between two relational algebra expressions it's obviously a relational algebra operator. I would expect that to be NATURAL JOIN. I haven't seen it used for CARTESIAN PRODUCT, but remember that a NATURAL JOIN with no common attributes is/returns a "Cartesian product". So your example does "give the Cartesian product of these two".

    Some relational algebra variants have tuples that are unordered with unique attribute names. Then typically CARTESIAN PRODUCT takes two relations that don't have any attributes in common and returns their NATURAL JOIN. Since the attribute names of tuple t in your calculus example aren't given any order, maybe it's that kind of relation.

    Some relational algebra variants have ordered tuples where attribute names can appear multiple times. Then typically CARTESIAN PRODUCT returns tuples with common attribute names appearing multiple times. This seems to be the case in the slides for the textbook by Silberschatz, Korth & Sudarshan. (Which uses "∧" only as AND.) Then a NATURAL JOIN has only one copy of common attributes but CARTESIAN JOIN has two, so they can differ. But in your example the two PROJECTION results have disjoint attribute sets. So NATURAL JOIN and CARTESIAN PRODUCT would return the same relation. (Assuming that attribute order is the same.)

    [The reason the same symbol is sometimes used for AND and NATURAL JOIN (and could be used for CARTESIAN PRODUCT) is that if relational algebra expression R holds the tuples where r(...) and relational algebra expression S holds the tuples where s(...) then R NATURAL JOIN S holds the tuples where r(...) AND s(...). In fact every relational algebra expression is the value of a corresponding relational calculus expression where relation names correspond to given predicates (meanings) and logic operators correspond to relation operators.]

    Use the relations, operators and symbols that you have been told to use by your instructor/textbook. If in doubt define your symbols or use words.