int自增序列 GUID性能测试
http://blog.csdn.net/fox123871/article/details/6578922
测试结果表明在最常用的插入删除上, int主键的性能并没有显著超过GUID主键, 优势在15%以下
分布式用GUID, 经常迁移用GUID
小的本地项目用自增序列
可以在程序中生产UUID存入字符串,也可以通过数据库自动生成UUID
不过,事实上,Oracle数据库的圈子里已经习惯用UUID了。保证生成的ID不仅是表独立的,而且是库独立的,这点在你想切分数据库的时候尤为重要。
Mysql也原生支持UUID select uuid();
java中的 UUID 是 jdk1.5增加了类java.Util.UUID
UUID uuid=UUID.randomUUID();
String uuidStr=uuid.toString(); //如:9b17a4f1-cae4-42ce-9cba-b899dcac8517
UUID.fromString(name)
存取数据库用 varchar就行了
postgre uuid 类型 contrib 函数和 pgcrypto 模块的 gen_random_uuid() 函数
postgre 8就支持uuid https://www.postgresql.org/docs/devel/static/uuid-ossp.html
Note: If you only need randomly-generated (version 4) UUIDs, consider using the gen_random_uuid() function from the pgcrypto module instead.
uuid-ossp provides functions to generate universally unique identifiers (UUIDs) using one of several standard algorithms:
uuid_generate_v1()
This function generates a version 1 UUID. This involves the MAC address of the computer and a time stamp. Note that UUIDs of this kind reveal the identity of the computer that created the identifier and the time at which it did so, which might make it unsuitable for certain security-sensitive applications.
uuid_generate_v1mc()
This function generates a version 1 UUID but uses a random multicast MAC address instead of the real MAC address of the computer.
uuid_generate_v3(namespace uuid, name text)
This function generates a version 3 UUID in the given namespace using the specified input name. The namespace should be one of the special constants produced by the uuid_ns_*() functions shown in Table F-32. (It could be any UUID in theory.) The name is an identifier in the selected namespace.
For example:
SELECT uuid_generate_v3(uuid_ns_url(), ‘http://www.postgresql.org‘);
The name parameter will be MD5-hashed, so the cleartext cannot be derived from the generated UUID. The generation of UUIDs by this method has no random or environment-dependent element and is therefore reproducible.
uuid_generate_v4()
This function generates a version 4 UUID, which is derived entirely from random numbers.
uuid_generate_v5(namespace uuid, name text)
This function generates a version 5 UUID, which works like a version 3 UUID except that SHA-1 is used as a hashing method. Version 5 should be preferred over version 3 because SHA-1 is thought to be more secure than MD5.