<feed xmlns='http://www.w3.org/2005/Atom'>
<title>ydb/library/cpp/timezone_conversion/convert.cpp, branch CLI_2.32.0</title>
<subtitle>Mirror of YDB github repos</subtitle>
<id>https://code.mastervirt.ru/ydb/atom?h=CLI_2.32.0</id>
<link rel='self' href='https://code.mastervirt.ru/ydb/atom?h=CLI_2.32.0'/>
<link rel='alternate' type='text/html' href='https://code.mastervirt.ru/ydb/'/>
<updated>2026-06-16T20:54:42Z</updated>
<entry>
<title>Speed up working with timezones</title>
<updated>2026-06-16T20:54:42Z</updated>
<author>
<name>shamteev</name>
<email>shamteev@yandex-team.com</email>
</author>
<published>2026-06-16T20:27:30Z</published>
<link rel='alternate' type='text/html' href='https://code.mastervirt.ru/ydb/commit/?id=9c0feecb216b98e6e483257cf2b2afafcd7d7c77'/>
<id>urn:sha1:9c0feecb216b98e6e483257cf2b2afafcd7d7c77</id>
<content type='text'>
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
</content>
</entry>
<entry>
<title>Restoring authorship annotation for &lt;petrk@yandex-team.ru&gt;. Commit 2 of 2.</title>
<updated>2022-02-10T13:47:26Z</updated>
<author>
<name>petrk</name>
<email>petrk@yandex-team.ru</email>
</author>
<published>2022-02-10T13:47:26Z</published>
<link rel='alternate' type='text/html' href='https://code.mastervirt.ru/ydb/commit/?id=1fe4b402b38f476dbe36f650c3049c92ae496d38'/>
<id>urn:sha1:1fe4b402b38f476dbe36f650c3049c92ae496d38</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Restoring authorship annotation for &lt;petrk@yandex-team.ru&gt;. Commit 1 of 2.</title>
<updated>2022-02-10T13:47:26Z</updated>
<author>
<name>petrk</name>
<email>petrk@yandex-team.ru</email>
</author>
<published>2022-02-10T13:47:26Z</published>
<link rel='alternate' type='text/html' href='https://code.mastervirt.ru/ydb/commit/?id=af66956edf116b93d5a07894ccb61dd4447d0b34'/>
<id>urn:sha1:af66956edf116b93d5a07894ccb61dd4447d0b34</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Restoring authorship annotation for Ivan Komarov &lt;Ivan.Komarov@dfyz.info&gt;. Commit 2 of 2.</title>
<updated>2022-02-10T13:46:49Z</updated>
<author>
<name>Ivan Komarov</name>
<email>Ivan.Komarov@dfyz.info</email>
</author>
<published>2022-02-10T13:46:49Z</published>
<link rel='alternate' type='text/html' href='https://code.mastervirt.ru/ydb/commit/?id=59aca5c5180c31691884667783dc966eb99d743a'/>
<id>urn:sha1:59aca5c5180c31691884667783dc966eb99d743a</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Restoring authorship annotation for Ivan Komarov &lt;Ivan.Komarov@dfyz.info&gt;. Commit 1 of 2.</title>
<updated>2022-02-10T13:46:48Z</updated>
<author>
<name>Ivan Komarov</name>
<email>Ivan.Komarov@dfyz.info</email>
</author>
<published>2022-02-10T13:46:48Z</published>
<link rel='alternate' type='text/html' href='https://code.mastervirt.ru/ydb/commit/?id=4de97ab2fe437cbe83e4c63234e809ddd5ac34f2'/>
<id>urn:sha1:4de97ab2fe437cbe83e4c63234e809ddd5ac34f2</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Restoring authorship annotation for Vlad Yaroslavlev &lt;vladon@vladon.com&gt;. Commit 2 of 2.</title>
<updated>2022-02-10T13:46:25Z</updated>
<author>
<name>Vlad Yaroslavlev</name>
<email>vladon@vladon.com</email>
</author>
<published>2022-02-10T13:46:25Z</published>
<link rel='alternate' type='text/html' href='https://code.mastervirt.ru/ydb/commit/?id=344ea37b4a345701ab0e67de2266a1c1bd7baf2d'/>
<id>urn:sha1:344ea37b4a345701ab0e67de2266a1c1bd7baf2d</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Restoring authorship annotation for Vlad Yaroslavlev &lt;vladon@vladon.com&gt;. Commit 1 of 2.</title>
<updated>2022-02-10T13:46:23Z</updated>
<author>
<name>Vlad Yaroslavlev</name>
<email>vladon@vladon.com</email>
</author>
<published>2022-02-10T13:46:23Z</published>
<link rel='alternate' type='text/html' href='https://code.mastervirt.ru/ydb/commit/?id=706b83ed7de5a473436620367af31fc0ceecde07'/>
<id>urn:sha1:706b83ed7de5a473436620367af31fc0ceecde07</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Restoring authorship annotation for Anton Samokhvalov &lt;pg83@yandex.ru&gt;. Commit 2 of 2.</title>
<updated>2022-02-10T13:45:17Z</updated>
<author>
<name>Anton Samokhvalov</name>
<email>pg83@yandex.ru</email>
</author>
<published>2022-02-10T13:45:17Z</published>
<link rel='alternate' type='text/html' href='https://code.mastervirt.ru/ydb/commit/?id=d3a398281c6fd1d3672036cb2d63f842d2cb28c5'/>
<id>urn:sha1:d3a398281c6fd1d3672036cb2d63f842d2cb28c5</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Restoring authorship annotation for Anton Samokhvalov &lt;pg83@yandex.ru&gt;. Commit 1 of 2.</title>
<updated>2022-02-10T13:45:15Z</updated>
<author>
<name>Anton Samokhvalov</name>
<email>pg83@yandex.ru</email>
</author>
<published>2022-02-10T13:45:15Z</published>
<link rel='alternate' type='text/html' href='https://code.mastervirt.ru/ydb/commit/?id=72cb13b4aff9bc9cf22e49251bc8fd143f82538f'/>
<id>urn:sha1:72cb13b4aff9bc9cf22e49251bc8fd143f82538f</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Restoring authorship annotation for &lt;orivej@yandex-team.ru&gt;. Commit 2 of 2.</title>
<updated>2022-02-10T13:45:01Z</updated>
<author>
<name>orivej</name>
<email>orivej@yandex-team.ru</email>
</author>
<published>2022-02-10T13:45:01Z</published>
<link rel='alternate' type='text/html' href='https://code.mastervirt.ru/ydb/commit/?id=2d37894b1b037cf24231090eda8589bbb44fb6fc'/>
<id>urn:sha1:2d37894b1b037cf24231090eda8589bbb44fb6fc</id>
<content type='text'>
</content>
</entry>
</feed>
