-1

While studying relational algebra i came across that to apply UNION,INTERSECTION and SET DIFFERENCE on any relational schema the relational schema need to have UNION COMPATIBLE because these operations are set operations

But cartesian product is also set operation,then why the condition of UNION COMPATIBILITY is not necessary when we apply cartesian product operation on two relational schemas?

John
  • 19
  • 4
  • What do you think a "set operation" is? What forces one taking sets *of tuples* to have inputs with the same schema, or if they're the same then have output with the same schema? There are certain important operators on sets of tuples that don't all do that: *relational algebra operators*. You have some assumptions about "set operation" that you are not pinning down yet you are using them for fuzzily producing expectations. What assumptions? What is your *definition* of "set operation" & if you use it properly what problem arises re product? (Your expectations are unjustified.) – philipxy Sep 03 '18 at 18:31

1 Answers1

1

For sets R & S,

A tuple is in R ∪ S if and only if it is in R OR in S.
A tuple is in R ∩ S if and only if it is in R AND in S.
A tuple is in R - S if and only if it is in R AND NOT in S.

For relations (which get defined as sets or as sets plus headings),

UNION returns tuples that are in one operand OR the other.
INTERSECTION returns tuples that are in one operand AND the other.
DIFFERENCE returns tuples that are in one operand AND NOT the other.

So we can call reasonably call these the "set" or "boolean" operations.

If every base relation holds the tuples that make a true proposition (statement) from some associated predicate (sentence template parameterized by attribute names) then every query result has a predicate made from its operand predicates, and its value holds the tuples that make a true proposition from that predicate:

Suppose U holds tuples where U & V holds the tuples where V. Then

U UNION V holds the tuples where U OR V
U INTERSECTION V holds the tuples where U AND V
U DIFFERENCE V holds the tuples where U AND NOT V

But more than that it's not just that those operators correspond to some boolean propositional logic connectives/nonterminals, but that every relational operator corresponds to a predicate logic connective/nonterminal, every query expression has an associated predicate, and every query result value holds the tuples that make a true proposition from that predicate:

U JOIN V holds the tuples where U AND V
U RESTRICTcondition holds the tuples where U AND condition
U PROJECT A holds the tuples where FORSOME values for all attributes but A, U
U RENAME A A' holds the tuples where U with A replaced by A'

So really all relational operators can be tied to the syntax & semantics of predicate logic. Which is the language/notation of precision in mathematics, science (including computer science) & engineering (including software engineering.) In fact, that's how we know what a query means. So it's not really that those three operators are in some sense boolean in nature so much as that all relational operators are logical: every relation expression corresponds to a predicate logic expression.

The three "set operators" are called that because the set that is the body of the result relation arises from the sets that are the bodies of the operand relations according to the set operators by the same names. And that might be a helpful way to group them in your mind or remember them or their names, and no doubt inspired their names. But in light of the correspondence between relation operators and predicate logic connectives/nonterminals and the correspondence between relation expressions and predicate logic expressions and the correspondence between predicates and relation values, the fact that some relation operators are reminiscent of some set operators is totally irrelevant.

(So is the fact that you can make an algebra with things like relations but whose bodies are bags instead of sets.)

philipxy
  • 14,867
  • 6
  • 39
  • 83
  • Ok. I will. Meanwhile see [this](https://stackoverflow.com/a/49022424/3404097) & its links & [my relational algebra answers involving predicates](https://stackoverflow.com/search?q=user%3A3404097+predicate+%5Brelational-algebra%5D) PS What is the first thing you don't understand? – philipxy Sep 03 '18 at 18:05