Skip to content

Optimize date_trunc on fixed-offset timezones #25325

Description

@niebayes

Problem

date_trunc(granularity, ts) on a timezone-aware ts column is much slower than on a timezone-naive column, even when the timezone is a fixed UTC offset (+00:00, +05:30, ...) where no DST is involved.

The fast arithmetic path in date_trunc is gated on the timezone being absent (parsed_tz.is_none()), so any timezone-aware input — including UTC and other fixed offsets — falls into the per-value chrono DateTime<Tz> conversion path, even though a fixed offset truncates identically to a timezone-naive value shifted by that offset.

Additionally, the chrono path eagerly allocates a DataFusionError per value via ok_or(exec_datafusion_err!(...)) even on the success path.

Proposal

Detect fixed-offset timezones (same grammar arrow uses: ±HH, ±HHMM, ±HH:MM, plus UTC) and route them through the existing integer paths: truncate_tz(v) == truncate_naive(v + offset) - offset. Keep the per-value chrono path only for named IANA timezones (DST), and use lazy ok_or_else error construction in that path.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions