使用 timestamp(0) 或 timestamptz(0)
Optimize 提供建议,帮助你识别和解决由 PostgreSQL 中使用 @db.Timestamp(0)
和 @db.Timestamptz(0)
原生类型引起的性能问题。
¥Optimize provides recommendations to help you identify and resolve performance issues caused by the use of @db.Timestamp(0)
and @db.Timestamptz(0)
native types in PostgreSQL.
@db.Timestamp(0)
和 @db.Timestamptz(0)
原生类型已在以下 User
模型中使用:
¥The @db.Timestamp(0)
and @db.Timestamptz(0)
native types have been used within the following User
model:
model User {
// ...
date DateTime @db.Timestamp(0)
deletedAt DateTime @db.Timestamptz(0)
// ...
}
为什么这是一个问题
¥Why this is a problem
使用精度为 0
的 @db.Timestamp(n)
或 @db.Timestamptz(n)
列时,数据库会将时间四舍五入到最接近的整秒,这可能会导致意外结果。
¥When using a @db.Timestamp(n)
or @db.Timestamptz(n)
column with a precision of 0
, the database rounds the time to the nearest whole second, which can lead to unexpected results.
例如,如果你将当前时间(例如 15:30:45.678
)插入到具有此精度的列中,它将向上舍入为 15:30:46
。此行为可能导致记录的时间与原始时间相比最多晚半秒,当精确的时间精度至关重要时,这可能会令人感到意外。
¥For example, if you insert the current time, such as 15:30:45.678
, into a column with this precision, it will round up to 15:30:46
. This behavior can cause the recorded time to appear up to half a second in the future compared to the original time, which may be surprising when precise time accuracy is critical.