Skip to content

Handle edge case for date_trunc optimization#19628

Merged
lnkuiper merged 1 commit intoduckdb:mainfrom
rcurtin:date_trunc_lteq_fix
Nov 7, 2025
Merged

Handle edge case for date_trunc optimization#19628
lnkuiper merged 1 commit intoduckdb:mainfrom
rcurtin:date_trunc_lteq_fix

Conversation

@rcurtin
Copy link
Contributor

@rcurtin rcurtin commented Nov 3, 2025

This is a bugfix for the date_trunc optimization pass in #18457. @colinmarc and @drin discovered a particular edge case that got overlooked.

The issue is that when we have date_trunc(part, t) <= const_rhs, this must be rewritten to

t < date_trunc(date_add(const_rhs, INTERVAL 1 part))

instead of

t <= date_trunc(date_add(const_rhs, INTERVAL 1 part))

You can cause this bug to happen in the current code if you use some t such that date_trunc(part, t) = t.

This should have been noticed because the same edge case handling is already implemented for the >= case, but I overlooked it. Anyway, it is an easy enough fix.

When date_trunc(p, t) = t, then we must ensure that the optimized expression uses < instead of <=.
@lnkuiper lnkuiper merged commit 44700e5 into duckdb:main Nov 7, 2025
54 checks passed
github-actions bot pushed a commit to duckdb/duckdb-r that referenced this pull request Nov 7, 2025
fix checkpointing on files that dont exist (duckdb/duckdb#19344)
Handle edge case for date_trunc optimization (duckdb/duckdb#19628)
github-actions bot added a commit to duckdb/duckdb-r that referenced this pull request Nov 7, 2025
fix checkpointing on files that dont exist (duckdb/duckdb#19344)
Handle edge case for date_trunc optimization (duckdb/duckdb#19628)

Co-authored-by: krlmlr <krlmlr@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants