Fix in memory query cache bug reported in bug#152.
authorTatsuo Ishii <ishii@postgresql.org>
Mon, 19 Oct 2015 04:18:06 +0000 (13:18 +0900)
committerTatsuo Ishii <ishii@postgresql.org>
Mon, 19 Oct 2015 04:18:06 +0000 (13:18 +0900)
If extended query protocol is used and a bind/execute message arrives
which uses a statement created by prior parse message, the temp_cache
is not initialized by a parse messages. Thus messages are added to pre
existing temp cache buffer which causes the trouble (when the cached
result returns, Data Row message and Command Complete message appeared
*twice*).
t-ishii@localhost:

pool_memqcache.c

index b9e33540ee2985697653c24edcd497e361f5a62f..a39e605dd5f7dbff99e415efa8eb75456a90e7e6 100644 (file)
@@ -2961,6 +2961,23 @@ void pool_handle_query_cache(POOL_CONNECTION_POOL *backend, char *query, Node *n
                                        {
                                                pool_error("ReadyForQuery: pool_commit_cache failed");
                                        }
+                                       else
+                                       {
+                                               /*
+                                                * Reset temporary query cache buffer. This is
+                                                * necessary if extended query protocol is used and a
+                                                * bind/execute message arrives which uses a statement
+                                                * created by prior parse message. In this case since
+                                                * the temp_cache is not initialized by a parse
+                                                * message, messages are added to pre existing temp
+                                                * cache buffer. The problem was found in bug#152.
+                                                * http://www.pgpool.net/mantisbt/view.php?id=152
+                                                */
+                                               POOL_TEMP_QUERY_CACHE *cache;
+                                               cache = pool_get_current_cache();
+                                               pool_discard_temp_query_cache(cache);
+                                               session_context->query_context->temp_cache = pool_create_temp_query_cache(query);
+                                       }
                                        free(cache_buffer);
                                }
                                pool_shmem_unlock();