There are several discussions about messaging systems but mostly related to email structure. How can be the most efficient way for members messaging in a normalized database?
I am thinking of creating a messages table with five columns:
ID (PRIMARY KEY)
First_Person (FK user_id)
Second_Person (FK user_id)
Message
date
My worry is about reading this large table.
finding all message for a person (e.g. user_id 876)
SELECT * FROM messages WHERE First_Person='876' OR Second_Person='876'
and communications between two persons
SELECT * FROM messages WHERE (First_Person='876' OR Second_Person='876')
AND (First_Person='1500' OR Second_Person='1500') ORDER DESC BY date
Since this kind of messaging is like chat, for thousands of members, this table can grow to billions of row (not millions). Then, it is efficient to search for messages in such a large table?