Reputation: 2028
I'm confused how expression is different PROJECT A(r − s) and PROJECT A(r) − PROJECT A(s) is in RDBMS. Can anyone show an example to prove above?
Upvotes: 1
Views: 348
Reputation: 3086
s = [x y]
0 0
1 1
2 2
r = [x y]
0 0
0 1
0 2
1 1
1 2
2 2
A = {y}
PROJECT A(r − s)=[y]
1
2
PROJECT A(r) − PROJECT A(s)=[y]
Here is how to generate (counter)examples like this. The OP problem translates into QBQL assertion:
a <AND> TABLE_DUM = a & r <AND> TABLE_DUM =s <AND> TABLE_DUM
->
a v ( r <AND> <NOT> s ) = (a v r) <AND> <NOT> (a v s).
Where all operations, except "v"
(generalized projection) are from D&D Algebra A. The first two implication conditions require relation a
to be empty, and relations r
and s
to have the same header. It outputs:
s = [p]
0
;
r = [p]
1
;
a = [r]
;
*** False Assertion ***
Although this is legitimate answer, some may feel uncomfortable with an idea of projecting relation onto an attribute which doesn't belong to the header. One needs to add one more condition for a
and r
headers to overlap: (a v s) <AND> TABLE_DUM != TABLE_DUM
. Then, the attributes {p,r} should be manually translated into OP's {x,y}. (It is where the bug noticed by Erwin has been introduced).
Upvotes: 2
Reputation: 18408
r = { TUPLE {X 1 , Y 1} }
s = { TUPLE {X 1 , Y 2} }
r MINUS s = r = { TUPLE {X 1 , Y 1} }
Take projections over X (A = {X} ???)
r PROJECT {X} === { TUPLE {X 1} }
s PROJECT {X} === { TUPLE {X 1} }
(r PROJECT {X}) MINUS (s PROJECT {X}) === { }
(r MINUS s) PROJECT {X} === { TUPLE {X 1} }
It's the Y 2 part in s. That's the difference between the tuples in r and s. If you "project away that difference" first, then whatever remains after that is equal, and computing the difference between things that are equal is of course nothing at all.
But if you first compute the difference, then the Y 2 part in the tuple in s causes the tuple in r (sloppily speaking) to not be discarded from the result, and then taking a projection on that result of course produces itself something nonempty.
Upvotes: 2