Mysql normal relationship table for the associated realtionship table

I have a question about the relationship between two tables.

Let's say we have table users and links.

users
+++++++++
id name
1  name1
2  name2
3  name3
+++++++++

links
+++++++++
id link
1  link1
2  link1
3  link1
+++++++++

Now the usual way to link these two to the name_links table. For instance:

name_links
++++++++++++
uid  lid
1    1
1    3
2    3
2    1
2    2
3    2
++++++++++++

Now I was wondering if it would be nice to make a table like this

name_links
++++++++++++
uid  lid
1    1,3
2    1,2,3
3    2
++++++++++++

The pros and cons that I can think of are as follows:

pros1:

You will always search by indexes, for faster queries select an example where uid = 1, and then select links 1.3. Both are indexes, so they will be a fast load.

If you have 1000 users and each of them has 20 links, this means that you need to go through 20,000 entries to get all the links (I think I'm not sure about that). Using this method, you accept only one index, and you're done.

cons1:

name_links, , 2 2, :
  + 1
  +
  +

, , .

cons2:

- 2, , , , .

, , , , .

, . ? , . .

, !

+1
3

:

  • (FIND_IN_SET )

  • , FOREIGN KEYs ( InnoDB)

  • -

, , , , .

, , , .

links , SET.

+3

, . , , , 3, .

, , "--", , , . , , , time_linked name_links.

0

I'm by no means a database expert, but the second option seems like a very bad idea to me. Even if you are lucky, you will never need to, say, search for a link in the name_link table, to do anything with links will be a lot of (unnecessary, IMO) additional work.

0
source

Source: https://habr.com/ru/post/1734713/


All Articles