Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-28608

Subquery gives wrong results in ON DUPLICATE KEY UPDATE ... part of INSERT

Details

    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):

      Attachments

        Activity

          alice Alice Sherepa added a comment -

          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)
          

          alice Alice Sherepa added a comment - 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)

          People

            psergei Sergei Petrunia
            janezr-bens Janez Resnik
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.