MySQL Forums
Forum List  »  Performance

Non deterministic functions
Posted by: Tobin Harris
Date: July 26, 2005 03:40AM

Hi there,

I realise that MySql will not use the query cache for queries containing functions are non-deterministic (i.e - return a different value for each call). However, regardless of the query cache being used, I noticed something else that was odd with the following query...

SELECT *
FROM articles
WHERE body_hash = MD5(LEFT(?body),900)

Here, ?body is a value passed in by the application.

This query is *slow*. However, I managed to decrease query time from 6.5 seconds to 0.3 seconds if I converted it to:

SELECT *
FROM articles
WHERE headline_hash = 'EDd450Fj4DXc120CDFD883SdfdS08D'

This required first doing a query to calculate the hash, and then passing that into the above query. I was surprised that this made a difference, since I'd expect MySQL to do some magic behind the scenes: calculating the hash once, and using that value for each row/field comparison. Is this not the case?

Note that the EXPLAIN reported that the same index was used for each of these two statements. It's just the query time that was much much faster.

Any thoughts/explanations welcome.

Tobin

Options: ReplyQuote


Subject
Views
Written By
Posted
Non deterministic functions
2550
July 26, 2005 03:40AM
1623
July 26, 2005 07:13PM
1521
July 27, 2005 03:17PM


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.