this query takes 2 minutes execute (changing 9 records):
update table1 t1 set t1.code_id = null, t1.code_group = null t1.another_id in (select t2.another_id table2 t2 ((t2.id_parent = 2658 , t2.year = 2016) or (t2.id = 2658 , t2.year = 2016)))
executing query alone takes 0.0030s:
select t2.another_id table2 t2 ((t2.id_parent = 2658 , t2.year = 2016) or (t2.id = 2658 , t2.year = 2016))
and returns 3 rows in form of integer.
here info both tables:
create table if not exists `table1` ( `another_id` int(11) not null, `table1_id` int(11) not null, `code_group` varchar(1) default null, `code_id` int(10) default null, primary key (`another_id`,`table1_id`), key `another_id` (`another_id`), key `code_group` (`code_group`,`code_id`) ) engine=myisam default charset=latin1; create table if not exists `table2` ( `id_year` int(11) not null, `id` int(11) not null, `id_parent` int(11) default null, `another_id` int(11) not null, `code_group` varchar(1) default null, `code_id` int(10) default null, primary key (`id_year`,`id`), key `id_parent` (`id_year`,`id_parent`) key `another_id` (`another_id`) ) engine=innodb default charset=utf8mb4 collate=utf8mb4_polish_ci;
is there anyone, can tell why needs 2 minutes execute query?
you can use inner join update following:t2.year not exist
update table1 t1 inner join table2 t2 on t2.another_id = t1.another_id , ((t2.id_parent= 2658 , t2.year= 2016) or (t2.id= 2658 , t2.year= 2016)) set t1.code_id = null, t1.code_group = null
Comments
Post a Comment