I'm making a web application which also includes notification functionality - a user may get one or more notifications (messages) from the system or other users at any time.
When there are new (unread) messages they will be displayed to the user in a popup window. The messages will be short (most of the time one sentence each, and only a few at a time), so they will be displayed completely and all at once.
The user will then have a "Dismiss" button which will mark these messages as "Read".
My question comes about implementing this "Dismiss" button. One approach would be to remember the ID's of the messages and mark each one individually. However that would require one query per message.
A better approach would be to remember the smallest ID and the largest ID, and then issue an UPDATE WHERE ID between XXX and YYY
. But is this safe? Can I be certain that the IDs of new rows INSERTED in the table will be larger then these IDs? Are there no exotic conditions that might foil this approach? (clustering? load balancing? replication? something else?)