linrrzqqq opened a new pull request, #64127:
URL: https://github.com/apache/doris/pull/64127
Problem Summary:
1. Fix nullable string/date literals in date diff functions being resolved
to TIMESTAMPTZ unexpectedly. The change unwraps `nullable()`/`non_nullable()`
when checking whether an argument is a literal during `signature search`, so
non-TIMESTAMPTZ date/time literals keep DATE/DATETIMEV2 semantics.
Timezone-bearing literals can still bind to TIMESTAMPTZ.
before:
```sql
Doris> explain SELECT DATEDIFF(NULLABLE('2021-12-31 12:23:34'),
NULLABLE('0000-01-01 00:00:00'));
+-------------------------------------------------------------------------------------------------------------------------------------+
| Explain String(Nereids Planner)
|
+-------------------------------------------------------------------------------------------------------------------------------------+
| PLAN FRAGMENT 0
|
| OUTPUT EXPRS:
|
| DATEDIFF(NULLABLE('2021-12-31 12:23:34'), NULLABLE('0000-01-01
00:00:00'))[#0] |
| PARTITION: UNPARTITIONED
|
|
|
| HAS_COLO_PLAN_NODE: false
|
|
|
| VRESULT SINK
|
| MYSQL_PROTOCOL
|
|
|
| 0:VUNION(11)
|
| constant exprs:
|
| datediff(CAST(nullable('2021-12-31 12:23:34') AS timestamptz(6)),
CAST(nullable('0000-01-01 00:00:00') AS timestamptz(6))) |
|
|
|
|
|
|
| ========== STATISTICS ==========
|
+-------------------------------------------------------------------------------------------------------------------------------------+
17 rows in set (0.046 sec)
```
now:
```sql
Doris> explain SELECT DATEDIFF(NULLABLE('2021-12-31 12:23:34'),
NULLABLE('0000-01-01 00:00:00'));
+-----------------------------------------------------------------------------------------------------------------------------------+
| Explain String(Nereids Planner)
|
+-----------------------------------------------------------------------------------------------------------------------------------+
| PLAN FRAGMENT 0
|
| OUTPUT EXPRS:
|
| DATEDIFF(NULLABLE('2021-12-31 12:23:34'), NULLABLE('0000-01-01
00:00:00'))[#0] |
| PARTITION: UNPARTITIONED
|
|
|
| HAS_COLO_PLAN_NODE: false
|
|
|
| VRESULT SINK
|
| MYSQL_PROTOCOL
|
|
|
| 0:VUNION(11)
|
| constant exprs:
|
| datediff(CAST(nullable('2021-12-31 12:23:34') AS datetimev2(6)),
CAST(nullable('0000-01-01 00:00:00') AS datetimev2(6))) |
|
|
|
|
|
|
| ========== STATISTICS ==========
|
+-----------------------------------------------------------------------------------------------------------------------------------+
```
2. Fixed incorrect number of days in February for the year `0000` in the
`DATE_DIFF` constant folding.
before:
```
Doris> set debug_skip_fold_constant=false;
Query OK, 0 rows affected (0.001 sec)
Doris> SELECT DATEDIFF('0001-01-01 00:00:00', '0000-01-01 00:00:00');
+--------------------------------------------------------+
| DATEDIFF('0001-01-01 00:00:00', '0000-01-01 00:00:00') |
+--------------------------------------------------------+
| 366 |
+--------------------------------------------------------+
1 row in set (0.007 sec)
Doris> set debug_skip_fold_constant=true;
Query OK, 0 rows affected (0.001 sec)
Doris> SELECT DATEDIFF('0001-01-01 00:00:00', '0000-01-01 00:00:00');
+--------------------------------------------------------+
| DATEDIFF('0001-01-01 00:00:00', '0000-01-01 00:00:00') |
+--------------------------------------------------------+
| 365 |
+--------------------------------------------------------+
1 row in set (0.009 sec)
```
now:
```sql
Doris> set debug_skip_fold_constant=false;
Query OK, 0 rows affected (0.003 sec)
Doris> SELECT DATEDIFF('0001-01-01 00:00:00', '0000-01-01 00:00:00');
+--------------------------------------------------------+
| DATEDIFF('0001-01-01 00:00:00', '0000-01-01 00:00:00') |
+--------------------------------------------------------+
| 365 |
+--------------------------------------------------------+
1 row in set (0.021 sec)
Doris> set debug_skip_fold_constant=true;
Query OK, 0 rows affected (0.001 sec)
Doris> SELECT DATEDIFF('0001-01-01 00:00:00', '0000-01-01 00:00:00');
+--------------------------------------------------------+
| DATEDIFF('0001-01-01 00:00:00', '0000-01-01 00:00:00') |
+--------------------------------------------------------+
| 365 |
+--------------------------------------------------------+
1 row in set (0.006 sec)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]