PostgreSQL在64位服务器上的int4和int8之间的性能差异

arc*_*eta 5 postgresql performance integer

假设PostgreSQL在64位服务器上运行,int4(32位)和int8(64位)列之间的性能差异是什么?手册指出int4比int8更有效,但是如果底层服务器是64位,则在性能上有实际差异(就(1)cpu,(2)内存和(3)存储而言)?

Den*_*rdy 7

就(1)cpu,(2)内存和(3)存储而言

坦白地说:

  1. 64位是32位的两倍。

  2. 64位是32位的两倍。

  3. 64位是32位的两倍。

我记得在wp-hacker中有一个线程做了一些基准测试。创建一个表,填写一百万行。然后查找,添加,分组,联接等。我不记得具体细节,但是使用int8确实比int4慢。


test=# create table int4_test (id int primary key);
CREATE TABLE
test=# create table int8_test (id bigint primary key);
CREATE TABLE
test=# insert into int4_test select i from generate_series(1,1000000) i;
INSERT 0 1000000
test=# insert into int8_test select i from generate_series(1,1000000) i;
INSERT 0 1000000
test=# vacuum analyze;
VACUUM
test=# \timing on
Timing is on.
test=# select sum(i.id) from int4_test i natural join int4_test j where i.id % 19 = 0;
     sum     
-------------
 26315710524
(1 row)

Time: 1364.925 ms
test=# select sum(i.id) from int4_test i natural join int4_test j where i.id % 19 = 0;
     sum     
-------------
 26315710524
(1 row)

Time: 1286.810 ms
test=# select sum(i.id) from int8_test i natural join int8_test j where i.id % 19 = 0;
     sum     
-------------
 26315710524
(1 row)

Time: 1610.638 ms
test=# select sum(i.id) from int8_test i natural join int8_test j where i.id % 19 = 0;
     sum     
-------------
 26315710524
(1 row)

Time: 1554.066 ms

test=# select count(*) from int4_test i natural join int4_test j where i.id % 19 = 0;
 count 
-------
 52631
(1 row)

Time: 1244.654 ms
test=# select count(*) from int4_test i natural join int4_test j where i.id % 19 = 0;
 count 
-------
 52631
(1 row)

Time: 1247.114 ms
test=# select count(*) from int8_test i natural join int8_test j where i.id % 19 = 0;
 count 
-------
 52631
(1 row)

Time: 1541.751 ms
test=# select count(*) from int8_test i natural join int8_test j where i.id % 19 = 0;
 count 
-------
 52631
(1 row)

Time: 1519.986 ms
Run Code Online (Sandbox Code Playgroud)

  • 这是在什么样的机器上执行的?64位机器还是32位机器? (6认同)