Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

mysql DELETE  "gets stuck"

Posted on 2014-12-01
6
Medium Priority
?
237 Views
Last Modified: 2014-12-01
I've inherited the following "nested" DELETE query,
where the desire is to delete those records in the Purchase_order_details table that
are referred to in the Sales_order_details  table.

tblPOdetails                           tblSOdetails
po_detail_key    <-------------- po_detail_key
                                                 so_header_key   =   123456  (a specific value when handed to mySQL)

DELETE FROM tblPurchase_order_details       
                        WHERE po_detail_key IN
                              (SELECT po_detail_key FROM tblSales_order_details
                                    WHERE so_header_key='{$SOHID']}'
                              )

The server shows the mySQL state of this query to be          "Sending data"
and it's stuck there until i restart mySQL on the server.

I can unravel the "nested" query to be implemented using a PHP loop, but wondering if there's
a way it can work WITHIN mySQL?

p.s. it's INNODB with no constraints defined,  all other queries work fine.
the design, etc.  had been translated from an ASP/Microsoft implementation from 15+ yrs ago.
0
Comment
Question by:willsherwood
  • 3
  • 2
6 Comments
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 40474656
This '{$SOHID']}' is not a valid anything that I know of.  Please post the actual code in the 'code' format so we can see what you are actually doing.  You can replace any sensitive data but otherwise keep the code as it is found.  Like this...

DELETE FROM tblPurchase_order_details       
                        WHERE po_detail_key IN
                              (SELECT po_detail_key FROM tblSales_order_details
                                    WHERE so_header_key='{$SOHID']}'
                              ) 

Open in new window

0
 
LVL 58

Accepted Solution

by:
Gary earned 2000 total points
ID: 40474660
Is this your exact sql as you have a square bracket and a nested apostrophe

'{$SOHID']}'

DELETE tblPurchase_order_details FROM  tblPurchase_order_details 
	INNER JOIN tblSales_order_details 
		ON tblSales_order_details.po_detail_key = tblPurchase_order_details.po_detail_key
	WHERE so_header_key='{$SOHID}'

Open in new window

0
 

Author Comment

by:willsherwood
ID: 40474713
sorry for the copy/paste typo.

the  '{$SOHID}'  is a PHP variable that expands to a literal/constant for the query

i'll try your INNER JOIN now !
0
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

 

Author Closing Comment

by:willsherwood
ID: 40474725
super, thanks for your help in translating to use  INNER JOIN - a great help!
0
 

Author Comment

by:willsherwood
ID: 40474730
p.s.   just curious why something like this would "hang" mySQL for THIS database  when executed
 (other db were operational
during the period that this  query took hold of the the database)
0
 
LVL 58

Expert Comment

by:Gary
ID: 40474758
Could be several things without knowing the db setup. But a join is better than a nested select which involves more work.
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Recursive SQL is one of the most fascinating and powerful and yet dangerous feature offered in many modern databases today using a Common Table Expression (CTE) first introduced in the ANSI SQL 99 standard. The first implementations of CTE began ap…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

972 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