-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 
Author Message
 Post subject: Of identifiers, natural, surrogate and composite keys
PostPosted: Sat Oct 01, 2005 12:27 pm 
Newbie

Joined: Mon Apr 25, 2005 6:17 pm
Posts: 2
I'm trying to understand the performance implications of using an identifier (basically surrogate key) that has no business meaning, instead of using a natural primary key (composite key in my case). The Hibernate best practices says "there are all sorts of reasons why you should use identifiers" - i think i understand at least some of the benefits of using them. However, I'm concerned about performance - database performance, not Hibernate's in-memory caching or object graph navigation performance. Simplistically, if I use natural primary keys, I have one constraint in the database for that table; if I use a surrogate PK, and "natural-id" to ensure uniqueness of the "business keys", I have 2 constraints.
Any thoughts on this?

Thanks

Vijay


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 01, 2005 12:52 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
I use natural keys


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 01, 2005 1:34 pm 
Senior
Senior

Joined: Thu Aug 04, 2005 4:54 am
Posts: 153
Location: Birmingham, UK
Surrogate primary keys mean that some poor maintenance programmer is less likely to tear their eyeballs out in a fit of rage in ten years time when they have to make some change to your system. Your natural primary key might seem fixed in stone and unchanging but this is not guraranteed.

Also never think your system won't be used in ten years time, I work for a massive comapny still using NT4 and a 15 year old mainframe app.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 01, 2005 1:48 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
I use natural keys for 20 years - relational database theory don't force usage surrogate keys - I don't know for advantage, it is natural design for me and I don't know different

When I make sql query I know natural keys and I make query easier

Surrogate keys have own advantage, but and natural keys too
I disagree that natural keys are bad design
I think that you use what you like

Hibernate support both


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 01, 2005 1:50 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
http://www.amazon.com/exec/obidos/tg/de ... 0201485559


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 01, 2005 2:57 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
http://www.amazon.com/exec/obidos/tg/de ... 4?v=glance

but it is only opinion

This is link for compare keys http://www.bcarter.com/intsurr1.htm (very good)
and one http://builder.com.com/5100-6388_14-1045050.html (favorite surrogate)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 01, 2005 3:17 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Here are a few rules:

1. Never post anything from Celko. Most of what he does is wrong. Yes, he is popular, but he definitely lacks fundamentals and is regularly debunked.

2. Never confuse "logical" and "physical". The question for primary keys is a very common source of confusion. You chose primary keys based on their logical integrity with the rest of the logical data model you are creating. This has nothing to do with their physical implementation, or the performance characteristics of such an implementation.

3. There is no "always use surrogate keys" or "always use natural keys" theory. Both have their place and use, depending on the logical data model.

Get the Fabian Pascal book, he summarizes these important points nicely.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 01, 2005 4:18 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
Quote:
1. Never post anything from Celko. Most of what he does is wrong. Yes, he is popular, but he definitely lacks fundamentals and is regularly debunked.


Quote:
Get the Fabian Pascal book, he summarizes these important points nicely.


What I can say ?

Quote:
3. There is no "always use surrogate keys" or "always use natural keys" theory. Both have their place and use, depending on the logical data model.


I agree.

There is different (for me) between an application for external users (web application, mostly) and an application for internal users (classical information systems, order entry, accounting etc)
I don't know for first type, but I know for last type of application.
For example, my employees or partners have surrogate keys (ID), but internal users use it like natural key - users know partner ID before name or address and search with id easy - what is it : natural or surrogate ? I think that all columns visible to users are natural and I show all columns to users - I don't force that you do it, this is my opinion only.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 09, 2006 12:32 pm 
Newbie

Joined: Thu Apr 06, 2006 1:02 pm
Posts: 4
I disagree with all Natural-Key-Lovers.

Yes, RDBMS theory recommends to have First Normal Form, Second Normal Form, and even Third Normal Form. And, we almost always have composite primary keys (instead of natural candidates + surrogate) in existing production databases. And, we almost never have true Second Normal Form: for performance optimizations, we sometimes have attributes depending on another attributes, additionally to primary key dependency.

Theory, and practice.

Now we have another demand: how to submit Composite PK via GET/POST, via SOAP, etc? How to use it in <OPTION> tag of HTML? What about security? Database identity should not have any business meaning...

We lose performace during inserts, because we should fire two constraints. Who cares!!! Compare 10ms of SQL INSERT execution via Network and JDBC with 0.1ms for firing of additional constraint.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 09, 2006 7:31 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
yes,

Natural-Key is perfect for database tools vendors like hibernate (or database vendor ever, but database vendor have resolved this a long time ago), but no for designer of database applications

Best


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.