我试图在这两种表设计之间进行选择,性能优先(使用关节查询)
多个表:每个项目(或键)都有自己的表
CREATE TABLE users_languages (
"user_id" bigint not null,
"language" integer not null,
primary key ("user_id", "language"),
foreign key ("user_id") references users ("user_id") on delete cascade
);
一张 KVP 表:包含所有项目/键
CREATE TABLE users_kvp (
"user_id" bigint not null,
"key" varchar not null, -- could be "language" or other
"value" integer not null,
primary key ("user_id", "key", "value"),
foreign key ("user_id") references users ("user_id") on delete cascade
);
我认为对于大多数操作来说最后一个会更慢,对吗?如果是,多少和何时?