Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook user_id : big_int, int or string?

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

like image 865
Mark Avatar asked Jan 31 '10 15:01

Mark


1 Answers

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.

like image 194
Phil Wallach Avatar answered Oct 09 '22 04:10

Phil Wallach