How to implement tag system

后端 未结 7 1647
悲&欢浪女
悲&欢浪女 2020-11-28 00:19

I was wondering what the best way is to implement a tag system, like the one used on SO. I was thinking of this but I can\'t come up with a good scalable solution.

I

相关标签:
7条回答
  • 2020-11-28 01:04
    CREATE TABLE Tags (
        tag VARHAR(...) NOT NULL,
        bid INT ... NOT NULL,
        PRIMARY KEY(tag, bid),
        INDEX(bid, tag)
    )
    

    Notes:

    • This is better than TOXI in that it does not go through an extra many:many table which makes optimization difficult.
    • Sure, my approach may be slightly more bulky (than TOXI) due to the redundant tags, but that is a small percentage of the whole database, and the performance improvements may be significant.
    • It is highly scalable.
    • It does not have (because it does not need) a surrogate AUTO_INCREMENT PK. Hence, it is better than Scuttle.
    • MySQLicious sucks because it cannot use an index (LIKE with leading wild card; false hits on substrings)
    • For MySQL, be sure to use ENGINE=InnoDB in order to get 'clustering' effects.

    Related discussions (for MySQL):
    many:many mapping table optimization
    ordered lists

    0 讨论(0)
提交回复
热议问题