uuid各函数性能对比

最近更新时间: 2024-10-17 17:10:00

  • 数据表结构。
postgres=# \d+ t_uuid
                                  Table "public.t_uuid"
 Column |          Type          |              Modifiers              | Storage  | Stats target | Description 
--------+------------------------+-------------------------------------+----------+--------------+-------------
 f1     | uuid                   | not null default uuid_generate_v1() | plain    |              | 
 f2     | character varying(256) |                                     | extended |              | 
Has OIDs: no
Distribute By SHARD(f2)
        Location Nodes: ALL DATANODES
  • uuid_generate_v3函数。
postgres=# insert into t_uuid(f1,f2) select uuid_generate_v3(uuid_ns_dns(), 'http://tbase.qq.com'),uuid_generate_v3(uuid_ns_dns(), 'http://tbase.qq.com') from generate_series(1,10000) as t;
INSERT 0 10000
Time: 58.407 ms
  • uuid_generate_v5函数。
postgres=# insert into t_uuid(f1,f2) select uuid_generate_v5(uuid_ns_dns(), 'http://tbase.qq.com'),uuid_generate_v5(uuid_ns_dns(), 'http://tbase.qq.com') from generate_series(1,10000) as t;
INSERT 0 10000
Time: 47.049 ms
  • uuid_generate_v1函数。
postgres=# insert into t_uuid(f1,f2) select uuid_generate_v1(),uuid_generate_v1() from generate_series(1,10000) as t;  
INSERT 0 10000
Time: 111.204 ms
  • uuid_generate_v4函数。
postgres=# insert into t_uuid(f1,f2) select uuid_generate_v4(),uuid_generate_v4() from generate_series(1,10000) as t; 
INSERT 0 10000
Time: 137.062 ms
  • uuid_generate_v1mc函数。
postgres=# insert into t_uuid(f1,f2) select uuid_generate_v1mc(),uuid_generate_v1mc() from generate_series(1,10000) as t;
INSERT 0 10000
Time: 125.663 ms
  • 测试数据对比
V1 v1mc V4 V3 V5
111.204 ms 125.663 ms 137.062 ms 58.407 ms 47.049 ms

可以看出V5的性能是最好的。