473,503 Members | 7,578 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

FW: Proper nesting of hierarchical objects

We've actually implemented this kind of thing in a different DBMS. The
physical design consists of a single "organization" table that's something
like:

Org_key (primary key)
Org_type (group, company, etc.)
Org_level (group is 1, company is 2, etc.)
Org_parent_key (foreign key to org that encompasses this org; this is a
"recursive relationship", i.e., a foreign key to the same table)
Org name, address, etc.

Advantages of this design:
- Its normalized, with the exception of org_level which could be derived by
counting how far down this organization is in the hierarchy
- Re-orgs are pretty easy, even promotions/demotions (level 3 becomes level
4, etc.)
- If a department moves to a different branch, its simply a matter of
changing the org_parent_key
- Easy to add another level below department (pretty common in my
organization)

My programmers hate it, but I'm not certain why. It seems easy to me to
create views that hide the recursion. There might be performance issues ...

Actually, a more flexible design has 2 tables. Table 1 is the org table:

Org_key (primary key)
Org_type
Org_level
Org name, address, etc.

Table 2 is the org relationship table (see below). The primary key is
org_key + org_parent_key.

Org_key
Org_parent_key
Relationship_type

Relationship type could be R for "responsible to", B for "budgets for",
etc., if organizations can have more than one hierarchy (yes it does happen
in ours).

Sorry if I didn't completely answer your question. Also, I don't know what
an "adjacency list" is.

-----Original Message-----
From: Michael Glaesemann [mailto:gr**@myrealbox.com]
Sent: Monday, November 08, 2004 2:40 AM
To: 'p************@postgresql.org' General
Subject: [GENERAL] Proper nesting of hierarchical objects

Hi all.

I'm working (well, rather, reworking) a database schema that, in part,
models a company organizational structure. For example:

group
company
division
head office
department
department
branch
department
department
branch
department
department
division
company
division ...

I would like to model each node of this hierarchy as a generic "org",
as they will all share a lot of characteristics, such as each will have
an address, phone numbers, email addresses (most departments have one
email address rather than an email address for each person... but
that's not my problem :). I'd prefer to model this with nested sets
rather than an adjacency list for easy summaries, but either way, I'd
like to make sure they nest properly, so I don't end up with companies
as children of departments, for example.

What I've done so far is assign an org_type (e.g., group, company,
division) to each org. My first thought was to assign each org_type a
number, and set the numbers such that parents had numbers higher than
children (or vice versa), and enforce that with triggers. One drawback
was that I might want to use department as a catchall for anything
relatively small, so a department could be a parent of another
department. Enforcing this could be implemented by requiring the parent
org_type number to be greater than or equal to the child org_type
number, but that would also allow, for example, companies to nest in
companies, which is undesirable.

My second thought was to set up a table that mapped allowable
parent-child relations, and again, enforce immediate parent-child
relationship validity using triggers. This is beginning to feel a bit
hackish to me, so I thought I'd ask if anyone had some advice, words of
encouragement, or pointers to where I might find information on
modeling this.

Comments, suggestions, ideas, hints, criticism appreciated!

Regards,

Michael Glaesemann
grzm myrealbox com
---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 23 '05 #1
1 2967
I missed the original post, but I think you both might want to do some
googling on nested set.

Robert Treat

On Tue, 2004-11-09 at 11:40, Garris, Nicole wrote:
We've actually implemented this kind of thing in a different DBMS. The
physical design consists of a single "organization" table that's something
like:

Org_key (primary key)
Org_type (group, company, etc.)
Org_level (group is 1, company is 2, etc.)
Org_parent_key (foreign key to org that encompasses this org; this is a
"recursive relationship", i.e., a foreign key to the same table)
Org name, address, etc.

Advantages of this design:
- Its normalized, with the exception of org_level which could be derived by
counting how far down this organization is in the hierarchy
- Re-orgs are pretty easy, even promotions/demotions (level 3 becomes level
4, etc.)
- If a department moves to a different branch, its simply a matter of
changing the org_parent_key
- Easy to add another level below department (pretty common in my
organization)

My programmers hate it, but I'm not certain why. It seems easy to me to
create views that hide the recursion. There might be performance issues ...

Actually, a more flexible design has 2 tables. Table 1 is the org table:

Org_key (primary key)
Org_type
Org_level
Org name, address, etc.

Table 2 is the org relationship table (see below). The primary key is
org_key + org_parent_key.

Org_key
Org_parent_key
Relationship_type

Relationship type could be R for "responsible to", B for "budgets for",
etc., if organizations can have more than one hierarchy (yes it does happen
in ours).

Sorry if I didn't completely answer your question. Also, I don't know what
an "adjacency list" is.

-----Original Message-----
From: Michael Glaesemann [mailto:gr**@myrealbox.com]
Sent: Monday, November 08, 2004 2:40 AM
To: 'p************@postgresql.org' General
Subject: [GENERAL] Proper nesting of hierarchical objects

Hi all.

I'm working (well, rather, reworking) a database schema that, in part,
models a company organizational structure. For example:

group
company
division
head office
department
department
branch
department
department
branch
department
department
division
company
division ...

I would like to model each node of this hierarchy as a generic "org",
as they will all share a lot of characteristics, such as each will have
an address, phone numbers, email addresses (most departments have one
email address rather than an email address for each person... but
that's not my problem :). I'd prefer to model this with nested sets
rather than an adjacency list for easy summaries, but either way, I'd
like to make sure they nest properly, so I don't end up with companies
as children of departments, for example.

What I've done so far is assign an org_type (e.g., group, company,
division) to each org. My first thought was to assign each org_type a
number, and set the numbers such that parents had numbers higher than
children (or vice versa), and enforce that with triggers. One drawback
was that I might want to use department as a catchall for anything
relatively small, so a department could be a parent of another
department. Enforcing this could be implemented by requiring the parent
org_type number to be greater than or equal to the child org_type
number, but that would also allow, for example, companies to nest in
companies, which is undesirable.

My second thought was to set up a table that mapped allowable
parent-child relations, and again, enforce immediate parent-child
relationship validity using triggers. This is beginning to feel a bit
hackish to me, so I thought I'd ask if anyone had some advice, words of
encouragement, or pointers to where I might find information on
modeling this.

Comments, suggestions, ideas, hints, criticism appreciated!

Regards,

Michael Glaesemann
grzm myrealbox com
---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org


---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2033
by: Reimar Bauer | last post by:
Hi all, I would like to use a hierarchical group oriented encryption. Is there something implemented or did you know something I could use? For explanaition. If you have a large building...
3
2987
by: Piet | last post by:
Hi, I am trying to generate an "hierarchical" layout based on wx.NoteBooks. That means, every page of a Notebook should be a NoteBookon its own. Here is a (short but complicated) piece of code...
1
3666
by: ALEX KLEIN | last post by:
I want to use fabricated hierarchical recordset in VB6 using ADO. I wrote code like dim rs as adodb.recordest set rs=new adodb.recordest rs.fields.append "a1",adChar,30 Then in loop I put...
3
5562
by: Cláudia Morgado | last post by:
Hello! Oracle has the option with the SQL CONECT BY statement to run through a hierarchical database with a single SQl-statement: <!--SQL SELECT ms_id,ms_parent FROM messages CONNECT BY PRIOR...
8
2845
by: Hardrock | last post by:
I encountered some difficulty in implementing dynamic loop nesting. I.e. the number of nesting in a for(...) loop is determined at run time. For example void f(int n) { For(i=0; i<=K; i++)...
5
2236
by: clintonG | last post by:
I'm looking for documentation and would not turn my nose up to any code from anybody who thinks they are good at the design of an algorythm that can be used to generated a hierarchical relational...
0
1426
by: stigbn | last post by:
When a DataSet is used as data source for a DataGrid one can get hiearachical datagrid by using relations among the DataTables of the DataSet. (By hierarchical datagrid, I mean columns that can be...
0
935
by: Craig | last post by:
I need to display a hierarchical diagram of a group of 300 objects, organized kind of like a class structure. What's the best way to do this in ASP.net? I'm even open to 3rd part asp products if...
7
2526
by: Paul | last post by:
Hello, I'm coming from a PHP background and am working on a large-scale VB.NET project. One of the cornerstones of this project is a reusable form class, to standardize our web forms. My goal...
0
7194
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7070
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7267
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4993
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.