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

Merge mergeable derived tables used at the top level of UPDATE statements

Details

    Description

      Currently in MariaDB derived tables used at the top level of UPDATE (and DELETE) statements are always materialized. As a result the base tables underlying a mergeable derived table cannot be updated while the mergeable view specified with the same SELECT expression as the derived table can be updated.

      MariaDB [test]> update (select * from t1 where a < 3) as t set a=14;
      ERROR 1288 (HY000): The target table t of the UPDATE is not updatable
       
      MariaDB [test]> update (select a from t1 where a < 3) as t, t2 set t.a=10 where t.a=t2.b;
      ERROR 1288 (HY000): The target table t of the UPDATE is not updatable
       
      MariaDB [test]> create view v1 as (select a from t1 where a < 3);
       
      MariaDB [test]> explain update v1 set a=14;
      +------+-------------+-------+------+---------------+------+---------+------+------+-------------+
      | id   | select_type | table | type | possible_keys | key  | key_len | ref  | rows | Extra       |
      +------+-------------+-------+------+---------------+------+---------+------+------+-------------+
      |    1 | SIMPLE      | t1    | ALL  | NULL          | NULL | NULL    | NULL | 4    | Using where |
      +------+-------------+-------+------+---------------+------+---------+------+------+-------------+
       
      MariaDB [test]> explain update v1 as t, t2 set t.a=10 where t.a=t2.b;
      +------+-------------+-------+------+---------------+------+---------+------+------+-------------+
      | id   | select_type | table | type | possible_keys | key  | key_len | ref  | rows | Extra       |
      +------+-------------+-------+------+---------------+------+---------+------+------+-------------+
      |    1 | SIMPLE      | t1    | ALL  | NULL          | NULL | NULL    | NULL | 4    | Using where |
      |    1 | SIMPLE      | t2    | ALL  | NULL          | NULL | NULL    | NULL | 5    | Using where |
      +------+-------------+-------+------+---------------+------+---------+------+------+-------------+
       

      The goal of this task is to change the current code to allow updating mergeable derived tables. When this task is finished we'll have:

      MariaDB [test]> explain update (select * from t1 where a < 3) as t set a=14;
      +------+-------------+-------+------+---------------+------+---------+------+------+-------------+
      | id   | select_type | table | type | possible_keys | key  | key_len | ref  | rows | Extra       |
      +------+-------------+-------+------+---------------+------+---------+------+------+-------------+
      |    1 | SIMPLE      | t1    | ALL  | NULL          | NULL | NULL    | NULL | 4    | Using where |
      +------+-------------+-------+------+---------------+------+---------+------+------+-------------+
       
      MariaDB [test]> explain update (select a from t1 where a < 3) as t, t2 set t.a=10 where t.a=t2.b;
      +------+-------------+-------+------+---------------+------+---------+------+------+-------------+
      | id   | select_type | table | type | possible_keys | key  | key_len | ref  | rows | Extra       |
      +------+-------------+-------+------+---------------+------+---------+------+------+-------------+
      |    1 | SIMPLE      | t1    | ALL  | NULL          | NULL | NULL    | NULL | 4    | Using where |
      |    1 | SIMPLE      | t2    | ALL  | NULL          | NULL | NULL    | NULL | 5    | Using where |
      +------+-------------+-------+------+---------------+------+---------+------+------+-------------+

      Attachments

        Issue Links

          Activity

            igor Igor Babaev created issue -
            igor Igor Babaev made changes -
            Field Original Value New Value
            serg Sergei Golubchik made changes -
            Rank Ranked higher
            serg Sergei Golubchik made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            psergei Sergei Petrunia made changes -
            Fix Version/s 10.7 [ 24805 ]
            Fix Version/s 10.6 [ 24028 ]
            ralf.gebhardt Ralf Gebhardt made changes -
            Fix Version/s 10.8 [ 26121 ]
            Fix Version/s 10.7 [ 24805 ]
            serg Sergei Golubchik made changes -
            Workflow MariaDB v3 [ 112841 ] MariaDB v4 [ 131848 ]
            serg Sergei Golubchik made changes -
            Fix Version/s 10.9 [ 26905 ]
            Fix Version/s 10.8 [ 26121 ]
            serg Sergei Golubchik made changes -
            Fix Version/s 10.10 [ 27530 ]
            Fix Version/s 10.9 [ 26905 ]
            ralf.gebhardt Ralf Gebhardt made changes -
            Fix Version/s 10.11 [ 27614 ]
            Fix Version/s 10.10 [ 27530 ]
            AirFocus AirFocus made changes -
            Description Currently in MariaDB derived tables used at the top level of UPDATE (and DELETE) statements are always materialized. As a result the base tables underlying a mergeable derived table cannot be updated while the mergeable view specified with the same SELECT expression as the derived table can be updated.
            {noformat}
            MariaDB [test]> update (select * from t1 where a < 3) as t set a=14;
            ERROR 1288 (HY000): The target table t of the UPDATE is not updatable

            MariaDB [test]> update (select a from t1 where a < 3) as t, t2 set t.a=10 where t.a=t2.b;
            ERROR 1288 (HY000): The target table t of the UPDATE is not updatable

            MariaDB [test]> create view v1 as (select a from t1 where a < 3);

            MariaDB [test]> explain update v1 set a=14;
            +------+-------------+-------+------+---------------+------+---------+------+------+-------------+
            | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
            +------+-------------+-------+------+---------------+------+---------+------+------+-------------+
            | 1 | SIMPLE | t1 | ALL | NULL | NULL | NULL | NULL | 4 | Using where |
            +------+-------------+-------+------+---------------+------+---------+------+------+-------------+

            MariaDB [test]> explain update v1 as t, t2 set t.a=10 where t.a=t2.b;
            +------+-------------+-------+------+---------------+------+---------+------+------+-------------+
            | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
            +------+-------------+-------+------+---------------+------+---------+------+------+-------------+
            | 1 | SIMPLE | t1 | ALL | NULL | NULL | NULL | NULL | 4 | Using where |
            | 1 | SIMPLE | t2 | ALL | NULL | NULL | NULL | NULL | 5 | Using where |
            +------+-------------+-------+------+---------------+------+---------+------+------+-------------+

            {noformat}
            The goal of this task is to change the current code to allow updating mergeable derived tables. When this task is finished we'll have:
            {noformat}
            MariaDB [test]> explain update (select * from t1 where a < 3) as t set a=14;
            +------+-------------+-------+------+---------------+------+---------+------+------+-------------+
            | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
            +------+-------------+-------+------+---------------+------+---------+------+------+-------------+
            | 1 | SIMPLE | t1 | ALL | NULL | NULL | NULL | NULL | 4 | Using where |
            +------+-------------+-------+------+---------------+------+---------+------+------+-------------+

            MariaDB [test]> explain update (select a from t1 where a < 3) as t, t2 set t.a=10 where t.a=t2.b;
            +------+-------------+-------+------+---------------+------+---------+------+------+-------------+
            | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
            +------+-------------+-------+------+---------------+------+---------+------+------+-------------+
            | 1 | SIMPLE | t1 | ALL | NULL | NULL | NULL | NULL | 4 | Using where |
            | 1 | SIMPLE | t2 | ALL | NULL | NULL | NULL | NULL | 5 | Using where |
            +------+-------------+-------+------+---------------+------+---------+------+------+-------------+
            {noformat}

            Currently in MariaDB derived tables used at the top level of UPDATE (and DELETE) statements are always materialized. As a result the base tables underlying a mergeable derived table cannot be updated while the mergeable view specified with the same SELECT expression as the derived table can be updated.

            {noformat}
            MariaDB [test]> update (select * from t1 where a < 3) as t set a=14;
            ERROR 1288 (HY000): The target table t of the UPDATE is not updatable

            MariaDB [test]> update (select a from t1 where a < 3) as t, t2 set t.a=10 where t.a=t2.b;
            ERROR 1288 (HY000): The target table t of the UPDATE is not updatable

            MariaDB [test]> create view v1 as (select a from t1 where a < 3);

            MariaDB [test]> explain update v1 set a=14;
            +------+-------------+-------+------+---------------+------+---------+------+------+-------------+
            | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
            +------+-------------+-------+------+---------------+------+---------+------+------+-------------+
            | 1 | SIMPLE | t1 | ALL | NULL | NULL | NULL | NULL | 4 | Using where |
            +------+-------------+-------+------+---------------+------+---------+------+------+-------------+

            MariaDB [test]> explain update v1 as t, t2 set t.a=10 where t.a=t2.b;
            +------+-------------+-------+------+---------------+------+---------+------+------+-------------+
            | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
            +------+-------------+-------+------+---------------+------+---------+------+------+-------------+
            | 1 | SIMPLE | t1 | ALL | NULL | NULL | NULL | NULL | 4 | Using where |
            | 1 | SIMPLE | t2 | ALL | NULL | NULL | NULL | NULL | 5 | Using where |
            +------+-------------+-------+------+---------------+------+---------+------+------+-------------+

            {noformat}

            The goal of this task is to change the current code to allow updating mergeable derived tables. When this task is finished we'll have:

            {noformat}
            MariaDB [test]> explain update (select * from t1 where a < 3) as t set a=14;
            +------+-------------+-------+------+---------------+------+---------+------+------+-------------+
            | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
            +------+-------------+-------+------+---------------+------+---------+------+------+-------------+
            | 1 | SIMPLE | t1 | ALL | NULL | NULL | NULL | NULL | 4 | Using where |
            +------+-------------+-------+------+---------------+------+---------+------+------+-------------+

            MariaDB [test]> explain update (select a from t1 where a < 3) as t, t2 set t.a=10 where t.a=t2.b;
            +------+-------------+-------+------+---------------+------+---------+------+------+-------------+
            | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
            +------+-------------+-------+------+---------------+------+---------+------+------+-------------+
            | 1 | SIMPLE | t1 | ALL | NULL | NULL | NULL | NULL | 4 | Using where |
            | 1 | SIMPLE | t2 | ALL | NULL | NULL | NULL | NULL | 5 | Using where |
            +------+-------------+-------+------+---------------+------+---------+------+------+-------------+
            {noformat}
            julien.fritsch Julien Fritsch made changes -
            Priority Major [ 3 ] Critical [ 2 ]
            julien.fritsch Julien Fritsch made changes -
            Fix Version/s 11.2 [ 28603 ]
            Fix Version/s 10.11 [ 27614 ]
            julien.fritsch Julien Fritsch made changes -
            Priority Critical [ 2 ] Major [ 3 ]
            julien.fritsch Julien Fritsch made changes -
            Priority Major [ 3 ] Critical [ 2 ]
            ralf.gebhardt Ralf Gebhardt made changes -
            Fix Version/s 11.3 [ 28565 ]
            Fix Version/s 11.2 [ 28603 ]
            serg Sergei Golubchik made changes -
            Priority Critical [ 2 ] Major [ 3 ]
            julien.fritsch Julien Fritsch made changes -
            Priority Major [ 3 ] Critical [ 2 ]
            serg Sergei Golubchik made changes -
            Fix Version/s 11.4 [ 29301 ]
            Fix Version/s 11.3 [ 28565 ]
            serg Sergei Golubchik made changes -
            Fix Version/s 11.5 [ 29506 ]
            Fix Version/s 11.4 [ 29301 ]
            julien.fritsch Julien Fritsch made changes -
            Issue Type Task [ 3 ] New Feature [ 2 ]
            julien.fritsch Julien Fritsch made changes -
            Status In Progress [ 3 ] Stalled [ 10000 ]
            serg Sergei Golubchik made changes -
            Priority Critical [ 2 ] Major [ 3 ]
            ralf.gebhardt Ralf Gebhardt made changes -
            Fix Version/s 11.6 [ 29515 ]
            Fix Version/s 11.5 [ 29506 ]
            ralf.gebhardt Ralf Gebhardt made changes -
            Fix Version/s 11.7 [ 29815 ]
            Fix Version/s 11.6 [ 29515 ]
            julien.fritsch Julien Fritsch made changes -
            Issue Type New Feature [ 2 ] Task [ 3 ]
            ralf.gebhardt Ralf Gebhardt made changes -
            Labels tech_debt
            serg Sergei Golubchik made changes -
            Fix Version/s 11.8 [ 29921 ]
            Fix Version/s 11.7 [ 29815 ]
            serg Sergei Golubchik made changes -
            Fix Version/s 11.8 [ 29921 ]
            serg Sergei Golubchik made changes -
            Fix Version/s 11.9 [ 29945 ]

            People

              igor Igor Babaev
              igor Igor Babaev
              Votes:
              1 Vote for this issue
              Watchers:
              8 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.