MySQL Forums
Forum List  »  Performance

Re: 5.5: UPDATE massively slower than SELECT. Both affect zero rows.
Posted by: Øystein Grøvlen
Date: May 22, 2015 02:19AM

Hi,

Without seeing any query plans, I am not sure there is much I can say (except urging you to upgrade to 5.6). You could try to rewrite the query as a single table update statement with a subquery. Something like:

UPDATE products AS p
SET p.modified = NOW()
WHERE p.upc IN
( SELECT v.upc FROM upcLike AS v
INNER JOIN batchList as l ON l.upc=concat('LC',convert(v.likecode,char))
INNER JOIN batches AS b ON b.batchID=l.batchID
WHERE l.upc LIKE 'LC%'
AND l.batchID = 4895
);

However, I suspect this will also be slow in MySQL 5.5. Make sure you have an index on the upc and batchid columns.

Some general comments on your query:
Do you really need to include the batches table?
Make sure the character set of your session is the same as for your columns. Otherwise, result of concat may be in another character set than the column it is compared with, and index will not be used.
Given that your WHERE clause filters only the batchList table, it would be beneficial to start with that table, but giving the join expression, an index can not be used to do look-ups from batchList into upcLike. Maybe you should consider to precompute the upc value and store it in an extra column in upcLike?

Øystein Grøvlen,
Senior Principal Software Engineer,
MySQL Group, Oracle,
Trondheim, Norway

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: 5.5: UPDATE massively slower than SELECT. Both affect zero rows.
915
May 22, 2015 02:19AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.