tengiz wrote:vc wrote:I thought you'd had a neater trick up your sleeve If one uses the true SERIALIZABLE, one should also be aware that the entire table will be locked, as the result of 'insert select max(id)+1', both for writes *and* reads. Here, SERIALIZABLE becomes SERIAL, nothing to be proud of, really.
No, that's no true. If there is a unique key (othewise select max(id) would be painful enough by istelf for large tables) on id and the DBMS supports key-range locking plus the optimizer is smart enough you can get away with only a couple of key-ranges being locked.
Yes, of course, with a unique index which is used as the max argument you'll avoid locking the entire table. In any other arrangement (non-unique indexes/no indexes), the entire table will be locked. Even with unique indexes, the locked subset of the table will be unavailable for reads.
VC