`search` should only clear `KEY_SET` if the search fails.  Is that really possible in this case?

More generally, why bother with the read-modify-write?  Wouldn't a random value work just as well, as long as the same value appears in all the tables?