pingcap / pingcap/tiflash

avg overflow

Open
#3,562 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

affects-5.4 affects-6.0 affects-6.1 affects-6.2 affects-6.3 affects-6.4 affects-6.5 affects-6.6 affects-7.0 affects-7.1 affects-7.5 affects-8.1 affects-8.5 component/compute severity/major type/bug
Dominant language
C++
Stars
1k
Forks
423
Avg merge
1d 15h
Merged PRs (30d)
24

Description

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)
create table t (a decimal(65,0), b decimal(65,30));
insert into t values (99999999999999999999999999999999999999999999999999999999999999999,99999999999999999999999999999999999.999999999999999999999999999999);
insert into t select * from t;
insert into t select * from t;
insert into t select * from t;


mysql> select * from t;
+-------------------------------------------------------------------+--------------------------------------------------------------------+
| a                                                                 | b                                                                  |
+-------------------------------------------------------------------+--------------------------------------------------------------------+
| 99999999999999999999999999999999999999999999999999999999999999999 | 99999999999999999999999999999999999.999999999999999999999999999999 |
| 99999999999999999999999999999999999999999999999999999999999999999 | 99999999999999999999999999999999999.999999999999999999999999999999 |
| 99999999999999999999999999999999999999999999999999999999999999999 | 99999999999999999999999999999999999.999999999999999999999999999999 |
| 99999999999999999999999999999999999999999999999999999999999999999 | 99999999999999999999999999999999999.999999999999999999999999999999 |
| 99999999999999999999999999999999999999999999999999999999999999999 | 99999999999999999999999999999999999.999999999999999999999999999999 |
| 99999999999999999999999999999999999999999999999999999999999999999 | 99999999999999999999999999999999999.999999999999999999999999999999 |
| 99999999999999999999999999999999999999999999999999999999999999999 | 99999999999999999999999999999999999.999999999999999999999999999999 |
| 99999999999999999999999999999999999999999999999999999999999999999 | 99999999999999999999999999999999999.999999999999999999999999999999 |
+-------------------------------------------------------------------+--------------------------------------------------------------------+
2. What did you expect to see? (Required)

99999999999999999999999999999999999999999999999999999999999999999

3. What did you see instead (Required)

mysql> select avg(a) from t group by b;
ERROR 1105 (HY000): other error for mpp stream: DB::Exception: Decimal math overflow

4. What is your TiFlash version? (Required)

master

root cause

in the projection after rewritten avg = sum/count, the sum overflows decaim(65,0), but the div's return type is decimal(65,4), whose length of integer is shorter than 65. It throws exception overflow after div.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the SQL reproduction for AVG over the decimal(65,0) and decimal(65,30) columns. Trace the projection where AVG is rewritten as SUM/COUNT, focusing on the SUM decimal precision and the division return type described in the issue. Done means the query returns the expected average without a Decimal math overflow.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, sql
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.