[MDEV-28608] Subquery gives wrong results in ON DUPLICATE KEY UPDATE ... part of INSERT Created: 2022-05-18  Updated: 2023-11-28

Status: Confirmed
Project: MariaDB Server
Component/s: Data Manipulation - Insert, Data Manipulation - Subquery, Data Manipulation - Update
Affects Version/s: 10.3, 10.4, 10.5, 10.6, 10.7, 10.8, 10.9
Fix Version/s: 10.4, 10.5, 10.6

Type: Bug Priority: Major
Reporter: Janez Resnik Assignee: Sergei Petrunia
Resolution: Unresolved Votes: 0
Labels: upstream


 Description   

In case of multi-row update like this

INSERT ... SELECT ... ON DUPLICATE KEY UPDATE b=(select ... )

all rows get last subquery result

This bug has been reported upstream, see https://bugs.mysql.com/107325

Tested mariadb versions (with issue):

Tested mysql versions (with issue):



 Comments   
Comment by Alice Sherepa [ 2022-06-03 ]

Thank you!
I repeated as described on 10.3-10.9

MariaDB [test]> CREATE TABLE tb1 (a int, b int, PRIMARY KEY (a));
Query OK, 0 rows affected (0.055 sec)
 
MariaDB [test]> insert into tb1 values (1,5),(2,5),(3,5);
Query OK, 3 rows affected (0.009 sec)
Records: 3  Duplicates: 0  Warnings: 0
 
MariaDB [test]> insert into tb1 (a,b)
    -> select a,6 from tb1 t1
    -> on duplicate key update b=(select t2.d from ((select 1 c,1 d) union (values (2,20),(3,33))) t2 where t2.c=t1.a);
Query OK, 6 rows affected (0.010 sec)
Records: 3  Duplicates: 3  Warnings: 0
 
MariaDB [test]> select * from tb1;
+---+------+
| a | b    |
+---+------+
| 1 |   33 |
| 2 |   33 |
| 3 |   33 |
+---+------+
3 rows in set (0.002 sec)
 
MariaDB [test]> select version();
+----------------------+
| version()            |
+----------------------+
| 10.9.2-MariaDB-debug |
+----------------------+
1 row in set (0.001 sec)

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