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:20:14 +0000 (15:20 +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 840ede6acb07953684268c42e8515ae808deccf1..6a5a11814570a2e79cc610de5629bba6d969a241 100755 (executable)
@@ -68,6 +68,8 @@ SELECT other_schema.volatile_func(1);
 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
@@ -79,6 +81,8 @@ EOF
        grep "fetched from cache" log/pgpool.log | grep immutable_func > /dev/null || success=false
        grep "fetched from cache" log/pgpool.log | grep volatile_func > /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 1ca6a997ebf11cc04666efa193388cae671130fd..14804cfa0e102b16c09dbca04e2c1678034b6539 100644 (file)
@@ -3,7 +3,7 @@
  * pgpool: a language independent connection pool server for PostgreSQL
  * written by Tatsuo Ishii
  *
- * Copyright (c) 2003-2020     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
@@ -1043,6 +1043,15 @@ 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);
 }