Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnionExec sometimes receives data truncated error from children when casting string to decimal #52644

Closed
pcqz opened this issue Apr 16, 2024 · 6 comments

Comments

@pcqz
Copy link

pcqz commented Apr 16, 2024

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

USE TEST;
CREATE TABLE `test1` (
  `bglac` varchar(21) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;

CREATE TABLE `test` (
  `id` int(11) DEFAULT NULL,
  `bglac` varchar(21) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
PARTITION BY HASH (`id`) PARTITIONS 3;

Unable to reproduce steadily when not in transaction:

insert into test values(1,'11,11');
insert into test1(bglac) select  sum(convert(ifnull(bglac, 0), decimal(21,3))) from test;

Reproduce steadily when in transaction using UnionScan:

begin;
insert into test values(1,'11,11');
insert into test1(bglac) select  sum(convert(ifnull(bglac, 0), decimal(21,3))) from test;

2. What did you expect to see? (Required)

No error.

3. What did you see instead (Required)

Sometimes report error if insert is not in transaction:

mysql> insert into test1(bglac) select  sum(convert(ifnull(bglac, 0), decimal(21,3))) from test;
ERROR 1265 (01000): Data truncated for column '%s' at row %d
mysql> insert into test1(bglac) select  sum(convert(ifnull(bglac, 0), decimal(21,3))) from test;
Query OK, 1 row affected, 1 warning (0.01 sec)
Records: 1  Duplicates: 0  Warnings: 1

Always report error in transaction:

mysql> begin;
Query OK, 0 rows affected (0.00 sec)
mysql> insert into test values(1,'11,11');
Query OK, 1 row affected (0.00 sec)
mysql> insert into test1(bglac) select  sum(convert(ifnull(bglac, 0), decimal(21,3))) from test;
ERROR 1265 (01000): Data truncated for column '%s' at row %d

4. What is your TiDB version? (Required)

v6.5.2

@pcqz pcqz added the type/bug The issue is confirmed as a bug. label Apr 16, 2024
@seiya-annie seiya-annie added sig/transaction SIG:Transaction and removed sig/transaction SIG:Transaction labels Apr 17, 2024
@seiya-annie
Copy link

it seems can be steadily reproduced on master branch

mysql> begin;
Query OK, 0 rows affected (0.00 sec)

mysql> insert into test values(1,'11,11');
Query OK, 1 row affected (0.00 sec)

mysql> insert into test1(bglac) select  sum(convert(ifnull(bglac, 0), decimal(21,3))) from test;
ERROR 1265 (01000): Data truncated for column '%s' at row %d
mysql> 
mysql> 
mysql> commit;
Query OK, 0 rows affected (0.00 sec)

mysql> delete from test1;
Query OK, 0 rows affected (0.00 sec)

mysql> delete from test;
Query OK, 1 row affected (0.00 sec)
mysql> insert into test values(1,'11,11');
Query OK, 1 row affected (0.00 sec)

mysql> insert into test1(bglac) select  sum(convert(ifnull(bglac, 0), decimal(21,3))) from test;
ERROR 1265 (01000): Data truncated for column '%s' at row %d
mysql> 
mysql> delete from test;
Query OK, 1 row affected (0.00 sec)

mysql> insert into test values(1,'11,11');
Query OK, 1 row affected (0.00 sec)

mysql> insert into test1(bglac) select  sum(convert(ifnull(bglac, 0), decimal(21,3))) from test;
ERROR 1265 (01000): Data truncated for column '%s' at row %d
mysql> 
mysql> select tidb_version();
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()                                                                                                                                                                                                                                                  |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v8.1.0-alpha-109-g1b3700c
Edition: Community
Git Commit Hash: 1b3700c1c1507fadc77dfa512f2f4f251921677b
Git Branch: HEAD
UTC Build Time: 2024-04-17 02:36:26
GoVersion: go1.21.4
Race Enabled: false
Check Table Before Drop: false
Store: tikv |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> 

@yibin87
Copy link
Contributor

yibin87 commented Apr 17, 2024

Reproduced the issue locally. There are two factors that lead to the random behavior:

  1. Plan changes due to statistic data. When statistic data is accurate, optimizer knows there is only 1 row data in test, then it prefers one-phase stream agg over two-phase hash agg, and the cast operation will be performed in tidb side; When statistic data is not ready, optimizer chooses two-phase hash agg, and the cast operation will be pushed down to tikv side.
  2. Tikv's cast string as decimal seems work silently when input is incorrect string; tidb's cast string as decimal will produce warning when incorrect string.

@yibin87
Copy link
Contributor

yibin87 commented Apr 17, 2024

related with #51879

@gengliqi
Copy link
Contributor

gengliqi commented May 9, 2024

fixed by tikv/tikv#16963

@gengliqi
Copy link
Contributor

/close

Copy link

ti-chi-bot bot commented May 10, 2024

@gengliqi: Closing this issue.

In response to this:

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@ti-chi-bot ti-chi-bot bot closed this as completed May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants