Re: The stupidest design I ever saw

From: Vadim Tropashko <vadimtro_invalid_at_yahoo.com>
Date: 5 Apr 2006 19:55:45 -0700
Message-ID: <1144292145.887204.212000_at_u72g2000cwu.googlegroups.com>


Neo wrote:
> > table Nodes (id number, ... -- content)
> > table Edges (tail number, head number, ... -- more content, if edges are labeled)
>
> How do I use the above schema to model the vehicle classes shown in the
> RDF example given earlier? I still don't see it.

No, you first please demonstrate that the above classification serves some useful purpose.

I prefer to write a database schema for cities and travel links instead. Here we go:

table Cities (
  name string
)
table Connections (
  tail string,
  head string,
  distance integer
)

Example query: find the shortest path between two cities.

Surprisingly, it's not easy to express this or parts explosion kind of query in XQuery (which is allegedly a superior tool for graph/tree related problems). You can compare XQuery solution

define function total (element PART $part) returns element PART {
let $subparts := $part/PART/total(.)
return
<PART NAME="$part/_at_NAME"
COST="$part/_at_COST + sum($subparts/_at_COST)">{ $subparts
}</PART>
}

from
http://homepages.inf.ed.ac.uk/wadler/papers/xquery-afp/xquery-afp-slides.pdf

with SQL (which I just mindlessly copying and pasting from my book without really making sure they accomplish the same thing):

select leaf, sum(factoredQuantity) from (

   select product(Quantity) factoredQuantity,

          first(Part) root, last(SubPart) leaf    from AssemblyEdges
   connect by prior Part = later SubPart ) where root = 'Bicycle'
group by leaf Received on Thu Apr 06 2006 - 04:55:45 CEST

Original text of this message