今天顺便看了一下,主要流程就是跟踪为什么begin后事物不会提交,最后发现在:
MYSQL_BIN_LOG::commit 函数中包含这个判断
if (!cache_mngr->trx_cache.is_binlog_empty() &&
ending_trans(thd, all) && !trx_stuff_logged)
如果begin的话ending_trans(thd, all) 将会返回为false,也就不会调用 order_commit流程了。
那么其主要判断就是:
bool ending_single_stmt_trans(THD* thd, const bool all)
{
return (!all && !thd->in_multi_stmt_transaction_mode());
}
下面是源码注释和函数:
Returns TRUE if session is in a multi-statement transaction mode.
OPTION_NOT_AUTOCOMMIT: When autocommit is off, a multi-statement
transaction is implicitly started on the first statement after a
previous transaction has been ended.
OPTION_BEGIN: Regardless of the autocommit status, a multi-statement
transaction can be explicitly started with the statements "STAR