[Rails-core] Composite primary key support in ActiveRecord?
Michael Koziarski
michael at koziarski.com
Sat Feb 18 19:25:37 GMT 2006
> 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.. ;)
Rick's reply covers that, use routes. Additionally, you may want to
consider adding another 'index' column rather than using the IDs like
that.
> 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?
If you're storing forum posts, you're looking at a lot of data, like
say, 1k per row. If you've maxed out a 64 bit integer, you've got
exabytes - yottabytes of storage. No one has that much storage,
Not google, or high end scientific supercomputers.
You'll be fine.
> In some ways, id's are like memory addresses, but no user ever get to
> see the memory address values.. Are there other reasons against the
> use of multiple integer column id's other than the fact that
> ActiveRecord doesn't support it?
Look at it another way, if you can live without it, why try to use it?
--
Cheers
Koz
More information about the Rails-core
mailing list