Skip to content

Conversation

@khaledalam
Copy link

Description

  • Fixes incorrect result when using BETWEEN with mixed temporal types (DATE, TIMESTAMP, YEAR) where one bound is NULL
  • The expression '2019-12-25' BETWEEN '2017-05-24' AND NULL was returning 0 instead of NULL

Root Cause

When YEAR is mixed with DATE/TIMESTAMP in BETWEEN, type aggregation returns REAL_RESULT. This bypassed temporal comparison, causing incompatible val_real() formats to be compared:

  • DATE → 20191225.0
  • TIMESTAMP → 20170524000000.0

Since 20191225.0 < 20170524000000.0, the value appeared less than the lower bound, returning FALSE before checking the NULL upper bound.

Solution

Added all_temporal check in Item_func_between::resolve_type() to force temporal comparison when all three arguments are temporal types, regardless of the aggregated cmp_type.

Plan

  • Added new test file func_between_temporal.test with 8 test cases
  • Verified fix compiles without errors
  • All new tests pass

@mysql-oca-bot
Copy link

Hi, thank you for submitting this pull request. In order to consider your code we need you to sign the Oracle Contribution Agreement (OCA). Please review the details and follow the instructions at https://oca.opensource.oracle.com/
Please make sure to include your MySQL bug system user (email) in the returned form.
Thanks

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants