Database Design for tags/tags

Source: Internet
Author: User

The tag/tag system can improve the intelligent matching degree of information for a system without talking about semantic networks. The network bookmarks delicious, and the tag system is doing well, through user tags and popular tags, people can easily find information of interest and organize information conveniently. Then how does the database system design such tag tags?

Phillips Keller proposed four solutions and tested MySQL performance:

Basically, these four solutions are:

1. A table contains a tags field, which stores tags separated by spaces or commas. The disadvantage is that the length is limited, the number of tags is limited, and the query like '% ABC %' is inefficient.

2. Same as above, full-text indexing is supported, or query using the CE Index

3. Two tables. The second is the tags table, which stores the foreign key and Tag Name of the first table. The number of instances in the first solution is limited.

4. three tables, the second tags table, and the third joined table, typical 3nf, the most common design. The tag supports a tree level. The disadvantage is that the joined table will be very large if the data volume is tens of millions!

There are also the fifth and sixth solutions, such as adding a cache layer, caching a query for "taga + tagb" for an hour, and adding redundant columns, such as taga, taganumber (number of content ), tagb, tagbnumber...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.