Re: MultiValue Databases

From: John <no_at_email>
Date: Wed, 08 Jun 2005 09:51:39 +0100
Message-ID: <42a6b195$0$12370$db0fefd9_at_news.zen.co.uk>


Neo wrote:

>>>*** xrdb query ***************************************
>>>(SELECT * phone# 111-1111  & * phone# 222-2222)
>>
>>**** RM's query ****************************************
>>here is a query ...
>>   SELECT person.name
>>   FROM   person,
>>          phone,
>>          person_phone
>>   WHERE        person.personID = person_phone.personID
>>   AND    person_phone.phoneID  =        phone.phoneID
>>   AND    phone.number = "111-1111"
>>INTERSECT
>>   SELECT person.name
>>   FROM   person,
>>          phone,
>>          person_phone
>>   WHERE        person.personID = person_phone.personID
>>   AND    person_phone.phoneID  =        phone.phoneID
>>   AND    phone.number = "222-2222"
>>
>>The xrdb query is less verbose, but that's not necessarily better.

>
>
> John, thanks for the proper query. I would agree that being less (or
> more) verbose isn't necessarily better.
>
>
>>As an aside, one of the things I like about relational algebra is that
>>it is defined in terms of a few simple operations and has a good
>>theoretical basis that allows you to reason about it.

>
>
> I would agree that relational algrebra is defined in terms of a few
> simple operations (select, project, join, union, intersection,
> complement, product, and division, etc) and has a good theoretical
> basis.
>
> Now suppose one wanted to store "John likes Mary". Below I add this
> data in xrdb and query for the relationship between John and Mary; and
> also between John and 111-1111. Starting with the provided RM
> schema/data, how can one use the relational operations to store and
> query the same? (If new schema is needed, please suggest one)
>
> (CREATE verb inst *like)
> (CREATE john like mary)
> (SELECT john * mary) // Query returns like.
> (SELECT john * 111-1111) // Query returns phone#.
>

Neo,

As a result of the warning that Lee provided, I'm happy to provide an answer to this one, but it will be the last. Perhaps you could answer Lee's questions to show good faith in the debate.

Right...

IF I needed to store entities and the relationships between them to support these queries, I would restructure the data as follows.

CREATE TABLE entities (id, name);
CREATE TABLE relationships (subject_id, object_id, verb);

INSERT INTO entities VALUES(1, "John");
INSERT INTO entities VALUES(2, "Mary");
INSERT INTO entities VALUES(3, "111-1111");

INSERT INTO relationships VALUES(1, 2, "likes"); INSERT INTO relationships VALUES(1, 3, "has the phone number");

Relationship between John and Mary:

SELECT verb
FROM relationships,

        entities AS subject,
        entities AS object

WHERE relationships.subject_id = subject.id AND relationships.object_id = object.id AND subject.name = "John"
AND object.name = "Mary";

Relationship between John and "111-1111":

SELECT verb
FROM relationships,

        entities AS subject,
        entities AS object

WHERE relationships.subject_id = subject.id AND relationships.object_id = object.id AND subject.name = "John"
AND object.name = "111-1111";

If we're interested in query size, then we could sugar the whole query away inside a sproc and simply ask the following.

SELECT relationship_between("John", "Mary"); SELECT relationship_between("John", "111-1111");

Again, nothing tested unfortunately, so there may be typos or simple errors.

An interesting Third Year Project for a student might be to implement xrdb using relational algebra. They would at least manage a good subset.

Anyway, hope this helps with the comparison.

John Received on Wed Jun 08 2005 - 10:51:39 CEST

Original text of this message