博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
postgresql-int,bigint,numeric效率测试
阅读量:4700 次
发布时间:2019-06-09

本文共 3596 字,大约阅读时间需要 11 分钟。

postgresql9.5的时候做过一个测试就是sum()的效率最终的测试结果是sum(int)>sum(numeric)>sum(bigint)当时比较诧异为啥sum(bigint)效率比sum(numeric)还低。sum(numeric)的效率比sum(bigint)快了10%。

pg10版本的时候对sum()的性能做了优化,pg10.4

最终的测试结果为pg10的效率大幅提升,sum(int)>sum(bigint)>sum(numeric),当一个表中有bigint,int时,谁放在第一列效率要高点。但是差别不是很大,效率都比numeric高。

 

 

bigint for smallint or int arguments, numeric for bigint arguments, otherwise the same as the argument data type

这次主要做abase5.0测试,以及pg11 jit测试。

插入1kw数据测试。

这里只是输出类型的转换,并不会太影响效率。
numeric的算术运算比整数类型要慢很多。
通过求助,最终了解到可能和pg的元组变形(tuple deform)有关,
这次创建三张表分别对应三种数据类型。
create table t_int(n_int int);
create table t_bigint(n_bigint bigint);
create table t_numeric(n_numeric numeric);
insert into t_int select generate_series(1,10000000);
insert into t_bigint select generate_series(1,10000000);
insert into t_numeric select generate_series(1,10000000);
 
 
numeric :
int:
bigint:
 
pg:bigint,numeric,int效率测试:
drop table t_int;
drop table t_bigint;
drop table t_numeric;
show shared_buffers;
 
drop table t_bigint
create table t_int(n_int int);
create table t_bigint(n_bigint bigint);
create table t_numeric(n_numeric numeric);
insert into t_int select generate_series(1,10000000);
insert into t_bigint select generate_series(1,10000000);
insert into t_numeric select generate_series(1,10000000);
numeric
select version();
explain analyze
select count(*) from t_num_type
 
SET max_parallel_workers_per_gather = 2;
show max_parallel_workers_per_gather ;
 
select version();
1.单表测试
explain (analyze,buffers,format text) select sum(n_int) from t_int;--560
explain (analyze,buffers,format text) select sum(n_bigint) from t_bigint;--575
explain (analyze,buffers,format text) select sum(n_numeric) from t_numeric;--868
sum(int)>sum(bigint)>sum(numeric)
2.一个表测试
drop table t_num_type
create table t_num_type(n_bigint bigint,n_numeric numeric,n_int int);
insert into t_num_type select n,n,n from generate_series(1,10000000) as t(n)
explain (analyze,buffers,format text) select sum(n_int) from t_num_type ;--661
explain (analyze,buffers,format text) select sum(n_bigint) from t_num_type;--625
explain (analyze,buffers,format text) select sum(n_numeric) from t_num_type;--946
 
sum(bigint)>sum(int)>sum(numeric)
但是整体比单表慢。
select * from t_num_type_3 limit 10
 
drop table t_num_type_2
create table t_num_type_2(n_int int,n_numeric numeric,n_bigint bigint);
insert into t_num_type_2 select n,n,n from generate_series(1,10000000) as t(n)
explain (analyze,buffers,format text) select sum(n_int) from t_num_type_2;--603
explain (analyze,buffers,format text) select sum(n_bigint) from t_num_type_2;--668
explain (analyze,buffers,format text) select sum(n_numeric) from t_num_type_2;--947
sum(int)>sum(bigint)>sum(numeric)
--show jit_above_cost
int放前面int快,bigint又慢了。
 
3.
create table t_num_type_3(n_bigint bigint,n_int int,n_numeric numeric);
insert into t_num_type_3 select n,n,n from generate_series(1,10000000) as t(n)
explain (analyze,buffers,format text) select sum(n_int) from t_num_type_3;--623
explain (analyze,buffers,format text) select sum(n_bigint) from t_num_type_3;--616
explain (analyze,buffers,format text) select sum(n_numeric) from t_num_type_3;--973
 
目前来bigint放到第一列总是快的。当int放到第一列的时候又比bigint快。
 
 
create table t_num_type_4(n_int int,n_bigint bigint,n_numeric numeric);
insert into t_num_type_4 select n,n,n from generate_series(1,10000000) as t(n)
explain (analyze,buffers,format text) select sum(n_int) from t_num_type_4;--617
explain (analyze,buffers,format text) select sum(n_bigint) from t_num_type_4;--643
explain (analyze,buffers,format text) select sum(n_numeric) from t_num_type_4;--973

 

转载于:https://www.cnblogs.com/zhangfx01/p/10216253.html

你可能感兴趣的文章
C#读写三菱PLC和西门子PLC数据 使用TCP/IP 协议
查看>>
vue中moudles的作用及使用方法
查看>>
负载均衡的常用算法
查看>>
JS版本 Bootstrap Modal
查看>>
题目41:对称平方数
查看>>
算法分析:快速选择
查看>>
例题2-2 在屏幕上显示两个短句。
查看>>
Sunscreen [POJ3614] [贪心]
查看>>
Java知多少(65)线程的挂起、恢复和终止
查看>>
数学学习笔记-函数
查看>>
HDU 3039 Go Home
查看>>
使用Grunt启动和运行
查看>>
哈希,最短路径,堆,排序,动态规划
查看>>
系统测试中需要注意的点
查看>>
Elasticsearch TermQuery 详解
查看>>
一个困扰了我N久的bug , android.enableAapt2=false 无效
查看>>
查看客户端的IP地址,机器名,MAC地址,登陆名等信息
查看>>
移动端经常遇到的小bug
查看>>
网络&热恋NSURLConnection代理及GET¥POST请求
查看>>
SshTerminal
查看>>