在开发历史和分层 SQL 表时,最好使用开始和停止日期字段还是每个日期使用单个日期字段?每个都有优点和缺点,但我正在寻找证据,证明哪个更优化、更优雅,并且最有效地考虑了极端情况。
例子 -
-- Start/Stop
create table roster (
id bigint identity primary key,
start_date date not null,
stop_date date not null,
employee_id int not null references employee (id),
supervisor_id int not null references employee (id),
unique(start_date, stop_date, employee_id)
)
-- Single Date
create table roster (
id bigint identity primary key,
row_date date not null,
employee_id int not null references employee (id),
supervisor_id int not null references employee (id),
unique(row_date, employee_id)
)