diff options
author | Tatsuo Ishii | 2024-09-28 13:34:57 +0000 |
---|---|---|
committer | Tatsuo Ishii | 2024-09-28 13:34:57 +0000 |
commit | bdbee93ceb9f1452f9eab56077c8041a68e53ba3 (patch) | |
tree | 8432ba8ca225f7eae695ce490c181914cda0e236 /src | |
parent | 4ac2f8801508922ef75c5f476b8edae988f635c1 (diff) |
[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
Diffstat (limited to 'src')
-rw-r--r-- | src/include/query_cache/pool_memqcache.h | 3 | ||||
-rw-r--r-- | src/query_cache/pool_memqcache.c | 8 | ||||
-rwxr-xr-x | src/test/regression/tests/006.memqcache/test.sh | 6 |
3 files changed, 16 insertions, 1 deletions
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 <sys/time.h> +#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 |