I have situation here about Innodb locking.
In transaction, We select from XYZ transaction table values and then updates it
SELECT ID INTO vID FROM XYZ WHERE FLAG = 1 ORDER BY TIME LIMIT 1 FOR UPDATE;
UPDATE XYZ SET FLAG=0 WHERE ID = vID;
UPDATE XYZ SET FLAG=1 WHERE ID = 2;
are keep on getting deadlock due to index locking, there is index on
FLAG, we can allow phantom read in session 1, we tried with READ
COMMITTED but still same, I think issue with next-key locking.
If i do following in SESSION 1 would that help in locking or still it would lock index.
UPDATE XYZ SET FLAG=0,ID=(@oID:=ID) ORDER BY TIME LIMIT 1;
SELECT @oID AS ID;