Fix query cache invalidation bug.
authorTatsuo Ishii <ishii@postgresql.org>
Thu, 1 May 2025 23:35:33 +0000 (08:35 +0900)
committerTatsuo Ishii <ishii@postgresql.org>
Thu, 8 May 2025 05:28:53 +0000 (14:28 +0900)
commit1a6bf4439c679e482532bdd75c82d5730c29affc
tree79f5f81ecc023e1e1e41dc7012a02c4f1c325511
parentf71380df9fca236a431b6c064ee2c9586a36c631
Fix query cache invalidation bug.

When an execute message is received, pgpool checks its max number of
rows paramter. If it's not zero, pgpool sets "partial_fetch" flag to
instruct pool_handle_query_cache() to not create query cache.  Problem
is, commit 2a99aa5d1 missed that even INSERT/UPDATE/DELETE sets the
execute message parameter to non 0 (mostly 1) and pgpool set the flag
for even none SELECTs. This resulted in failing to invalidate query
cache because if the flag is true, subsequent code in
pool_handle_query_cache() skips cache invalidation.  It was an
oversight in this commit (my fault):
https://git.postgresql.org/gitweb/?p=pgpool2.git;a=commit;h=2a99aa5d1910f1fd4855c8eb6751a26cbaa5e48d

To fix this change Execute() to check if the query is read only SELECT
before setting the flag.

Also add test to 006.memqcache.

Problem reported by and a test program provided by Achilleas Mantzios <a.mantzios@cloud.gatewaynet.com>.

Discussion: [pgpool-general: 9427] Clarification on query results cache visibility
https://www.pgpool.net/pipermail/pgpool-general/2025-April/009430.html

Backpatch-through: v4.2
src/protocol/pool_proto_modules.c
src/test/regression/tests/006.memqcache/expected.5 [new file with mode: 0644]
src/test/regression/tests/006.memqcache/query_cache_bug5.data [new file with mode: 0644]
src/test/regression/tests/006.memqcache/test.sh