Sql 一个表或多个具有关系的表
我有170个属性的实体。这是来自车辆监控的数据。每个实体都有数据时间标签和唯一的gps终端id。Datetime和终端id-这些是分组操作的条件。我可以为所有实体创建一个表:Sql 一个表或多个具有关系的表,sql,database,postgresql,database-performance,Sql,Database,Postgresql,Database Performance,我有170个属性的实体。这是来自车辆监控的数据。每个实体都有数据时间标签和唯一的gps终端id。Datetime和终端id-这些是分组操作的条件。我可以为所有实体创建一个表: CREATE TABLE rows { terminal_id long reference terminals(id), time timestamp, -- description 170 attributes PRIMARY KEY(terminal_id, time) } 或者我可以创建许
CREATE TABLE rows {
terminal_id long reference terminals(id),
time timestamp,
-- description 170 attributes
PRIMARY KEY(terminal_id, time)
}
或者我可以创建许多具有关系的表:
CREATE TABLE rows {
row_id long PRIMARY KEY,
terminal_id long reference terminals(id),
time timestamp -- need create index for group by
}
CREATE TABLE gps {
row_id long references rows(row_id),
-- description gps attributes
}
CREATE TABLE fuel {
row_id long references rows(row_id),
-- description fuel attributes
}
-- etc.
请为这种类型的数据库提供最佳结构。在我看来,将属性移动到不同的表中没有任何好处,事实上,由于从数据库获取数据需要额外的连接,因此性能会更差。您描述的分解仅在建模可能彼此独立存在的不同实体时才需要,而这不是您的情况