pingcap / pingcap/tidb

Unexpected "index out of range" Error with Complex JOIN and Multiple Functions

Open
#67,006 2 comments 0 reactions 0 assignees View on GitHub
contribution may-affects-7.1 may-affects-7.5 may-affects-8.1 may-affects-8.5 severity/major sig/execution type/bug
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 combination of functions (INET6_NTOA, ILIKE, and PERIOD_ADD) along with complex JOINs. The query should not return an "index out of range" error, and removing any of these functions results in a normal execution. This could indicate a bug in TiDB’s handling of multiple functions in complex joins.

### 1. Minimal reproduce step (Required)

```sql

DROP DATABASE IF EXISTS test;
CREATE DATABASE test;
USE test;
CREATE TABLE t70(c0 CHAR);
CREATE TABLE t0 LIKE t70;
INSERT INTO t0 VALUES (1);

-- sql:
SELECT INET6_NTOA(X'68656C6C6F') ILIKE tom20.c0 OR PERIOD_ADD(202309, 42) AS c19
FROM ((t70 AS tom17 JOIN t70 AS tom18) RIGHT JOIN t0 AS tom20 ON true);
```

### 2. What did you expect to see? (Required)
I expected to see the query return a valid result set, with the function INET6_NTOA(X'68656C6C6F') being evaluated and compared using the ILIKE operator and the result of PERIOD_ADD(202309, 42) returned in the final column c19.

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

The query returns an unexpected error:

ERROR 1105 (HY000): runtime error: index out of range [0] with length 0

### 4. What is your TiDB version? (Required)

+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 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.01 sec)

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.