facebook userid的数据类型是什么 [英] What is the datatype of facebook userid

查看:410
本文介绍了facebook userid的数据类型是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

facebook用来存储userid的数据类型是什么,对于这种字段性能和可伸缩性而言,最好的数据类型应该是什么.

What datatype facebook uses to store userid, what should be that best data type for such field performance and scalability perspective.

如果使用int 4字节,那么我猜它还不够大;如果使用8字节int,那么如何为每个用户分配随机数或为字符串分配相同的数字.

If one uses int 4 bytes then i guess it ain't big enough, if 8 bytes int then how to assign random numbers to each user or same for string.

那么为用户提供固定长度的随机ID,同时又要牢记可扩展性和性能的最佳方法是什么?

So what is the best way to give user a random id of fix length, keeping scalability and performance in mind?

推荐答案

好问题. Facebook ID和Tweet ID都可能导致问题.两者都超出了32位整数范围.根据编程语言的具体情况和目的(例如数据库,代码等),您可能希望使用float或double,但以我的经验将它们强制转换为字符串是令人满意的.

Good question. Facebook IDs can lead to problems as well as Tweet IDs. Both exceed the 32bit integer range. Depending on programming language specifics and the purpose (e.g. database, code, etc.) you may want to use float or double but in my experience casting them to string is satisfactory.

在MySQL中,如标记所示,提供了 BIGINT 数据类型,该数据类型足够大以将这些ID存储为数字.棘手的部分是当您读取这些值并在程序代码中对其进行处理时.大于系统体系结构/编程语言所允许的最大值的那些错误可能会导致错误或被截断,从而导致不一致.

In MySQL, as tagged, provided is the BIGINT data type, which is large enough to store these IDs as numbers. The tricky part is when you read these values and process them in your program code. Those that are greater than the maximum allowed by system architecture / programming language may cause errors or be truncated leading to inconsistency.

如果要在MySQL中使用固定长度的大ID,一个好的做法是使用 CHAR 类型和十六进制格式,或者您可以使用 UUID 格式.

If you want to use fixed length large IDs in MySQL, a good practice is to use the CHAR type and HEX format or you can use the UUID format.

这篇关于facebook userid的数据类型是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆