views:

121

answers:

5

Facebook's user id's go up to 2^32 .. which by my count it 4294967296.

mySQL's unsigned int's range is 0 to 4294967295 (which is 1 short - or my math is wrong) and its unsigned big int's range is 0 to 18446744073709551615

int = 4 bytes, bigint = 8 bytes

OR

Do I store it as a string?

varchar(10) = ? bytes

How will it effect efficiency, I heard that mysql handle's numbers far better than strings (performance wise). So what do you guys recommend

A: 

Unless you expect more than 60% of the world's population to sign up, int should do?

Tarydon
Maybe I wasn't clear... I am making a facebook app.. so the fact that facebooks id's are 64bit is very relvant... an id I just got from an account was... '100000719084526' so I guess my math was wrong on 2^32. I guess bigint it is
Mark
A: 

I would just stick with INT. It's easy, it's small, it works and you can always change the column to a larger size in the future if you need to.

FYI:

VARCHAR(n) ==> variable, up to n + 1 bytes
CHAR(n) ==> fixed, n bytes

nickf
so for facebook I would need in excess of 16 bytes as a varchar if the longest an ID could be was 15 char.
Mark
No - int won't work for a growing number of Facebook user IDs, that are bigints.
Karl B
You are so full of bad ideas.
deadprogrammer
+5  A: 

Because Facebook assigns the IDs, and not you, you must use BIGINTs.

Facebook does not assign the IDs sequentially, and I suspect they have some regime for assigning numbers.

I recently fixed exactly this bug, so it is a real problem.

I would make it UNSIGNED, simply because that is what it is.

I would not use a string. That makes comparisons painful and your indexes clunkier than they need to be.

Phil Wallach
From here: http://wiki.developers.facebook.com/index.php/User_ID "If you're storing it in a MySQL database, use the BIGINT unsigned datatype."
Karl B
+1  A: 

Your math is a little wrong... remember that the largest number you can store in N bytes is 2^(N) - 1... not 2^(N). There are 2^N possible numbers, however the largest number you can store is 1 less that.

If Facebook uses an unsigned big int, then you should use that. They probably don't assign them sequentially.

Yes, you could get away with a varchar... however it would be slower (but probably not as much as you are thinking).

Polaris878
A: 

You can't use INT any more. Last night I had two user ids that maxed out INT(10).

Jeff Conrad