From 5511e8ed5941e3b5a7687f87a1fb4fa75815ee7b Mon Sep 17 00:00:00 2001 From: Oleksandr Byelkin Date: Mon, 5 Mar 2018 17:43:30 +0100 Subject: [PATCH 1/4] MDEV-15328: MariaDB 10.2.13 Crashes upon CALL PROCEDURE PARAM LAST_INSERT_ID () There is not current SELECT during assigning SP parameters, do not use it if current_select is empty. --- mysql-test/r/query_cache.result | 19 +++++++++++++++++++ mysql-test/r/sp.result | 8 ++++++++ mysql-test/t/query_cache.test | 15 +++++++++++++++ mysql-test/t/sp.test | 10 ++++++++++ sql/sql_lex.h | 29 ++++++++++++++++------------- 5 files changed, 68 insertions(+), 13 deletions(-) diff --git a/mysql-test/r/query_cache.result b/mysql-test/r/query_cache.result index eb9b1d16011..ee734845a9e 100644 --- a/mysql-test/r/query_cache.result +++ b/mysql-test/r/query_cache.result @@ -2168,6 +2168,25 @@ show status like "Qcache_hits"; Variable_name Value Qcache_hits 1 drop table t1; +# +# MDEV-15328: MariaDB 10.2.13 Crashes upon CALL PROCEDURE PARAM +# LAST_INSERT_ID () +# (part 2, part 1 is in sp.test) +# +create table t1 (a int); +insert into t1 values (1); +CREATE FUNCTION foo (i INT UNSIGNED ) RETURNS int deterministic RETURN 1; +show status like "Qcache_queries_in_cache"; +Variable_name Value +Qcache_queries_in_cache 0 +SELECT foo( LAST_INSERT_ID() ) from t1; +foo( LAST_INSERT_ID() ) +1 +show status like "Qcache_queries_in_cache"; +Variable_name Value +Qcache_queries_in_cache 0 +DROP FUNCTION foo; +drop table t1; restore defaults SET GLOBAL query_cache_type= default; SET GLOBAL query_cache_size= default; diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result index d99780ad2ee..274727d58c4 100644 --- a/mysql-test/r/sp.result +++ b/mysql-test/r/sp.result @@ -8335,3 +8335,11 @@ ERROR 42S22: Unknown column 'name2' in 'field list' drop procedure p1; drop procedure p2; drop procedure p3; +# +# MDEV-15328: MariaDB 10.2.13 Crashes upon CALL PROCEDURE PARAM +# LAST_INSERT_ID () +# (part 1, part 2 is in query_cache.test) +# +CREATE PROCEDURE foo ( IN i INT UNSIGNED ) BEGIN END; +CALL foo( LAST_INSERT_ID() ); +DROP PROCEDURE foo; diff --git a/mysql-test/t/query_cache.test b/mysql-test/t/query_cache.test index c354032bc36..1b1e24bc6f4 100644 --- a/mysql-test/t/query_cache.test +++ b/mysql-test/t/query_cache.test @@ -1767,6 +1767,21 @@ show status like "Qcache_inserts"; show status like "Qcache_hits"; drop table t1; +--echo # +--echo # MDEV-15328: MariaDB 10.2.13 Crashes upon CALL PROCEDURE PARAM +--echo # LAST_INSERT_ID () +--echo # (part 2, part 1 is in sp.test) +--echo # + +create table t1 (a int); +insert into t1 values (1); +CREATE FUNCTION foo (i INT UNSIGNED ) RETURNS int deterministic RETURN 1; +show status like "Qcache_queries_in_cache"; +SELECT foo( LAST_INSERT_ID() ) from t1; +show status like "Qcache_queries_in_cache"; +DROP FUNCTION foo; +drop table t1; + --echo restore defaults SET GLOBAL query_cache_type= default; SET GLOBAL query_cache_size= default; diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test index 68a0c060906..529ebd4736a 100644 --- a/mysql-test/t/sp.test +++ b/mysql-test/t/sp.test @@ -9840,3 +9840,13 @@ call p3(); drop procedure p1; drop procedure p2; drop procedure p3; + +--echo # +--echo # MDEV-15328: MariaDB 10.2.13 Crashes upon CALL PROCEDURE PARAM +--echo # LAST_INSERT_ID () +--echo # (part 1, part 2 is in query_cache.test) +--echo # + +CREATE PROCEDURE foo ( IN i INT UNSIGNED ) BEGIN END; +CALL foo( LAST_INSERT_ID() ); +DROP PROCEDURE foo; diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 88462477de9..6d281930d1f 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -2902,21 +2902,24 @@ public: { safe_to_cache_query= 0; - /* - There are no sense to mark select_lex and union fields of LEX, - but we should merk all subselects as uncacheable from current till - most upper - */ - SELECT_LEX *sl; - SELECT_LEX_UNIT *un; - for (sl= current_select, un= sl->master_unit(); - un != &unit; - sl= sl->outer_select(), un= sl->master_unit()) + if (current_select) // initialisation SP variables has no SELECT { - sl->uncacheable|= cause; - un->uncacheable|= cause; + /* + There are no sense to mark select_lex and union fields of LEX, + but we should merk all subselects as uncacheable from current till + most upper + */ + SELECT_LEX *sl; + SELECT_LEX_UNIT *un; + for (sl= current_select, un= sl->master_unit(); + un != &unit; + sl= sl->outer_select(), un= sl->master_unit()) + { + sl->uncacheable|= cause; + un->uncacheable|= cause; + } + select_lex.uncacheable|= cause; } - select_lex.uncacheable|= cause; } void set_trg_event_type_for_tables(); From 248e5d01a57d4d3783081112ce4852593dfe3742 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Mon, 12 Mar 2018 18:29:31 +0000 Subject: [PATCH 2/4] MDEV-14581 Warning info not cleared when caching THD In thread caching code, clear THD's warnings before reuse. --- mysql-test/t/warnings-master.opt | 2 +- mysql-test/t/warnings.test | 12 ++++++++++++ sql/mysqld.cc | 4 ++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/mysql-test/t/warnings-master.opt b/mysql-test/t/warnings-master.opt index 21356507809..1aa6001465b 100644 --- a/mysql-test/t/warnings-master.opt +++ b/mysql-test/t/warnings-master.opt @@ -1 +1 @@ ---loose-skip-innodb +--loose-skip-innodb --thread-handling=one-thread-per-connection diff --git a/mysql-test/t/warnings.test b/mysql-test/t/warnings.test index 573f3c538c7..9360d32f93d 100644 --- a/mysql-test/t/warnings.test +++ b/mysql-test/t/warnings.test @@ -286,3 +286,15 @@ SHOW WARNINGS; DROP TABLE t1; DROP FUNCTION f1; + +# MDEV-14581 Warning info not cleared when caching THD +connect (con1,localhost,root,,); +SELECT TIME('10:10:10.11111111111'); +disconnect con1; + +connect (con2,localhost,root,,); +SHOW WARNINGS; +disconnect con2; + +connection default; + diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 1cf15abebdc..6783231022c 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -2961,6 +2961,10 @@ static bool cache_thread(THD *thd) _db_pop_(); #endif + /* Clear warnings. */ + if (!thd->get_stmt_da()->is_warning_info_empty()) + thd->get_stmt_da()->clear_warning_info(thd->query_id); + set_timespec(abstime, THREAD_CACHE_TIMEOUT); while (!abort_loop && ! wake_thread && ! kill_cached_threads) { From 68482a22155f1b741d0c19cff87292688ce17fc4 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Mon, 12 Mar 2018 18:38:40 +0000 Subject: [PATCH 3/4] MDEV-14581 - changded .result file --- mysql-test/r/warnings.result | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mysql-test/r/warnings.result b/mysql-test/r/warnings.result index 3f4f62dc935..596cf5f2795 100644 --- a/mysql-test/r/warnings.result +++ b/mysql-test/r/warnings.result @@ -357,3 +357,15 @@ Error 1062 Duplicate entry '11' for key 'a' DROP TABLE t1; DROP FUNCTION f1; +connect con1,localhost,root,,; +SELECT TIME('10:10:10.11111111111'); +TIME('10:10:10.11111111111') +10:10:10.111111 +Warnings: +Note 1292 Truncated incorrect time value: '10:10:10.11111111111' +disconnect con1; +connect con2,localhost,root,,; +SHOW WARNINGS; +Level Code Message +disconnect con2; +connection default; From 9d95b8665a3d87ab857e77e220effc64454eb881 Mon Sep 17 00:00:00 2001 From: Alexey Botchkov Date: Mon, 12 Mar 2018 23:43:42 +0400 Subject: [PATCH 4/4] MDEV-15217 Assertion `thd->transaction.xid_state.xid.is_null()' failed in trans_xa_start. test fixed. --- mysql-test/r/xa.result | 1 - mysql-test/t/xa.test | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/mysql-test/r/xa.result b/mysql-test/r/xa.result index 782be3834d1..6ae4a06399c 100644 --- a/mysql-test/r/xa.result +++ b/mysql-test/r/xa.result @@ -282,7 +282,6 @@ INSERT INTO t1 SELECT * FROM t2; connection default; REPLACE INTO t2 SELECT * FROM t2; connection con1; -ERROR 40001: Deadlock found when trying to get lock; try restarting transaction disconnect con1; connect con2,localhost,root,,test; INSERT INTO t3 VALUES (1); diff --git a/mysql-test/t/xa.test b/mysql-test/t/xa.test index 85a792822dd..58ad1caaeef 100644 --- a/mysql-test/t/xa.test +++ b/mysql-test/t/xa.test @@ -414,7 +414,7 @@ INSERT INTO t1 SELECT * FROM t2; REPLACE INTO t2 SELECT * FROM t2; --connection con1 ---error ER_LOCK_DEADLOCK +--error 0, ER_LOCK_DEADLOCK, ER_LOCK_WAIT_TIMEOUT --reap --disconnect con1