具有文章和标签的关系数据库的最佳结构 [英] Best structure for a relational database with articles and tags
问题描述
有一个相当简单的系统:
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屋!