Skip to content

Commit cb83b19

Browse files
committed
Bug#25571453: ASSERTION `MDL_CHECKER::IS_READ_LOCKED(M_THD, *OBJECT)' FAILED
The assertion was triggered when executing TRUNCATE TABLE if the truncated table was used by a view in a different schema and the view was locked with LOCK TABLES. In that case the schema containing the truncated table was not locked. This caused the assert to be triggered by the data dictionary code as a schema lock is required in order to check if the table has been locked properly. The problem had no ill effects on release builds. This patch fixes the problem by making sure that the schema containing the truncated table is locked.
1 parent b3a3501 commit cb83b19

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

mysql-test/r/truncate.result

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,16 @@ HANDLER t1 READ FIRST;
159159
ERROR 42S02: Unknown table 't1' in HANDLER
160160
DROP TABLE t1;
161161
# End of 6.0 tests
162+
#
163+
# Bug#25571453: ASSERTION `MDL_CHECKER::IS_READ_LOCKED(M_THD, *OBJECT)'
164+
# FAILED
165+
#
166+
CREATE TABLE t1(a INT);
167+
CREATE SCHEMA s1;
168+
CREATE VIEW s1.v1 AS SELECT * FROM t1;
169+
LOCK TABLE s1.v1 WRITE;
170+
TRUNCATE TABLE t1;
171+
UNLOCK TABLES;
172+
DROP VIEW s1.v1;
173+
DROP TABLE t1;
174+
DROP SCHEMA s1;

mysql-test/t/truncate.test

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,21 @@ DROP TABLE t1;
175175

176176
--echo # End of 6.0 tests
177177

178+
--echo #
179+
--echo # Bug#25571453: ASSERTION `MDL_CHECKER::IS_READ_LOCKED(M_THD, *OBJECT)'
180+
--echo # FAILED
181+
--echo #
182+
183+
CREATE TABLE t1(a INT);
184+
CREATE SCHEMA s1;
185+
CREATE VIEW s1.v1 AS SELECT * FROM t1;
186+
LOCK TABLE s1.v1 WRITE;
187+
# This used to cause an assert to be triggered.
188+
TRUNCATE TABLE t1;
189+
UNLOCK TABLES;
190+
DROP VIEW s1.v1;
191+
DROP TABLE t1;
192+
DROP SCHEMA s1;
178193

179194
########################################
180195
##### WL#7554 set schema `test` back to what it was

sql/sql_truncate.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@ bool Sql_cmd_truncate_table::truncate_table(THD *thd, TABLE_LIST *table_ref)
489489
DBUG_ASSERT((!table_ref->table) ||
490490
(table_ref->table && table_ref->table->s));
491491

492+
dd::Schema_MDL_locker mdl_locker(thd);
492493
dd::cache::Dictionary_client::Auto_releaser releaser(thd->dd_client());
493494

494495
/* Initialize, or reinitialize in case of reexecution (SP). */
@@ -542,6 +543,9 @@ bool Sql_cmd_truncate_table::truncate_table(THD *thd, TABLE_LIST *table_ref)
542543
}
543544
else /* It's not a temporary table. */
544545
{
546+
if (mdl_locker.ensure_locked(table_ref->db))
547+
DBUG_RETURN(true);
548+
545549
if (lock_table(thd, table_ref, &hton))
546550
DBUG_RETURN(TRUE);
547551

0 commit comments

Comments
 (0)