I have an inbox messages (innodb) table set up where "id" is the primary index, auto-increment. Each row is an individual message. I have a second column called "conversation_id" which is an id for a group of messages between sender/receiver. All messages within the conversation will have the same conversation_id number.
Problem: How do I do a MySQL Insert where I find the largest "conversation_id" number and add 1 to it (Max(col) + 1) - and not have the race condition? The race condition is a big issue since hundreds of people will be sending messages every minute, and I do not want multiple users claiming the same "conversation_id" if the send messages all at the same time.
conversationstable with its own auto-incrementing primary key instead? You can then use theidfromconversationsas theconversation_idinmessages. Aconversationstable would also allow you to store any attributes that relate to the whole conversation instead of just to a single message. - Phil Ross