Problem with very slow MYSql cross table update query

Hi,
I am trying to write a MySql cross table update query but it just runs and runs. I have a table called inventoryitem which is related to a table called masterproduct which is related to a table called manufacturer. I am trying to update the value of the Manufacturer_RID field in the inventoryitem to be equal to the manufacturer that is matched to the masterproduct that is matched to the inventoryitem.

There are around 1000 inventoryitems for client # 7665227, around 150,000 masterproducts and 1000 manufacturers.

My query is:

UPDATE inventoryitem
INNER JOIN masterproduct ON inventoryitem.GID = masterproduct.ID INNER

JOIN manufacturer ON masterproduct.MfgText=manufacturer.Name
SET inventoryitem.Manufacturer_REN='Manufacturer',

inventoryitem.Manufacturer_RID=manufacturer.ID
WHERE inventoryitem.Client_RID='7665227';

I believe that I may need to use indexing to speed this up to be useable but I know nothing at all about indexing.

Could anyone point me in the right direction?

Thanks,
Pete
Pete BradstreetAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gheistCommented:
You update one table - why the joins?
0
Pete BradstreetAuthor Commented:
Because the value that I am updating the inventory item with is coming from the manufacturer table.
0
gheistCommented:
Can you post
EXPLAIN <your query here> ;
?
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

Pete BradstreetAuthor Commented:
Hi,
The query is shown above, here it is again:

UPDATE inventoryitem
INNER JOIN masterproduct ON inventoryitem.GID = masterproduct.ID INNER
JOIN manufacturer ON masterproduct.MfgText=manufacturer.Name
SET inventoryitem.Manufacturer_REN='Manufacturer',
inventoryitem.Manufacturer_RID=manufacturer.ID
WHERE inventoryitem.Client_RID='7665227';

The issue seems to be that the join between the masterproduct.MfgText and the manufacturer.Name involves two text fields rather than a primary id field, the query is very slow. I was wondering whether I needed to index either of these two fields and if so, how that is done? The other possibility is that my sql above is written poorly and that there is a a cleaner way to achieve the updating of the inventoryitem.Manufacturer_RID based on the manufacturer.id which is related to the masterproduct which is in turn related to the inventoryitem?
0
gheistCommented:
Can you run query trace without executing it against your database?
0
Pete BradstreetAuthor Commented:
I am not familiar with query trace so I will read up on it and get back to you.
0
gheistCommented:
Are you capable of running following SQL statement:
EXPLAIN
UPDATE inventoryitem
INNER JOIN masterproduct ON inventoryitem.GID = masterproduct.ID
INNER JOIN manufacturer ON masterproduct.MfgText=manufacturer.Name
SET inventoryitem.Manufacturer_REN='Manufacturer',
inventoryitem.Manufacturer_RID=manufacturer.ID
WHERE inventoryitem.Client_RID='7665227';
0
Tomas Helgi JohannssonCommented:
Hi!

Take all columns for each table of the joins  and check if there exist an index on those columns.
For example the table masterproduct there should be an index on these two columns (ID, MfgText)
and on this index  (Client_RID,Manufacturer_REN,Manufacturer_RID) on the table inventoryitem.

Regards,
     Tomas Helgi
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Tomas Helgi JohannssonCommented:
Hi!

Please see this article on grading ( A should be the default as stated in it )
http://support.experts-exchange.com/customer/portal/articles/481419

Regards,
    Tomas Helgi
0
Pete BradstreetAuthor Commented:
My apologies, how do I change it to A?
0
Tomas Helgi JohannssonCommented:
Ask a Moderator for assistance by using the "Request for Attention" button.

Regards,
    Tomas Helgi
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.