TiDB planner should convert always-false filter to tableDual
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Enhancement
```
mysql> explain select count(*) from lineitem where '2018-01-01' > '2019-01-01';
+--------------------+---------+------+---------------+---------------------------+
| id | estRows | task | access object | operator info |
+--------------------+---------+------+---------------+---------------------------+
| StreamAgg_8 | 1.00 | root | | funcs:count(1)->Column#18 |
| └─TableDual_10 | 0.00 | root | | rows:0 |
+--------------------+---------+------+---------------+---------------------------+
```
Since `'2018-01-01' > '2019-01-01'` is always false, so TiDB convert it to TableDual, it is as expected, however,
```
mysql> explain select count(*) from lineitem where L_RECEIPTDATE > 't';
+----------------------------+-------------+--------------+----------------+---------------------------------------+
| id | estRows | task | access object | operator info |
+----------------------------+-------------+--------------+----------------+---------------------------------------+
| StreamAgg_12 | 1.00 | root | | funcs:count(1)->Column#18 |
| └─TableReader_19 | 0.00 | root | | data:Selection_18 |
| └─Selection_18 | 0.00 | cop[tiflash] | | gt(tpch.lineitem.l_receiptdate, NULL) |
| └─TableFullScan_17 | 59986052.00 | cop[tiflash] | table:lineitem | keep order:false |
+----------------------------+-------------+--------------+----------------+---------------------------------------+
4 rows in set, 1 warning (0.00 sec)
```
`gt(tpch.lineitem.l_receiptdate, NULL)` is also always false, but TiDB does not convert it to TableDual
Contributor guide
Assessment
This issue has not been assessed yet.