planner: non-prep plan cache support negative numbers
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## 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)
```
Contributor guide
Assessment
This issue has not been assessed yet.