简体   繁体   English

多语言目录(带有自定义字段)数据库结构设计

[英]Multilang catalog(with custom fields) DB structure design

Soon I'll be working on catalog(php+mysql) that will have multilang content support. 很快,我将研究具有多语言内容支持的目录(php + mysql)。 And now I'm considering the best approach to design the database structure. 现在,我正在考虑设计数据库结构的最佳方法。 At the moment I see 3 ways for multilang handling: 目前,我看到3种多语言处理方式:

1) Having separate tables for each language specific data, ie schematicly it'll look like this: 1)对于每种语言特定的数据都有单独的表,即,示意图看起来像这样:

  • There will be one table Main_Content_Items , storing basic data that cannot be translated like ID, creation_date, hits, votes on so on - it will be only one and will refer to all languages. 将有一个表Main_Content_Items ,存储了无法翻译的基本数据,例如ID,creation_date,命中率,票数等等-它只会是一个,并且会引用所有语言。

And here are tables that will be dublicated for each language: 这是每种语言都会被复制的表格:

  • Common_Data_LANG table(example: common_data_en_us) (storing common/"static" fields that can be translated, but are present for eny catalog item: title, desc and so on...) Common_Data_LANG表(示例:common_data_en_us) (存储可以转换的common /“ static”字段,但存在于eny目录项:title,desc等...)
  • Extra_Fields_Data_LANG table (storing extra fields data that can be translated, but can be different for custom item groups, ie like: | id | item_id | field_type | value | ...) Then on items request we will look in table according to user/default language and join translatable data with main_content table. Extra_Fields_Data_LANG表 (存储可以翻译的额外字段数据,但对于自定义项目组可能有所不同,例如:| id | item_id | field_type | value | ...)。然后在请求项目时,我们将根据用户/默认语言,并将可翻译数据与main_content表连接。

Pros: 优点:

  • we can update "main" data(ie hits, votes...) that are updated most often with only one query 我们可以仅通过一个查询就更新最经常更新的“主要”数据(即点击数,投票数...)
  • we don't need o dublicate data 4x or more times if we have 4 or more languages in comparison with structure using only one table with 'lang' field. 与仅使用带有'lang'字段的一个表的结构相比,如果我们有4种或更多种语言,则不需要4倍或更多次复制数据。 So MySql queries would take less time to go through 100000(for example) records catalog rather then 400000 or more 因此,MySql查询通过100000(例如)个记录目录所花费的时间更少,而不是400000或更多

Cons: 缺点:

  • +2 tables for each language 每种语言+2张桌子

2) Using 'lang' field in content tables: 2)在内容表中使用“ lang”字段:

  • Main_Content_Items table (storing basic data that cannot be translated like ID, creation_date, hits, votes on so on...) Main_Content_Items表 (存储无法转换的基本数据,例如ID,creation_date,命中率,投票等等)
  • Common_Data table (storing common/"static" fields that can be translated, but are present for eny catalog item: | id | item_id | lang | title | desc | and so on...) Common_Data表 (存储可以转换但存在于eny目录项的common /“ static”字段:| id | item_id | lang | title | desc |依此类推...)
  • Extra_Fields_Data table (storing extra fields data that can be translated, but can be different for custom item groups, ie like: | id | item_id | lang | field_type | value | ...) So we'll join common_data and extra_fields to main_content_items according to 'lang' field. Extra_Fields_Data表 (存储可以翻译的额外字段数据,但对于自定义项目组可能有所不同,例如:| id | item_id | lang | field_type | value | ...)因此,我们将根据common_data和extra_fields连接到main_content_items到“ lang”字段。

Pros: 优点:

  • we can update "main" data(ie hits, votes...) that are updated most often with only one query 我们可以仅通过一个查询就更新最经常更新的“主要”数据(即点击数,投票数...)
  • we only 3 tables for content data 我们只有3个表格用于内容数据

Cons: 缺点:

  • we have custom_data and extra_fields table filled with data for all languages, so its X time bigger and queries run slower 我们在custom_data和extra_fields表中填充了所有语言的数据,因此其X时间更长,查询运行速度更慢

3) Same as 2nd way, but with Main_Content_Items table merged with Common_Data, that has 'lang' field: 3)与第二种方法相同,但Main_Content_Items表与Common_Data合并,具有“ lang”字段:

Pros: 优点:

  • ...? ...?

Cons: 缺点:

  • we need to update update "main" data(ie hits, votes...) that are updated most often with for every language 我们需要更新每种语言最频繁更新的“主要”数据(即点击数,投票数...)
  • we have custom_data and extra_fields table filled with data for all languages, so its X time bigger and queries run slower 我们在custom_data和extra_fields表中填充了所有语言的数据,因此其X时间更长,查询运行速度更慢

Will be glad to hear suggestions about "what is better" and "why"? 听到关于“什么更好”和“为什么”的建议会很高兴吗? Or are there better ways? 还是有更好的方法?

Thanks in advance... 提前致谢...

I've given a similar anwer in this question and highlighted the advantages of this technique (it would be, for example, important for me to let the application decide on the language and build the query accordingly by only changing the lang parameter in the WHERE clause of the SQL query. 我在这个问题上给出了类似的答案,并强调了该技术的优势(例如,对于我来说,让应用程序决定语言并仅通过更改WHERElang参数来构建查询就很重要。 SQL查询的子句。

This get's pretty close to your second solution. 这非常接近您的第二个解决方案。 I didn't quite got the "extra_fields" but if it makes sense, you could(!) merge it into the common_data table. 我不太了解“ extra_fields”,但如果有道理, 可以将其合并到common_data表中。 I would advise you against the first idea since there will be too many tables and it can be easy to lose track about the items in there. 我建议您不要第一个想法,因为桌子太多了,很容易迷失那里的物品。

To your edit: I still consider the second approach the better one (it's my optinion so it's relative ;)) I'm no expert on optimization but I think that with proper indexes and proper table structure speed should be not be a problem. 编辑:我仍然认为第二种方法更好(这是我的选择,所以是相对的;)我不是优化专家,但我认为拥有适当的索引和适当的表结构速度应该不是问题。 As always, the best way to find the most effective way is doing both methods and see which is best since speed will vary from data, structure, .... 与往常一样,找到最有效方法的最佳方法是同时执行这两种方法,并查看哪种方法最好,因为速度会因数据,结构等而异。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM