Bug #102681 result of "datetime_val not between NULL and NULL" is unexpected
Submitted: 22 Feb 2021 5:29 Modified: 22 Feb 2021 6:03
Reporter: jiangtao guo Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S3 (Non-critical)
Version:8.0,5.7.33, 8.0.23 OS:Any
Assigned to: CPU Architecture:Any

[22 Feb 2021 5:29] jiangtao guo
Description:
expression: e1 not between e2 and e3;

If e2 and e3 are both NULL, and e1 is any type but date/datetime/timestamp, the result is NULL.

Bug if e1 is date/datetime/timestamp, the result is true.

I think the result should always be NULL.

Server version: 8.0.23 MySQL Community Server - GPL
mysql> select 1 from dual where cast('0000-01-01' as datetime) not between null and null;
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0.00 sec)

mysql> select 1 from dual where '0000-01-01' not between null and null;
Empty set (0.00 sec)

mysql> select 1 from dual where 123 not between null and null;
Empty set (0.00 sec)

How to repeat:
select 1 from dual where cast('0000-01-01' as datetime) not between null and null;

select 1 from dual where '0000-01-01' not between null and null;

select 1 from dual where 123 not between null and null;

Suggested fix:
The implementation of Item_func_between::val_int()in MySQL 5.6 handles situations when the second and third arguments are both NULL except for date/datetime/timestamp.

Maybe should add the following code when handle date/datetime/timestamp types, just like other types do.

```
    if (args[1]->null_value && args[2]->null_value)
      null_value=1;
```
[22 Feb 2021 6:03] MySQL Verification Team
Hello jiangtao,

Thank you for the report and test case.

regards,
Umesh