2011-07-09 181 views
3

假設PostgreSQL在64位服務器上運行,int4(32位)和int8(64位)列之間的性能差異是什麼?該手冊指出int4比int8更有效,但如果底層服務器是64位,是否存在實際的性能差異(根據(1)cpu,(2)內存和(3)存儲)?64位服務器上PostgreSQL中int4和int8的性能差異

回答

4

在(1)的CPU而言,(2)存儲器和(3)存儲

直截了當地把:

  1. 64位的兩倍,32位一樣大。

  2. 64位是32位的兩倍大。

  3. 64位是32位的兩倍大。

我記得wp-hackers中的一個線程做了一些基準測試。創建一個表格,填寫一百萬行。然後找到,添加,組,加入等。我不記得具體情況,但使用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 
+0

+1完整的答案! (我同意) – Bohemian

2

在存儲和內存方面,答案很明顯:INT8是INT4的兩倍,因此它使用兩倍的存儲量和兩倍的內存。在計算(CPU)性能方面,我懷疑它在64位機器上完全沒有區別,在某些情況下,INT4在32位機器上可能更有效。雖然除非你對這些INT進行復雜的數學運算(而不是將它們用作序列等),但計算差異可能爲零,或幾乎爲零。

一旦你開始用你的INT做複雜的事情,它不再是一個真正的數據庫性能問題。