Skip to content
  • Maheedhar PV's avatar
    cbd87693
    Bug#30194841 INSERT ON DUPLICATE KEY UPDATE UPDATES THE WRONG ROW · cbd87693
    Maheedhar PV authored
    Cause
    
    When multiple sessions are inserting into a table having
    auto-increment column, unique key constraint using IODKU (without
    having explicit values for the auto-increment column) into a table,
    the insert can fail with the unique index violation.
    
    In such a case, the failing insert has a valid current-id for the
    auto-increment column but an old/invalid value (the interleaving
    session has used up the id and the failing session has not yet updated
    its own next auto-increment id) as the next-id. This failed insert
    updates the correct row(the row violating unique key).
    
    The invalid value of next-id of the auto-increment column is saved and
    reused as the current-id for the subsequent inserts. These subsequent
    inserts, without having explicit values for the auto-increment column,
    end up updating rows because of the auto-increment key violation
    during the insert.
    
    Fix
    
    When an insert of a IODKU fails, retain the auto-increment id of the
    failed row (current-id, not the next-id) to be used for next insert.
    
    Change-Id: I7df17c90992b3658ced6d6b2a89e50546c4ce5a9
    cbd87693
    Bug#30194841 INSERT ON DUPLICATE KEY UPDATE UPDATES THE WRONG ROW
    Maheedhar PV authored
    Cause
    
    When multiple sessions are inserting into a table having
    auto-increment column, unique key constraint using IODKU (without
    having explicit values for the auto-increment column) into a table,
    the insert can fail with the unique index violation.
    
    In such a case, the failing insert has a valid current-id for the
    auto-increment column but an old/invalid value (the interleaving
    session has used up the id and the failing session has not yet updated
    its own next auto-increment id) as the next-id. This failed insert
    updates the correct row(the row violating unique key).
    
    The invalid value of next-id of the auto-increment column is saved and
    reused as the current-id for the subsequent inserts. These subsequent
    inserts, without having explicit values for the auto-increment column,
    end up updating rows because of the auto-increment key violation
    during the insert.
    
    Fix
    
    When an insert of a IODKU fails, retain the auto-increment id of the
    failed row (current-id, not the next-id) to be used for next insert.
    
    Change-Id: I7df17c90992b3658ced6d6b2a89e50546c4ce5a9
Loading