pingcap / pingcap/tidb

INNER JOIN and LEFT JOIN return inconsistent results with `INSTR` predicate

Open
#69,148 4 comments 0 reactions 0 assignees View on GitHub
affects-7.5 affects-8.1 affects-8.5 contribution severity/critical sig/planner type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

INNER JOIN and LEFT JOIN with the same join condition and WHERE predicate produce inconsistent results. For rows where the join condition matches, INNER JOIN should not return fewer rows than LEFT JOIN.

### 1. Minimal reproduce step (Required)

```sql
DROP DATABASE IF EXISTS testdb;
CREATE DATABASE testdb;
USE testdb;
CREATE TABLE t0(c0 INT);
CREATE TABLE t1(c0 INT PRIMARY KEY);
INSERT INTO t0 VALUES (1), (-1.8E9);
INSERT INTO t1 VALUES (1), (-1.8E9);

SELECT * FROM t0 INNER JOIN t1 ON t0.c0 = t1.c0 WHERE INSTR((t1.c0 IS NOT NULL) / (t0.c0 ^ -1146764518), TRUE) AND t1.c0 IS NOT NULL;

SELECT * FROM t0 LEFT JOIN t1 ON t0.c0 = t1.c0 WHERE INSTR((t1.c0 IS NOT NULL) / (t0.c0 ^ -1146764518), TRUE) AND t1.c0 IS NOT NULL;
```

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

When the join condition `t0.c0 = t1.c0` matches and `t1.c0 IS NOT NULL` is satisfied, both INNER JOIN and LEFT JOIN should return the matching rows. Therefore, the two queries should return the same result set.

```sql
mysql> SELECT * FROM t0 LEFT JOIN t1 ON t0.c0 = t1.c0 WHERE INSTR((t1.c0 IS NOT NULL) / (t0.c0 ^ -1146764518), TRUE) AND t1.c0 IS NOT NULL;
+------------+------------+
| c0 | c0 |
+------------+------------+
| -1800000000| -1800000000|
+------------+------------+
1 row in set
```

The INNER JOIN query should also return `{(-1800000000, -1800000000)}`.

### 3. What did you see instead (Required)

```sql
mysql> SELECT * FROM t0 INNER JOIN t1 ON t0.c0 = t1.c0 WHERE INSTR((t1.c0 IS NOT NULL) / (t0.c0 ^ -1146764518), TRUE) AND t1.c0 IS NOT NULL;
Empty set
```

The INNER JOIN incorrectly returns an empty set, while the LEFT JOIN (which should preserve at least as many rows) returns `{(-1800000000, -1800000000)}`.

### 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-06-04 05:49:11
GoVersion: go1.25.8
Race Enabled: false
Check Table Before Drop: false
Store: unistore
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.