Handling innoDB deadlock

后端 未结 3 613
旧巷少年郎
旧巷少年郎 2021-02-09 06:08

I\'ve been getting a Deadlock found when trying to get lock; try restarting transaction error on my InnoDB tables. Here is the query:

UPDATE views 
         


        
3条回答
  •  北恋
    北恋 (楼主)
    2021-02-09 06:30

    You may have to play some games with the Transaction Isolation/MVCC features

    Option 1) You may want to surround the query in a begin commit block

    BEGIN;
    
    UPDATE views
    SET visit_cnt = visit_cnt + 1
    WHERE visit_day = DATE(NOW())
    AND article_id = '4838';
    
    < Any actions in the trigger would be part of the transaction >
    
    COMMIT;
    

    Option 2) You may want to disable autocommit for your session

    SET autocommit = 0;
    

    Option 3) Change the transaction isolation before launching the query to expose dirty reads

    This one is a stretch !!!

    SET tx_isolation = READ_COMMITTED;
    

    or

    SET tx_isolation = READ_UNCOMMITTED;
    

    Give it a Try and let us all know !!!

提交回复
热议问题