Re: constraints in algebra instead of calculus
Date: Fri, 15 Jun 2007 09:23:33 -0700
Message-ID: <1181924613.177924.277440_at_g37g2000prf.googlegroups.com>
On May 26, 7:27 am, paul c <toledobythe..._at_oohay.ac> wrote:
> Vadim Tropashko wrote:
> > On May 20, 9:08 pm, paul c <toledobythe..._at_oohay.ac> wrote:
>
> >>Marshall wrote:
>
> >>>Okay, a while back we were talking about writing constraints
> >>>in a language with aspects of the relational calculus, specifically
> >>>the existential and universal quantifiers. The point was made
> >>>that that's unnecessary; the calculus is no more expressive
> >>>than the algebra.
>
> >>>So it ought to be possible to write any constraint from the
> >>>calculus in the algebra.
>
> >>>Well, I'm having a hard time figuring out how to do it. Can
> >>>anyone help?
>
> >>>How does one write a functional dependency in the algebra?
> >>>A foreign key?
>
> >>>Marshall
>
> >>I thought that one was easy, if FK is the set of 'foreign key'
> >>attributes and A is the 'referencing table' and using an op like D&D
> >><AND>, then it's something like A{FK} <AND> B{FK} = A{FK}. (I like this
> >>one because it's particularly easy to implement.)-
>
> > FK is easy indeed. Assuming that we rename attributes of A and B in
> > such a way that x becomes a common FK attribute, a FK constraint is
> > written in relational lattice as
>
> > A \/ X < B \/ X
>
> > where X is the empty relation with attribute x. Naturally, I'd suggest
> > too call the constraint between arbitrary 3 relations
>
> > A \/ C < B \/ C
>
> > as a generalized FK...
>
> Regarding the FD, or key for short, which hasn't been mentioned much so
> far, here's what I've seen so far, assuming one relvar A with
> non-overlapping attribute sets K and FK:
>
> 1) Use a COUNT function to test that the projection on K has the same
> cardinality as A. (I've seen this approach in a number of different
> places, so maybe it is most common.)
>
> 2) Take the PRODUCT of A and A with K and NK RENAME'd to RK and RNK and
> test that RNK = NK whenever K = RK.
>
> 3) Use TTM-style GROUP/UNGROUP to test that
> UNGROUP {NK}
> (GROUP ( (A GROUP {NK} as NK ))
> = A
Given a relation R(x,y,z,t), make the following 3 relations:
- R'(x,y') = project R to (x,y) and rename y->y'
- R"(x,y") = project R to (x,y) and rename y->y"
- Id(y',y") -- identity relation y'=y"
The FD constraint is written as
Id(y',y") /\ R'(x,y') > R'(x,y') /\ R"(x,y")
Without clutter of attributes the inequality looks much cleaner:
Id /\ R' > R' /\ R"
Remarkably, it is shaped very similarly to FK constraint
A \/ X < B \/ X
that was mentioned earlier in the thread.
This is fine, but what are the implications? Can it be demonstrated