具有文章和标签的关系数据库的最佳结构 [英] Best structure for a relational database with articles and tags

查看:112
本文介绍了具有文章和标签的关系数据库的最佳结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个相当简单的系统:

articles的表,tags的表,article_tags的表,其中包含标签的ID和为其分配的商品.

当我想获取所有文章及其所有标签的列表时,我必须进行一些GROUP_CONCAT()查询以获取用逗号分隔的标签列表,我可以将其分解并显示. /p>

在大页面上加载的速度越来越慢,我担心这不是最好的方法.我最近提出了一个问题有关获取带有特定标签的所有文章,最终使用双重联接寻求解决方案.该查询运行很快,但是常规"查询(例如,获取最新的10篇文章及其所有标签)最多需要1秒钟才能运行.

我的表索引很好,其他查询运行很快.对于这种SQL结构,是否有更好的方法/设计模式?任何提示都将非常有用.

谢谢, 马特

解决方案

表结构正确,最好的方法是使用asked a question recently about getting all articles with a specific tag, and ended up going for a solution using double joins. This query runs quickly, but a "general" query (eg grabbing the newest 10 articles along with all their tags) takes up to 1 second to run.

My tables are indexed pretty well and other queries run quickly. Is there a better way / design pattern for this kind of SQL structure? Any tips would be really useful.

Thanks, Matt

解决方案

The table structure is correct, the best approach would be to analyze the execution plan of the query using the EXPLAIN syntax, and post it if you need help with it.

这篇关于具有文章和标签的关系数据库的最佳结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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