我有一个字典的复杂数据库方案。每个对象(本质上是一个翻译)与此类似:如何建模和查询关系数据库中的对象?
Entry {
keyword;
examples;
tags;
Translations;
}
与
Translation {
text;
tags;
examples;
}
和
Example {
text;
translation;
phonetic_script;
}
即标签(即语法),可以属于关键字本身,或翻译(外语的语法)和类似的例子可以属于翻译本身(即解释外来词)或者条目中的文本。我结束了此类关系设计的:
entries(id,keyword,)
tags(tag)
examples(id,text,...)
entrytags(entry_id,tag)
entryexamples(entry_id,example_id)
translations(id,belongs_to_entry,...)
translationtags(transl_id, tag)
translationexamples(transl_id,example_id)
我的主要任务就是查询这个数据库。说我搜索“富”,我目前的处理方式是:
query all entries with foo, get ids A
foreach id in A
query all examples belonging to id
query all tags belonging to id
query all translations belonging to A, store their ids in B
foreach tr_id in B
query all tags belonging to tr_id
query all examples belonging to tr_id
重建我的对象。这看起来很麻烦,而且很慢。我不明白我可以通过使用连接或其他方式显着改善这一点。我很难将这些对象建模为数据库中的关系。这是一个适当的设计?
我该如何提高查询时间的效率?
我可能会考虑一个不同的数据库解决方案,如NoSQL。 RDBMS不是一切的解决方案。 – Amirshk