Skip to content

planner: the global binding is not working when using Prepared Statement with "select ... as col ... group by col" #57992

Open
@qw4990

Description

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

create table t (d datetime);
create global binding for
  select hour(`d`) as `hour` from t group by `hour`
using 
  select hour(`d`) as `hour` from t group by `hour`;

select hour(`d`) as `hour` from t group by `hour`;
select @@last_plan_from_binding;

prepare st from "select hour(`d`) as `hour` from t group by `hour`";
execute st;
select @@last_plan_from_binding;

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

Both the normal query and the prepared statement can use the global binding.

3. What did you see instead (Required)

mysql> select hour(`d`) as `hour` from t group by `hour`;
Empty set (0.00 sec)

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

mysql> 
mysql> prepare st from "select hour(`d`) as `hour` from t group by `hour`";
Query OK, 0 rows affected (0.00 sec)

mysql> execute st;
Empty set (0.00 sec)

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

4. What is your TiDB version? (Required)

Master

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions