0

I have a query below which updates a Tune table if the MD5 (16char string) column in the Persistence table matches the MD5 column in the Tune table.

The Tune table contains about 50,000 records and its taking about 29 seconds to perform the below update. I'm assuming I can speed this up using an index (?).. Actually its 29 seconds without the WHERE statement and 17 seconds with the WHERE - but thats still a long time.

UPDATE Tune
SET Rating = ( SELECT Rating FROM Persistence WHERE Persistence.MD5=Tune.MD5 LIMIT 1)
WHERE EXISTS ( SELECT Rating FROM Persistence WHERE Persistence.MD5=Tune.MD5 LIMIT 1)

My question is: Which table to I create an index on? Do I need to create indices for both tables?

Or.. is there a faster way of doing what I'm trying to do?

1 Answer 1

0

I indexed Persistence as follows - now I have an immediate return.

CREATE  INDEX PERSISTMD5 ON Persistence (MD5);

UPDATE Tune 
SET Rating = ( SELECT Rating FROM Persistence INDEXED BY PERSISTMD5 WHERE Persistence.MD5=Tune.MD5 LIMIT 1)
WHERE EXISTS ( SELECT Rating FROM Persistence INDEXED BY PERSISTMD5  WHERE Persistence.MD5=Tune.MD5 LIMIT 1 )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.