Ways to implement tags - pros and cons of each

后端 未结 5 1675
野趣味
野趣味 2021-01-30 05:33

Related

Using SO as an example, what is the most sensible way to manage tags if you anticipate they will change often?

Way 1: Seriously denormalized (comma delim

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-30 06:06

    I personally favour solution #3.

    I don't agree that solution #1 is easier to mantain. Think of the situation where you have to change the name of a tag.

    Solution #1:

    UPDATE posts SET tag = REPLACE(tag, "oldname", "newname") WHERE tag LIKE("%oldname%")
    

    Solution #3:

    UPDATE tags SET tag = "newname" WHERE tag = "oldname" 
    

    The first one is way heavier.

    Also you have to deal with the commas when deleting tags (OK, it's easily done but still, more difficult that just deleting one line in the taggings table)

    As for solution #2... is neither fish nor fowl

提交回复
热议问题