jeudi 13 août 2015

Why is "update foo ... where bar is null" letting multiple callers claim the same row?

I have a fairly basic query:

UPDATE the_table SET col1=[something], col2=[something else] WHERE col1 IS NULL AND col2 IS NULL;

Immediately after issuing the query, the caller does:

SELECT col3 FROM the_table where col1=[something], col2=[something else];

Unfortunately, concurrent callers are claiming the same row.

I'd rather not do a SELECT FOR UPDATE, because the [select, update, select] would involve three rpcs to the database instead of two (which is bad enough.)

I gather that some dialects of sql allow UPDATE the_table WITH(UPDLOCK), but mine (galera/MySQL) does not. I find it appalling that I'd have to go through this many DB hits to execute such a basic concept. I find that most of my searching efforts end on pages that discuss dialects that DO support UPDLOCK.

Where does it go from here?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire