Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to optimise a hierarchie?
Message
From
14/11/2000 05:19:44
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
14/11/2000 02:52:50
Wouter Schut
Www.Selectif.Nl/Www.Seweso-Systems.Com
Andelst, Netherlands
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00441471
Message ID:
00441486
Views:
8
>I have a table (project) wich has a relationship with itself, every record has a unique id and one field points to a parent record in the same table. This creates a hierarchy (without loops). Further I have an other table (activity) wich also has a relation with the first table (project one-to-many activity). Now my question is: how can I optimise these tables so that when I select a record in the [project] table the [activity] table will show all the associated records, this means when I select the 'root' record in project I will get the entire [activity] table, and when I select a 'leaf' record I will get only a few records from the activity table.
>
>I could create several indexes in the activity table wich will hold the 'parent' id, the 'parents' 'parent' id, the 'parents' 'parents' 'parent' id and so on. But this way the hierarchy can't be infinitely deep! Is there an other way to do this? (You must assume the hierarchy is infinitely deep and infinitely wide and every project has an infinite number of activity's).

Woter,
How and where you would show, will be editable or not etc would have different strategies. ie:
-Could be a treeview structure
-Could use ADO wt MS hierarchial grid
-Prepare and show in grid via a routine

All hierarchic levels could be in a field like :
1_3_567_78_
To squeeze field you could use bintoc() instead. For small sets this would work but for larger sets just holding :
NodeKey, ParentKey as in any traditional treeview structure sounds more feasible. Behind the scenes you could hide a treeview with node text holding say PK as char. inlist(myKey,chrtran(Node.Fullpath,'\',',')) would make an exression to select records for that level. You could have node.key as PK+'_' and simply search an elements position in treeview nodes(PK+'_') to get node.fullpath. Of course this again is only feasible for small sets for treeview loading is extra slow. ADO hierarchical set sounds more feasible. In ADO sets you could create an hierarchy in same table as you define (ie: employee, reportsto and s/he reportsto ...)
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform