Live chat database design, recent contacts need to create separate tables?

The

requirement is something like this
I have a table to record the chat content, and the field looks like this

msgid
from
to
content
time

then I need to show the user"s recent contacts. Theoretically, I can query all the recent contacts from this chat list through sql, but now I need to delete the recent contacts and keep the chat records, that is to say, it is impossible for me to delete the recent contact records by clearing the chat records of the two people.
so do I need to create another list of recent contacts? And then maintain this list of recent contacts while both parties are texting each other?

Mar.20,2021

it is recommended that you create a separate table to save recent contacts.
1. From a functional design point of view, the recent contact is an independent feature that does not rely on chat history, as you have already said.
2. In terms of system performance, there will be a performance bottleneck when the amount of data is large every time the nearest contact is calculated from the chat log table.


Thank you for inviting me. You're on the right track. It depends on your needs, but if you look at your needs, recent contacts need to be recorded for a long time, so it is recommended that you set up a separate table to save the relevant data. And this table does not require many fields, and the impact will not be great. Of course, a less good solution is to directly add a field to the corresponding user table to record the recent contact id in the specified format, but there are many uncertainties that may affect it and are not friendly to later maintenance, so it is not recommended.

Menu