User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Database Design section within the Web Development category of DaniWeb, a massive community of 427,225 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,233 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Database Design advertiser: Programming Forums
Views: 1299 | Replies: 5
Reply
Join Date: Jun 2008
Posts: 3
Reputation: monksorlo is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
monksorlo monksorlo is offline Offline
Newbie Poster

need help with subtype supertype

  #1  
Jun 24th, 2008
I'm a recent college grad and I'm building a database for my family business, which is a writing instrument manufacturer. I learnt about the concepts of subtype and supertype, but my professor told us that he almost never use subtype and supertype, instead he would do something else just for performance reasons. Can any expert here please tell me how should I go about subtype and supertype. I'm totally lost as to how to actually implement it. Thanks in advance
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2008
Posts: 295
Reputation: tesuji is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 41
tesuji tesuji is offline Offline
Posting Whiz in Training

Re: need help with subtype supertype

  #2  
Jun 25th, 2008
Hi monksorlo

what do you mean by subtype/supertype. Does this deal with the concept of Generalization/Specialization of extended entity relationship model? you may state an example.

If your professor suggest doing something else just for performance reasons at that very early design stage, you may change professors.

krs,
tesu
Last edited by tesuji : Jun 25th, 2008 at 9:20 pm.
Reply With Quote  
Join Date: Jun 2008
Posts: 3
Reputation: monksorlo is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
monksorlo monksorlo is offline Offline
Newbie Poster

Re: need help with subtype supertype

  #3  
Jun 28th, 2008
That professor is actually really good. Performance is kind of like his specialty, that's why he talks about it a lot.
What I mean by supertype and subtype is, for example, we have parts, there are two different kinds of parts. One is manufactured parts, the other one is purchased part. the purchased part table has a relation with the supplier table, while the manufactured part is a relaltion with equipment and such.

I have two questions
1. how do I write it out in sql
2. is there any way to achieve the same result while boosting performance


Thanks very much for helping!!
Last edited by monksorlo : Jun 28th, 2008 at 2:51 am.
Reply With Quote  
Join Date: Apr 2008
Posts: 295
Reputation: tesuji is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 41
tesuji tesuji is offline Offline
Posting Whiz in Training

Re: need help with subtype supertype

  #4  
Jun 28th, 2008
Hi monksorlo,

sorry, it has never been my intention to discredit your prof. My given statement sounds kind of sloppy.

Your subtype/supertype is exactly that what I meant with the extension of entity relationship model Generalization/Specialization. Supertype is equivalent to generalization and subtype to specialization.

As for your first question, there are several ways to map supertype/subtype of EERM into SQL of relational model. I will give you the common solution (what is indeed not that high-performance).

Supertype contains all attributes in common of all specializations. So what is in common of both manufactured and purchased parts? Obviously part number, name, category, Dimensions like weight etc.

Specialized attributes of manufactured parts would be the material the part is made from, equipment (what s that?), etc. Purchased parts is specizfied by supplier, price, delivery time etc. I assume there is only one supplier for a specific part, that is an one-to-many relationship. (If there are various supplier for same part and a specific supplier supplies various parts you would have a many-to-many relationship. If so, you must create a linking table what links purchased parts and supplier). Now we can create tables and their relationships:

-- supertype parts
create table parts(partnumber integer not null, name varchar(100), category char(10), weight decimal(10,2), primary key (partnumber));

-- subtypes, there can only be one-to-one relationship between supertype and subtypes (except you allow that a specific part can be both manufatured and purchased, sometimes)

-- -- subtype manufactured parts
create table manparts(partnumber integer not null, materialnumber integer, equipmentnumber integer, primary key (partnumber), foreign key (partnumber) references parts, foreign key (equipmentnumber) references equipment);

-- -- subtype purchased parts
create table purchparts (partnumber integer not null, suppliernumber integer, price decimal (10,2), deliverytime integer, primary key (partnumber), foreign key (partnumber) references parts, foreign key (suppliernumber) references supplier );

Now we want to query our tables, e.g.
-- list of all parts and their supplier names. This can be done by two inner joins:

select parts.partnumber, parts.name, purchparts.price, supplier.name
from parts join purchparts join suppliers;

(This does function only if you have supplied all primary and foreign keys, for example suppliernumber must be primary key of table suppliers and foreign key of purchparts)

Now your second question: well, here you see the (not-that-important) problem with the performance: Because whole information is spread over three tables two joins are necessary (what is absolutely common, particularly if you have done correct normalization up to 3NF)

How can we reduce number of joins what would really improve performance?

By definition, between supertype and subtpyes can only be an one-to-one relationship. Therefore all common attributes of supertype can be moved into the associated suptypes, for example

-- merge parts with purchparts:

create table purchasedparts(partnumber integer not null, name varchar(100), category char(10), weight decimal(10,2), suppliernumber integer, price decimal (10,2),
deliverytime integer, primary key (partnumber), foreign key (suppliernumber) references supplier);

Now our query again:

-- list of all parts and their supplier names. This can be done by ONE inner join:
select partnumber, purchasedparts.name, price, supplier.name
from purchasedparts join suppliers;

Here we need only one join what gains better performance.

I hop this "much-too-long thesis" helps you.

krs,
tesu
Last edited by tesuji : Jun 28th, 2008 at 7:09 pm.
Information is moving—you know, nightly news is one way, of course, but it's also moving through the blogosphere and through the Internets. I promise you I will listen to what has been said here, even though I wasn't here. Ann and I will carry out this equivocal message to the world. I'm the master of low expectations.
Reply With Quote  
Join Date: Jun 2008
Posts: 3
Reputation: monksorlo is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
monksorlo monksorlo is offline Offline
Newbie Poster

Re: need help with subtype supertype

  #5  
Jul 3rd, 2008
Thanks very very much for taking the time to respond to my questions. I really really appreciate it. It is wonderfully helpful
Reply With Quote  
Join Date: Jul 2008
Location: Islamabad
Posts: 3
Reputation: bilalhaider is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
bilalhaider's Avatar
bilalhaider bilalhaider is offline Offline
Newbie Poster

Re: need help with subtype supertype

  #6  
Jul 23rd, 2008
Dear i got really confused after viewing the answer. I have a confusion that what is the need (partnumber integer not null) in each table in case of implementing super type and subtype.
Could we use simply "type" attribute in the super type parts table as all the parts have common features like part number and name only difference is one is manufactured and the other is purchased. Why so much replication?
Am i right?
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Database Design Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Database Design Forum

All times are GMT -4. The time now is 11:34 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC