哪个是具有大数据列或多个表的更高效的单表? (休眠 - 数据库)

时间:2012-10-26 09:15:39

标签: database hibernate database-design relational-database database-optimization

我的网络应用程序是在Grails中实现的。

我的情况是我有一个包含更多列的域类(hibernate类),其中一些是大字符串,最多4000个字符。

例如:

String description // max 4000
// column2, column3, etc

现在我必须为这些元素实现一个多语言数据库,我的策略是为每种语言都有一个字段。

String description_en_US
String description_de_DE

我的问题是,如果我为每种语言都有一个单独的表,或者将它保存在一个大表中,它是否更有效。 这个问题有两个部分。首先,如果在加载数据时使用大内存,那么对hibernate更有效,第二,这对数据库更有效?

以后我会有超过10种语言。

2 个答案:

答案 0 :(得分:1)

我之前已经处理过类似的情况,我们有一张桌子,里面有一些价值观。需要以多种语言存储他们的翻译值。经过几次讨论后,头脑风暴,我们最终确定了以下方法。

Table1: MainTable 

     id, Description, Column1, column2 ......


Tables2: MainTransTable

     id, MainTable_id (FK), Language, description_trans

因此它将是MainTable实体&它将拥有MainTransTable实体的集合(一对多关系)。每个MainTransTable将根据语言列

表示给定语言的MainTable的翻译版本
Advantages:
- In future if you want to add value for another language, then you just need to add another row in MainTransTable
- Currently you are only translating only one column. So in future if you decide to translate any other columns,  you can use same table structure with new trans column added in trans table

答案 1 :(得分:1)

我无法回答这个问题,但我强烈建议不要使用某个语言的字段,而是使用另一个包含语言和此表的引用的表。这是因为如果您必须添加另一种语言,则不必更改现有表的结构,只需将另一行添加到languages表中,并且可以在描述表中将该键用作外键。我认为长串不是问题。您希望维护描述表中有多少条目?