好吧,我总是这样做:
create table language (
id bigserial primary key,
code varchar(10) not null
);
create table entity (
id bigserial primary key
);
create table entity_description (
id bigserial primary key,
language_id bigint not null,
constraint fk__entity_description__language
foreign key language_id
references language(id),
entity_id bigint not null,
constraint fk__entity_description__entity
foreign key entity_id
references entity(id),
name varchar(20) not null
);
但我想知道.. 为什么我不会这样做:
create table language (
id bigserial primary key,
code varchar(10) not null
);
create table entity (
id bigserial primary key
);
create table entity_description (
language_id bigint not null,
constraint fk__entity_description__language
foreign key language_id
references language(id),
entity_id bigint not null,
constraint fk__entity_description__entity
foreign key entity_id
references entity(id),
primary key (language_id, entity_id),
name varchar(20) not null
);
我的问题是
(language_id, entity_id)
,language_id
和entity_id
是否为表格entity_description
分别编入索引?如果我提取的是.. WHERE entity_description.id = x
,那么这比获取.. WHERE (entity_description.language_id, entity_description.entity_id) = (x,y)
要慢吗?