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

multi clustered index + partition table, insert ignore... on duplicate key update return wrong result #25846

Closed
vivid392845427 opened this issue Jun 30, 2021 · 3 comments · Fixed by #25859
Labels
affects-5.0 This bug affects 5.0.x versions. severity/major sig/transaction SIG:Transaction type/bug The issue is confirmed as a bug.

Comments

@vivid392845427
Copy link

vivid392845427 commented Jun 30, 2021

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

CREATE TABLE tbl_51 (
col_334 mediumint(9) NOT NULL DEFAULT '-3217641',
col_335 mediumint(8) unsigned NOT NULL DEFAULT '2002468',
col_336 enum('alice','bob','charlie','david') COLLATE utf8_general_ci NOT NULL DEFAULT 'alice',
PRIMARY KEY (col_334,col_336,col_335) /*T![clustered_index] CLUSTERED */,
UNIQUE KEY idx_116 (col_334,col_335),
UNIQUE KEY idx_117 (col_336,col_334),
KEY idx_118 (col_336)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci
PARTITION BY HASH( col_334 )
PARTITIONS 6;
insert into tbl_51 values(-3112969,3273861,'charlie'),(-3040776,4159759,'charlie');
insert ignore into tbl_51 (col_336) values ( 'alice' ) , ( 'david' ) , ( 'charlie' ) , ( 'charlie' ) , ( 'alice' ) on duplicate key update col_335 = 7685969;

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

mysql> select * from tbl_51;
+----------+---------+---------+
| col_334 | col_335 | col_336 |
+----------+---------+---------+
| -3112969 | 3273861 | charlie |
| -3217641 | 7685969 | alice |
| -3217641 | 2002468 | charlie |
| -3040776 | 4159759 | charlie |
+----------+---------+---------+

3. What did you see instead (Required)

only occur on 5.0 and partition table, master is the same as expect

mysql> select * from tbl_51;
+----------+---------+---------+
| col_334 | col_335 | col_336 |
+----------+---------+---------+
| -3040776 | 4159759 | charlie |
| -3112969 | 3273861 | charlie |
| -3217641 | 7685969 | alice |
+----------+---------+---------+

4. What is your TiDB version? (Required)

Release Version: v5.0.2-42-g18d69e5
Edition: Community
Git Commit Hash: 18d69e5
Git Branch: HEAD
UTC Build Time: 2021-06-28 18:22:53
GoVersion: go1.13.7
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false

@vivid392845427 vivid392845427 added the type/bug The issue is confirmed as a bug. label Jun 30, 2021
@vivid392845427 vivid392845427 changed the title clustered index multi clustered index, insert ignore... on duplicate key update return wrong result Jun 30, 2021
@vivid392845427 vivid392845427 changed the title multi clustered index, insert ignore... on duplicate key update return wrong result multi clustered index + partition table, insert ignore... on duplicate key update return wrong result Jun 30, 2021
@lysu
Copy link
Contributor

lysu commented Jul 1, 2021

CREATE TABLE `tbl_51` (
  `col_334` mediumint(9) NOT NULL DEFAULT '-3217641',
  `col_335` mediumint(8) unsigned NOT NULL DEFAULT '2002468',
  `col_336` enum('alice','bob','charlie','david') COLLATE utf8_general_ci NOT NULL DEFAULT 'alice',
  PRIMARY KEY (`col_334`,`col_336`,`col_335`) /*T![clustered_index] CLUSTERED */,
  UNIQUE KEY `idx_116` (`col_334`,`col_335`),
  UNIQUE KEY `idx_117` (`col_336`,`col_334`),
  KEY `idx_118` (`col_336`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci
PARTITION BY HASH( `col_334` )
PARTITIONS 6;

insert ignore into tbl_51(col_335, col_336) values(7685969, 'alice'),(2002468, 'bob');
insert ignore into tbl_51(col_335, col_336) values(2002468, 'david') on duplicate key update col_335 = 7685969;
select * from tbl_51;

should be

+----------+---------+---------+
| col_334  | col_335 | col_336 |
+----------+---------+---------+
| -3217641 | 7685969 | alice   |
| -3217641 | 2002468 | bob     |
+----------+---------+---------+

but got

+----------+---------+---------+
| col_334  | col_335 | col_336 |
+----------+---------+---------+
| -3217641 | 7685969 | alice   |
+----------+---------+---------+

@cfzjywxk
Copy link
Contributor

@lysu
The release-3.0 pick is not merged yet, shall we close this issue?

@github-actions
Copy link

Please check whether the issue should be labeled with 'affects-x.y' or 'backport-x.y.z',
and then remove 'needs-more-info' label.

@jebter jebter added affects-5.0 This bug affects 5.0.x versions. and removed needs-more-info labels Aug 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-5.0 This bug affects 5.0.x versions. severity/major sig/transaction SIG:Transaction type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants