Re: Transitive Closure with XDb1

From: Paul <paul_at_test.com>
Date: Fri, 14 May 2004 11:15:42 +0100
Message-ID: <b%0pc.4146$NK4.356968_at_stones.force9.net>


Neo wrote:

>>whole    part
>>=====    ====
>>universe john
>>universe mary
>>universe mars
>>universe venus
>>mars     john
>>venus    mary

>
> Technically, the above output using TClose(Contains) is incorrect. The
> parts of universe should be mars, venus, john and mary. No output row
> represents a person or a planet. It instead lists relationships
> between universe and john, universe and mary, etc.

Well, that's what transitive closure means: http://en.wikipedia.org/wiki/Transitive_closure "...the transitive closure of a binary relation R on a set X is the smallest transitive relation on X that contains R."

So in common terms that's saying that you start with a relation that has ony two columns, that are of the same type, and the transitive closure operator returns a relation with only two columns, that are of the same type.

If you wanted to know, say, all the things in the "universe": SELECT part FROM TCLOSE(Contains) WHERE whole = 'universe'

> In addition, using the more appropriate schema T_Contains, T_Planet
> and T_Person, how does one use TClose()? XDb1's T_Relative() works for
> hierarchies consisting of different kinds of things (ie Planet,
> Country, State, City, House, Person, including those added at
> run-time).

I'm not sure what you mean by this schema - could you expand on it? By definition, transitive closure is only for hierarchies of the same type of thing.

If you have relations for say Planets, Countries, Persons are you saying you want to know all Countries on a given planet, plus all persons in each country? In logic, that would be two separate predicates.

If you wanted some table to output them in the same column, you'd have to cast Country and Person to the same datatype:

SELECT CAST(country AS char) AS CountryOrPerson FROM Countries
WHERE Planet = 'Earth'
UNION
SELECT CAST(person AS char) AS CountryOrPerson FROM Persons p NATURAL JOIN Countries c
WHERE c.Planet = 'Earth'

> In addition, how does one use TClose() to get parts of
> mars, since mars is not a table but a row? XDb1's T_Relative() returns
> parts of mars.

SELECT part FROM TCLOSE(Contains) WHERE whole = 'mars'

I'd suggest reading up on basic first-order predicate logic, it's very useful for understanding where the relational model is coming from. Here's a good start for online information: http://en.wikipedia.org/wiki/First-order_predicate_calculus

Paul. Received on Fri May 14 2004 - 12:15:42 CEST

Original text of this message