[MDEV-30588] Failed to update duplicate data when running insert... on duplicate key update. Created: 2023-02-07  Updated: 2023-02-07  Resolved: 2023-02-07

Status: Closed
Project: MariaDB Server
Component/s: Data Manipulation - Insert, Storage Engine - InnoDB
Affects Version/s: 10.5.16
Fix Version/s: N/A

Type: Bug Priority: Critical
Reporter: Zeng Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None

Issue Links:
Duplicate
duplicates MDEV-30046 wrong row targeted with "insert ... o... Stalled
Relates
relates to MDEV-371 Unique indexes for blobs Closed

 Description   

When we execute the following SQL statement, we failed to update the row where the duplicate data is located.

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (t BLOB, n INT, UNIQUE (t));
INSERT INTO t1 VALUES ('Hrecvx_0004ln-00',1), ('Hrecvx_0004mm-00',1);
INSERT INTO t1 VALUES ('Hrecvx_0004mm-00',2) ON DUPLICATE KEY UPDATE n = VALUES ;

Result: The SQL statement update the value of n in the line where Hrecvx_0004ln-00 is located. However, it should update the line where Hrecvx_0004mm-00 is located.

mysql> DROP TABLE IF EXISTS t1;
Query OK, 0 rows affected (0.00 sec)
 
mysql> CREATE TABLE t1 (t BLOB, n INT, UNIQUE (t));
Query OK, 0 rows affected (0.01 sec)
 
mysql> INSERT INTO t1 VALUES ('Hrecvx_0004ln-00',1), ('Hrecvx_0004mm-00',1);
Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0
 
mysql> SELECT * FROM t1;
+------------------+------+
| t                | n    |
+------------------+------+
| Hrecvx_0004ln-00 |    1 |
| Hrecvx_0004mm-00 |    1 |
+------------------+------+
2 rows in set (0.00 sec)
 
mysql> INSERT INTO t1 VALUES ('Hrecvx_0004mm-00',2) ON DUPLICATE KEY UPDATE n = VALUES (n);
Query OK, 2 rows affected (0.00 sec)
 
mysql> SELECT * FROM t1;
+------------------+------+
| t                | n    |
+------------------+------+
| Hrecvx_0004ln-00 |    2 |
| Hrecvx_0004mm-00 |    1 |
+------------------+------+
2 rows in set (0.00 sec)


Generated at Thu Feb 08 10:17:23 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.