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: non-prep plan cache support negative numbers #44977

Open
qw4990 opened this issue Jun 27, 2023 · 0 comments
Open

planner: non-prep plan cache support negative numbers #44977

qw4990 opened this issue Jun 27, 2023 · 0 comments
Labels
epic/plan-cache sig/planner SIG: Planner type/enhancement The issue or PR belongs to an enhancement.

Comments

@qw4990
Copy link
Contributor

qw4990 commented Jun 27, 2023

Enhancement

As shown below, non-prep plan cache cannot support queries with any negative number.
The root cause is that all negative numbers are parsed as builtinFuncMinus(positive-number), and currently the plan cache cannot handle it.
Better to parse negative numbers as negative-number directly.

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

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

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

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

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

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

mysql> explain format='plan_cache' select * from t where a>-1;
+-------------------------+----------+-----------+---------------+--------------------------------+
| id                      | estRows  | task      | access object | operator info                  |
+-------------------------+----------+-----------+---------------+--------------------------------+
| TableReader_7           | 3333.33  | root      |               | data:Selection_6               |
| └─Selection_6           | 3333.33  | cop[tikv] |               | gt(archdb.t.a, -1)             |
|   └─TableFullScan_5     | 10000.00 | cop[tikv] | table:t       | keep order:false, stats:pseudo |
+-------------------------+----------+-----------+---------------+--------------------------------+
3 rows in set, 1 warning (0.00 sec)

mysql> show warnings;
+---------+------+---------------------------------------------------------------------------------------+
| Level   | Code | Message                                                                               |
+---------+------+---------------------------------------------------------------------------------------+
| Warning | 1105 | skip non-prepared plan-cache: query has some unsupported Node *ast.UnaryOperationExpr |
+---------+------+---------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
@qw4990 qw4990 added type/enhancement The issue or PR belongs to an enhancement. sig/planner SIG: Planner epic/plan-cache labels Jun 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
epic/plan-cache sig/planner SIG: Planner type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

No branches or pull requests

1 participant