震精 - PostgreSQL decimal64 decimal128 高效率数值 类型扩展

文章介绍了PostgreSQL中decimal效率问题及解决方案,如使用pgdecimal插件,特别是decimal64和decimal128类型,它们在性能上优于内置的numeric类型,减少了palloc的调用。文章详细阐述了pgdecimal的安装和性能对比测试,展示了其在数据分析和大数据处理中的优势。
摘要由CSDN通过智能技术生成

标签

PostgreSQL , decimal64 , decimal128 , float4 , float8 , numeric


背景

PostgreSQL内置的数值类型包括

整型、浮点、整型序列、"无限"精度数值

Name Storage Size Description Range
smallint 2 bytes small-range integer -32768 to +32767
integer 4 bytes typical choice for integer -2147483648 to +2147483647
bigint 8 bytes large-range integer -9223372036854775808 to +9223372036854775807
decimal variable user-specified precision, exact up to 131072 digits before the decimal point; up to 16383 digits after the decimal point
numeric variable user-specified precision, exact up to 131072 digits before the decimal point; up to 16383 digits after the decimal point
real 4 bytes variable-precision, inexact 6 decimal digits precision
double precision 8 bytes variable-precision, inexact 15 decimal digits precision
smallserial 2 bytes small autoincrementing integer 1 to 32767
serial 4 bytes autoincrementing integer 1 to 2147483647
bigserial 8 bytes large autoincrementing integer 1 to 9223372036854775807

其中除了 "无限"精度数值类型。他类型都是定长存储,使用时不需要调用palloc,效率较高。

如果你要使用超过双精能表示的有效范围的数值,目前只能选择decimal\numeric类型,而这个类型前面说了,由于是变长设计,需要调用palloc,效率一般。

那么在数据分析领域,或者需要处理非常多的数据记录时,numeric类型的开销是较大的。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值