在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);
https://blog.csdn.net/luojinbai/article/details/42914299
numeric :https://explain.depesz.com/s/Lk6P
int:https://explain.depesz.com/s/4Xo4
bigint:https://explain.depesz.com/s/niQI
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
https://explain.depesz.com/s/Ivks
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

postgresql-int,bigint,numeric效率测试相关推荐

  1. mssql linux性能,MSSQL 的Top 和 MAX 效率测试

    环境: MSSQL 2008, 都在没有使用缓存的情况下面执行 表中有8W 条记录 分类1有134条记录 分别测试了3个语句 -- A select 字段1 from 表1 WHERE Ftype=' ...

  2. vector,数组,动态数组效率测试

    对vector.数组.new创建的动态数组.预先reverse的vector测试代码如下: #include <iostream> #include <vector> #inc ...

  3. C++风格与C风格文件读写效率测试-vs2015,vs2017

    C++风格与C风格文件读写效率测试-vs2015,vs2017 1 void test_write() 2 { 3 const int TEST_SIZE = 100000000; 4 const c ...

  4. 详解C调用lua脚本效率测试

    详解C调用lua脚本效率测试 C调用lua脚本效率测试是本文要介绍的内容,以下代码以C语言为基准,测试了C调用Lua循环和循环调用Lua的效率.结论是不要频繁地穿越C/Lua边界. #include  ...

  5. go 分段锁ConcurrentMap,map+读写锁,sync.map的效率测试

    分段锁ConcurrentMap的实现请参考笔者的另外一篇博客: go 分段锁ConcurrentMap的实现源码 效率测试结论: 1. go自带的map不是多协程安全的 2. 分段锁Concurre ...

  6. mysql 5.7 udf http_mysql下mysql-udf-http效率测试小记

    看到张宴的博客上关于"http/rest客户端的文章",怎样安装啥的直接都跳过,下面直接进入测试阶段,测试环境:虚拟机 复制代码 代码如下: [root@localhost ~]# ...

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

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

  8. 三次多项式曲线php,多项式计算的效率测试,多项式计算效率_PHP教程

    多项式计算的效率测试,多项式计算效率 多项式计算调用库函数pow方法和秦九韶算法,我们来测算下他们的运行效率 计算函数f(x)=1+(Σxi/i)(i从1取到m); 用ctime时间函数来测试运行时间 ...

  9. (转)大数据量分页存储过程效率测试附代码

    大数据量分页存储过程效率测试附代码 在项目中,我们经常遇到或用到分页,那么在大数据量(百万级以上)下,哪种分页算法效率最优呢?我们不妨用事实说话. 测试环境 硬件:CPU 酷睿双核T5750  内存: ...

最新文章

  1. Luogu P1082 同余方程(NOIP 2012) 题解报告
  2. 疑难杂症——bash: /dev/null: Permission denied
  3. 第二届「机器智能前沿论坛」强势来袭,众多机器学习大咖邀你共话AI未来!
  4. rnn中文语音识别java_语音识别算法阅读之RNN-T-2018
  5. 与时间相关的java源码_Java 调整日期和时间
  6. www.cnblog.org无法访问了
  7. Spring4.x(16)--SpringEL-正则表达式
  8. 字符串去空格符(c++)
  9. centos5安装mysql 5.6.19 mysql-devel_Centos5.8 安装 MySQL5.6.19
  10. (原)python爬虫入门(2)---排序爬取的辽宁科技大学热点新闻
  11. 韩顺平循序渐进学java 第18讲 查找
  12. js对象深拷贝的简单实现
  13. C#中?与??的区别
  14. 本周大新闻|PS VR2已确认20款大作,Magic Leap 1低价清库存
  15. PC软件-实用工具 True Launch Bar
  16. python 自动打包pyd
  17. 使用 Keras 进行面部表情识别
  18. 华三光纤交换机默认密码和重置方法
  19. 基于STM32F103--时钟树详解和系统时钟内部流程解析
  20. 30天搞定spark源码系列-RDD番外篇-shuffledRDD

热门文章

  1. mysql性能优化学习笔记
  2. IOS开发之网络编程--文件压缩和解压缩
  3. Centos安装php提示virtual memory exhausted: Cannot allocate memory
  4. 基于类的软件复用技术
  5. jQuery 自定义事件的学习笔记
  6. 二、十六进制数互相转换
  7. java selenium_关于selenium的介绍
  8. ETH突破620美元关口 日内涨幅为5.36%
  9. SAP License:固定资产减值的两种逻辑
  10. 赛锐信息:SAP安全漏洞审计及工具介绍