1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

MDEV-14551 Can't find record in table on multi-table update with ORDER BY

preserve positions if the multi-update join is using tmp table:

* store positions in the tmp table if needed
  JOIN::add_fields_for_current_rowid()

* take positions from the tmp table, not from file->position():
  multi_update::prepare2()
This commit is contained in:
Sergei Golubchik
2018-04-04 15:34:40 +02:00
parent e17e798599
commit 28dbdf3d79
12 changed files with 218 additions and 12 deletions

View File

@ -968,3 +968,75 @@ NULL 6
7 7
8 8
drop table t1, t2;
create table t1 (i int) engine=memory;
insert t1 values (1),(2);
create table t2 (f int) engine=myisam;
insert t2 values (1),(2);
explain update t1, t2 set f = 126 order by f limit 2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort
1 SIMPLE t2 ALL NULL NULL NULL NULL 2
update t1, t2 set f = 126 order by f limit 2;
select * from t2;
f
126
2
drop table t1, t2;
create table t0(a int);
insert t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t1 (a int, b int, c int, key(a));
insert t1 select a,a,a from t0;
create table t2 as select * from t1;
create table t3 as select * from t1;
select * from t1, t2 where t1.a=t2.a and t1.b in (select b from t3 where t3.c<=t2.c) order by t2.c, t1.c limit 5;
a b c a b c
0 0 0 0 0 0
1 1 1 1 1 1
2 2 2 2 2 2
3 3 3 3 3 3
4 4 4 4 4 4
set optimizer_switch='firstmatch=off';
explain update t1, t2 set t2.c=1 where t1.a=t2.a and t1.b in (select b from t3 where t3.c< t2.c) order by t2.c, t1.c limit 10;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 10 Using temporary; Using filesort
1 PRIMARY t1 ALL a NULL NULL NULL 10 Using where
1 PRIMARY t3 ALL NULL NULL NULL NULL 10 Using where; Start temporary; End temporary
update t1, t2 set t2.c=1 where t1.a=t2.a and t1.b in (select b from t3 where t3.c<=t2.c) order by t2.c, t1.c limit 5;
select * from t2;
a b c
0 0 1
1 1 1
2 2 1
3 3 1
4 4 1
5 5 5
6 6 6
7 7 7
8 8 8
9 9 9
set optimizer_switch=default;
drop table t0,t1,t2,t3;
create table t0 (x int);
create table t1 (a int);
create table t2 (b int, c int default 0);
insert t0 (x) values (0),(10);
insert t1 (a) values (1), (2);
insert t2 (b) values (1), (2);
create view v1 as select t2.b,t2.c from t1, t2
where t1.a=t2.b and t2.b < 3 with check option;
select * from t0 join v1 on (x=c);
x b c
0 1 0
0 2 0
explain update v1,t0 set c=1 where b=1 and x=c order by x,b limit 1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where; Using temporary; Using filesort
1 SIMPLE t2 ALL NULL NULL NULL NULL 2 Using where
1 SIMPLE t0 ALL NULL NULL NULL NULL 2 Using where
update v1,t0 set c=1 where b<3 and x=c order by x,b limit 1;
select * from v1;
b c
1 1
2 0
drop view v1;
drop table t0, t1,t2;