From 02cd3675c4d211118c06478c50a7a515251bc2fc Mon Sep 17 00:00:00 2001 From: Lawrin Novitsky Date: Mon, 22 May 2023 15:07:05 +0200 Subject: [PATCH] MDEV-31064 Changes in a SP are not immediately seen in I_S.parameters If procedure is changed in one connection, and other procedure has already called the initial version of the procedure, the query to INFORMATION_SCHEMA.PARAMETERS would use obsolete information from sp cache for that connection. That happens because cache invalidating method only increments cache version, and does not flush (all) the cache(s), and changing of a procedure only invalidates cache, and removes the procedure's cache entry from local thread cache only. The fix adds the check if sp info obtained from the cache for forming of results for the query to I_S, is not obsoleted, and does not use it, if it is. The test has been added to main.information_schema. It changes the SP in one connection, and ensures, that the change is seen in the query to the I_S.PARAMETERS in other connection, that already has called the procedure before the change. --- mysql-test/main/information_schema.result | 22 ++++++++++++++++++++++ mysql-test/main/information_schema.test | 22 ++++++++++++++++++++++ sql/sp.cc | 4 +++- 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/mysql-test/main/information_schema.result b/mysql-test/main/information_schema.result index 2160eee08a7..e17bb73d4e7 100644 --- a/mysql-test/main/information_schema.result +++ b/mysql-test/main/information_schema.result @@ -2401,3 +2401,25 @@ progress # # End of 10.3 tests # +# +# MDEV-MDEV-31064 Changes of the procedure are not immediatly seen in queries to I_S.parameter from other connections +# +CREATE PROCEDURE sp1(IN p1 INT, IN p2 INT) +BEGIN +END; +connect con2, localhost, root,,; +CALL sp1(10, 20); +connection default; +CREATE OR REPLACE PROCEDURE sp1(p1 INT) +BEGIN +END; +connection con2; +SELECT COUNT(*) FROM information_schema.parameters WHERE SPECIFIC_NAME = 'sp1'; +COUNT(*) +1 +disconnect con2; +connection default; +DROP PROCEDURE sp1; +# +# End of 10.4 tests +# diff --git a/mysql-test/main/information_schema.test b/mysql-test/main/information_schema.test index b9ed6326350..7b5884ef6b5 100644 --- a/mysql-test/main/information_schema.test +++ b/mysql-test/main/information_schema.test @@ -2114,3 +2114,25 @@ select progress from information_schema.processlist limit 1; --echo # --echo # End of 10.3 tests --echo # + +--echo # +--echo # MDEV-MDEV-31064 Changes of the procedure are not immediatly seen in queries to I_S.parameter from other connections +--echo # +CREATE PROCEDURE sp1(IN p1 INT, IN p2 INT) +BEGIN +END; +--connect(con2, localhost, root,,) +CALL sp1(10, 20); +--connection default +CREATE OR REPLACE PROCEDURE sp1(p1 INT) +BEGIN +END; +--connection con2 +SELECT COUNT(*) FROM information_schema.parameters WHERE SPECIFIC_NAME = 'sp1'; +--disconnect con2 +--connection default +DROP PROCEDURE sp1; + +--echo # +--echo # End of 10.4 tests +--echo # diff --git a/sql/sp.cc b/sql/sp.cc index af9c7901c5a..87af91187e7 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -3018,7 +3018,9 @@ Sp_handler::sp_load_for_information_schema(THD *thd, TABLE *proc_table, sp_cache **spc= get_cache(thd); sp_name sp_name_obj(&db, &name, true); // This can change "name" *free_sp_head= 0; - if ((sp= sp_cache_lookup(spc, &sp_name_obj))) + sp= sp_cache_lookup(spc, &sp_name_obj); + + if (sp && !(sp->sp_cache_version() < sp_cache_version())) { return sp; }