I have to optimize my little-big database, because it's too slow, maybe we'll find another solution together. 

First of all let's talk about data that are stored in the database. There are two objects: `users` and let's say `messages`

*Users*

There is something like that:

```
 +----+---------+-------+-----+
 | id | user_id | login | etc |
 +----+---------+-------+-----+
 |  1 |  100001 |   A   | ....|
 |  2 |  100002 |   B   | ....|
 |  3 |  100003 |   C   | ....|
 |... |  ...... |  ...  | ....|
 +----+---------+-------+-----+

```

There is no problem inside this table. (Don't afraid of `id` and `user_id`. `user_id` is used by another application, so it has to be here.)

*Messages* 

And the second table has some problem. Each user has for example messages like this:

```
 +----+---------+------+----+
 | id | user_id | from | to |
 +----+---------+------+----+
 |  1 |   1     | aab  | bbc|
 |  2 |   2     | vfd  | gfg|
 |  3 |   1     | aab  | bbc|
 |  4 |   1     | fge  | gfg|
 |  5 |   3     | aab  | gdf|
 |... |  ...... |  ... | ...|
 +----+---------+------+----+

```

There is no need to `edit` messages, but there should be an opportunity to updated the list of messages for the user. For example, an external service sends all user's messages to the db and the list has to be updated. 
And the most important thing is that there are about 30 Mio of users and average user has 500+ of messages. Another problem that I have to search through the field `from` and calculate number of matches. I designed a simple SQL query with join, but it takes too much time to get the data.

So...it's quite big amount of data. I decided not to use RDS (I used Postgresql) and decided to move to databases like `Clickhouse` and so on. 

However I faced with a problem that for example `Clickhouse` doesn't support `UPDATE` statement. 

To resolve this issues I decided to store messages as one row. So the table `Messages` should be like this: 

```
                 Here I'd like to store messages in JSON format
                 {"from":"aaa", "to":bbe"}
                 {"from":"ret", "to":fdd"}
                 {"from":"gfd", "to":dgf"}
                    ||                        
                    \/
 +----+---------+----------+------+    And there I'd like to store the 
 | id | user_id | messages | hash | <= hash of the messages. 
 +----+---------+----------+------+   

```

I think that full-text search inside the `messages` column will save some time resources and so on. 

Do you have any ideas? :)