(示例數據庫:9.3.5)web
test=# insert into tbl_time1 select generate_series(1,100000000),clock_timestamp(),now();
INSERT 0 100000000
Time: 525833.218 ms
約:8.7分鐘數據庫
test=# select count(1) from tbl_time1;
count
-----------
100000000
(1 row)
Time: 3070658.058 ms
約:51.2分鐘oop
test=# alter table tbl_time1 add primary key (id);
ALTER TABLE
Time: 981276.804 ms
約:16.4分鐘測試
這個有 where id > 0
test=# select count(id) from tbl_time1 where id > 0;
count
-----------
100000000
(1 row)
Time: 244243.112 ms
約:4.071分鐘spa
這個無 where id > 0
test=# select count(id) from tbl_time1;
count
-----------
100000000
(1 row)
Time: 548650.606 ms
約:9.144分鐘.net
enable_bitmapscan = off
enable_hashagg = on
enable_hashjoin = on
enable_indexscan = on
enable_indexonlyscan = on#惟一索引掃描
#enable_material = on
#enable_mergejoin = on
#enable_nestloop = on
enable_seqscan = off
#enable_sort = on
enable_tidscan = ofform
test=# select count(id) from tbl_time1 where id > 0;
count
-----------
100000000
(1 row)
Time: 87501.151 ms
約:1.456分鐘索引
問題:內存
1.count都會掃全表很慢的 ?count 超過幾十萬 都是掃全表的? 修改配置文件,是 Index Only Scan的 enable_indexonlyscan = on 優先get
2.沒辦法查詢控制在秒級嗎? 測試測試機是普通PC的,之前的AMD4核,8G內存,7200轉 的硬盤。不過,相信再調優下內存,我以爲應該是能夠的。