E
E
exxagw2016-10-23 05:01:55
PHP
exxagw, 2016-10-23 05:01:55

How to design a database for dialogs?

The dialogue has from 2 users (4, 5, 10 people, etc.).
Before, I wrote the dialog in "users" people separated by commas, i.e.:
dialog_id | users
1 | 2,3,4,5
And when displaying his dialogs, he used the following construction:

WHERE users LIKE '{$user_id},%' OR  users LIKE '%,{$user_id}' OR  users LIKE '%,{$user_id},%'

Are there more "beautiful" methods of communication between the dialog and the user?
Option to create another table dilog_users
dialog_id | user_id
1 | 2
1 | 3
1 | 4
1 | 5
But it seems to me that this will not really inflate the database, and there will not be much difference.
ps dialogs in php and a node for sockets (well, parts of the logic)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
B
bnytiki, 2016-10-23
@bnytiki

Are there more "beautiful" methods of communication between the dialog and the user?
Option to create another table dilog_users
dialog_id | user_id
1 | 2
1 | 3
1 | 4
1 | 5
But it seems to me that this will not really inflate the database, and there will not be much difference.

MySQL is a RELATIONAL DBMS.
It is absolutely normal and completely natural for her to store data in this way.
There is no need to worry about DBMS bloat - modern DBMSs store billions of rows and work with them quickly.
The LIKE method is absolutely unnatural for relational DBMS, which, as the DBMS "bloats", will lead to extremely slow operation.

I
index0h, 2016-10-23
@index0h

LIKE is a wildly slow operation, it should be used in extremely rare cases, and then only for small tables.
Your MANY_TO_MANY option below is orders of magnitude better.

A
Alexander Taratin, 2016-10-23
@Taraflex

Go PostgreSQL
https://www.postgresql.org/docs/9.1/static/arrays.html
blog.lerner.co.il/looking-postgresql-arrays

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question