mysql不提交事务意味着什么_MySQL:begin后事务为什么不提交-阿里云开发者社区...

MySQL中,BEGIN后事务不会自动提交,关键在于MYSQL_BIN_LOG::commit函数的判断。当ending_trans(thd, all)返回false,事务不会执行order_commit流程。主要判断条件是session是否处于多语句事务模式,这通过检查option_bits的OPTION_NOT_AUTOCOMMIT和OPTION_BEGIN位来确定。trans_begin函数设置OPTION_BEGIN标志,并可能开启一致性快照,从而使得事务保持未提交状态。" 133424136,19673107,组件与模块的差异解析,"['编程', '组件化', '模块化']
摘要由CSDN通过智能技术生成

今天顺便看了一下,主要流程就是跟踪为什么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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值