Half a croissant, on a plate, with a sign in front of it saying '50c'

h a l f b a k e r y
The leaning tower of Piezo

idea: add, search, annotate, link, view, overview, recent, by name, best, random

meta: news, help, about, links, report a problem

account: Browse anonymously, or get an account and write.

User:
Pass:
Login
Create account.


                               

SQL for trees
UDA in SQL as a mean to work with recursive hierarchies
  (+2, -5)
(+2, -5)
  [vote for,
against]


The problem: unlimited depth tree represented as (id, pid) relation is hard to use in RDBMS.

The solution: First you need a logical description of your UDA (user defined aggregation) functions recursivly traversing unlimited depth tree by one traverse pattern per function.

Second, you need an index optimizing of and used by such UDA functions.

Third, you need such UDA implementation.

I've got a prototype already.


panserg, Mar 29 2002

[link]






       Ooooo a prototype! I suppose you're going to use your swell new database to destroy a major North American city if we don't meet your demands, aren't you?

spartanica, Mar 29 2002
  

       [panserg] you might have to wait a while for the more technical users here to make worthwhile comments. I wish I knew enough about DBs to comment but, alas, I don't.

bristolz, Mar 29 2002
  

       Firstly, [panserg] claims to have baked this idea.
Secondly, there's no description or indication as to how or why this method is better.

phoenix, Mar 29 2002
  

       Slaked Quick Lime is not good for trees. It makes them drop their leaves prematurely and gives them that ghostly look as they stand there bare in the moonlight.

neelandan, Mar 30 2002
  

       That's right neelandan, but it also masks those annoying dead fish odors.

thumbwax, Mar 30 2002
  

       So, is that a prototypo?

UnaBubba, Mar 30 2002
  

       I'm working with trees in SQL right now, and it's an ABSOLUTE BITCH. I wish there was something better. Are you telling me you have such a thing?

sadie, Apr 24 2002
  

       I've found that you can do trees in SQL by adding two extra columns to the table, sort of like a tree index. This stores the tree "path" and a "depth" of the placement. When you pull out the statement, you need to sort by the "path" and monitor the "depth". If the depth changes, move in or out. The path is really just used for sorting (so that should include your sort index). You could also add another column that stores the actual IDs so you can easily look up parents, siblings, delete whole branch, yada...   

       The real trick is saving this data and converting it in your host application. Here's a sample tree...   

       ID, name, description, sort, depth, tree, path 1, 'parent', '', 'a', 1, '/a', '/1' 2, 'child', '', 'a', '/a/a', '/1/2' 3, 'another child', 'b', '/a/b', '1/3' etc...   

       I also have done some stuff with joining tables, returning the ID from multiple tables and then monitor those field, indenting and stuff when they change. I agree that if some software function existed where you can define that, it would be really cool.   

       Can I check out that prototype? I could send you something as well.

jkichline, Apr 25 2002
  

       OODBMS, anyone?

globaltourniquet, Apr 25 2002
  

       What I'm saying is, SQL, SchmeQL. This application is right up OO's alley. Forget the relational model here. Recursive hierarchies are a snap with an OODBMS.

globaltourniquet, Apr 25 2002
  

       Representing a tree structure in SQL isn't the problem, [jkichline]. The problem is navigating it in any reasonable way, because in SQL that gets incredibly clumsy.   

       It's even worse when you have a lattice, a many-to-many tree that must be represented with a separate table.

sadie, Apr 26 2002
  

       umm.... XML

danostuporstar, May 14 2002
  

       Oracle SQL has a thingie called CONNECT BY (look it up in the manual). It sorta can do what you want (it screws up if you have a loop, which you wouldn't have in a tree, but still...). Of course, I vote for this feature; I've been in a few situations where it would have been very welcome.

grisha, Jun 01 2002
  

       This idea is most disappointing. I was hoping for some sort of database query performed by vegetables.

cp, Jun 02 2002
  
      
[annotate]
  


 
back: main index
 business 
 computer 
 culture 
 fashion 
 food 
 halfbakery 
 home 
 other 
 product 
 public 
 science 
 sport 
 vehicle