From 707d8653c46d4f457aecfee4eacf678a2ccc87c7 Mon Sep 17 00:00:00 2001 From: Alexey Botchkov Date: Wed, 24 Mar 2021 15:05:24 +0400 Subject: [PATCH] MDEV-25228 JSON_TABLE: Server crashes in Query_cache::unlink_table. JSON_TABLE shojldn't be counted in the query_cache. --- mysql-test/main/query_cache.result | 7 +++++++ mysql-test/main/query_cache.test | 7 +++++++ sql/sql_cache.cc | 6 ++++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/mysql-test/main/query_cache.result b/mysql-test/main/query_cache.result index c835e25e396..020c7472694 100644 --- a/mysql-test/main/query_cache.result +++ b/mysql-test/main/query_cache.result @@ -2227,6 +2227,13 @@ SHOW STATUS LIKE 'Qcache_inserts'; Variable_name Value Qcache_inserts 0 drop table t1; +# +# MDEV-25228 JSON_TABLE: Server crashes in Query_cache::unlink_table. +# +CREATE TABLE t (a INT); +SELECT * FROM t JOIN JSON_TABLE('{}' , '$' COLUMNS(b FOR ORDINALITY)) AS jt; +a b +DROP TABLE t; restore defaults SET GLOBAL query_cache_type= default; SET GLOBAL query_cache_size=@save_query_cache_size; diff --git a/mysql-test/main/query_cache.test b/mysql-test/main/query_cache.test index 0d747b97acc..66785b42c36 100644 --- a/mysql-test/main/query_cache.test +++ b/mysql-test/main/query_cache.test @@ -1818,6 +1818,13 @@ select * from t1, json_table(t1.a, '$' columns (f varchar(20) path '$.a')) as jt SHOW STATUS LIKE 'Qcache_inserts'; drop table t1; +--echo # +--echo # MDEV-25228 JSON_TABLE: Server crashes in Query_cache::unlink_table. +--echo # +CREATE TABLE t (a INT); +SELECT * FROM t JOIN JSON_TABLE('{}' , '$' COLUMNS(b FOR ORDINALITY)) AS jt; +DROP TABLE t; + --echo restore defaults SET GLOBAL query_cache_type= default; SET GLOBAL query_cache_size=@save_query_cache_size; diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc index 80681eee44a..49f42eb95c5 100644 --- a/sql/sql_cache.cc +++ b/sql/sql_cache.cc @@ -4094,11 +4094,13 @@ Query_cache::process_and_count_tables(THD *thd, TABLE_LIST *tables_used, *tables_type|= HA_CACHE_TBL_NONTRANSACT; continue; } - if (tables_used->derived) + if (tables_used->derived || tables_used->table_function) { DBUG_PRINT("qcache", ("table: %s", tables_used->alias.str)); table_count--; - DBUG_PRINT("qcache", ("derived table skipped")); + DBUG_PRINT("qcache", (tables_used->table_function ? + "table function skipped" : + "derived table skipped")); continue; }