在这里,我正在创建 table product_feature_text
,与 table 具有 1:N 关系product
。由于应用程序必须支持多种用户语言,lang_code
因此添加了一个列来将英语文本与其他语言文本区分开来。
由于我想以每种语言按字母顺序展示产品功能,因此我创建了四个部分索引,它们的特定collate
. 预计所有产品功能都具有title
四种语言,lang_code = 'ES'
例如,将有 25% 的行带有 。
这是对真实案例的过度简化,但足以描述情况。
create table product_feature_text (
id bigint generated by default as identity primary key,
-- reference to the parent product
product_id bigint not null,
-- language dependent columns
lang_code char(2),
title varchar,
foreign key (product_id) references product (id)
);
create index on product_feature_text (title collate "en-US") where lang_code = 'EN';
create index on product_feature_text (title collate "es-ES") where lang_code = 'ES';
create index on product_feature_text (title collate "fr_FR") where lang_code = 'FR';
create index on product_feature_text (title collate "de_DE") where lang_code = 'DE';
这是该案例的最佳索引方法吗?
评论的附录:一个典型的查询是
select text
from product_feature
where product_id = 1024
and lang_code = 'FR'
order by title collate "fr_FR"
哪里product_id
可能有任何东西。