mysql+after+commit_MYSQL下read committed 和repeatable read级别下一致性非锁定读笔记+实测...

14.2.2.2 Consistent Nonlocking Reads

Aconsistent readmeans thatInnoDBuses multi-versioning to present to a query a snapshot of the database at a point in time. The query sees the changes made by transactions that committed before that point of time, and no changes made by later or uncommitted transactions. The exception to this rule is that the query sees the changes made by earlier statements within the same transaction. This exception causes the following anomaly: If you update some rows in a table, aSELECTsees the latest version of the updated rows, but it might also see older versions of any rows. If other sessions simultaneously update the same table, the anomaly means that you might see the table in a state that never existed in the database.

If the transactionisolation levelisREPEATABLE READ(the default level), all consistent reads within the same transaction read the snapshot established by the first such read in that transaction. You can get a fresher snapshot for your queries by committing the current transaction and after that issuing new queries.

WithREAD COMMITTEDisolation level, each consistent read within a transaction sets and reads its own fresh snapshot

我们在可重复读下做个实验:

1289872619687976960.htm

同时开启两个事务,打开两个mysql连接,分别begin;

事务A:         begin;

select count(*) from Account where user_id = 'a';  //此时查到一条记录

abfa7dbac0ad4d96af83ce08e68df49a.png

事务B begin;

1289872619687976960.htm

此时在事务B中:

update Account set user_id = 'p_1' where user_id = 'a';

305cfc58808d41babd4f93fa8e658410.png

1289872619687976960.htm

此时在事务A中继续执行相同条件查询,结果和上一张图片相同(B未提交,当然看不到了),之后,B中commit

1289872619687976960.htm

我们再来A中按照user_id = 'a' 和user_id = 'p_1'两种方式进行查询。

5ecdca9468d94b27a4d07fdbde729746.png

1289872619687976960.htm

1289872619687976960.htm

从这里可以看到,在A中,一致性非锁定读读取的仍然是同一个快照版本,即旧的版本,此时存在新的版本,user_id 为'p_1',这时候我们按照user_id=‘p_1’查不到数据,但是,在同一个事务中,我们不是select,而用update,就会查到数据,因为此时没有使用一致性非锁定读,select对应的是旧快照的版本,而update修改的确是最新的版本,我们继续执行update

先确认下查不到数据

3b4e86aba5a91c1cc776e4d5608eed6b.png

1289872619687976960.htm

此时执行更新:

b74ed7747af746e999211bb97056bb60.png

1289872619687976960.htm

这是正如上面所说,update竟然是有数据的。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
问题: this.$store.commit('setUrl', this.$store.state.HOST + url)失效 回答: 这个问题可能是由于以下几个原因导致的。首先,你需要确保在调用`this.$store.commit('setUrl', this.$store.state.HOST + url)`之前,已经正确地引入了Vuex并创建了store配置项。你可以参考引用\[3\]中的代码示例来确保正确引入和创建store。其次,你需要确认`setUrl`这个mutation是否已经在Vuex的store中正确定义。你可以在store的mutations中添加一个名为`setUrl`的mutation,并在其中更新state中的url值。最后,你需要检查`this.$store.state.HOST`和`url`的值是否正确。你可以使用`console.log`来打印这两个值,以确保它们的正确性。如果问题仍然存在,请提供更多的代码和错误信息,以便我能够更好地帮助你解决问题。 #### 引用[.reference_title] - *1* *2* [Vue 2.x 常用知识点笔记(万字笔记)](https://blog.csdn.net/m0_67266042/article/details/123367905)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [前端-Vue.js从入门到精通基础笔记(理论+实操+知识点速查)](https://blog.csdn.net/qq_39514248/article/details/125623493)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值