In the spirit of the Good Practice/Bad Practice series, this post
is – apart from my first as contributing engineer at Open Query –
a basic level application tip. More advanced application
developers will already be aware of the issue.
It is easy to overlook certain “non-deterministic” functions in
your queries which will prevent the query cache from caching its
results. Common examples include NOW(), CURDATE(), and RAND()
(here is the complete list).
Obviously when RAND() is used, you usually don’t expect the same
result if the query is repeated, so this isn’t a concern. But
other cases, particularly date/time related queries, can actually
benefit from the cache, and there is a simple workaround. When
the query cache is able to satisfy a query, the overhead (in
latency and CPU) of parsing and planning the query is …
[Read more]