uuid与serial 在TDSQL PG中性能对比

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

  • uuid插入1万条数据。
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

postgres=# insert into t_uuid(f2) select t from generate_series(1,1000000) as t;
INSERT 0 1000000
Time: 4869.140 ms (00:04.869) 
  • serial插入1万条数据。
postgres=# \d+ t_serial
                                                     Table "public.t_serial"
 Column |          Type          |                       Modifiers                       | Storage  | Stats target | Description 
--------+------------------------+-------------------------------------------------------+----------+--------------+-------------
 f1     | integer                | not null default nextval('t_serial_f1_seq'::regclass) | plain    |              | 
 f2     | character varying(256) |                                                       | extended |              | 
Has OIDs: no
Distribute By SHARD(f1)
        Location Nodes: ALL DATANODES

postgres=#  insert into t_serial(f2) select t from generate_series(1,1000000) as t;      
INSERT 0 1000000
Time: 3683.533 ms (00:03.684)
  • uuid pgbench结果。
pghost: 172.16.0.42 pgport: 11016 nclients: 32 duration: 600 dbName: postgres
transaction type: insert_t_uuid.sql
scaling factor: 1
query mode: prepared
number of clients: 32
number of threads: 1
duration: 600 s
number of transactions actually processed: 531667
latency average = 36.166 ms
tps = 884.807291 (including connections establishing)
tps = 884.813103 (excluding connections establishing)
script statistics:
 - statement latencies in milliseconds:
         0.013  \set id random(1, 10000000)
        36.094  insert into t_uuid(f2) values(:id::text) ;
  • erial pgbench结果。
transaction type: insert_t_serial.sql
scaling factor: 1
query mode: prepared
number of clients: 32
number of threads: 1
duration: 600 s
number of transactions actually processed: 493799
latency average = 38.889 ms
tps = 822.864578 (including connections establishing)
tps = 822.869984 (excluding connections establishing)
script statistics:
 - statement latencies in milliseconds:
         0.013  \set id random(1, 10000000)
        38.861  insert into t_serial(f2) values(:id::text) ;
  • 测试数据对比 。
uuid用时 Serial用时 百分比 Uuid pgbench Serial pgbench 百分比
4.869s 3.684s 75.66% 884 822 92.98%