如何为动态生成 Select 语句的 30 列表创建索引
我有一个包含语言翻译的表。它有 30 个栏目,涵盖 30 种语言。
我的要求是从所有列中搜索特定单词(说“你好”)。
我动态创建 Select 语句:
Select * from Languages 其中{英语=“你好” 或者法语=“你好” OR German = "hello"}
{} 内的语句是动态生成的。
如果我必须为这样的表建立索引,我该怎么做?
我是否必须为所有 30 列创建一个索引,还是为每一列创建单独的 30 个索引?
请建议更好的选择。
I have a table containing language translations. It has 30 columns for 30 languages.
My requirement is to search from all columns for a particular word (say "hello").
I dynamically create Select statement:
Select * from Languages
where {English = "hello"
OR French = "hello"
OR German = "hello"}
Statement inside {} is generated dynamically.
If I have to index such a table, how do I do that?
Will I have to create one index for all 30 columns or create seperate 30 indexes for each column?
Please suggest better option.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您不应该有 30 列,您应该使用一个表,其中有一列用于语言名称,一列用于单词,以及一个将 30 行关联在一起的 id。然后您可以简单地查询
WORD = 'hello'
。如果绝对必须保留 30 列,则需要创建 30 个索引,并且查询的性能将比所需速度慢 30 倍。
You shouldn't have 30 columns, you should use a table with a column for language name, and a column for the word, and an id to associate the 30 rows together. Then you can simply query for
WORD = 'hello'
.If you absolutely must keep 30 columns, you will need to create 30 indexes, and the performance of the query will be 30 times slower than it needs to be.
我将创建第二个包含 [id, lang, value] 的表,并按 id 和值对其进行索引。您可以设置一个视图来复制您正在使用的表,反之亦然,并为该视图建立索引
I would create a second table that contains [id, lang, value], and index it by the id and value. You can set up a view that replicates the table you are working with from this, or vice versa, and index the view
如果您必须拥有全部 30 列,则需要单独为每列建立索引。
If you must have all 30 columns, you will need to separately index each column.