Skip to content

GROUP BY ? in prepared statement causes error in TiDB (MySQL compatible) #62556

@WalterWj

Description

@WalterWj

Bug Report

Please answer these questions before submitting your issue. Thanks!


1. Minimal reproduce step (Required)

MySQL 8.4.4

create table t1(id bigint primary key, name varchar(100));
prepare stmt from 'select name, ? from t1 group by name, ?';
set @a="0", @b="0";
execute stmt using @a, @b;

TiDB 8.5.2

create table t1(id bigint primary key nonclustered, name varchar(100));
prepare stmt from 'select name, ? from t1 group by name, ?';
show warnings;
set @a="0", @b="0";
execute stmt using @a, @b;

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

The query should behave the same as in MySQL 8.4.4:
No error should be reported, and the statement should execute successfully, returning an empty set.


3. What did you see instead (Required)

In TiDB 8.5.2, when executing execute stmt using @a, @b;, the following error occurs:

ERROR 1105 (HY000): Unknown column '0' in 'group statement'

And when preparing the statement, a warning is shown:

Warning | 1105 | skip prepared plan-cache: query has 'group by ?' is un-cacheable

4. What is your TiDB version? (Required)

select tidb_version();

Example output:

Release Version: v8.5.2
Edition: Community

Compatibility Conclusion

This SQL works fine in MySQL 8.4.4, but fails in TiDB 8.5.2.
It seems to be a compatibility issue regarding parameter placeholders in the GROUP BY clause.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions