Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 一个表或多个具有关系的表_Sql_Database_Postgresql_Database Performance - Fatal编程技术网

Sql 一个表或多个具有关系的表

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) } 或者我可以创建许

我有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 {
   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.

请为这种类型的数据库提供最佳结构。

在我看来,将属性移动到不同的表中没有任何好处,事实上,由于从数据库获取数据需要额外的连接,因此性能会更差。您描述的分解仅在建模可能彼此独立存在的不同实体时才需要,而这不是您的情况