Many database rows vs one comma separated values row

后端 未结 4 1515
萌比男神i
萌比男神i 2021-01-04 13:02

I\'m creating a table for allowing website users to become friends. I\'m trying to determine which is the best table design to store and return a user\'s friends. The goal i

相关标签:
4条回答
  • 2021-01-04 13:20

    The first method is better in just about every way. Not only will you utilize your DBs indexes to find records faster, it will make modification far far easier.

    0 讨论(0)
  • 2021-01-04 13:23

    First method is definitely better. It's what makes relational databases great :)

    It will allow you to search for and group by much more specific criteria than the 2nd method.

    Say you wanted to write a query so users could see who had them as a friend. The 2nd method would require you to use IN() and would be much slower than simply using JOINS.

    0 讨论(0)
  • 2021-01-04 13:30

    Use the power of the relational database. Definitely go with the first approach. MySQL is faster than you think, and it regularly deals with VERY large datasets.

    0 讨论(0)
  • 2021-01-04 13:41

    Breaking from 1st normal form is usually not desirable because

    1. Easy to Orpahned ids
    2. Easy to insert invalid data types
    3. Updates can require full table scans
    4. Increases concurrency issues
    5. No way to create the key (user_id, friend_id)
    0 讨论(0)
提交回复
热议问题