HowardQin commented on issue #25451: URL: https://github.com/apache/doris/issues/25451#issuecomment-1780788366
你好,我研究了一下,根本原因是doris的decimal底层是用32位、64位或128位整数存储,只能在一定范围内保证精确度,而且这个范围并不是很大。这一点与Oracle、PG或mysql不同。 根据decimal乘法结果的推算规则: DECIMAL(23,10) x DECIMAL(23,10) => DECIMAL(38,20) DECIMAL(23,10) x DECIMAL(23,10) x DECIMAL(23,10) => DECIMAL(38,30) 三个DECIMAL(23,10) 推算出积的scale为30,这样挤占了整数部分的位数,导致整数部分溢出。 我想了想,没有什么好的解决办法,只能手动加CAST,如果你试一下4个DECIMAL(23,10) 类型相乘,就会发现系统自动加了CAST,decimal退化成了double。 本质上,是因为doris的decimal实现和Oracle之类的OLTP数据库不同,我研究了一下PG,它用多个字节存储decimal数据,precision可以远远超过38,而doris的实现最多只用一个128位整数存储整个decimal,对于大数据量的decimal乘或加运算,最终只能当作double来算,不能保证精确度,也许这样是为了性能。 还有很多类似decimal运算的issue和pr,我觉得都源于doris的decimal底层实现,除非社区想将decimal实现为和OLTP数据库一样的精确类型,否则无解。 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
