#67851·tidb

Unexpected Error in HAVING Clause with Contradictory IS NULL/IS NOT NULL Logic on LEFT JOIN

Author: jinhui-laiCreated Apr 17, 2026Updated Sep 17, 2026
Labelstype/bugcontributionsig/plannerseverity/majoraffects-7.1affects-7.5affects-8.1affects-8.5

Bug Report

Hi, I found a bug in TiDB 8.5.6. Executing a LEFT JOIN query where the HAVING clause contains a specific condition x IS NOT NULL AND NOT (x IS NOT NULL) AND x IS NULL causes TiDB to throw an internal panic (ERROR 1105) instead of returning an empty result set.

1. Minimal reproduce step (Required)

sql
CREATE TABLE t0(c0 CHAR);
CREATE TABLE t1(c0 CHAR, PRIMARY KEY(c0));
INSERT INTO t1 VALUES ('1'),('2');
SELECT * FROM t0 LEFT JOIN t1 ON TRUE HAVING t1.c0 IS NOT NULL AND t1.c0 IS NULL; -- Empty set (0.01 sec)√
SELECT * FROM t0 LEFT JOIN t1 ON TRUE HAVING t1.c0 IS NOT NULL AND NOT (t1.c0 IS NOT NULL); --Empty set (0.01 sec)√
SELECT * FROM t0 INNER JOIN t1 ON TRUE HAVING t1.c0 IS NOT NULL AND NOT (t1.c0 IS NOT NULL) AND t1.c0 IS NULL; --Empty set (0.01 sec)√
SELECT * FROM t0 LEFT JOIN t1 ON TRUE HAVING t1.c0 IS NOT NULL AND NOT (t1.c0 IS NOT NULL) AND t1.c0 IS NULL; -- expect: Empty set
ERROR 1105 (HY000): interface conversion: expression.Expression is *expression.Constant, not *expression.ScalarFunction

2. What did you expect to see? (Required)

sql
SELECT * FROM t0 LEFT JOIN t1 ON TRUE HAVING t1.c0 IS NOT NULL AND NOT (t1.c0 IS NOT NULL) AND t1.c0 IS NULL; 
Empty set (0.01 sec)

3. What did you see instead (Required)

sql
SELECT * FROM t0 LEFT JOIN t1 ON TRUE HAVING t1.c0 IS NOT NULL AND NOT (t1.c0 IS NOT NULL) AND t1.c0 IS NULL; 
ERROR 1105 (HY000): interface conversion: expression.Expression is *expression.Constant, not *expression.ScalarFunction

4. What is your TiDB version? (Required)

| Release Version: v8.5.6 Edition: Community Git Commit Hash: ae18096e023780bb56bfce33698abec0d4640d0a Git Branch: HEAD UTC Build Time: 2026-04-14 07:15:36 GoVersion: go1.25.8 Race Enabled: false Check Table Before Drop: false Store: tikv |