【发布时间】:2021-03-16 12:31:09
【问题描述】:
在阅读 PostreSQL (13) 文档时,我遇到了this 页面,其中列出了不同日期时间类型的存储大小。
除其他外,它指出:
Name Storage Size Description Low Value High Value Resolution
---- ------------ ----------- --------- ---------- ----------
timestamp without time zone 8 bytes both date and time (no time zone) 4713 BC 294276 AD 1 microsecond
timestamp with time zone 8 bytes both date and time, with time zone 4713 BC 294276 AD 1 microsecond
time with time zone 12 bytes time of day (no date), with time zone 00:00:00+1559 24:00:00-1559 1 microsecond
我可以理解timestamp without time zone:低值和高值之间大约有 (4713 + 294276) * 365 * 24 * 60 * 60 * 1000000 微秒。 (不考虑日历变化等)。这相当于大约 2^63 个值,这些值可以存储在 8 个字节中。
但是,timestamp with timezone 具有相同的范围和分辨率,并且可以额外存储时区信息。如果我们已经使用 63 位作为值,则只剩下一位,不足以存储时区,因此内部存储的工作方式必须有所不同。
更奇怪的是,虽然时间戳只使用 8 个字节,但 time with time zone 需要 12 个字节,尽管它具有相同的分辨率和更小的允许值范围。
因此我的问题是:PostgreSQL 中这些类型的内部存储如何工作?
【问题讨论】:
-
不相关,但是:
time with time zone应该是not be used -
这个问题可以通过阅读源码来回答。 (Postgres 是开源的)
标签: postgresql timestamp storage