Offering an alternative approach:
I had the same problem at work before. I spent a good week trying to figure out how to do this. As a result, I created a connection table, as you did, but the table contains only unread messages, and does not track the messages read.
Insofar as
- The status quo is "everyone has read all their messages."
- Receiving unread messages (or their number) should be as fast as possible.
- - .
, , , ( *), " " , , - , .
, " " , , . , , "SELECT COUNT(*) FROM unread WHERE user = foo".
, . , , - . . , , . (, , ", " ), .
, .
YMMV, HTH.