Types and "join compatibility"

From: André Nęss <andre.naess_at_gmail.com>
Date: 30 Jul 2005 10:24:24 -0700
Message-ID: <1122744264.923970.145560_at_f14g2000cwb.googlegroups.com>



I've recently been playing around with a tiny implementation of the relational algebra based on the description in Date's "an Introduction to database systems" (7th. ed.).

As I started considering how to add a simple type system to the implementation I stumbled upon something that my (possibly lacking) googling skills can't find an answer to, so I hope someone here might shed some light on it. The question is: given a relation A, with a single attribute a of type TypeA, and a relation B with a single attribute b of type TypeB, where TypeA is a subtype of TypeB, what (if anything) does it mean to perform the natural join of A and B (the same goes for union I guess...) Of course I here assume that you either rename A.a to b or B.b to a before performing the operation.

My take is that it should be possible to do so, and that the type of the single resulting attribute should be TypeA, as this is the most generic type. So the b attribute of B must be cast before the join is performed.

But I also wondered about being able to cast the attribute a into TypeB. Because TypeB presumably constrains the possible values of TypeA, this would mean that if A.a was cast to TypeB, some tuples in A no longer satisfy the conditions defined by TypeB and should be discarded. So in theory you could perform a restrict on A where the restriction constraint would be the constraints of TypeB, leaving you with a relation with a single attribute whose values are all compatible with TypeB.

I'm interesting in both theoretical considerations as well as practical experiences. Does there exist any (prototype) implementations of the relational algebra coupled with a fairly powerful type system?

If someone can provide straight answers that would be great, but I'm also very interested in pointers to material I might study to understand this in more detail. If something similar has been discussed here before (I'm sure it has) I would be very interesting in reading those threads. As I mentioned, except for an article about using a union type as the attribute type I've not been able to find any threads that cover this. Received on Sat Jul 30 2005 - 19:24:24 CEST

Original text of this message