Re: What databases have taught me

From: Neo <neo55592_at_hotmail.com>
Date: 25 Jun 2006 17:45:13 -0700
Message-ID: <1151282713.171815.174910_at_r2g2000cwb.googlegroups.com>


> By the way, do any real-estate listings really track fridges?

The andriod-based realtor that I am wiring in my garage, will :)

> Most of your allegedly tough examples are based on physical modeling.

If you mean't any modelling that that requires a table join or hierarchy, then there is some truth to that. In general, modelling hierarchies in RM cause some minor adjustments where as in dbd, it makes little difference if one is modelling a list, tree, table, or graph; they all require equally verbose scripts :) but the method remains largely unchanged.

The tough part of dbd examples are the minimal impact to existing data/scripts/queries/code when meeting new data requirements unknown in advance (see example below).

> > [Sample query to find first real-estate listing in dbd example 117]:
> >
> > (and (select single-family instance *)
> > (select * has (and (select bedroom instance *)
> > (select * has (and (select carpet instance *)
> > (select * color purple)))))
> > (select * has (and (select kitchen instance *)
> > (select * has (and (select fridge instance *)
> > (select * mfg sears))))))
>
> [RMDB's query]:
> SELECT * FROM houses
> WHERE houseType="single family"
> AND houseID in
> (SELECT houseID FROM rooms WHERE carpetColor="purple")
> AND houseID in (SELECT houseID FROM furniture
> WHERE furnitureType="fridge" AND brand="Sears")
>
> Note that I am assuming that the fridge can be anywhere in the house.
> Adding kitchen-only would add another clause or join to the query.

The above two queries are roughly equivalent (although the underlying data is structure is different, may need to add T_hasHierarchy). The most significant difference that is determinable from the queries is that in dbd's example, the fridge is located in the kitchen, where as in the RMDB example, the fridge is located in the house (which makes the RMDB query slightly simpler). Another signficant different that the fridge is a thing that could be move from one room to another or even one house to another without worrying about what attributes/subParts/contents belong to it.

> People often put a 2nd fridge in their garage... I wonder how your query would look if the fridge could be in any room.

Below is dbd's script to create a second fridge and locate it in the garage. The new fridge is also classified as an appliance. It's serial# is FRZ001. It's manufacturer is Panasonic whose phone# is 333-4444.. It's style is low-profile. It needs freon. Both serial# and phone# are attributes that are created on-the-fly.

(create (and (select garage instance *)

             (select (select * MLS# A2868Z) has *))
        has
        (block (new)
               (create appliance instance (it))
               (create fridge instance (it))
               (block (new 'FRZ001 'serial#))
               (create (it) (. 'serial#) (. 'FRZ001))
               (create (it) mfg (block (new)
                                       (create mfg instance (it))
                                       (create (it) name (word+
'panasonic))
                                       (block (new '333-4444 'phone#))
                                       (create (it) (. 'phone#) (.
'333-4444))
                                       (return (it))))
               (create (it) style (val+ 'low-profile))
               (create (it) note (val+ 'needs_freon))
               (return (it))))

The significant thing that I wanted you (and mAsterdam) to notice is that adding the second fridge, which was unknown when the data was original modelled, doesn't affect the original script/schema/queries. Below is a new query (old one still works) to find house using the added fridge. Also note that this query includes a second color (pink) for carpet. The carpet in that room always had 2 colors previously but the first query only utilized one of its colors. The carpet is a thing that has its own attributes, etc and could be move to attic, if desired.

(and (select single-family instance *)

     (select * has (and (select bedroom instance *)
                        (select * has (and (select carpet instance *)
                                           (select * color pink)
                                           (select * color purple)))))
     (select * has (and (select kitchen instance *)
                        (select * has (and (select fridge instance *)
                                           (select * mfg sears)))))
     (select * has (and (select garage instance *)
                        (select * has (and (select fridge instance *)
                                           (select * mfg
panasonic))))))

Note: I will be updating the web page to include the above additions. Received on Mon Jun 26 2006 - 02:45:13 CEST

Original text of this message