MySQL UPDATE Query Hangs

Posted on 2014-07-11
Last Modified: 2014-07-24
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.
Question by:JP_TechGroup

    Author Comment

    I should add that if I run it in Access to which I am connected locally via ODBC, it runs in 5 seconds.
    LVL 26

    Expert Comment

    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.
    LVL 53

    Accepted Solution

    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:

    LVL 107

    Expert Comment

    by:Ray Paseur
    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

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
    Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now