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

Wrong result for UPDATE ... ORDER BY LIMIT which uses tmp.table

Details

    Description

      Discovered while debugging MDEV-35848.

      Preamble:

      drop table if exists t1, t2;
      create table t1 (id int primary key, v int);
      create table t2 (id int primary key, v int);
      insert into t1 (id, v) values (2,3),(1,4);
      insert into t2 (id, v) values (5,5),(6,6);
      

      Test case:

      UPDATE t1, t2 SET t1.v=-1, t2.v=-1 ORDER BY t1.id, t2.id LIMIT 2;
      

      Observed result:

      MariaDB [test]> select * from t1;
      +----+------+
      | id | v    |
      +----+------+
      |  1 |   -1 |
      |  2 |   -1 |
      +----+------+
      2 rows in set (0.002 sec)
       
      MariaDB [test]> select * from t2;
      +----+------+
      | id | v    |
      +----+------+
      |  5 |   -1 |
      |  6 |    6 |
      +----+------+
      2 rows in set (0.001 sec)
      

      Expected result:

      MariaDB [test]> select * from t1;
      +----+------+
      | id | v    |
      +----+------+
      |  1 |   -1 |
      |  2 |    3 |
      +----+------+
      2 rows in set (0.002 sec)
       
      MariaDB [test]> select * from t2;
      +----+------+
      | id | v    |
      +----+------+
      |  5 |   -1 |
      |  6 |   -1 |
      +----+------+
      2 rows in set (0.001 sec)
      

      From debugging, we see that between the calls to items1= ref_ptr_array_slice(slice_num: 2); and set_items_ref_array(src_arr: items1); (both from JOIN::make_aggr_tables_info()) the ORDER BY clause gets reversed so that t2 is before t1.

      Attachments

        Issue Links

          Activity

            People

              psergei Sergei Petrunia
              Gosselin Dave Gosselin
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

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