[pgpool-committers: 10299] pgpool: Fix yet another query cache bug in streaming replication mode.

Tatsuo Ishii ishii at postgresql.org
Sat Dec 14 20:53:20 JST 2024


Fix yet another query cache bug in streaming replication mode.

If query cache is enabled and query is operated in extended query mode
and pgpool is running in streaming replication mode, an execute
message could return incorrect results.

This could happen when an execute message comes with a non 0 row
number parameter. In this case it fetches up to the specified number of
rows and returns "PortalSuspended" message. Pgpool-II does not create
query cache for this.  But if another execute message with 0 row
number parameter comes in, it fetches rest of rows (if any) and
creates query cache with the number of rows which the execute messages
fetched.

Obviously this causes unwanted results later on: another execute
messages returns result from query cache which has only number of rows
captured by the previous execute message with limited number of rows.

Another trouble is when multiple execute messages are sent
consecutively.  In this case Pgpool-II returned exactly the same
results from query cache for each execute message. This is wrong since
the second or subsequent executes should return 0 rows.

To fix this, new boolean fields "atEnd" and "partial_fetch" are
introduced in the query context. They are initialized to false when a
query context is created (also initialized when bind message is
received). If an execute message with 0 row number is executed, atEnd
is set to true upon receiving CommandComplete message. If an execute
message with non 0 row number is executed, partial_fetch is set to
true and never uses the cache result, nor creates query cache.

When atEnd is true, pgpool will return CommandComplete message with
"SELECT 0" as a result of the execute message.

Also tests for this case is added to the 006.memqcache regression
test.

Backpatch-through: v4.2
Discussion: [pgpool-hackers: 4547] Bug in query cache
https://www.pgpool.net/pipermail/pgpool-hackers/2024-December/004548.html

Branch
------
V4_3_STABLE

Details
-------
https://git.postgresql.org/gitweb?p=pgpool2.git;a=commitdiff;h=8a3d3b7c9c3158d84460ff7bdd21aaec81f2213b

Modified Files
--------------
src/context/pool_query_context.c                   |  2 +
src/include/context/pool_query_context.h           |  6 +++
src/include/query_cache/pool_memqcache.h           |  5 ++-
src/protocol/CommandComplete.c                     | 14 +++++-
src/protocol/pool_proto_modules.c                  | 49 ++++++++++++++++++---
src/query_cache/pool_memqcache.c                   | 49 +++++++++++++++++++--
src/test/regression/tests/006.memqcache/expected.4 | 51 ++++++++++++++++++++++
.../tests/006.memqcache/query_cache_bug4.data      | 37 ++++++++++++++++
src/test/regression/tests/006.memqcache/test.sh    |  6 ++-
9 files changed, 206 insertions(+), 13 deletions(-)



More information about the pgpool-committers mailing list