pingcap / pingcap/tidb

Incorrect type cast in prepared statement

Open
#63,678 0 comments 0 reactions 0 assignees View on GitHub
contribution sig/planner type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

Please answer these questions before submitting your issue. Thanks!

### 1. Minimal reproduce step (Required)

Hi,

In the following test case, the normal query returns `0.4`, but the prepared statement returns `0`. I tried in MySQL 9.4.0, both return `0.4`.

In TiDB:
```
CREATE TABLE t0(c0 CHAR);
INSERT INTO t0 VALUES ('6');
SELECT CAST(SUBSTRING_INDEX(0.4, 'a', t0.c0) AS BINARY) FROM t0; -- 0.4
SET @c = 0.4;
SET @d = 'a';
PREPARE prepare_query FROM 'SELECT CAST(SUBSTRING_INDEX(?, ?, t0.c0) AS BINARY) FROM t0';
EXECUTE prepare_query USING @c,@d; -- 0
```

In MySQL:
```
CREATE TABLE t0(c0 CHAR);
INSERT INTO t0 VALUES ('6');
SELECT CAST(SUBSTRING_INDEX(0.4, 'a', t0.c0) AS BINARY) FROM t0; -- 0.4
SET @c = 0.4;
SET @d = 'a';
PREPARE prepare_query FROM 'SELECT CAST(SUBSTRING_INDEX(?, ?, t0.c0) AS BINARY) FROM t0';
EXECUTE prepare_query USING @c,@d; -- 0.4
```

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

The prepared statement should return `0.4`

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

The prepared statement returns `0`

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

Release Version: v9.0.0-beta.2.pre-196-g312226f869\nEdition: Community\nGit Commit Hash: 312226f869d56922135e1c177cac6c90319c3134\nGit Branch: HEAD\nUTC Build Time: 2025-09-21 08:27:14\nGoVersion: go1.23.11\nRace Enabled: false\nCheck Table Before Drop: false\nStore: unistore\nKernel Type: Classic

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.