pingcap / pingcap/tidb

Inconsistent result between normal SELECT and prepared SELECT, related to GROUP BY

Open
#65,835 1 comment 0 reactions 0 assignees View on GitHub
contribution severity/minor 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, there are two equivalent queries, however, the normal SELECT returns 2 rows, but the prepared SELECT returns 1 row.

```
CREATE TABLE t0(c0 NUMERIC UNSIGNED , c2 DOUBLE ZEROFILL NOT NULL );
INSERT IGNORE INTO t0(c2) VALUES (-1.997930299E9);
REPLACE INTO t0 VALUES (1403506458, 0.20756409900353212);
CREATE OR REPLACE ALGORITHM=MERGE VIEW v0(c0) AS SELECT CAST(t0.c2 AS BINARY) FROM t0;
SELECT -448010795 AS ref0 FROM v0 WHERE true GROUP BY ((v0.c0)=('0'));
-- -448010795
-- -448010795
SET @b=true;
PREPARE prepare_query FROM "SELECT -448010795 AS ref0 FROM v0 WHERE ? GROUP BY ((v0.c0)=('0'))";
EXECUTE prepare_query USING @b;
-- -448010795
```

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

These two queries should have the same results.

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

These two queries have different results.

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

Release Version: v9.0.0-beta.2.pre-1118-gfc6f7b2e42\nEdition: Community\nGit Commit Hash: fc6f7b2e42be08957a9b80e5761bfa4793066353\nGit Branch: master\nUTC Build Time: 2026-01-26 12:27:51\nGoVersion: go1.25.6\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.