mirror of
https://github.com/MariaDB/server.git
synced 2025-01-19 13:32:33 +01:00
d4450e6696
NDB table". SQL-layer was not marking fields which were used in triggers as such. As result these fields were not always properly retrieved/stored by handler layer. So one might got wrong values or lost changes in triggers for NDB, Federated and possibly InnoDB tables. This fix solves the problem by marking fields used in triggers appropriately. Also this patch contains the following cleanup of ha_ndbcluster code: We no longer rely on reading LEX::sql_command value in handler in order to determine if we can enable optimization which allows us to handle REPLACE statement in more efficient way by doing replaces directly in write_row() method without reporting error to SQL-layer. Instead we rely on SQL-layer informing us whether this optimization applicable by calling handler::extra() method with HA_EXTRA_WRITE_CAN_REPLACE flag. As result we no longer apply this optimzation in cases when it should not be used (e.g. if we have on delete triggers on table) and use in some additional cases when it is applicable (e.g. for LOAD DATA REPLACE). Finally this patch includes fix for bug#20728 "REPLACE does not work correctly for NDB table with PK and unique index". This was yet another problem which was caused by improper field mark-up. During row replacement fields which weren't explicity used in REPLACE statement were not marked as fields to be saved (updated) so they have retained values from old row version. The fix is to mark all table fields as set for REPLACE statement. Note that in 5.1 we already solve this problem by notifying handler that it should save values from all fields only in case when real replacement happens.
119 lines
3.7 KiB
Text
119 lines
3.7 KiB
Text
drop table if exists t1, t2, t3;
|
|
create table t1 (id int primary key, a int not null, b decimal (63,30) default 0) engine=ndb;
|
|
create table t2 (op char(1), a int not null, b decimal (63,30));
|
|
create table t3 select 1 as i;
|
|
create trigger t1_bu before update on t1 for each row
|
|
begin
|
|
insert into t2 values ("u", old.a, old.b);
|
|
set new.b = old.b + 10;
|
|
end;//
|
|
create trigger t1_bd before delete on t1 for each row
|
|
begin
|
|
insert into t2 values ("d", old.a, old.b);
|
|
end;//
|
|
insert into t1 values (1, 1, 1.05), (2, 2, 2.05), (3, 3, 3.05), (4, 4, 4.05);
|
|
update t1 set a=5 where a != 3;
|
|
select * from t1 order by id;
|
|
id a b
|
|
1 5 11.050000000000000000000000000000
|
|
2 5 12.050000000000000000000000000000
|
|
3 3 3.050000000000000000000000000000
|
|
4 5 14.050000000000000000000000000000
|
|
select * from t2 order by op, a, b;
|
|
op a b
|
|
u 1 1.050000000000000000000000000000
|
|
u 2 2.050000000000000000000000000000
|
|
u 4 4.050000000000000000000000000000
|
|
delete from t2;
|
|
update t1, t3 set a=6 where a = 5;
|
|
select * from t1 order by id;
|
|
id a b
|
|
1 6 21.050000000000000000000000000000
|
|
2 6 22.050000000000000000000000000000
|
|
3 3 3.050000000000000000000000000000
|
|
4 6 24.050000000000000000000000000000
|
|
select * from t2 order by op, a, b;
|
|
op a b
|
|
u 5 11.050000000000000000000000000000
|
|
u 5 12.050000000000000000000000000000
|
|
u 5 14.050000000000000000000000000000
|
|
delete from t2;
|
|
delete from t1 where a != 3;
|
|
select * from t1 order by id;
|
|
id a b
|
|
3 3 3.050000000000000000000000000000
|
|
select * from t2 order by op, a, b;
|
|
op a b
|
|
d 6 21.050000000000000000000000000000
|
|
d 6 22.050000000000000000000000000000
|
|
d 6 24.050000000000000000000000000000
|
|
delete from t2;
|
|
insert into t1 values (1, 1, 1.05), (2, 2, 2.05), (4, 4, 4.05);
|
|
delete t1 from t1, t3 where a != 3;
|
|
select * from t1 order by id;
|
|
id a b
|
|
3 3 3.050000000000000000000000000000
|
|
select * from t2 order by op, a, b;
|
|
op a b
|
|
d 1 1.050000000000000000000000000000
|
|
d 2 2.050000000000000000000000000000
|
|
d 4 4.050000000000000000000000000000
|
|
delete from t2;
|
|
insert into t1 values (4, 4, 4.05);
|
|
insert into t1 (id, a) values (4, 1), (3, 1) on duplicate key update a= a + 1;
|
|
select * from t1 order by id;
|
|
id a b
|
|
3 4 13.050000000000000000000000000000
|
|
4 5 14.050000000000000000000000000000
|
|
select * from t2 order by op, a, b;
|
|
op a b
|
|
u 3 3.050000000000000000000000000000
|
|
u 4 4.050000000000000000000000000000
|
|
delete from t2;
|
|
delete from t3;
|
|
insert into t3 values (4), (3);
|
|
insert into t1 (id, a) (select i, 1 from t3) on duplicate key update a= a + 1;
|
|
select * from t1 order by id;
|
|
id a b
|
|
3 5 23.050000000000000000000000000000
|
|
4 6 24.050000000000000000000000000000
|
|
select * from t2 order by op, a, b;
|
|
op a b
|
|
u 4 13.050000000000000000000000000000
|
|
u 5 14.050000000000000000000000000000
|
|
delete from t2;
|
|
replace into t1 (id, a) values (4, 1), (3, 1);
|
|
select * from t1 order by id;
|
|
id a b
|
|
3 1 0.000000000000000000000000000000
|
|
4 1 0.000000000000000000000000000000
|
|
select * from t2 order by op, a, b;
|
|
op a b
|
|
d 5 23.050000000000000000000000000000
|
|
d 6 24.050000000000000000000000000000
|
|
delete from t1;
|
|
delete from t2;
|
|
insert into t1 values (3, 1, 1.05), (4, 1, 2.05);
|
|
replace into t1 (id, a) (select i, 2 from t3);
|
|
select * from t1 order by id;
|
|
id a b
|
|
3 2 0.000000000000000000000000000000
|
|
4 2 0.000000000000000000000000000000
|
|
select * from t2 order by op, a, b;
|
|
op a b
|
|
d 1 1.050000000000000000000000000000
|
|
d 1 2.050000000000000000000000000000
|
|
delete from t1;
|
|
delete from t2;
|
|
insert into t1 values (3, 1, 1.05), (5, 2, 2.05);
|
|
load data infile '../std_data_ln/loaddata5.dat' replace into table t1 fields terminated by '' enclosed by '' ignore 1 lines (id, a);
|
|
select * from t1 order by id;
|
|
id a b
|
|
3 4 0.000000000000000000000000000000
|
|
5 6 0.000000000000000000000000000000
|
|
select * from t2 order by op, a, b;
|
|
op a b
|
|
d 1 1.050000000000000000000000000000
|
|
d 2 2.050000000000000000000000000000
|
|
drop tables t1, t2, t3;
|
|
End of 5.0 tests
|