mysql - Should I use selects before updates to reduce rollbacks? -


let's have table of items counter counts how many have of each item. table want check if have 1 of item , 2 of item b , decrease counter if do. if don't have enough of both items neither of them touched.

what best solution this?

solution 1

start transaction , try update table count >= required amount. if 1 of queries not update something, use rollback.

solution 2

use select first check if items there, in solution 1.

what best solution?

while solution 1 cleanest solution i'm still worried innodb rollback performance not good. solution 1 not use selects, when items exist best solution.

but if talking hundred items , high fail ratio(does not have enough of items)? selecting first check if items exists update not have run if items missing , rollback can skipped.

what think best solution in such situation need update lot of stuff, it's or nothing, , result nothing? 1, 2 or else, , why?

use solution 2. rollback meant used recover unexpected failures, not part of normal processing.


Comments