JP_TechGroup
asked on
MySQL UPDATE Query Hangs
I have a FEDERATED table from another local database from which I have created a VIEW in MySQL, set up as below:
Using this VIEW I am attempting to run an UPDATE query on the local database as follows:
The query times out after 10 minutes and does not actually appear to run at all.
The view returns a dataset of around 13,000 lines and the udate query is addressing about 19,000 lines.
I am at a loss as to why it hangs. Thanks for reading.
select `wo_line_items`.`work_order_id` AS `work_order_id`,
sum(`wo_line_items`.`quantity`) AS `SumOfquantity`,
sum(`wo_line_items`.`shipped`) AS `SumOfshipped`,
(sum(`wo_line_items`.`quantity`) - sum(`wo_line_items`.`shipped`)) AS `shipped`
from (`work_orders` join `wo_line_items` on((`work_orders`.`id` = `wo_line_items`.`work_order_id`)))
group by `wo_line_items`.`work_order_id`,`work_orders`.`status` having ((sum(`wo_line_items`.`quantity`) > 0)
and (`work_orders`.`status` = _utf8'inspection complete'))
Using this VIEW I am attempting to run an UPDATE query on the local database as follows:
UPDATE wtbl_stages INNER JOIN view_shipped ON wtbl_stages.wo_id = view_shipped.work_order_id SET
wtbl_stages.stage_date_in = Now(), wtbl_stages.stage_date_out = Now(),
wtbl_stages.stage_action_id = 3, wtbl_stages.stage_notes = 'Auto Closed by Woksu'
WHERE (((wtbl_stages.stage_action_id) is null) AND ((wtbl_stages.process_id)= 21) AND (`view_shipped`.`shipped`)=0);
The query times out after 10 minutes and does not actually appear to run at all.
The view returns a dataset of around 13,000 lines and the udate query is addressing about 19,000 lines.
I am at a loss as to why it hangs. Thanks for reading.
Views are not very good in terms of performance in MySQL as they don't get to use the tables indexes. They kind of scan the result set they produce. Another thing is that I am not sure how can you update a view, if that is what you are trying to do.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You might want to use EXPLAIN SELECT on the view query to see if it's susceptible of being optimized. You might also want to consider embedding it into the UPDATE query, instead of keeping it as a view. That might give you access to the table indexes, and indexed tables will always give better performance.
ASKER