mysql> show create table tidb_mdl_view\G
*************************** 1. row ***************************
View: tidb_mdl_view
Create View: CREATE ALGORITHM=UNDEFINED DEFINER=``@`` SQL SECURITY DEFINER VIEW `tidb_mdl_view` (`job_id`, `db_name`, `table_name`, `query`, `session_id`, `txnstart`, `SQL_DIGESTS`) AS (SELECT `job_id` AS `job_id`,`db_name` AS `db_name`,`table_name` AS `table_name`,`query` AS `query`,`session_id` AS `session_id`,`txnstart` AS `txnstart`,TIDB_DECODE_SQL_DIGESTS(`all_sql_digests`, 4096) AS `SQL_DIGESTS` FROM ((`information_schema`.`ddl_jobs`) JOIN `information_schema`.`cluster_tidb_trx`) JOIN `information_schema`.`cluster_processlist` WHERE (`ddl_jobs`.`state`!=_UTF8MB4'synced' AND `ddl_jobs`.`state`!=_UTF8MB4'cancelled') AND FIND_IN_SET(`ddl_jobs`.`table_id`, `cluster_tidb_trx`.`related_table_ids`) AND `cluster_tidb_trx`.`session_id`=`cluster_processlist`.`id`)
character_set_client: utf8mb4
collation_connection: utf8mb4_bin
1 row in set (0.00 sec)
`ddl_jobs`.`state`!=_UTF8MB4'synced' AND `ddl_jobs`.`state`!=_UTF8MB4'cancelled'
mdl视图表定义存在的 bug,它 job state 只过滤了 ‘sync’ 和 ‘cancelled’,还有一些其他代表已经结束的状态例如上面显示的 ‘done’ 没有过滤掉,导致错误的视图结果。