zoukankan      html  css  js  c++  java
  • Caused by: java.sql.BatchUpdateException: Transaction error, need to rollback. errno:1205 Lock wait timeout exceeded; try restarting transaction

    更新的时候报

    Caused by: java.sql.BatchUpdateException: Transaction error, need to rollback. errno:1205 Lock wait timeout exceeded; try restarting transaction

    update_time=now() where streaming_no=?
    

      

    找半天,给streaming_no加上索引就好了

    mysql> show index from T_VSOP_CUSTOMER_INFO_RECORD
        -> ;
    +-----------------------------+------------+--------------------+--------------+--------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
    | Table                       | Non_unique | Key_name           | Seq_in_index | Column_name  | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
    +-----------------------------+------------+--------------------+--------------+--------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
    | T_VSOP_CUSTOMER_INFO_RECORD |          0 | PRIMARY            |            1 | id           | A         |     2428448 | NULL     | NULL   |      | BTREE      |         |               |
    | T_VSOP_CUSTOMER_INFO_RECORD |          1 | index_streaming_no |            1 | streaming_no | A         |     2671571 | NULL     | NULL   |      | BTREE      |         |               |
    +-----------------------------+------------+--------------------+--------------+--------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
    2 rows in set
    

     

    --未加索引的外键会存在的问题
    1.引起全表锁。
    2.当使用了on delete cascade,而且没有对子表加索引,要从父表中删除多行时,每删除一行就要扫描一次子表。
    3.当你从父表查询子表,你会发现没有索引的话会使查询变慢。


    --什么时候不需要对外键增加索引
    1.不会从父表中删除行。
    2.不会去更新父表的主键。
    3.不会从父表连接到子表。

    如果更新的where条件没有索引 则会产生表锁

  • 相关阅读:
    20162324 2016-2017-2《Java程序设计》课程总结
    Java实验五网络编程与安全
    Java结对编程之挑战出题
    实验四Android开发
    Java四则运算总结
    实验三
    Java结对编程四则运算一周小结
    队列课下作业
    20162325 金立清 S2 W5 C14
    2017-2018-1 我爱学Java 第二周 作业
  • 原文地址:https://www.cnblogs.com/JAYIT/p/6226627.html
Copyright © 2011-2022 走看看