Details
-
Task
-
Status: Stalled (View Workflow)
-
Major
-
Resolution: Unresolved
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
- blocks
-
MDEV-18511 CTE support for UPDATE and DELETE statements
-
- Open
-
Activity
Field | Original Value | New Value |
---|---|---|
Link | This issue blocks MDEV-18511 [ MDEV-18511 ] |
Rank | Ranked higher |
Status | Open [ 1 ] | In Progress [ 3 ] |
Fix Version/s | 10.7 [ 24805 ] | |
Fix Version/s | 10.6 [ 24028 ] |
Fix Version/s | 10.8 [ 26121 ] | |
Fix Version/s | 10.7 [ 24805 ] |
Workflow | MariaDB v3 [ 112841 ] | MariaDB v4 [ 131848 ] |
Fix Version/s | 10.9 [ 26905 ] | |
Fix Version/s | 10.8 [ 26121 ] |
Fix Version/s | 10.10 [ 27530 ] | |
Fix Version/s | 10.9 [ 26905 ] |
Fix Version/s | 10.11 [ 27614 ] | |
Fix Version/s | 10.10 [ 27530 ] |
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} |
Priority | Major [ 3 ] | Critical [ 2 ] |
Fix Version/s | 11.2 [ 28603 ] | |
Fix Version/s | 10.11 [ 27614 ] |
Priority | Critical [ 2 ] | Major [ 3 ] |
Priority | Major [ 3 ] | Critical [ 2 ] |
Fix Version/s | 11.3 [ 28565 ] | |
Fix Version/s | 11.2 [ 28603 ] |
Priority | Critical [ 2 ] | Major [ 3 ] |
Priority | Major [ 3 ] | Critical [ 2 ] |
Fix Version/s | 11.4 [ 29301 ] | |
Fix Version/s | 11.3 [ 28565 ] |
Fix Version/s | 11.5 [ 29506 ] | |
Fix Version/s | 11.4 [ 29301 ] |
Issue Type | Task [ 3 ] | New Feature [ 2 ] |
Status | In Progress [ 3 ] | Stalled [ 10000 ] |
Priority | Critical [ 2 ] | Major [ 3 ] |
Fix Version/s | 11.6 [ 29515 ] | |
Fix Version/s | 11.5 [ 29506 ] |
Fix Version/s | 11.7 [ 29815 ] | |
Fix Version/s | 11.6 [ 29515 ] |
Issue Type | New Feature [ 2 ] | Task [ 3 ] |
Labels | tech_debt |
Fix Version/s | 11.8 [ 29921 ] | |
Fix Version/s | 11.7 [ 29815 ] |
Fix Version/s | 11.8 [ 29921 ] |
Fix Version/s | 11.9 [ 29945 ] |