sql - Optimize MySQL query because it gets time out -
can me optimizing query. can not execute because phpmyadmin connection gets timed out , have no access change time out parameter.
here query:
insert `goods` (`goods_id`, `price`, `name`) select `sales_goods`.`goods_id`, `sales_goods`.`price`, `sales_goods`.`goods_id` `sales_goods` `sales_goods`.`sales_goods_id` in ( select max(`sales_goods`.`sales_goods_id`) `sales_goods` `sales_goods`.`sales_goods_id` in ( select `sales_goods`.`sales_goods_id` `sales_goods` `sales_goods`.`goods_id` not in (select `goods`.`goods_id` `goods`) ) group `sales_goods`.`goods_id` )
aside ensuring tables propery indexed can replace in
subqueries inner join
, , not in
subqueries left join/is null
, should improve performance:
insert `goods` (`goods_id`, `price`, `name`) select `sales_goods`.`goods_id`, `sales_goods`.`price`, `sales_goods`.`goods_id` `sales_goods` inner join ( select max(`sales_goods`.`sales_goods_id`) `sales_goods` left join `goods` on `goods`.`goods_id` = `sales_goods`.`goods_id` `goods`.`goods_id` null group `sales_goods`.`goods_id` ) maxsalesgoods on maxsalesgoods.sales_goods_id = `sales_goods`.`sales_goods_id`