在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);
 
 
 
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

postgresql-int,bigint,numeric效率测试的更多相关文章

  1. ORM for Net主流框架汇总与效率测试

    框架已经被越来越多的人所关注与使用了,今天我们就来研究一下net方面的几个主流ORM框架,以及它们的效率测试(可能会有遗漏欢迎大家讨论). ORM框架:Object/Relation Mapping( ...

  2. NHibernate Demo 和 效率测试

    本文关于NHibernate的Demo和效率测试,希望对大家有用. 1.先去官网下载Nhibernate 2.放入到项目中并建立Helper类 private static ISession _Ses ...

  3. 关于 pgsql 数据库json几个函数用法的效率测试

    关于 pgsql 数据库json几个函数用法的效率测试 关于pgsql 几个操作符的效率测试比较1. json::->> 和 ->> 测试方法:单次运行100次,运行10个单次 ...

  4. Python_线程、线程效率测试、数据隔离测试、主线程和子线程

    0.进程中的概念 三状态:就绪.运行.阻塞 就绪(Ready):当进程已分配到除CPU以外的所有必要资源,只要获得处理机便可立即执行,这时的进程状态成为就绪状态. 执行/运行(Running)状态:当 ...

  5. 进程池原理及效率测试Pool

    为什么会有进程池的概念? 当我们开启50个进程让他们都将100这个数减1次减到50,你会发现特别慢! 效率问题,原因: 1,开辟内存空间.因为每开启一个进程,都会开启一个属于这个进程池的内存空间,因为 ...

  6. 纯PHP Codeigniter(CI) ThinkPHP效率测试

    最近一直想做一个技术类的新闻站点,想做的执行效率高些,想用PHP做,一直纠结于用纯PHP做还是用CI或者THINKPHP.用纯PHP效率高,缺点 n多,比如安全方面.构架方面等等等等:用CI.thin ...

  7. Python--day39--进程池原理及效率测试

    #为什么要有进程池的概念 #效率 #每次开启进程都要创建一个属于这个进程的内存空间 #寄存器 堆栈 文件 #进程过多 操作系统调度进程 # #进程池 #python中的 先创建一个属于进程的池子 #这 ...

  8. 关于pgsql 几个操作符的效率测试比较

    关于pgsql 几个操作符的效率测试比较1. json::->> 和 ->> 测试方法:单次运行100次,运行10个单次取平均时间.测试结果:->> 效率高 5% ...

  9. kudu系列: Java API使用和效率测试

    Kudu+Impala很适合数据分析, 但直接使用Insert values语句往Kudu表插入数据, 效率实在不好, 测试下来insert的速度仅为80笔/秒. 原因也是显然的, Kudu本身写入效 ...

随机推荐

  1. 2018.10.24 NOIP模拟 小 C 的序列(链表+数论)

    传送门 考虑到a[l],gcd(a[l],a[l+1]),gcd(a[l],a[l+1],a[l+2])....gcd(a[l]...a[r])a[l],gcd(a[l],a[l+1]),gcd(a[ ...

  2. 在table中tr的display:block在firefox下显示布局错乱问题

    [转自:] http://blog.csdn.net/sd2131512/article/details/4720345 按照常理,对于某一单元行需要显示时,使用:display:block属性,不需 ...

  3. ext中对json数据的处理解析

    看贴:http://blog.csdn.net/xieshengjun2009/article/details/5959687

  4. BitMap的简单实现

    面试结束的这些日子好几次接触到BitMap这个东西.到底是啥呢,究其原因就是虽然它的使用条件较为苛刻,但是它对应的时间复杂度和空间复杂度真的是惊人的好. 首先是根据其思想先写了一个比较差的实现代码: ...

  5. 音频管理器(AudioManager)

    MainActivity.java package com.wwj.serviceandboardcast;   import android.app.Activity; import android ...

  6. MongoDB-环境搭建

    1.下载并安装MongoDB服务 下载地址:mongodb-win32-x86_64-2008plus-ssl-3.2.8-signed 可直接运行mongod命令启动MongoDB服务器,也可以将M ...

  7. winSockets编程(七)WSAAsyncSelect模式

    占位## #include <WinSock2.h> #include <Windows.h> #include <StrSafe.h> #pragma comme ...

  8. Python之turtle库

    在命令行下```python -m pip install turtle``` 大致有两种命令: 运动命令: forward(distance) #向前移动距离distance代表距离 backwar ...

  9. java重定向与请求转发的区别

    最近工作不算太忙,今天在这里对java中的重定向和请求转发稍作总结,希望能帮助到大家. 请求转发: request.getRequestDispatcher().forward(); 重定向: res ...

  10. POJ1064--Cable master(Binary Search)

    Description Inhabitants of the Wonderland have decided to hold a regional programming contest. The J ...