在数据库中存储标签的最有效方法是什么? [英] What is the most efficient way to store tags in a database?

查看:23
本文介绍了在数据库中存储标签的最有效方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在我的网站上实施一个类似于 stackoverflow 使用的标记系统,我的问题是 - 存储标记以便搜索和过滤它们的最有效方法是什么?

我的想法是这样的:

表:项目列:Item_ID、标题、内容表:标签列:标题、Item_ID

是不是太慢了?有没有更好的办法?

解决方案

一项将有许多标签.一个标签将属于许多项目.这对我来说意味着您很可能需要一个中间表来克服多对多障碍.

类似于:

<块引用>

表格:项目
列:Item_ID、Item_Title、内容

<块引用>

表格:标签
列:Tag_ID、Tag_Title

<块引用>

表格:Items_Tags
列:Item_ID、Tag_ID

可能是因为您的网络应用非常受欢迎,并且需要在未来进行非规范化,但过早地将水搅浑是没有意义的.

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 searched and filtered?

My idea is this:

Table: Items
Columns: Item_ID, Title, Content

Table: Tags
Columns: Title, Item_ID

Is this too slow? Is there a better way?

解决方案

One item is going to have many tags. And one tag will belong to many items. This implies to me that you'll quite possibly need an intermediary table to overcome the many-to-many obstacle.

Something like:

Table: Items
Columns: Item_ID, Item_Title, Content

Table: Tags
Columns: Tag_ID, Tag_Title

Table: Items_Tags
Columns: Item_ID, Tag_ID

It might be that your web app is very very popular and need de-normalizing down the road, but it's pointless muddying the waters too early.

这篇关于在数据库中存储标签的最有效方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆