MDEV-12874 UPDATE statements with the same source and target
This commit is contained in:
parent
26ff92f7ac
commit
1a74d12da6
147
mysql-test/include/update_use_source.inc
Normal file
147
mysql-test/include/update_use_source.inc
Normal file
@ -0,0 +1,147 @@
|
||||
# Include to test update with same table as source and target
|
||||
|
||||
--echo #
|
||||
--echo # Update a with value from subquery on the same table, no search clause. ALL access
|
||||
--echo #
|
||||
|
||||
start transaction;
|
||||
--enable_info ONCE
|
||||
update t1
|
||||
set c1=(select a.c3
|
||||
from t1 a
|
||||
where a.c3 = t1.c3);
|
||||
select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1 ;
|
||||
rollback;
|
||||
|
||||
--echo #
|
||||
--echo # Update with search clause on the same table
|
||||
--echo #
|
||||
|
||||
start transaction;
|
||||
--enable_info ONCE
|
||||
update t1
|
||||
set c1=10
|
||||
where c1 <2
|
||||
and exists (select 'X'
|
||||
from t1 a
|
||||
where a.c1 = t1.c1);
|
||||
select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1 ;
|
||||
rollback;
|
||||
|
||||
--echo #
|
||||
--echo # Update via RANGE or INDEX access if an index or a primary key exists
|
||||
--echo #
|
||||
|
||||
explain update t1 set c1=0 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 > 3;
|
||||
start transaction;
|
||||
--enable_info ONCE
|
||||
update t1 set c1=c1+10 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3;
|
||||
select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
|
||||
rollback;
|
||||
|
||||
--echo #
|
||||
--echo # Update with order by
|
||||
--echo #
|
||||
|
||||
start transaction;
|
||||
update t1 set c1=c1+10 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3 order by c2;
|
||||
select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
|
||||
rollback;
|
||||
|
||||
--echo #
|
||||
--echo Update using a view in subquery
|
||||
--echo #
|
||||
|
||||
start transaction;
|
||||
--enable_info ONCE
|
||||
update t1
|
||||
set c1=c1 +(select max(a.c2)
|
||||
from v1 a
|
||||
where a.c1 = t1.c1) ;
|
||||
select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
|
||||
rollback;
|
||||
|
||||
--echo #
|
||||
--echo # Update throw a view
|
||||
--echo #
|
||||
|
||||
start transaction;
|
||||
--enable_info ONCE
|
||||
update v1
|
||||
set c1=c1 + (select max(a.c2)
|
||||
from t1 a
|
||||
where a.c1 = v1.c1) +10
|
||||
where c3 > 3;
|
||||
select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
|
||||
rollback;
|
||||
|
||||
--echo #
|
||||
--echo # Update through a view and using the view in subquery
|
||||
--echo #
|
||||
|
||||
start transaction;
|
||||
--enable_info ONCE
|
||||
update v1
|
||||
set c1=c1 + 1
|
||||
where c1 <2
|
||||
and exists (select 'X'
|
||||
from v1 a
|
||||
where a.c1 = v1.c1);
|
||||
select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
|
||||
rollback;
|
||||
|
||||
--echo #
|
||||
--echo # Update through a view and using the view in subquery
|
||||
--echo #
|
||||
|
||||
start transaction;
|
||||
--enable_info ONCE
|
||||
update v1
|
||||
set c1=(select max(a.c1)+10
|
||||
from v1 a
|
||||
where a.c1 = v1.c1)
|
||||
where c1 <10
|
||||
and exists (select 'X'
|
||||
from v1 a
|
||||
where a.c2 = v1.c2);
|
||||
select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
|
||||
rollback;
|
||||
|
||||
--echo #
|
||||
--echo # Update of the index or primary key (c3)
|
||||
--echo #
|
||||
|
||||
start transaction;
|
||||
explain update t1 set c3=c3+10 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
|
||||
--enable_info ONCE
|
||||
update t1 set c3=c3+10 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
|
||||
select c3 from t1;
|
||||
rollback;
|
||||
|
||||
--echo #
|
||||
--echo # update with a limit
|
||||
--echo #
|
||||
|
||||
start transaction;
|
||||
--enable_info ONCE
|
||||
update t1
|
||||
set c1=(select a.c3
|
||||
from t1 a
|
||||
where a.c3 = t1.c3)
|
||||
limit 2;
|
||||
select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1 ;
|
||||
rollback;
|
||||
|
||||
--echo #
|
||||
--echo # update with a limit and an order by
|
||||
--echo #
|
||||
|
||||
start transaction;
|
||||
--enable_info ONCE
|
||||
update t1
|
||||
set c1=(select a.c3
|
||||
from t1 a
|
||||
where a.c3 = t1.c3)
|
||||
order by c3 desc limit 2;
|
||||
select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1 ;
|
||||
rollback;
|
@ -15,74 +15,6 @@ create table t2aA (col1 int);
|
||||
create view v1Aa as select * from t1aA;
|
||||
create view v2aA as select * from v1aA;
|
||||
create view v3Aa as select v2Aa.col1 from v2aA,t2Aa where v2Aa.col1 = t2aA.col1;
|
||||
update v2aA set col1 = (select max(col1) from v1Aa);
|
||||
ERROR HY000: The definition of table 'v1Aa' prevents operation UPDATE on table 'v2aA'
|
||||
update v2Aa set col1 = (select max(col1) from t1Aa);
|
||||
ERROR HY000: The definition of table 'v2Aa' prevents operation UPDATE on table 'v2Aa'
|
||||
update v2aA set col1 = (select max(col1) from v2Aa);
|
||||
ERROR HY000: Table 'v2aA' is specified twice, both as a target for 'UPDATE' and as a separate source for data
|
||||
update v2aA,t2Aa set v2Aa.col1 = (select max(col1) from v1aA) where v2aA.col1 = t2aA.col1;
|
||||
ERROR HY000: The definition of table 'v1aA' prevents operation UPDATE on table 'v2aA'
|
||||
update t1aA,t2Aa set t1Aa.col1 = (select max(col1) from v1Aa) where t1aA.col1 = t2aA.col1;
|
||||
ERROR HY000: The definition of table 'v1Aa' prevents operation UPDATE on table 't1aA'
|
||||
update v1aA,t2Aa set v1Aa.col1 = (select max(col1) from v1aA) where v1Aa.col1 = t2aA.col1;
|
||||
ERROR HY000: Table 'v1aA' is specified twice, both as a target for 'UPDATE' and as a separate source for data
|
||||
update t2Aa,v2Aa set v2aA.col1 = (select max(col1) from v1aA) where v2Aa.col1 = t2aA.col1;
|
||||
ERROR HY000: The definition of table 'v1aA' prevents operation UPDATE on table 't2Aa'
|
||||
update t2Aa,t1Aa set t1aA.col1 = (select max(col1) from v1Aa) where t1Aa.col1 = t2aA.col1;
|
||||
ERROR HY000: The definition of table 'v1Aa' prevents operation UPDATE on table 't2Aa'
|
||||
update t2Aa,v1aA set v1Aa.col1 = (select max(col1) from v1aA) where v1Aa.col1 = t2aA.col1;
|
||||
ERROR HY000: The definition of table 'v1aA' prevents operation UPDATE on table 't2Aa'
|
||||
update v2aA,t2Aa set v2Aa.col1 = (select max(col1) from t1aA) where v2aA.col1 = t2aA.col1;
|
||||
ERROR HY000: The definition of table 'v2aA' prevents operation UPDATE on table 'v2aA'
|
||||
update t1Aa,t2Aa set t1aA.col1 = (select max(col1) from t1Aa) where t1aA.col1 = t2aA.col1;
|
||||
ERROR HY000: Table 't1Aa' is specified twice, both as a target for 'UPDATE' and as a separate source for data
|
||||
update v1aA,t2Aa set v1Aa.col1 = (select max(col1) from t1Aa) where v1aA.col1 = t2aA.col1;
|
||||
ERROR HY000: The definition of table 'v1aA' prevents operation UPDATE on table 'v1aA'
|
||||
update t2Aa,v2Aa set v2aA.col1 = (select max(col1) from t1aA) where v2Aa.col1 = t2aA.col1;
|
||||
ERROR HY000: Table 't2Aa' is specified twice, both as a target for 'UPDATE' and as a separate source for data
|
||||
update t2Aa,t1Aa set t1aA.col1 = (select max(col1) from t1Aa) where t1aA.col1 = t2aA.col1;
|
||||
ERROR HY000: Table 't2Aa' is specified twice, both as a target for 'UPDATE' and as a separate source for data
|
||||
update t2Aa,v1Aa set v1aA.col1 = (select max(col1) from t1Aa) where v1Aa.col1 = t2aA.col1;
|
||||
ERROR HY000: Table 't2Aa' is specified twice, both as a target for 'UPDATE' and as a separate source for data
|
||||
update v2aA,t2Aa set v2Aa.col1 = (select max(col1) from v2aA) where v2Aa.col1 = t2aA.col1;
|
||||
ERROR HY000: Table 'v2aA' is specified twice, both as a target for 'UPDATE' and as a separate source for data
|
||||
update t1aA,t2Aa set t1Aa.col1 = (select max(col1) from v2aA) where t1aA.col1 = t2aA.col1;
|
||||
ERROR HY000: The definition of table 'v2aA' prevents operation UPDATE on table 't1aA'
|
||||
update v1aA,t2Aa set v1Aa.col1 = (select max(col1) from v2Aa) where v1aA.col1 = t2aA.col1;
|
||||
ERROR HY000: The definition of table 'v2Aa' prevents operation UPDATE on table 'v1aA'
|
||||
update t2Aa,v2aA set v2Aa.col1 = (select max(col1) from v2aA) where v2Aa.col1 = t2aA.col1;
|
||||
ERROR HY000: The definition of table 'v2aA' prevents operation UPDATE on table 't2Aa'
|
||||
update t2Aa,t1Aa set t1aA.col1 = (select max(col1) from v2aA) where t1Aa.col1 = t2aA.col1;
|
||||
ERROR HY000: The definition of table 'v2aA' prevents operation UPDATE on table 't2Aa'
|
||||
update t2Aa,v1Aa set v1aA.col1 = (select max(col1) from v2Aa) where v1Aa.col1 = t2aA.col1;
|
||||
ERROR HY000: The definition of table 'v2Aa' prevents operation UPDATE on table 't2Aa'
|
||||
update v3aA set v3Aa.col1 = (select max(col1) from v1aA);
|
||||
ERROR HY000: The definition of table 'v1aA' prevents operation UPDATE on table 'v3aA'
|
||||
update v3aA set v3Aa.col1 = (select max(col1) from t1aA);
|
||||
ERROR HY000: The definition of table 'v3aA' prevents operation UPDATE on table 'v3aA'
|
||||
update v3aA set v3Aa.col1 = (select max(col1) from v2aA);
|
||||
ERROR HY000: The definition of table 'v2aA' prevents operation UPDATE on table 'v3aA'
|
||||
update v3aA set v3Aa.col1 = (select max(col1) from v3aA);
|
||||
ERROR HY000: Table 'v3aA' is specified twice, both as a target for 'UPDATE' and as a separate source for data
|
||||
delete v2Aa from v2aA,t2Aa where (select max(col1) from v1aA) > 0 and v2Aa.col1 = t2aA.col1;
|
||||
ERROR HY000: The definition of table 'v1aA' prevents operation DELETE on table 'v2aA'
|
||||
delete t1aA from t1Aa,t2Aa where (select max(col1) from v1Aa) > 0 and t1aA.col1 = t2aA.col1;
|
||||
ERROR HY000: The definition of table 'v1Aa' prevents operation DELETE on table 't1Aa'
|
||||
delete v1aA from v1Aa,t2Aa where (select max(col1) from v1aA) > 0 and v1Aa.col1 = t2aA.col1;
|
||||
ERROR HY000: Table 'v1Aa' is specified twice, both as a target for 'DELETE' and as a separate source for data
|
||||
delete v2aA from v2Aa,t2Aa where (select max(col1) from t1Aa) > 0 and v2aA.col1 = t2aA.col1;
|
||||
ERROR HY000: The definition of table 'v2Aa' prevents operation DELETE on table 'v2Aa'
|
||||
delete t1aA from t1Aa,t2Aa where (select max(col1) from t1aA) > 0 and t1Aa.col1 = t2aA.col1;
|
||||
ERROR HY000: Table 't1Aa' is specified twice, both as a target for 'DELETE' and as a separate source for data
|
||||
delete v1aA from v1Aa,t2Aa where (select max(col1) from t1aA) > 0 and v1aA.col1 = t2aA.col1;
|
||||
ERROR HY000: The definition of table 'v1Aa' prevents operation DELETE on table 'v1Aa'
|
||||
delete v2Aa from v2aA,t2Aa where (select max(col1) from v2Aa) > 0 and v2aA.col1 = t2aA.col1;
|
||||
ERROR HY000: Table 'v2aA' is specified twice, both as a target for 'DELETE' and as a separate source for data
|
||||
delete t1Aa from t1aA,t2Aa where (select max(col1) from v2Aa) > 0 and t1Aa.col1 = t2aA.col1;
|
||||
ERROR HY000: The definition of table 'v2Aa' prevents operation DELETE on table 't1aA'
|
||||
delete v1Aa from v1aA,t2Aa where (select max(col1) from v2aA) > 0 and v1Aa.col1 = t2aA.col1;
|
||||
ERROR HY000: The definition of table 'v2aA' prevents operation DELETE on table 'v1aA'
|
||||
insert into v2Aa values ((select max(col1) from v1aA));
|
||||
ERROR HY000: The definition of table 'v1aA' prevents operation INSERT on table 'v2Aa'
|
||||
insert into t1aA values ((select max(col1) from v1Aa));
|
||||
|
@ -3714,34 +3714,6 @@ insert into m1 (a) values ((select max(a) from v1));
|
||||
ERROR HY000: The definition of table 'v1' prevents operation INSERT on table 'm1'
|
||||
insert into m1 (a) values ((select max(a) from tmp, v1));
|
||||
ERROR HY000: The definition of table 'v1' prevents operation INSERT on table 'm1'
|
||||
update m1 set a = ((select max(a) from m1));
|
||||
ERROR HY000: Table 'm1' is specified twice, both as a target for 'UPDATE' and as a separate source for data
|
||||
update m1 set a = ((select max(a) from m2));
|
||||
ERROR HY000: Table 'm1' is specified twice, both as a target for 'UPDATE' and as a separate source for data
|
||||
update m1 set a = ((select max(a) from t1));
|
||||
ERROR HY000: Table 'm1' is specified twice, both as a target for 'UPDATE' and as a separate source for data
|
||||
update m1 set a = ((select max(a) from t2));
|
||||
ERROR HY000: Table 'm1' is specified twice, both as a target for 'UPDATE' and as a separate source for data
|
||||
update m1 set a = ((select max(a) from t3, m1));
|
||||
ERROR HY000: Table 'm1' is specified twice, both as a target for 'UPDATE' and as a separate source for data
|
||||
update m1 set a = ((select max(a) from t3, m2));
|
||||
ERROR HY000: Table 'm1' is specified twice, both as a target for 'UPDATE' and as a separate source for data
|
||||
update m1 set a = ((select max(a) from t3, t1));
|
||||
ERROR HY000: Table 'm1' is specified twice, both as a target for 'UPDATE' and as a separate source for data
|
||||
update m1 set a = ((select max(a) from t3, t2));
|
||||
ERROR HY000: Table 'm1' is specified twice, both as a target for 'UPDATE' and as a separate source for data
|
||||
update m1 set a = ((select max(a) from tmp, m1));
|
||||
ERROR HY000: Table 'm1' is specified twice, both as a target for 'UPDATE' and as a separate source for data
|
||||
update m1 set a = ((select max(a) from tmp, m2));
|
||||
ERROR HY000: Table 'm1' is specified twice, both as a target for 'UPDATE' and as a separate source for data
|
||||
update m1 set a = ((select max(a) from tmp, t1));
|
||||
ERROR HY000: Table 'm1' is specified twice, both as a target for 'UPDATE' and as a separate source for data
|
||||
update m1 set a = ((select max(a) from tmp, t2));
|
||||
ERROR HY000: Table 'm1' is specified twice, both as a target for 'UPDATE' and as a separate source for data
|
||||
update m1 set a = ((select max(a) from v1));
|
||||
ERROR HY000: The definition of table 'v1' prevents operation UPDATE on table 'm1'
|
||||
update m1 set a = ((select max(a) from tmp, v1));
|
||||
ERROR HY000: The definition of table 'v1' prevents operation UPDATE on table 'm1'
|
||||
drop view v1;
|
||||
drop temporary table tmp;
|
||||
drop table t1, t2, t3, m1, m2;
|
||||
|
@ -442,7 +442,6 @@ drop table t1, t2, t3;
|
||||
create table t1 (col1 int);
|
||||
create table t2 (col1 int);
|
||||
update t1,t2 set t1.col1 = (select max(col1) from t1) where t1.col1 = t2.col1;
|
||||
ERROR HY000: Table 't1' is specified twice, both as a target for 'UPDATE' and as a separate source for data
|
||||
delete t1 from t1,t2 where t1.col1 < (select max(col1) from t1) and t1.col1 = t2.col1;
|
||||
ERROR HY000: Table 't1' is specified twice, both as a target for 'DELETE' and as a separate source for data
|
||||
drop table t1,t2;
|
||||
|
@ -583,8 +583,6 @@ a b
|
||||
0 10
|
||||
1 11
|
||||
2 12
|
||||
update t1 set b= (select b from t1);
|
||||
ERROR HY000: Table 't1' is specified twice, both as a target for 'UPDATE' and as a separate source for data
|
||||
update t1 set b= (select b from t2);
|
||||
ERROR 21000: Subquery returns more than 1 row
|
||||
update t1 set b= (select b from t2 where t1.a = t2.a);
|
||||
|
@ -587,8 +587,6 @@ a b
|
||||
0 10
|
||||
1 11
|
||||
2 12
|
||||
update t1 set b= (select b from t1);
|
||||
ERROR HY000: Table 't1' is specified twice, both as a target for 'UPDATE' and as a separate source for data
|
||||
update t1 set b= (select b from t2);
|
||||
ERROR 21000: Subquery returns more than 1 row
|
||||
update t1 set b= (select b from t2 where t1.a = t2.a);
|
||||
|
@ -590,8 +590,6 @@ a b
|
||||
0 10
|
||||
1 11
|
||||
2 12
|
||||
update t1 set b= (select b from t1);
|
||||
ERROR HY000: Table 't1' is specified twice, both as a target for 'UPDATE' and as a separate source for data
|
||||
update t1 set b= (select b from t2);
|
||||
ERROR 21000: Subquery returns more than 1 row
|
||||
update t1 set b= (select b from t2 where t1.a = t2.a);
|
||||
|
@ -586,8 +586,6 @@ a b
|
||||
0 10
|
||||
1 11
|
||||
2 12
|
||||
update t1 set b= (select b from t1);
|
||||
ERROR HY000: Table 't1' is specified twice, both as a target for 'UPDATE' and as a separate source for data
|
||||
update t1 set b= (select b from t2);
|
||||
ERROR 21000: Subquery returns more than 1 row
|
||||
update t1 set b= (select b from t2 where t1.a = t2.a);
|
||||
|
@ -589,8 +589,6 @@ a b
|
||||
0 10
|
||||
1 11
|
||||
2 12
|
||||
update t1 set b= (select b from t1);
|
||||
ERROR HY000: Table 't1' is specified twice, both as a target for 'UPDATE' and as a separate source for data
|
||||
update t1 set b= (select b from t2);
|
||||
ERROR 21000: Subquery returns more than 1 row
|
||||
update t1 set b= (select b from t2 where t1.a = t2.a);
|
||||
|
@ -586,8 +586,6 @@ a b
|
||||
0 10
|
||||
1 11
|
||||
2 12
|
||||
update t1 set b= (select b from t1);
|
||||
ERROR HY000: Table 't1' is specified twice, both as a target for 'UPDATE' and as a separate source for data
|
||||
update t1 set b= (select b from t2);
|
||||
ERROR 21000: Subquery returns more than 1 row
|
||||
update t1 set b= (select b from t2 where t1.a = t2.a);
|
||||
|
1201
mysql-test/r/update_use_source.result
Normal file
1201
mysql-test/r/update_use_source.result
Normal file
File diff suppressed because it is too large
Load Diff
@ -943,74 +943,6 @@ create table t3 (col1 datetime not null);
|
||||
create view v1 as select * from t1;
|
||||
create view v2 as select * from v1;
|
||||
create view v3 as select v2.col1 from v2,t2 where v2.col1 = t2.col1;
|
||||
update v2 set col1 = (select max(col1) from v1);
|
||||
ERROR HY000: The definition of table 'v1' prevents operation UPDATE on table 'v2'
|
||||
update v2 set col1 = (select max(col1) from t1);
|
||||
ERROR HY000: The definition of table 'v2' prevents operation UPDATE on table 'v2'
|
||||
update v2 set col1 = (select max(col1) from v2);
|
||||
ERROR HY000: Table 'v2' is specified twice, both as a target for 'UPDATE' and as a separate source for data
|
||||
update v2,t2 set v2.col1 = (select max(col1) from v1) where v2.col1 = t2.col1;
|
||||
ERROR HY000: The definition of table 'v1' prevents operation UPDATE on table 'v2'
|
||||
update t1,t2 set t1.col1 = (select max(col1) from v1) where t1.col1 = t2.col1;
|
||||
ERROR HY000: The definition of table 'v1' prevents operation UPDATE on table 't1'
|
||||
update v1,t2 set v1.col1 = (select max(col1) from v1) where v1.col1 = t2.col1;
|
||||
ERROR HY000: Table 'v1' is specified twice, both as a target for 'UPDATE' and as a separate source for data
|
||||
update t2,v2 set v2.col1 = (select max(col1) from v1) where v2.col1 = t2.col1;
|
||||
ERROR HY000: The definition of table 'v1' prevents operation UPDATE on table 't2'
|
||||
update t2,t1 set t1.col1 = (select max(col1) from v1) where t1.col1 = t2.col1;
|
||||
ERROR HY000: The definition of table 'v1' prevents operation UPDATE on table 't2'
|
||||
update t2,v1 set v1.col1 = (select max(col1) from v1) where v1.col1 = t2.col1;
|
||||
ERROR HY000: The definition of table 'v1' prevents operation UPDATE on table 't2'
|
||||
update v2,t2 set v2.col1 = (select max(col1) from t1) where v2.col1 = t2.col1;
|
||||
ERROR HY000: The definition of table 'v2' prevents operation UPDATE on table 'v2'
|
||||
update t1,t2 set t1.col1 = (select max(col1) from t1) where t1.col1 = t2.col1;
|
||||
ERROR HY000: Table 't1' is specified twice, both as a target for 'UPDATE' and as a separate source for data
|
||||
update v1,t2 set v1.col1 = (select max(col1) from t1) where v1.col1 = t2.col1;
|
||||
ERROR HY000: The definition of table 'v1' prevents operation UPDATE on table 'v1'
|
||||
update t2,v2 set v2.col1 = (select max(col1) from t1) where v2.col1 = t2.col1;
|
||||
ERROR HY000: Table 't2' is specified twice, both as a target for 'UPDATE' and as a separate source for data
|
||||
update t2,t1 set t1.col1 = (select max(col1) from t1) where t1.col1 = t2.col1;
|
||||
ERROR HY000: Table 't2' is specified twice, both as a target for 'UPDATE' and as a separate source for data
|
||||
update t2,v1 set v1.col1 = (select max(col1) from t1) where v1.col1 = t2.col1;
|
||||
ERROR HY000: Table 't2' is specified twice, both as a target for 'UPDATE' and as a separate source for data
|
||||
update v2,t2 set v2.col1 = (select max(col1) from v2) where v2.col1 = t2.col1;
|
||||
ERROR HY000: Table 'v2' is specified twice, both as a target for 'UPDATE' and as a separate source for data
|
||||
update t1,t2 set t1.col1 = (select max(col1) from v2) where t1.col1 = t2.col1;
|
||||
ERROR HY000: The definition of table 'v2' prevents operation UPDATE on table 't1'
|
||||
update v1,t2 set v1.col1 = (select max(col1) from v2) where v1.col1 = t2.col1;
|
||||
ERROR HY000: The definition of table 'v2' prevents operation UPDATE on table 'v1'
|
||||
update t2,v2 set v2.col1 = (select max(col1) from v2) where v2.col1 = t2.col1;
|
||||
ERROR HY000: The definition of table 'v2' prevents operation UPDATE on table 't2'
|
||||
update t2,t1 set t1.col1 = (select max(col1) from v2) where t1.col1 = t2.col1;
|
||||
ERROR HY000: The definition of table 'v2' prevents operation UPDATE on table 't2'
|
||||
update t2,v1 set v1.col1 = (select max(col1) from v2) where v1.col1 = t2.col1;
|
||||
ERROR HY000: The definition of table 'v2' prevents operation UPDATE on table 't2'
|
||||
update v3 set v3.col1 = (select max(col1) from v1);
|
||||
ERROR HY000: The definition of table 'v1' prevents operation UPDATE on table 'v3'
|
||||
update v3 set v3.col1 = (select max(col1) from t1);
|
||||
ERROR HY000: The definition of table 'v3' prevents operation UPDATE on table 'v3'
|
||||
update v3 set v3.col1 = (select max(col1) from v2);
|
||||
ERROR HY000: The definition of table 'v2' prevents operation UPDATE on table 'v3'
|
||||
update v3 set v3.col1 = (select max(col1) from v3);
|
||||
ERROR HY000: Table 'v3' is specified twice, both as a target for 'UPDATE' and as a separate source for data
|
||||
delete v2 from v2,t2 where (select max(col1) from v1) > 0 and v2.col1 = t2.col1;
|
||||
ERROR HY000: The definition of table 'v1' prevents operation DELETE on table 'v2'
|
||||
delete t1 from t1,t2 where (select max(col1) from v1) > 0 and t1.col1 = t2.col1;
|
||||
ERROR HY000: The definition of table 'v1' prevents operation DELETE on table 't1'
|
||||
delete v1 from v1,t2 where (select max(col1) from v1) > 0 and v1.col1 = t2.col1;
|
||||
ERROR HY000: Table 'v1' is specified twice, both as a target for 'DELETE' and as a separate source for data
|
||||
delete v2 from v2,t2 where (select max(col1) from t1) > 0 and v2.col1 = t2.col1;
|
||||
ERROR HY000: The definition of table 'v2' prevents operation DELETE on table 'v2'
|
||||
delete t1 from t1,t2 where (select max(col1) from t1) > 0 and t1.col1 = t2.col1;
|
||||
ERROR HY000: Table 't1' is specified twice, both as a target for 'DELETE' and as a separate source for data
|
||||
delete v1 from v1,t2 where (select max(col1) from t1) > 0 and v1.col1 = t2.col1;
|
||||
ERROR HY000: The definition of table 'v1' prevents operation DELETE on table 'v1'
|
||||
delete v2 from v2,t2 where (select max(col1) from v2) > 0 and v2.col1 = t2.col1;
|
||||
ERROR HY000: Table 'v2' is specified twice, both as a target for 'DELETE' and as a separate source for data
|
||||
delete t1 from t1,t2 where (select max(col1) from v2) > 0 and t1.col1 = t2.col1;
|
||||
ERROR HY000: The definition of table 'v2' prevents operation DELETE on table 't1'
|
||||
delete v1 from v1,t2 where (select max(col1) from v2) > 0 and v1.col1 = t2.col1;
|
||||
ERROR HY000: The definition of table 'v2' prevents operation DELETE on table 'v1'
|
||||
insert into v2 values ((select max(col1) from v1));
|
||||
ERROR HY000: The definition of table 'v1' prevents operation INSERT on table 'v2'
|
||||
insert into t1 values ((select max(col1) from v1));
|
||||
@ -2024,8 +1956,6 @@ create view v1 as select f59, f60 from t1 where f59 in
|
||||
(select f59 from t1);
|
||||
update v1 set f60=2345;
|
||||
ERROR HY000: The target table v1 of the UPDATE is not updatable
|
||||
update t1 set f60=(select max(f60) from v1);
|
||||
ERROR HY000: The definition of table 'v1' prevents operation UPDATE on table 't1'
|
||||
drop view v1;
|
||||
drop table t1;
|
||||
create table t1 (s1 int);
|
||||
|
@ -24,74 +24,6 @@ create view v1Aa as select * from t1aA;
|
||||
create view v2aA as select * from v1aA;
|
||||
create view v3Aa as select v2Aa.col1 from v2aA,t2Aa where v2Aa.col1 = t2aA.col1;
|
||||
-- error 1443
|
||||
update v2aA set col1 = (select max(col1) from v1Aa);
|
||||
-- error 1443
|
||||
update v2Aa set col1 = (select max(col1) from t1Aa);
|
||||
-- error 1093
|
||||
update v2aA set col1 = (select max(col1) from v2Aa);
|
||||
-- error 1443
|
||||
update v2aA,t2Aa set v2Aa.col1 = (select max(col1) from v1aA) where v2aA.col1 = t2aA.col1;
|
||||
-- error 1443
|
||||
update t1aA,t2Aa set t1Aa.col1 = (select max(col1) from v1Aa) where t1aA.col1 = t2aA.col1;
|
||||
-- error 1093
|
||||
update v1aA,t2Aa set v1Aa.col1 = (select max(col1) from v1aA) where v1Aa.col1 = t2aA.col1;
|
||||
-- error 1443
|
||||
update t2Aa,v2Aa set v2aA.col1 = (select max(col1) from v1aA) where v2Aa.col1 = t2aA.col1;
|
||||
-- error 1443
|
||||
update t2Aa,t1Aa set t1aA.col1 = (select max(col1) from v1Aa) where t1Aa.col1 = t2aA.col1;
|
||||
-- error 1443
|
||||
update t2Aa,v1aA set v1Aa.col1 = (select max(col1) from v1aA) where v1Aa.col1 = t2aA.col1;
|
||||
-- error 1443
|
||||
update v2aA,t2Aa set v2Aa.col1 = (select max(col1) from t1aA) where v2aA.col1 = t2aA.col1;
|
||||
-- error 1093
|
||||
update t1Aa,t2Aa set t1aA.col1 = (select max(col1) from t1Aa) where t1aA.col1 = t2aA.col1;
|
||||
-- error 1443
|
||||
update v1aA,t2Aa set v1Aa.col1 = (select max(col1) from t1Aa) where v1aA.col1 = t2aA.col1;
|
||||
-- error 1093
|
||||
update t2Aa,v2Aa set v2aA.col1 = (select max(col1) from t1aA) where v2Aa.col1 = t2aA.col1;
|
||||
-- error 1093
|
||||
update t2Aa,t1Aa set t1aA.col1 = (select max(col1) from t1Aa) where t1aA.col1 = t2aA.col1;
|
||||
-- error 1093
|
||||
update t2Aa,v1Aa set v1aA.col1 = (select max(col1) from t1Aa) where v1Aa.col1 = t2aA.col1;
|
||||
-- error 1093
|
||||
update v2aA,t2Aa set v2Aa.col1 = (select max(col1) from v2aA) where v2Aa.col1 = t2aA.col1;
|
||||
-- error 1443
|
||||
update t1aA,t2Aa set t1Aa.col1 = (select max(col1) from v2aA) where t1aA.col1 = t2aA.col1;
|
||||
-- error 1443
|
||||
update v1aA,t2Aa set v1Aa.col1 = (select max(col1) from v2Aa) where v1aA.col1 = t2aA.col1;
|
||||
-- error 1443
|
||||
update t2Aa,v2aA set v2Aa.col1 = (select max(col1) from v2aA) where v2Aa.col1 = t2aA.col1;
|
||||
-- error 1443
|
||||
update t2Aa,t1Aa set t1aA.col1 = (select max(col1) from v2aA) where t1Aa.col1 = t2aA.col1;
|
||||
-- error 1443
|
||||
update t2Aa,v1Aa set v1aA.col1 = (select max(col1) from v2Aa) where v1Aa.col1 = t2aA.col1;
|
||||
-- error 1443
|
||||
update v3aA set v3Aa.col1 = (select max(col1) from v1aA);
|
||||
-- error 1443
|
||||
update v3aA set v3Aa.col1 = (select max(col1) from t1aA);
|
||||
-- error 1443
|
||||
update v3aA set v3Aa.col1 = (select max(col1) from v2aA);
|
||||
-- error 1093
|
||||
update v3aA set v3Aa.col1 = (select max(col1) from v3aA);
|
||||
-- error 1443
|
||||
delete v2Aa from v2aA,t2Aa where (select max(col1) from v1aA) > 0 and v2Aa.col1 = t2aA.col1;
|
||||
-- error 1443
|
||||
delete t1aA from t1Aa,t2Aa where (select max(col1) from v1Aa) > 0 and t1aA.col1 = t2aA.col1;
|
||||
-- error 1093
|
||||
delete v1aA from v1Aa,t2Aa where (select max(col1) from v1aA) > 0 and v1Aa.col1 = t2aA.col1;
|
||||
-- error 1443
|
||||
delete v2aA from v2Aa,t2Aa where (select max(col1) from t1Aa) > 0 and v2aA.col1 = t2aA.col1;
|
||||
-- error 1093
|
||||
delete t1aA from t1Aa,t2Aa where (select max(col1) from t1aA) > 0 and t1Aa.col1 = t2aA.col1;
|
||||
-- error 1443
|
||||
delete v1aA from v1Aa,t2Aa where (select max(col1) from t1aA) > 0 and v1aA.col1 = t2aA.col1;
|
||||
-- error 1093
|
||||
delete v2Aa from v2aA,t2Aa where (select max(col1) from v2Aa) > 0 and v2aA.col1 = t2aA.col1;
|
||||
-- error 1443
|
||||
delete t1Aa from t1aA,t2Aa where (select max(col1) from v2Aa) > 0 and t1Aa.col1 = t2aA.col1;
|
||||
-- error 1443
|
||||
delete v1Aa from v1aA,t2Aa where (select max(col1) from v2aA) > 0 and v1Aa.col1 = t2aA.col1;
|
||||
-- error 1443
|
||||
insert into v2Aa values ((select max(col1) from v1aA));
|
||||
-- error 1443
|
||||
insert into t1aA values ((select max(col1) from v1Aa));
|
||||
@ -176,4 +108,3 @@ DROP TABLE `ttt`;
|
||||
|
||||
|
||||
--echo End of 5.0 tests.
|
||||
|
||||
|
@ -2732,38 +2732,6 @@ insert into m1 (a) values ((select max(a) from v1));
|
||||
insert into m1 (a) values ((select max(a) from tmp, v1));
|
||||
|
||||
|
||||
--error ER_UPDATE_TABLE_USED
|
||||
update m1 set a = ((select max(a) from m1));
|
||||
--error ER_UPDATE_TABLE_USED
|
||||
update m1 set a = ((select max(a) from m2));
|
||||
--error ER_UPDATE_TABLE_USED
|
||||
update m1 set a = ((select max(a) from t1));
|
||||
--error ER_UPDATE_TABLE_USED
|
||||
update m1 set a = ((select max(a) from t2));
|
||||
|
||||
--error ER_UPDATE_TABLE_USED
|
||||
update m1 set a = ((select max(a) from t3, m1));
|
||||
--error ER_UPDATE_TABLE_USED
|
||||
update m1 set a = ((select max(a) from t3, m2));
|
||||
--error ER_UPDATE_TABLE_USED
|
||||
update m1 set a = ((select max(a) from t3, t1));
|
||||
--error ER_UPDATE_TABLE_USED
|
||||
update m1 set a = ((select max(a) from t3, t2));
|
||||
|
||||
--error ER_UPDATE_TABLE_USED
|
||||
update m1 set a = ((select max(a) from tmp, m1));
|
||||
--error ER_UPDATE_TABLE_USED
|
||||
update m1 set a = ((select max(a) from tmp, m2));
|
||||
--error ER_UPDATE_TABLE_USED
|
||||
update m1 set a = ((select max(a) from tmp, t1));
|
||||
--error ER_UPDATE_TABLE_USED
|
||||
update m1 set a = ((select max(a) from tmp, t2));
|
||||
|
||||
--error ER_VIEW_PREVENT_UPDATE
|
||||
update m1 set a = ((select max(a) from v1));
|
||||
--error ER_VIEW_PREVENT_UPDATE
|
||||
update m1 set a = ((select max(a) from tmp, v1));
|
||||
|
||||
drop view v1;
|
||||
drop temporary table tmp;
|
||||
drop table t1, t2, t3, m1, m2;
|
||||
@ -2948,4 +2916,3 @@ eval set global storage_engine=$default;
|
||||
# Check that all connections opened by test cases in this file are really
|
||||
# gone so execution of other tests won't be affected by their presence.
|
||||
--source include/wait_until_count_sessions.inc
|
||||
|
||||
|
@ -391,7 +391,6 @@ drop table t1, t2, t3;
|
||||
#
|
||||
create table t1 (col1 int);
|
||||
create table t2 (col1 int);
|
||||
-- error ER_UPDATE_TABLE_USED
|
||||
update t1,t2 set t1.col1 = (select max(col1) from t1) where t1.col1 = t2.col1;
|
||||
-- error ER_UPDATE_TABLE_USED
|
||||
delete t1 from t1,t2 where t1.col1 < (select max(col1) from t1) and t1.col1 = t2.col1;
|
||||
|
@ -325,8 +325,6 @@ create table t2 (a int NOT NULL, b int, primary key (a));
|
||||
insert into t1 values (0, 10),(1, 11),(2, 12);
|
||||
insert into t2 values (1, 21),(2, 22),(3, 23);
|
||||
select * from t1;
|
||||
-- error ER_UPDATE_TABLE_USED
|
||||
update t1 set b= (select b from t1);
|
||||
-- error ER_SUBQUERY_NO_1_ROW
|
||||
update t1 set b= (select b from t2);
|
||||
update t1 set b= (select b from t2 where t1.a = t2.a);
|
||||
|
245
mysql-test/t/update_use_source.test
Normal file
245
mysql-test/t/update_use_source.test
Normal file
@ -0,0 +1,245 @@
|
||||
--source include/have_sequence.inc
|
||||
--source include/have_innodb.inc
|
||||
|
||||
create table t1 (old_c1 integer, old_c2 integer,c1 integer, c2 integer, c3 integer) engine=InnoDb;
|
||||
create view v1 as select * from t1 where c2=2;
|
||||
delimiter /;
|
||||
create trigger trg_t1 before update on t1 for each row
|
||||
begin
|
||||
set new.old_c1=old.c1;
|
||||
set new.old_c2=old.c2;
|
||||
end;
|
||||
/
|
||||
delimiter ;/
|
||||
|
||||
insert into t1(c1,c2,c3) values (1,1,1);
|
||||
insert into t1(c1,c2,c3) values (1,2,2);
|
||||
insert into t1(c1,c2,c3) values (1,3,3);
|
||||
insert into t1(c1,c2,c3) values (2,1,4);
|
||||
insert into t1(c1,c2,c3) values (2,2,5);
|
||||
insert into t1(c1,c2,c3) values (2,3,6);
|
||||
insert into t1(c1,c2,c3) values (2,4,7);
|
||||
insert into t1(c1,c2,c3) values (2,5,8);
|
||||
|
||||
commit;
|
||||
select * from t1;
|
||||
|
||||
--echo Test without any index
|
||||
--source include/update_use_source.inc
|
||||
|
||||
--echo Test with an index on updated columns
|
||||
create index t1_c2 on t1 (c2,c1);
|
||||
--source include/update_use_source.inc
|
||||
|
||||
--echo Test with an index on updated columns
|
||||
create index t1_c3 on t1 (c3);
|
||||
--source include/update_use_source.inc
|
||||
|
||||
--echo Test with a primary key on updated columns
|
||||
drop index t1_c3 on t1;
|
||||
alter table t1 add primary key (c3);
|
||||
--source include/update_use_source.inc
|
||||
|
||||
--echo # Update with error "Subquery returns more than 1 row"
|
||||
--error ER_SUBQUERY_NO_1_ROW
|
||||
update t1 set c2=(select c2 from t1);
|
||||
|
||||
--echo # Update with error "Subquery returns more than 1 row" and order by
|
||||
--error ER_SUBQUERY_NO_1_ROW
|
||||
update t1 set c2=(select c2 from t1) order by c3;
|
||||
|
||||
-- echo Duplicate value on update a primary key
|
||||
start transaction;
|
||||
--error ER_DUP_ENTRY
|
||||
update t1 set c3=0 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3;
|
||||
rollback;
|
||||
|
||||
-- echo Duplicate value on update a primary key with ignore
|
||||
start transaction;
|
||||
--enable_info ONCE
|
||||
update ignore t1 set c3=0 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3;
|
||||
rollback;
|
||||
|
||||
-- echo Duplicate value on update a primary key and limit
|
||||
start transaction;
|
||||
--error ER_DUP_ENTRY
|
||||
update t1 set c3=0 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3 limit 2;
|
||||
rollback;
|
||||
|
||||
-- echo Duplicate value on update a primary key with ignore and limit
|
||||
start transaction;
|
||||
--enable_info ONCE
|
||||
update ignore t1 set c3=0 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3 limit 2;
|
||||
rollback;
|
||||
|
||||
--echo # Update no rows found
|
||||
--enable_info ONCE
|
||||
update t1
|
||||
set c1=10
|
||||
where c1 <2
|
||||
and exists (select 'X'
|
||||
from t1 a
|
||||
where a.c1 = t1.c1 + 10);
|
||||
|
||||
--echo # Update no rows changed
|
||||
drop trigger trg_t1;
|
||||
start transaction;
|
||||
--enable_info ONCE
|
||||
update t1
|
||||
set c1=c1
|
||||
where c1 <2
|
||||
and exists (select 'X'
|
||||
from t1 a
|
||||
where a.c1 = t1.c1);
|
||||
rollback;
|
||||
|
||||
--echo #
|
||||
--echo # Check call of after trigger
|
||||
--echo #
|
||||
|
||||
delimiter /;
|
||||
create or replace trigger trg_t2 after update on t1 for each row
|
||||
begin
|
||||
declare msg varchar(100);
|
||||
if (new.c3 = 5) then
|
||||
set msg=concat('in after update trigger on ',new.c3);
|
||||
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = msg;
|
||||
end if;
|
||||
end;
|
||||
/
|
||||
delimiter ;/
|
||||
--error 1644
|
||||
update t1 set c1=2 where c3 in (select distinct a.c3 from t1 a where a.c1=t1.c1);
|
||||
|
||||
--echo #
|
||||
--echo # Check update with order by and after trigger
|
||||
--echo #
|
||||
|
||||
--error 1644
|
||||
update t1 set c1=2 where c3 in (select distinct a.c3 from t1 a where a.c1=t1.c1) order by t1.c2;
|
||||
|
||||
drop view v1;
|
||||
--echo #
|
||||
--echo # Check update on view with check option
|
||||
--echo #
|
||||
|
||||
create view v1 as select * from t1 where c2=2 with check option;
|
||||
|
||||
start transaction;
|
||||
-- error 1369
|
||||
update v1 set c2=3 where c1=1;
|
||||
rollback;
|
||||
|
||||
start transaction;
|
||||
-- error 1369
|
||||
update v1 set c2=(select max(c3) from v1) where c1=1;
|
||||
rollback;
|
||||
|
||||
start transaction;
|
||||
update v1 set c2=(select min(va.c3) from v1 va), c1=0 where c1=1;
|
||||
rollback;
|
||||
|
||||
drop view v1;
|
||||
drop table t1;
|
||||
|
||||
--echo #
|
||||
--echo # Test with a temporary table
|
||||
--echo #
|
||||
|
||||
create temporary table t1 (c1 integer, c2 integer, c3 integer) engine=InnoDb;
|
||||
insert into t1(c1,c2,c3) values (1,1,1);
|
||||
insert into t1(c1,c2,c3) values (1,2,2);
|
||||
insert into t1(c1,c2,c3) values (1,3,3);
|
||||
insert into t1(c1,c2,c3) values (2,1,4);
|
||||
insert into t1(c1,c2,c3) values (2,2,5);
|
||||
insert into t1(c1,c2,c3) values (2,3,6);
|
||||
insert into t1(c1,c2,c3) values (2,4,7);
|
||||
insert into t1(c1,c2,c3) values (2,5,8);
|
||||
|
||||
start transaction;
|
||||
--enable_info ONCE
|
||||
update t1
|
||||
set c1=(select a.c2
|
||||
from t1 a
|
||||
where a.c3 = t1.c3) limit 3;
|
||||
select * from t1 ;
|
||||
rollback;
|
||||
drop table t1;
|
||||
|
||||
--echo #
|
||||
--echo # Test on dynamic columns (blob)
|
||||
--echo #
|
||||
|
||||
create table assets (
|
||||
item_name varchar(32) primary key, -- A common attribute for all items
|
||||
dynamic_cols blob -- Dynamic columns will be stored here
|
||||
);
|
||||
INSERT INTO assets VALUES ('MariaDB T-shirt', COLUMN_CREATE('color', 'blue', 'size', 'XL'));
|
||||
INSERT INTO assets VALUES ('Thinkpad Laptop', COLUMN_CREATE('color', 'black', 'price', 500));
|
||||
SELECT item_name, COLUMN_GET(dynamic_cols, 'color' as char) AS color FROM assets;
|
||||
UPDATE assets SET dynamic_cols=COLUMN_ADD(dynamic_cols, 'warranty', '3 years') WHERE item_name='Thinkpad Laptop';
|
||||
SELECT item_name, COLUMN_GET(dynamic_cols, 'warranty' as char) AS color FROM assets;
|
||||
UPDATE assets SET dynamic_cols=COLUMN_ADD(dynamic_cols, 'warranty', '4 years')
|
||||
WHERE item_name in (select b.item_name
|
||||
from assets b
|
||||
where COLUMN_GET(b.dynamic_cols, 'color' as char) ='black');
|
||||
SELECT item_name, COLUMN_GET(dynamic_cols, 'warranty' as char) AS color FROM assets;
|
||||
|
||||
UPDATE assets SET dynamic_cols=COLUMN_ADD(dynamic_cols, 'warranty', (select COLUMN_GET(b.dynamic_cols, 'color' as char)
|
||||
from assets b
|
||||
where assets.item_name = item_name));
|
||||
SELECT item_name, COLUMN_GET(dynamic_cols, 'warranty' as char) AS color FROM assets;
|
||||
drop table assets ;
|
||||
|
||||
--echo #
|
||||
--echo # Test on fulltext columns
|
||||
--echo #
|
||||
CREATE TABLE ft2(copy TEXT,FULLTEXT(copy)) ENGINE=MyISAM;
|
||||
INSERT INTO ft2(copy) VALUES
|
||||
('MySQL vs MariaDB database'),
|
||||
('Oracle vs MariaDB database'),
|
||||
('PostgreSQL vs MariaDB database'),
|
||||
('MariaDB overview'),
|
||||
('Foreign keys'),
|
||||
('Primary keys'),
|
||||
('Indexes'),
|
||||
('Transactions'),
|
||||
('Triggers');
|
||||
SELECT * FROM ft2 WHERE MATCH(copy) AGAINST('database');
|
||||
update ft2 set copy = (select max(concat('mykeyword ',substr(b.copy,1,5))) from ft2 b WHERE MATCH(b.copy) AGAINST('database'))
|
||||
where MATCH(copy) AGAINST('keys');
|
||||
SELECT * FROM ft2 WHERE MATCH(copy) AGAINST('mykeyword');
|
||||
drop table ft2;
|
||||
|
||||
--echo #
|
||||
--echo # Test with MyISAM
|
||||
--echo #
|
||||
|
||||
create table t1 (old_c1 integer, old_c2 integer,c1 integer, c2 integer, c3 integer) engine=MyISAM;
|
||||
insert t1 (c1,c2,c3) select 0,seq,seq%10 from seq_1_to_500;
|
||||
insert t1 (c1,c2,c3) select 1,seq,seq%10 from seq_1_to_400;
|
||||
insert t1 (c1,c2,c3) select 2,seq,seq%10 from seq_1_to_300;
|
||||
insert t1 (c1,c2,c3) select 3,seq,seq%10 from seq_1_to_200;
|
||||
create index t1_idx1 on t1(c3);
|
||||
analyze table t1;
|
||||
|
||||
update t1 set c1=2 where exists (select 'x' from t1);
|
||||
select count(*) from t1 where c1=2;
|
||||
update t1 set c1=3 where c3 in (select c3 from t1 b where t1.c3=b.c1);
|
||||
select count(*) from t1 where c1=3;
|
||||
drop table t1;
|
||||
|
||||
|
||||
--echo #
|
||||
--echo # Test error on multi_update conversion on view with order by or limit
|
||||
--echo #
|
||||
|
||||
create table t1 (c1 integer) engine=InnoDb;
|
||||
create table t2 (c1 integer) engine=InnoDb;
|
||||
create view v1 as select t1.c1 as "t1c1" ,t2.c1 as "t2c1" from t1,t2 where t1.c1=t2.c1;
|
||||
--error ER_BAD_FIELD_ERROR
|
||||
update v1 set t1c1=2 order by 1;
|
||||
update v1 set t1c1=2 limit 1;
|
||||
drop table t1;
|
||||
drop table t2;
|
||||
drop view v1;
|
@ -865,74 +865,6 @@ create view v1 as select * from t1;
|
||||
create view v2 as select * from v1;
|
||||
create view v3 as select v2.col1 from v2,t2 where v2.col1 = t2.col1;
|
||||
-- error ER_VIEW_PREVENT_UPDATE
|
||||
update v2 set col1 = (select max(col1) from v1);
|
||||
-- error ER_VIEW_PREVENT_UPDATE
|
||||
update v2 set col1 = (select max(col1) from t1);
|
||||
-- error ER_UPDATE_TABLE_USED
|
||||
update v2 set col1 = (select max(col1) from v2);
|
||||
-- error ER_VIEW_PREVENT_UPDATE
|
||||
update v2,t2 set v2.col1 = (select max(col1) from v1) where v2.col1 = t2.col1;
|
||||
-- error ER_VIEW_PREVENT_UPDATE
|
||||
update t1,t2 set t1.col1 = (select max(col1) from v1) where t1.col1 = t2.col1;
|
||||
-- error ER_UPDATE_TABLE_USED
|
||||
update v1,t2 set v1.col1 = (select max(col1) from v1) where v1.col1 = t2.col1;
|
||||
-- error ER_VIEW_PREVENT_UPDATE
|
||||
update t2,v2 set v2.col1 = (select max(col1) from v1) where v2.col1 = t2.col1;
|
||||
-- error ER_VIEW_PREVENT_UPDATE
|
||||
update t2,t1 set t1.col1 = (select max(col1) from v1) where t1.col1 = t2.col1;
|
||||
-- error ER_VIEW_PREVENT_UPDATE
|
||||
update t2,v1 set v1.col1 = (select max(col1) from v1) where v1.col1 = t2.col1;
|
||||
-- error ER_VIEW_PREVENT_UPDATE
|
||||
update v2,t2 set v2.col1 = (select max(col1) from t1) where v2.col1 = t2.col1;
|
||||
-- error ER_UPDATE_TABLE_USED
|
||||
update t1,t2 set t1.col1 = (select max(col1) from t1) where t1.col1 = t2.col1;
|
||||
-- error ER_VIEW_PREVENT_UPDATE
|
||||
update v1,t2 set v1.col1 = (select max(col1) from t1) where v1.col1 = t2.col1;
|
||||
-- error ER_UPDATE_TABLE_USED
|
||||
update t2,v2 set v2.col1 = (select max(col1) from t1) where v2.col1 = t2.col1;
|
||||
-- error ER_UPDATE_TABLE_USED
|
||||
update t2,t1 set t1.col1 = (select max(col1) from t1) where t1.col1 = t2.col1;
|
||||
-- error ER_UPDATE_TABLE_USED
|
||||
update t2,v1 set v1.col1 = (select max(col1) from t1) where v1.col1 = t2.col1;
|
||||
-- error ER_UPDATE_TABLE_USED
|
||||
update v2,t2 set v2.col1 = (select max(col1) from v2) where v2.col1 = t2.col1;
|
||||
-- error ER_VIEW_PREVENT_UPDATE
|
||||
update t1,t2 set t1.col1 = (select max(col1) from v2) where t1.col1 = t2.col1;
|
||||
-- error ER_VIEW_PREVENT_UPDATE
|
||||
update v1,t2 set v1.col1 = (select max(col1) from v2) where v1.col1 = t2.col1;
|
||||
-- error ER_VIEW_PREVENT_UPDATE
|
||||
update t2,v2 set v2.col1 = (select max(col1) from v2) where v2.col1 = t2.col1;
|
||||
-- error ER_VIEW_PREVENT_UPDATE
|
||||
update t2,t1 set t1.col1 = (select max(col1) from v2) where t1.col1 = t2.col1;
|
||||
-- error ER_VIEW_PREVENT_UPDATE
|
||||
update t2,v1 set v1.col1 = (select max(col1) from v2) where v1.col1 = t2.col1;
|
||||
-- error ER_VIEW_PREVENT_UPDATE
|
||||
update v3 set v3.col1 = (select max(col1) from v1);
|
||||
-- error ER_VIEW_PREVENT_UPDATE
|
||||
update v3 set v3.col1 = (select max(col1) from t1);
|
||||
-- error ER_VIEW_PREVENT_UPDATE
|
||||
update v3 set v3.col1 = (select max(col1) from v2);
|
||||
-- error ER_UPDATE_TABLE_USED
|
||||
update v3 set v3.col1 = (select max(col1) from v3);
|
||||
-- error ER_VIEW_PREVENT_UPDATE
|
||||
delete v2 from v2,t2 where (select max(col1) from v1) > 0 and v2.col1 = t2.col1;
|
||||
-- error ER_VIEW_PREVENT_UPDATE
|
||||
delete t1 from t1,t2 where (select max(col1) from v1) > 0 and t1.col1 = t2.col1;
|
||||
-- error ER_UPDATE_TABLE_USED
|
||||
delete v1 from v1,t2 where (select max(col1) from v1) > 0 and v1.col1 = t2.col1;
|
||||
-- error ER_VIEW_PREVENT_UPDATE
|
||||
delete v2 from v2,t2 where (select max(col1) from t1) > 0 and v2.col1 = t2.col1;
|
||||
-- error ER_UPDATE_TABLE_USED
|
||||
delete t1 from t1,t2 where (select max(col1) from t1) > 0 and t1.col1 = t2.col1;
|
||||
-- error ER_VIEW_PREVENT_UPDATE
|
||||
delete v1 from v1,t2 where (select max(col1) from t1) > 0 and v1.col1 = t2.col1;
|
||||
-- error ER_UPDATE_TABLE_USED
|
||||
delete v2 from v2,t2 where (select max(col1) from v2) > 0 and v2.col1 = t2.col1;
|
||||
-- error ER_VIEW_PREVENT_UPDATE
|
||||
delete t1 from t1,t2 where (select max(col1) from v2) > 0 and t1.col1 = t2.col1;
|
||||
-- error ER_VIEW_PREVENT_UPDATE
|
||||
delete v1 from v1,t2 where (select max(col1) from v2) > 0 and v1.col1 = t2.col1;
|
||||
-- error ER_VIEW_PREVENT_UPDATE
|
||||
insert into v2 values ((select max(col1) from v1));
|
||||
-- error ER_VIEW_PREVENT_UPDATE
|
||||
insert into t1 values ((select max(col1) from v1));
|
||||
@ -1803,8 +1735,6 @@ create view v1 as select f59, f60 from t1 where f59 in
|
||||
(select f59 from t1);
|
||||
-- error ER_NON_UPDATABLE_TABLE
|
||||
update v1 set f60=2345;
|
||||
-- error ER_VIEW_PREVENT_UPDATE
|
||||
update t1 set f60=(select max(f60) from v1);
|
||||
drop view v1;
|
||||
drop table t1;
|
||||
|
||||
|
@ -278,6 +278,7 @@ int mysql_update(THD *thd,
|
||||
killed_state killed_status= NOT_KILLED;
|
||||
Update_plan query_plan(thd->mem_root);
|
||||
Explain_update *explain;
|
||||
TABLE_LIST *update_source_table;
|
||||
query_plan.index= MAX_KEY;
|
||||
query_plan.using_filesort= FALSE;
|
||||
DBUG_ENTER("mysql_update");
|
||||
@ -290,9 +291,11 @@ int mysql_update(THD *thd,
|
||||
if (mysql_handle_derived(thd->lex, DT_INIT))
|
||||
DBUG_RETURN(1);
|
||||
|
||||
if (table_list->is_multitable())
|
||||
if (((update_source_table=unique_table(thd, table_list,
|
||||
table_list->next_global, 0)) ||
|
||||
table_list->is_multitable()))
|
||||
{
|
||||
DBUG_ASSERT(table_list->view != 0);
|
||||
DBUG_ASSERT(update_source_table || table_list->view != 0);
|
||||
DBUG_PRINT("info", ("Switch to multi-update"));
|
||||
/* pass counter value */
|
||||
thd->lex->table_count= table_count;
|
||||
@ -1540,16 +1543,6 @@ int mysql_multi_update_prepare(THD *thd)
|
||||
}
|
||||
DBUG_PRINT("info", ("table: %s want_privilege: %u", tl->alias,
|
||||
(uint) table->grant.want_privilege));
|
||||
if (tl->lock_type != TL_READ &&
|
||||
tl->lock_type != TL_READ_NO_INSERT)
|
||||
{
|
||||
TABLE_LIST *duplicate;
|
||||
if ((duplicate= unique_table(thd, tl, table_list, 0)))
|
||||
{
|
||||
update_non_unique_table_error(table_list, "UPDATE", duplicate);
|
||||
DBUG_RETURN(TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
Set exclude_from_table_unique_test value back to FALSE. It is needed for
|
||||
|
Loading…
x
Reference in New Issue
Block a user