From bdbee93ceb9f1452f9eab56077c8041a68e53ba3 Mon Sep 17 00:00:00 2001 From: Tatsuo Ishii Date: Sat, 28 Sep 2024 22:34:57 +0900 Subject: [New feature] Force to make query cache. Recognize /*FORCE QUERY CACHE*/ SQL statement comment so that any read only SELECT/with queries are cached. This is opposite to /*NO QUERY CACHE*/ comment. This feature should be used carefully. See the manual for more details. Discussion: https://github.com/pgpool/pgpool2/issues/56 --- src/include/query_cache/pool_memqcache.h | 3 +++ src/query_cache/pool_memqcache.c | 8 +++++++- src/test/regression/tests/006.memqcache/test.sh | 6 ++++++ 3 files changed, 16 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/include/query_cache/pool_memqcache.h b/src/include/query_cache/pool_memqcache.h index 9607fb835..6e94d3479 100644 --- a/src/include/query_cache/pool_memqcache.h +++ b/src/include/query_cache/pool_memqcache.h @@ -29,6 +29,9 @@ #include "pool.h" #include +#define FORCE_QUERY_CACHE "/*FORCE QUERY CACHE*/" +#define FORCE_QUERY_CACHE_COMMENT_SZ (sizeof(FORCE_QUERY_CACHE)-1) + #define NO_QUERY_CACHE "/*NO QUERY CACHE*/" #define NO_QUERY_CACHE_COMMENT_SZ (sizeof(NO_QUERY_CACHE)-1) diff --git a/src/query_cache/pool_memqcache.c b/src/query_cache/pool_memqcache.c index ad1501c0c..7ff8a80d9 100644 --- a/src/query_cache/pool_memqcache.c +++ b/src/query_cache/pool_memqcache.c @@ -925,7 +925,13 @@ pool_is_allow_to_cache(Node *node, char *query) SelectContext ctx; /* - * If NO QUERY CACHE comment exists, do not cache. + * If FORCE QUERY CACHE comment exists, cache it unconditionally. + */ + if (!strncasecmp(query, FORCE_QUERY_CACHE, FORCE_QUERY_CACHE_COMMENT_SZ)) + return true; + + /* + * If NO QUERY CACHE comment exists, do not cache unconditionally. */ if (!strncasecmp(query, NO_QUERY_CACHE, NO_QUERY_CACHE_COMMENT_SZ)) return false; diff --git a/src/test/regression/tests/006.memqcache/test.sh b/src/test/regression/tests/006.memqcache/test.sh index 05f9e26a1..e7e2353b9 100755 --- a/src/test/regression/tests/006.memqcache/test.sh +++ b/src/test/regression/tests/006.memqcache/test.sh @@ -91,6 +91,10 @@ SELECT '2022-07-05 10:00:00'::TIMETZ; SELECT '2022-07-05 10:00:00'::TIMETZ; SELECT to_timestamp(0); SELECT to_timestamp(0); +/*FORCE QUERY CACHE*/SELECT now(); +/*FORCE QUERY CACHE*/SELECT now(); +/*NO QUERY CACHE*/SELECT 1; +/*NO QUERY CACHE*/SELECT 1; EOF success=true @@ -110,6 +114,8 @@ EOF grep "fetched from cache" log/pgpool.log | grep 'TIMESTAMPTZ;' > /dev/null && success=false grep "fetched from cache" log/pgpool.log | grep 'TIMETZ;' > /dev/null && success=false grep "fetched from cache" log/pgpool.log | grep 'to_timestamp' > /dev/null && success=false + grep "fetched from cache" log/pgpool.log | grep 'FORCE QUERY CACHE' > /dev/null || success=false + grep "fetched from cache" log/pgpool.log | grep 'NO QUERY CACHE' > /dev/null && success=false if [ $success = false ];then ./shutdownall -- cgit v1.2.3