[MDEV-23336] CHECK OPTION is ignored for a multi-table update over a view Created: 2020-07-30  Updated: 2023-04-27

Status: Confirmed
Project: MariaDB Server
Component/s: Views
Affects Version/s: 10.1.45, 10.2.32, 10.3.23, 10.4.13, 10.5.3, 10.2, 10.3, 10.4, 10.5, 10.6
Fix Version/s: 10.4, 10.5, 10.6

Type: Bug Priority: Critical
Reporter: Igor Babaev Assignee: Oleksandr Byelkin
Resolution: Unresolved Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-23340 Incomplete condition is checked when ... Open
relates to MDEV-23347 Embedded view's check option is not h... Open

 Description   

For multi-table update statements that update views defined using WITH CHECK OPTION clause the clause may be ignored.
The problem can be reproduced with the following test case:

create table t1 (a int) engine=myisam;
insert into t1 values (0), (3), (1);
create table t2 (a int) engine=myisam;
insert into t2 values (1), (0);
create view v1 as select * from t1 where a < 2 with check option;
update v1,t2 set v1.a=2 where v1.a=t2.a and t2.a=1;
select * from t1;
drop view v1;
drop table t1,t2;

We can see that the update statements succeeds and v1 is updated ignoring the condition in WHERE a < 2:

MariaDB [test]> update v1,t2 set v1.a=2 where v1.a=t2.a and t2.a=1;
Query OK, 1 row affected (0.001 sec)
Rows matched: 1  Changed: 1  Warnings: 0
 
MariaDB [test]> select * from t1;
+------+
| a    |
+------+
|    0 |
|    3 |
|    2 |
+------+
3 rows in set (0.001 sec)



 Comments   
Comment by Igor Babaev [ 2020-07-30 ]

This is a serious bug that is not easy to fix. It happens because no deep copy is created for the condition to be checked after update of a row of the underlying base table. Shallow copy is of no good in the reported test case because after the merge of the the WHERE condition of the view and the WHERE condition of the statements the resulting WHERE condition is modified by the optimizer: the condition t1.a < 2 is replaced with the condition 1 < 2.

Generated at Thu Feb 08 09:21:38 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.