-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix the issue that decimal divide not round. (#6471)
- Loading branch information
1 parent
2480a1d
commit 77c4d0f
Showing
4 changed files
with
314 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
# Copyright 2023 PingCAP, Ltd. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# decimal / decimal | ||
mysql> drop table if exists test.t; | ||
mysql> create table test.t(a decimal(4,0), b decimal(40, 20)); | ||
mysql> alter table test.t set tiflash replica 1 | ||
mysql> insert into test.t values (1, 10000), (1, 10001), (1, 20000), (1, 20001); | ||
func> wait_table test t | ||
mysql> set tidb_enforce_mpp=1; select a, b, a/b from test.t order by b; | ||
+------+----------------------------+--------+ | ||
| a | b | a/b | | ||
+------+----------------------------+--------+ | ||
| 1 | 10000.00000000000000000000 | 0.0001 | | ||
| 1 | 10001.00000000000000000000 | 0.0001 | | ||
| 1 | 20000.00000000000000000000 | 0.0001 | | ||
| 1 | 20001.00000000000000000000 | 0.0000 | | ||
+------+----------------------------+--------+ | ||
|
||
# int / decimal | ||
mysql> drop table if exists test.t; | ||
mysql> create table test.t(a int, b decimal(40, 20)); | ||
mysql> alter table test.t set tiflash replica 1 | ||
mysql> insert into test.t values (1, 10000), (1, 10001), (1, 20000), (1, 20001); | ||
func> wait_table test t | ||
mysql> set tidb_enforce_mpp=1; select a, b, a/b from test.t order by b; | ||
+------+----------------------------+--------+ | ||
| a | b | a/b | | ||
+------+----------------------------+--------+ | ||
| 1 | 10000.00000000000000000000 | 0.0001 | | ||
| 1 | 10001.00000000000000000000 | 0.0001 | | ||
| 1 | 20000.00000000000000000000 | 0.0001 | | ||
| 1 | 20001.00000000000000000000 | 0.0000 | | ||
+------+----------------------------+--------+ | ||
|
||
# decimal / int | ||
mysql> drop table if exists test.t; | ||
mysql> create table test.t(a int, b decimal(40, 20)); | ||
mysql> alter table test.t set tiflash replica 1 | ||
mysql> insert into test.t values (1, 10000), (1, 10001), (1, 20000), (1, 20001); | ||
func> wait_table test t | ||
mysql> set tidb_enforce_mpp=1; select a, b, a/b from test.t order by b; | ||
+------+----------------------------+--------+ | ||
| a | b | a/b | | ||
+------+----------------------------+--------+ | ||
| 1 | 10000.00000000000000000000 | 0.0001 | | ||
| 1 | 10001.00000000000000000000 | 0.0001 | | ||
| 1 | 20000.00000000000000000000 | 0.0001 | | ||
| 1 | 20001.00000000000000000000 | 0.0000 | | ||
+------+----------------------------+--------+ | ||
|
||
# int / int | ||
mysql> drop table if exists test.t; | ||
mysql> create table test.t(a int, b int); | ||
mysql> alter table test.t set tiflash replica 1 | ||
mysql> insert into test.t values (1, 10000), (1, 10001), (1, 20000), (1, 20001); | ||
func> wait_table test t | ||
mysql> set tidb_enforce_mpp=1; select a, b, a/b from test.t order by b; | ||
+------+-------+--------+ | ||
| a | b | a/b | | ||
+------+-------+--------+ | ||
| 1 | 10000 | 0.0001 | | ||
| 1 | 10001 | 0.0001 | | ||
| 1 | 20000 | 0.0001 | | ||
| 1 | 20001 | 0.0000 | | ||
+------+-------+--------+ | ||
|
||
mysql> drop table if exists test.t; | ||
mysql> create table test.t(a decimal(10,0), b decimal(10,0)); | ||
mysql> alter table test.t set tiflash replica 1 | ||
mysql> insert into test.t values (2147483647, 1), (2147483647, 1073741823), (2147483647, 1073741824), (2147483647, 2147483646), (2147483647, 2147483647); | ||
mysql> insert into test.t values (-2147483647, 1), (-2147483647, 1073741823), (-2147483647, 1073741824), (-2147483647, 2147483646), (-2147483647, 2147483647); | ||
mysql> insert into test.t values (-2147483647, -1), (-2147483647, -1073741823), (-2147483647, -1073741824), (-2147483647, -2147483646), (-2147483647, -2147483647); | ||
mysql> insert into test.t values (2147483647, -1), (2147483647, -1073741823), (2147483647, -1073741824), (2147483647, -2147483646), (2147483647, -2147483647); | ||
func> wait_table test t | ||
mysql> set tidb_enforce_mpp=1; select b, a, b/(a*10000) from test.t where a/b order by b; | ||
+-------------+-------------+-------------+ | ||
| b | a | b/(a*10000) | | ||
+-------------+-------------+-------------+ | ||
| -2147483647 | 2147483647 | -0.0001 | | ||
| -2147483647 | -2147483647 | 0.0001 | | ||
| -2147483646 | 2147483647 | -0.0001 | | ||
| -2147483646 | -2147483647 | 0.0001 | | ||
| -1073741824 | 2147483647 | -0.0001 | | ||
| -1073741824 | -2147483647 | 0.0001 | | ||
| -1073741823 | -2147483647 | 0.0000 | | ||
| -1073741823 | 2147483647 | 0.0000 | | ||
| -1 | 2147483647 | 0.0000 | | ||
| -1 | -2147483647 | 0.0000 | | ||
| 1 | -2147483647 | 0.0000 | | ||
| 1 | 2147483647 | 0.0000 | | ||
| 1073741823 | -2147483647 | 0.0000 | | ||
| 1073741823 | 2147483647 | 0.0000 | | ||
| 1073741824 | -2147483647 | -0.0001 | | ||
| 1073741824 | 2147483647 | 0.0001 | | ||
| 2147483646 | -2147483647 | -0.0001 | | ||
| 2147483646 | 2147483647 | 0.0001 | | ||
| 2147483647 | -2147483647 | -0.0001 | | ||
| 2147483647 | 2147483647 | 0.0001 | | ||
+-------------+-------------+-------------+ | ||
mysql> delete from test.t; | ||
mysql> insert into test.t values (2147483647, 9999999999), (9999999999, 2147483647), (1, 9999999999), (4999999999, 9999999999), (5000000000, 9999999999); | ||
mysql> insert into test.t values (-2147483647, 9999999999), (-9999999999, 2147483647), (-1, 9999999999), (-4999999999, 9999999999), (-5000000000, 9999999999); | ||
mysql> insert into test.t values (-2147483647, -9999999999), (-9999999999, -2147483647), (-1, -9999999999), (-4999999999, -9999999999), (-5000000000, -9999999999); | ||
mysql> insert into test.t values (2147483647, -9999999999), (9999999999, -2147483647), (1, -9999999999), (4999999999, -9999999999), (5000000000, -9999999999); | ||
mysql> set tidb_enforce_mpp=1; select b, a, b/(a*10000) from test.t where a/b order by b; | ||
+-------------+-------------+-------------+ | ||
| b | a | b/(a*10000) | | ||
+-------------+-------------+-------------+ | ||
| -9999999999 | 2147483647 | -0.0005 | | ||
| -9999999999 | -4999999999 | 0.0002 | | ||
| -9999999999 | 5000000000 | -0.0002 | | ||
| -9999999999 | 4999999999 | -0.0002 | | ||
| -9999999999 | -2147483647 | 0.0005 | | ||
| -9999999999 | -5000000000 | 0.0002 | | ||
| -2147483647 | -9999999999 | 0.0000 | | ||
| -2147483647 | 9999999999 | 0.0000 | | ||
| 2147483647 | 9999999999 | 0.0000 | | ||
| 2147483647 | -9999999999 | 0.0000 | | ||
| 9999999999 | -4999999999 | -0.0002 | | ||
| 9999999999 | -2147483647 | -0.0005 | | ||
| 9999999999 | -5000000000 | -0.0002 | | ||
| 9999999999 | 2147483647 | 0.0005 | | ||
| 9999999999 | 5000000000 | 0.0002 | | ||
| 9999999999 | 4999999999 | 0.0002 | | ||
+-------------+-------------+-------------+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters