pingcap/tidb

expression calculation will lose precision in special order.

Open

#15,884 创建于 2020年3月31日

在 GitHub 查看
 (1 评论) (0 反应) (0 负责人)Go (6,186 fork)batch import
challenge-programcomponent/expressionhelp wantedseverity/moderatesig/executiontype/bug

仓库指标

Star
 (40,090 star)
PR 合并指标
 (平均合并 18天 2小时) (30 天内合并 292 个 PR)

描述

Description

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. What did you do?

Admittedly, TiDB has some optimizations that were not considered in expression calculation. But these points had been polished up in MySQL for the past few decades. We still need trails and errors to backfill more of this.

one is in expression calculation.

mysql> select '971580' * (5/6);
+-------------------+
| '971580' * (5/6)  |
+-------------------+
| 809617.6140000001 |
+-------------------+
1 row in set (0.00 sec)

mysql> select '971580' * 5/6;
+----------------+
| '971580' * 5/6 |
+----------------+
|         809650 |
+----------------+
1 row in set (0.00 sec)

2. What did you expect to see?

The first case above will lose precision in (5/6)(default keep 4 digits in new decimal), then multiple with cast('971580' as double) to got 809617.6140000001, but the second won't.

More interesting things, when we use 971580 directly, it will get 809649.9997 which is more precise than case 1.

3. What did you see instead?

the case 1 calculation should be more precise, at least be the same result as using 971580 directly.

4. What version of TiDB are you using? (tidb-server -V or run select tidb_version(); on TiDB)

all the branch

SIG slack channel

#sig-exec

Score

  • 300

Mentor

  • @qw4990

贡献者指南