Re: [PDO] Client side cache for prepared queries
[email protected] (Julien Palard) Tue, 2 Aug 2011 13:23:59 +0200
| Newsgroups | php.pdo |
|---|---|
| Message-ID | <CAOO=pgCmAUe3JSLftTTkZfHmMkjRB4eyDiBsF9LbHfM3jWENZg@mail.gmail.com> |
Reading this, I think I should add some precisions : On Tue, Aug 2, 2011 at 11:42 AM, Goran Miskovic <[email protected]> wrote= : > Beginning with MySQL 5.1.17, prepared statements use the query cache unde= r > certain conditions, which differ depending on the preparation method. > See:=A0http://dev.mysql.com/doc/refman/5.1/en/query-cache-operation.html 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 building. Am I clear ? or not ? Wrong ? or not ? --=20 Julien Palard