加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

PostgreSQL中COUNT的各条件下(1亿条数据)例子

发布时间:2020-12-13 17:19:28 所属栏目:百科 来源:网络整理
导读:插入一亿条数据 (示例数据库:9.3.5) 参考资料:http://www.oschina.net/question/96003_70381 ? 1 2 3 4 test=# insert into tbl_time1 select generate_series(1,100000000),clock_timestamp(),now(); INSERT 0 100000000 Time : 525833.218 ms 约:8.7分钟

插入一亿条数据

(示例数据库:9.3.5)
参考资料:http://www.oschina.net/question/96003_70381

?
1
2
3
4
test=# insert into tbl_time1 select generate_series(1,100000000),clock_timestamp(),now();
INSERT 0 100000000
Time : 525833.218 ms
约:8.7分钟



COUNT,没有索引,1亿条数据。


?
4
5
6
7
select count (1) from tbl_time1;
count
-----------
100000000
(1 row)
: 3070658.058 ms
约:51.2分钟

添加主键索引耗时

4
alter table add primary key (id);
ALTER TABLE
: 981276.804 ms
约:16.4分钟

COUNT,有索引(主键),1亿条数据,注意 where id > 0 的条件

7
8
这个有 where id > 0
(id) id > 0;
count
-----------
100000000
(1 row)
: 244243.112 ms
约:4.071分钟

COUNT,有索引(主键),1亿条数据,注意没有 where id > 0 的条件

这个无 tbl_time1;
: 548650.606 ms
约:9.144分钟

通过修改配置文件调优

8
9
10
11
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 = off

id > 0;
-----------
: 87501.151 ms
约:1.456分钟


转载自: http://www.oschina.net/question/107976_178878

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

相关内容
推荐文章
站长推荐
热点阅读