mysql事务,索引产生死锁的问题

请求并发访问这个接口

 

实现类如下

 

 

第一条sql:select <include refid="Base_Column_List" />

from t_bank_card b

where account_id = #{accountId,jdbcType=VARCHAR} and card_no=#{cardNo,jdbcType=VARCHAR} for update

 

 

 

第二条sql:<update id="updateBankCardStatus" parameterType="com.credit.account.model.BankCard" >

  update t_bank_card

  <set>

    <if test="status != null" >

      status = #{status,jdbcType=VARCHAR},

    </if>

    <if test="updateTime != null" >

      update_time = #{updateTime,jdbcType=TIMESTAMP},

    </if>

    <if test="protocolNo != null">

      protocol_no = #{protocolNo,jdbcType=VARCHAR}

    </if>

  </set>

  where account_id = #{accountId,jdbcType=VARCHAR} and status = #{updateStatus,jdbcType=VARCHAR}

</update>

 

 

组合索引

 

 

当第一个线程执行完select for update,第二个线程还在等待执行select for update, 第一个线程执行完update之后,第二个线程还没有执行完select for update就报错了:

 

org.springframework.dao.DeadlockLoserDataAccessException:

### Error querying database.  Cause: com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException: Unknown error 1213

### The error may exist in file [D:\new\credit-service\target\classes\mapper\account\BankCardMapper.xml]

### The error may involve com.credit.account.dao.BankCardMapper.selectByAccountIdAndCardNo-Inline

### The error occurred while setting parameters

### SQL: select       b.id, b.account_id,b.card_no, b.status, b.bank_code, b.yborderid,b.create_time,b.card_top,b.card_last,b.update_time,b.bank_name,b.protocol_no         from t_bank_card b     where account_id = ? and card_no=? for update

### Cause: com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException: Unknown error 1213

; Unknown error 1213; nested exception is com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException: Unknown error 1213

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值