diff options
| author | shamteev <[email protected]> | 2026-06-16 23:27:30 +0300 |
|---|---|---|
| committer | shamteev <[email protected]> | 2026-06-16 23:54:42 +0300 |
| commit | 9c0feecb216b98e6e483257cf2b2afafcd7d7c77 (patch) | |
| tree | 7cba26adc554588f42d7779d484b858bd92e0dbc /contrib/tools/python3/src | |
| parent | 42a93ecbc67ce6324fcb8e463301883ff214a31f (diff) | |
Speed up working with timezones
Optimize timezone-aware query functions (timestamp_floor\_\*\_tz, format_timestamp_tz)
Problem: queries using timezone functions on a non-Moscow/non-UTC zone (e.g.
Europe/Bucharest) ran 10-20x slower than their non-timezone equivalents. For
Moscow/UTC a lookup table handles the conversion; for any other zone the code
falls back to live cctz calls.
Cause, confirmed by flamegraph and code:
1. NDatetime::ToCivilTime performed two independent timezone lookups per call.
cctz::convert(tp, tz) is defined as tz.lookup(tp).cs, and the function then
called tz.lookup(tp) again for the offset/is_dst fields. Both pieces of data
are already present in a single absolute_lookup result.
2. TimestampFloorDayTZInternal (and Month/Quarter/Year variants) located the
start of the period via a binary search that called ToCivilTime on every
iteration — \~18 iterations for the day case. Combined with (1) that is \~38
cctz lookups per call, and timestamp_floor_day_tz appears twice per row in a
typical WHERE clause.
* Changelog entry
Type: fix
1. ToCivilTime now does a single tz.lookup(tp) and reuses both cs and the
offset/is_dst fields. Behavior is identical; affects all callers.
2. TimestampFloor\{Day,Month,Quarter,Year\}TZ compute the period start directly
(subtract the civil time-of-day, or build the first second of the period and
convert it back), then verify the result. The binary search is kept as a
fallback for the rare days that do not start at midnight (DST transitions at
00:00, historical offset shifts), so results are unchanged.
commit_hash:295ee82832ab2a4a35920067e7c063d6992bb083
Diffstat (limited to 'contrib/tools/python3/src')
0 files changed, 0 insertions, 0 deletions
