Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

planner: bindings for in (?) can not match in (?, ... ?) #44298

Closed
qw4990 opened this issue May 31, 2023 · 5 comments · Fixed by #46940
Closed

planner: bindings for in (?) can not match in (?, ... ?) #44298

qw4990 opened this issue May 31, 2023 · 5 comments · Fixed by #46940
Assignees
Labels
epic/sql-plan-management first-time-contributor Indicates that the PR was contributed by an external member and is a first-time contributor. good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. needs-cherry-pick-release-6.5 needs-cherry-pick-release-7.1 sig/planner SIG: Planner type/enhancement

Comments

@qw4990
Copy link
Contributor

qw4990 commented May 31, 2023

Enhancement

See the case below, the binding for ... a in (1, 2, 3) can not match queries with only 1 element in the in-list ... a in (1) :

mysql> create table t (a int);
Query OK, 0 rows affected (0.09 sec)

mysql> create binding for select * from t where a in(1, 2, 3) using select * from t where a in (1, 2, 3);
Query OK, 0 rows affected (0.01 sec)

mysql> select * from t where a in (1, 2,3);
Empty set (0.01 sec)

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

mysql> select * from t where a in (1, 2);
Empty set (0.01 sec)

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

mysql> select * from t where a in (1);
Empty set (0.00 sec)

mysql> select @@last_plan_from_binding;
+--------------------------+
| @@last_plan_from_binding |
+--------------------------+
|                        0 |
+--------------------------+
1 row in set (0.00 sec)
@qw4990 qw4990 added type/enhancement help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. sig/planner SIG: Planner epic/sql-plan-management first-time-contributor Indicates that the PR was contributed by an external member and is a first-time contributor. labels May 31, 2023
@qw4990 qw4990 self-assigned this May 31, 2023
@IAmUnbounded
Copy link

Can I give this a try ?

@isabella0428
Copy link
Contributor

/assign

@qw4990
Copy link
Contributor Author

qw4990 commented Sep 11, 2023

Another issue needed to be solve:

mysql> create binding for select * from t where a in (1, 2, 3) using select * from t where a in (1);
ERROR 1105 (HY000): hinted sql and origin sql don't match when hinted sql erase the hint info, after erase hint info, originSQL:select * from `test` . `t` where `a` in ( ... ), hintedSQL:select * from `test` . `t` where `a` in ( ? )

@qw4990
Copy link
Contributor Author

qw4990 commented Sep 11, 2023

A new issue:

create binding for select * from t where a in (1) using select * from t where a in (1);
drop binding for select * from t where a in (1, 2, 3);
show bindings;

@qw4990
Copy link
Contributor Author

qw4990 commented Sep 12, 2023

A small test plan for this issue:

  • Bindings for in (?) can work for in (?, ?, ?)
  • Bindings for in (?, ?, ?) can work for in (?)
  • Bindings with multiple in-lists, e.g. a in (?) and b in (?) can work for a in (?,?,?) and b in (?,?,?)
  • Create bindings with in (?) and in (?,?,?) and only 1 bindings will be left
  • create binding for ... in (?) using ... in (?, ?, ?) can succeed
  • create binding for ... in (?, ?, ?) using ... in (?) can succeed
  • Create binding with in(?) or in(?,?,?) and then drop binding by using in (?,?,?) or in(?)
  • Create binding with in(?) or in(?,?,?) and then set binding status by using in (?,?,?) or in(?)
  • Create fast binding from in (?) and it can work for in (?,?,?)
  • Create a binding in (?) on an old TiDB and then upgrade it, and then this binding can work for in (?) and in (?,?,?)
  • Create a binding in (?,?,?) on an old TiDB and then upgrade it, and then this binding can work for in (?) and in (?,?,?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
epic/sql-plan-management first-time-contributor Indicates that the PR was contributed by an external member and is a first-time contributor. good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. needs-cherry-pick-release-6.5 needs-cherry-pick-release-7.1 sig/planner SIG: Planner type/enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants