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

clustered string primary with dup prefixed uk, insert ignore ... on duplicate key update return wrong result #25809

Closed
vivid392845427 opened this issue Jun 28, 2021 · 3 comments · Fixed by #25905
Assignees
Labels
affects-4.0 This bug affects 4.0.x versions. affects-5.0 This bug affects 5.0.x versions. severity/critical sig/transaction SIG:Transaction type/bug This issue is a bug.

Comments

@vivid392845427
Copy link

vivid392845427 commented Jun 28, 2021

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

CREATE TABLE `tbl_16` (
  `col_70` varbinary(444) NOT NULL DEFAULT 'bezhs',
  PRIMARY KEY (`col_70`) clustered,
  UNIQUE KEY `idx_22` (`col_70`(1))
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
 insert into tbl_16 values('lldcxiyfjrqzgj');
 insert ignore into tbl_16 values ( 'lalozlkdosasfklmflo' ) on duplicate key update col_70 = 'lyhohxtby';

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

mysql> insert ignore into tbl_16 values ( 'lalozlkdosasfklmflo' ) on duplicate key update col_70 = 'lyhohxtby';
Query OK, 2 rows affected (0.00 sec)

mysql> select * from tbl_16;
+-----------+
| col_70    |
+-----------+
| lyhohxtby |
+-----------+
1 row in set (0.00 sec)

3. What did you see instead (Required)

only occur in 5.0-release, master is the same as expected

mysql>  insert ignore into tbl_16 values ( 'lalozlkdosasfklmflo' ) on duplicate key update col_70 = 'lyhohxtby';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> select * from tbl_16;
+----------------+
| col_70         |
+----------------+
| lldcxiyfjrqzgj |
+----------------+
1 row in set (0.00 sec)

4. What is your TiDB version? (Required)

Release Version: v5.0.2-40-g64b7ecd
Edition: Community
Git Commit Hash: 64b7ecd7938a69c34169cd4edc3055544f51e423
Git Branch: HEAD
UTC Build Time: 2021-06-25 18:24:59
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 This issue is a bug. label Jun 28, 2021
@lysu lysu changed the title new collation + clustered index, insert ignore ... on duplicate key update return wrong result clustered string primary with dup prefixed uk, insert ignore ... on duplicate key update return wrong result Jun 30, 2021
@lysu
Copy link
Collaborator

lysu commented Jun 30, 2021

this question trigger condition is :

  • clustered index string primary key - primary key (col_70)
  • a prefixed secondary index with the same column but has prefix length - UNIQUE KEY idx_22 (col_70(1))
  • insert ignore into on duplicate update change the column value but not change prefixed part

so , it will trigger handle change logic, but 'handle changed' doesn't make 'index value changed'...so it cause problem 😢

@lysu
Copy link
Collaborator

lysu commented Jun 30, 2021

the 5.1 and master use new memdb's stage handle feature, so it can avoid this problem

but 3.0, 4.0, 5.0 ti use old version memdb, we cannot backport master logic and need another fix...

@github-actions
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-4.0 This bug affects 4.0.x versions. affects-5.0 This bug affects 5.0.x versions. severity/critical sig/transaction SIG:Transaction type/bug This issue is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants