pingcap / pingcap/tidb

Prepare query with ORDER BY clause does not work with sql binding

Open
#63,805 3 comments 0 reactions 1 assignee Claimed by @qw4990 View on GitHub
affects-8.5 good first issue help wanted report/customer severity/moderate 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)

```
mysql> create table t(id int, a int, key idx(a));
Query OK, 0 rows affected (0.05 sec)

mysql> create binding for select min(id),a from t where a=1 group by a order by min(id) using select min(id),a from t use index(idx) where a=1 group by a order by min(id);
Query OK, 0 rows affected (0.00 sec)

mysql> select min(id),a from t where a=1 group by a order by min(id);
Empty set (0.02 sec)

mysql> select @@last_plan_from_binding;
+--------------------------+
| @@last_plan_from_binding |
+--------------------------+
| 1 |
+--------------------------+
1 row in set (0.00 sec)

mysql> prepare stmt from 'select min(id),a from t where a=? group by a order by min(id)';
Query OK, 0 rows affected (0.00 sec)

mysql> set @a=1;
Query OK, 0 rows affected (0.00 sec)

mysql> execute stmt using @a;
Empty set (0.00 sec)

mysql> select @@last_plan_from_binding;
+--------------------------+
| @@last_plan_from_binding |
+--------------------------+
| 0 |
+--------------------------+
1 row in set (0.00 sec)
```

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

The last_plan_from_binding returns 1 for prepare query.

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

The binding doesn't work.

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

v8.5.3

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.