What is the most efficient way to store tags in a database?

后端 未结 7 1202
無奈伤痛
無奈伤痛 2020-11-27 09:06

I am implementing a tagging system on my website similar to one stackoverflow uses, my question is - what is the most effective way to store tags so that they may be searche

7条回答
  •  囚心锁ツ
    2020-11-27 09:27

    If you don't mind using a bit of non-standard stuff, Postgres version 9.4 and up has an option of storing a record of type JSON text array.

    Your schema would be:

    Table: Items
    Columns: Item_ID:int, Title:text, Content:text
    
    Table: Tags
    Columns: Item_ID:int, Tag_Title:text[]
    

    For more info, see this excellent post by Josh Berkus: http://www.databasesoup.com/2015/01/tag-all-things.html

    There are more various options compared thoroughly for performance and the one suggested above is the best overall.

提交回复
热议问题