diff --git a/mysql-test/main/flush.result b/mysql-test/main/flush.result index 941dc63e3da..c73125e3420 100644 --- a/mysql-test/main/flush.result +++ b/mysql-test/main/flush.result @@ -606,6 +606,17 @@ drop view v1, v2; drop table t1; disconnect con1; # +# MDEV-25837 Assertion `thd->locked_tables_mode == LTM_NONE' failed in Locked_tables_list::init_locked_tables. +# +CREATE FUNCTION f() RETURNS INTEGER RETURN 1; +CREATE TABLE t (a INT); +CREATE VIEW v AS SELECT 2 FROM t WHERE f() < 3; +FLUSH TABLE v WITH READ LOCK; +UNLOCK TABLES; +DROP VIEW v; +DROP FUNCTION f; +DROP TABLE t; +# # Test FLUSH THREADS # set @save_thread_cache_size=@@global.thread_cache_size; diff --git a/mysql-test/main/flush.test b/mysql-test/main/flush.test index 97830238b0e..f546b6f1fca 100644 --- a/mysql-test/main/flush.test +++ b/mysql-test/main/flush.test @@ -722,6 +722,19 @@ drop view v1, v2; drop table t1; disconnect con1; +--echo # +--echo # MDEV-25837 Assertion `thd->locked_tables_mode == LTM_NONE' failed in Locked_tables_list::init_locked_tables. +--echo # + +CREATE FUNCTION f() RETURNS INTEGER RETURN 1; +CREATE TABLE t (a INT); +CREATE VIEW v AS SELECT 2 FROM t WHERE f() < 3; +FLUSH TABLE v WITH READ LOCK; + +UNLOCK TABLES; +DROP VIEW v; +DROP FUNCTION f; +DROP TABLE t; --echo # --echo # Test FLUSH THREADS diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 51e4bcad16b..e46a8587503 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -5553,7 +5553,8 @@ bool lock_tables(THD *thd, TABLE_LIST *tables, uint count, uint flags) DEBUG_SYNC(thd, "after_lock_tables_takes_lock"); if (thd->lex->requires_prelocking() && - thd->lex->sql_command != SQLCOM_LOCK_TABLES) + thd->lex->sql_command != SQLCOM_LOCK_TABLES && + thd->lex->sql_command != SQLCOM_FLUSH) { /* We just have done implicit LOCK TABLES, and now we have