diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 9b95bb00918..8763957de1a 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -2708,6 +2708,16 @@ static inline void binlog_gtid_end_transaction(THD *thd) { (void)mysql_bin_log.gtid_end_transaction(thd); } +static bool thd_has_read_write(THD *thd) { + Ha_trx_info *ha_info = thd->get_transaction()->ha_trx_info(Transaction_ctx::SESSION); + + for (; ha_info; ha_info = ha_info->next()) { + if (ha_info->is_trx_read_write()) return true; + } + + return false; +} + /** Execute command saved in thd and lex->sql_command. @@ -4717,7 +4727,12 @@ finish: } else if (!thd->in_sub_stmt && (thd->lex->sql_command != SQLCOM_CREATE_TABLE || !thd->lex->create_info->m_transactional_ddl)) { - thd->mdl_context.release_statement_locks(); + if (thd->tx_isolation <= ISO_READ_COMMITTED && + !thd_has_read_write(thd)) { + thd->mdl_context.release_transactional_locks(); + } else { + thd->mdl_context.release_statement_locks(); + } } // If the client wishes to have transaction state reported, we add whatever