pgpool2.git / summary / log / commit / refs
commit c7d3ad9fd6f792fa52ec4214c1cc60570fd2f371
Author: Tatsuo Ishii <ishii@sraoss.co.jp>
Date: Wed Aug 05 02:37:28 2020 +0000
Fix query cache bug.
If EXPLAIN ANALYZE takes data-modifying SQL, it must invalidate query
cache, but actually it was missed.
Author: Hou, Zhijie
Discussion: https://www.pgpool.net/pipermail/pgpool-hackers/2020-August/003767.html
src/query_cache/pool_memqcache.c | 17 +++++++++++++++++
src/test/regression/tests/006.memqcache/test.sh | 13 +++++++++----
2 files changed, 26 insertions(+), 4 deletions(-)
diff --git a/src/query_cache/pool_memqcache.c b/src/query_cache/pool_memqcache.c
index 9d2bb1b7a..263274769 100644
--- a/src/query_cache/pool_memqcache.c
+++ b/src/query_cache/pool_memqcache.c
@@ -1248,6 +1248,23 @@ pool_extract_table_oids(Node *node, int **oidsp)
}
return num_oids;
}
+ else if (IsA(node, ExplainStmt))
+ {
+ ListCell *cell;
+ DefElem *def;
+ ExplainStmt *stmt = (ExplainStmt *) node;
+
+ foreach(cell, stmt->options)
+ {
+ def = lfirst(cell);
+ if (strncmp("analyze", def->defname, 7) == 0)
+ {
+ return pool_extract_table_oids(stmt->query, oidsp);
+ }
+ }
+
+ table = NULL;
+ }
else
{
ereport(DEBUG1,
diff --git a/src/test/regression/tests/006.memqcache/test.sh b/src/test/regression/tests/006.memqcache/test.sh
index 549c8a600..50ab7d2b7 100755
--- a/src/test/regression/tests/006.memqcache/test.sh
+++ b/src/test/regression/tests/006.memqcache/test.sh
@@ -43,6 +43,7 @@ CREATE SCHEMA other_schema;
CREATE TABLE t1 (i int);
CREATE TABLE black_t (i int);
CREATE TABLE with_modify (i int);
+CREATE TABLE explain_analyze (i int);
CREATE VIEW normal_v AS SELECT * FROM t1;
CREATE VIEW white_v AS SELECT * FROM t1;
CREATE FUNCTION public.immutable_func(INTEGER) returns INTEGER AS 'SELECT \$1' LANGUAGE SQL IMMUTABLE;
@@ -60,10 +61,13 @@ SELECT * FROM with_modify;
WITH cte AS (INSERT INTO with_modify values(1) RETURNING *) SELECT * FROM with_modify;
WITH cte AS (INSERT INTO with_modify values(1) RETURNING *) SELECT * FROM with_modify;
SELECT * FROM with_modify;
-select public.immutable_func(1);
-select public.immutable_func(1);
-select other_schema.volatile_func(1);
-select other_schema.volatile_func(1);
+SELECT public.immutable_func(1);
+SELECT public.immutable_func(1);
+SELECT other_schema.volatile_func(1);
+SELECT other_schema.volatile_func(1);
+SELECT * FROM explain_analyze;
+EXPLAIN ANALYZE INSERT INTO explain_analyze VALUES(1);
+SELECT * FROM explain_analyze;
EOF
success=true
@@ -74,6 +78,7 @@ EOF
grep "fetched from cache" log/pgpool.log | grep with_modify > /dev/null && success=false
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
if [ $success = false ];then
./shutdownall
exit 1
[parent: de133ec84885]