• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 586
  • Last Modified:

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:

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'))

Open in new window

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); 

Open in new window

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.
1 Solution
JP_TechGroupAuthor Commented:
I should add that if I run it in Access to which I am connected locally via ODBC, it runs in 5 seconds.
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.
Views are have very limited ability to be used for update.  I see at least one problem in that there is a GROUP BY.  Probably other thins as well because there are a lot of restrictions and limitations.

This page from the manual explains them:


Ray PaseurCommented:
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.

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now