Do the index existence check inside the transaction