From 4723a9c0829c484080527edfc718fce2f5695946 Mon Sep 17 00:00:00 2001 From: johnnymatthews <9611008+johnnymatthews@users.noreply.github.com> Date: Wed, 10 Jan 2024 11:50:02 -0400 Subject: [PATCH] Explains that date is generally faster than datetime. --- docs/en/sql-reference/data-types/datetime.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/en/sql-reference/data-types/datetime.md b/docs/en/sql-reference/data-types/datetime.md index 42a1ca5aaac..83b3c8b88e5 100644 --- a/docs/en/sql-reference/data-types/datetime.md +++ b/docs/en/sql-reference/data-types/datetime.md @@ -18,6 +18,12 @@ Supported range of values: \[1970-01-01 00:00:00, 2106-02-07 06:28:15\]. Resolution: 1 second. +## Speed + +The `Date` datatype is faster than `DateTime` under _most_ conditions. + +The `Date` type requires 2 bytes of storage, while `DateTime` requires 4. However, when the database compresses the database, this difference is amplified. This amplification is due to the minutes and seconds in `DateTime` being less compressible. Filtering and aggregating `Date` instead of DateTime is also faster. + ## Usage Remarks The point in time is saved as a [Unix timestamp](https://en.wikipedia.org/wiki/Unix_time), regardless of the time zone or daylight saving time. The time zone affects how the values of the `DateTime` type values are displayed in text format and how the values specified as strings are parsed (‘2020-01-01 05:00:01’).