On Feb 18, 2006, at 10:56 AM, Dae San Hwang wrote:
Thank you for the reply!
I especially liked your analogy of ID to memory address though I'm not
yet 100% convinced. Following are my reasonings behind the preference
for multiple integer column id's:
1. I tend to think URL as a part of the user interface. If the user
look at (usually simple and structured in rails application) URL,
wouldn't she be confused by the seemingly random and very large number
assigned to her reply post? Topic's id #87 corresponds to the
87th-ness nature of the topic posted in the forum. Reply id #3 would
correspond to the 3rd-ness nature of the reply to the given topic,
reply id #1074 would not. I know, I know, I might sound like someone
who is suffering ocd.. ;)
2. This one is a bit more practical issue. Let's say I'm building a
public forum hosting service. (It is indeed something I have in
mind.) At some point, my site hosts 10,000 forums, each having its
own forum_id. Let's say each forum has average of 10,000 topics, each
having its own topic_id. And each topic has average of 100 replies,
each having its own reply_id. If I have to use a flat integer id
space, there will be replies with id like #10,000,000,000. (10,000 *
10,000 * 100) Now, 32-bit unsigned integer can't handle it since its
max value would 4,294,967,295. I could just use 64-bit unsigned
integer, I guess, but it does take more spaces and what if my site
becomes even more successful to the extent even 64-bit integer will
max out?
I don't think this is going to be an issue. I don't think you're going
to accumulate over 9 quintillion posts in one database in the lifetime
of the forum, you'd likely partition well before hitting this limit.
(I'm assuming postgresql's bigserial here for the 9 quintillion value,
i'm not familiar with other dbs).
You might check out acts as tree or acts as nested set (or create
something along those lines) which should allow you to structure it the
way you want without requiring composite keys.
-Scott
_______________________________________________
Rails-core mailing list
Rails-core@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-core