Unexpected Result Difference with CONVERT_TZ and CEIL(MAX()) due to NOT NULL Constraint
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Bug Report
It seems that the issue may be related to the behavior of CONVERT_TZ when combined with CEIL(MAX()) in the query. The only difference between the two queries is the presence of the NOT NULL constraint on the column c0, but this should not cause such a significant difference in the result. This suggests that the issue could be related to the handling of CONVERT_TZ with the HAVING clause.
### 1. Minimal reproduce step (Required)
```sql
DROP DATABASE IF EXISTS test;
CREATE DATABASE test;
USE test;
-- Create table with NOT NULL constraint on column c0
CREATE TABLE t0(c0 CHAR UNIQUE NOT NULL);
INSERT INTO t0 VALUES (1);
-- Query 1:
SELECT CEIL(MAX(b'101010')) AS c0
FROM t0 AS tom0
GROUP BY tom0.c0
HAVING CONVERT_TZ('2025-12-31 14:30:00', 'Europe/Amsterdam', '+00:00');
-- Drop and recreate table without NOT NULL constraint on column c0
DROP TABLE t0;
CREATE TABLE t0(c0 CHAR UNIQUE);
INSERT INTO t0 VALUES (1);
-- Query 2:
SELECT CEIL(MAX(b'101010')) AS c0
FROM t0 AS tom0
GROUP BY tom0.c0
HAVING CONVERT_TZ('2025-12-31 14:30:00', 'Europe/Amsterdam', '+00:00');
```
### 2. What did you expect to see? (Required)
I expected the results to be consistent, as the only difference between the two queries is the NOT NULL constraint on the c0 column. Both queries should return the same result, and the presence or absence of the NOT NULL constraint should not affect the behavior of the CEIL(MAX()) and CONVERT_TZ functions.
### 3. What did you see instead (Required)
```sql
Output1:
+------+
| c0 |
+------+
| 42 |
+------+
1 row in set (0.00 sec)
Output2:
+------+
| c0 |
+------+
| 0 |
+------+
1 row in set, 1 warning (0.00 sec)
```
### 4. What is your TiDB version? (Required)
```sql
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version() |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v8.5.5
Edition: Community
Git Commit Hash: 1fa258b833ff113883beeba40bc130be7ce66610
Git Branch: HEAD
UTC Build Time: 2026-03-12 08:34:59
GoVersion: go1.25.5
Race Enabled: false
Check Table Before Drop: false
Store: unistore |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
```
Contributor guide
Assessment
This issue has not been assessed yet.