Reading this, I think I should add some precisions :
On Tue, Aug 2, 2011 at 11:42 AM, Goran Miskovic <email@example.com> wrote:
> Beginning with MySQL 5.1.17, prepared statements use the query cache under
> certain conditions, which differ depending on the preparation method.
You (and the mysql documentation) are speaking about "server side
result cache" (albeit they wrote query cache), here I'm speaking of
"client side prepared query cache" in its strict sense. I'll try to
make the difference clear here :
* Caching the prepared query aimed to reuse memory structure and
execution plan from previous prepared query.
* Caching the prepared query is independent of values, we only speak
here of the prepared query not the executed query.
* Caching the prepared query should be implemented client side to
avoid one round trip.
* The aim of the caching here is to reuse a prepared query, not its result.
Use case :
A website, like any other, have, say, a request to fetch the content
of a post and its comments, the query is executed once per post page,
so a prepared query here is almost useless (Good to prevent injection,
bad cause of an additional RTT to the sql server)
If the client does prepared query cache, in this case, the RTT needed
to tell the serveur to create the query is done only once, and each
following pages that reuse the same SQL connection will got a cache
hit doing the pdo::prepare, economising one RTT and the query plan
Am I clear ? or not ? Wrong ? or not ?