pingcap / pingcap/tidb

`CASE WHEN` in prepared statement return wrong result on FLOAT value

Open
#62,717 1 comment 1 reaction 1 assignee Claimed by @hawkingrei View on GitHub
contribution impact/wrong-result may-affects-6.5 may-affects-7.1 may-affects-7.5 may-affects-8.1 may-affects-8.5 severity/major 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, the following test case contains a normal SELECT query and a prepared statement, they are equivalent but have different results.

```
CREATE TABLE t0(c0 FLOAT);
REPLACE INTO t0(c0) VALUES (100000030);
SET @c = false;
SELECT t0.c0 FROM t0 WHERE ((t0.c0)NOT LIKE(CASE WHEN false THEN false ELSE t0.c0 END ));
PREPARE prepare_query FROM 'SELECT t0.c0 FROM t0 WHERE ((t0.c0)NOT LIKE(CASE WHEN false THEN ? ELSE t0.c0 END ))';
EXECUTE prepare_query USING @c;
```

The SELECT query returns an empty result but the prepared statement returns `100000030`.

Then I run the following query and find the `CASE WHEN` expression returns wrong value

```
SET @c = false;
PREPARE prepare_query FROM 'SELECT ((CASE WHEN false THEN ? ELSE t0.c0 END )) FROM t0';
EXECUTE prepare_query USING @c; -- 100000032
```

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

`CASE WHEN` returns correct result in prepared statement.

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

`CASE WHEN` returns wrong result in prepared statement.

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

tidb_version()
Release Version: v9.0.0-beta.2.pre-149-g96f5396\nEdition: Community\nGit Commit Hash: 96f5396be12ae6c5bf440bd22b1e0bec532aff9e\nGit Branch: HEAD\nUTC Build Time: 2025-07-21 20:48:44\nGoVersion: go1.23.11\nRace Enabled: false\nCheck Table Before Drop: false\nStore: tikv\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.