Solved

mysql DELETE  "gets stuck"

Posted on 2014-12-01
6
234 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 83

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 500 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

623 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