Fix query cache to not cache SQLValueFunctions (CURRENT_TIME, CURRENT_USER etc.).
authorTatsuo Ishii <ishii@sraoss.co.jp>
Wed, 7 Jul 2021 04:03:59 +0000 (13:03 +0900)
committerTatsuo Ishii <ishii@sraoss.co.jp>
Wed, 7 Jul 2021 06:24:38 +0000 (15:24 +0900)
Checking SQLValueFunctions was missed whether to be cached or not and
they were regarded as non function objects. As a result they were
cached.

Also add more test cases.

src/test/regression/tests/006.memqcache/test.sh
src/utils/pool_select_walker.c

index 165d3a7d78d7bc462a1c0383618416d3d7f2ccfa..a5e77c588cd2af75d9c787b81f96ab0e86f2ddd3 100755 (executable)
@@ -61,6 +61,8 @@ SELECT * FROM with_modify;
 SELECT * FROM explain_analyze;
 EXPLAIN ANALYZE INSERT INTO explain_analyze VALUES(1);
 SELECT * FROM explain_analyze;
+SELECT CURRENT_TIMESTAMP;
+SELECT CURRENT_USER;
 EOF
 
        success=true
@@ -70,6 +72,8 @@ EOF
        grep "fetched from cache" log/pgpool.log | grep white_v > /dev/null || success=false
        grep "fetched from cache" log/pgpool.log | grep with_modify > /dev/null && success=false
        grep "fetched from cache" log/pgpool.log | grep explain_analyze > /dev/null && success=false
+       grep "fetched from cache" log/pgpool.log | grep CURRENT_TIMESTAMP > /dev/null && success=false
+       grep "fetched from cache" log/pgpool.log | grep CURRENT_USER > /dev/null && success=false
        if [ $success = false ];then
                ./shutdownall
                exit 1
index 29fd05a9387d7ba1eb4f2b04534c7b3c1ff13fbe..af903176a95cddf38a5ae6748fdc0071c0a3f493 100644 (file)
@@ -3,7 +3,7 @@
  * pgpool: a language independent connection pool server for PostgreSQL
  * written by Tatsuo Ishii
  *
- * Copyright (c) 2003-2019     PgPool Global Development Group
+ * Copyright (c) 2003-2021     PgPool Global Development Group
  *
  * Permission to use, copy, modify, and distribute this software and
  * its documentation for any purpose and without fee is hereby
@@ -1026,6 +1026,15 @@ static bool non_immutable_function_call_walker(Node *node, void *context)
                        return false;
                }
        }
+       else if (IsA(node, SQLValueFunction))
+       {
+               /*
+                * SQLValueFunctions (CURRENT_TIME, CURRENT_USER etc.) are regarded as
+                * non immutable functions.
+                */
+               ctx->has_non_immutable_function_call = true;
+               return false;
+       }
 
        return raw_expression_tree_walker(node, non_immutable_function_call_walker, context);
 }