pingcap / tidb

TiDB is an open-source, cloud-native, distributed, MySQL-Compatible database for elastic scale and real-time analytics. Try AI-powered Chat2Query free at : https://www.pingcap.com/tidb-serverless/
https://pingcap.com
Apache License 2.0
36.89k stars 5.81k forks source link

optimize the plan built for a range scan on int #11143

Open wshwsh12 opened 5 years ago

wshwsh12 commented 5 years ago

Feature Request

Is your feature request related to a problem? Please describe:

Now the plan built for a range scan on int can be better. e.g.

mysql> CREATE TABLE tb (a int1);
mysql> Desc select * from tb where a > 200;
+---------------------+----------+------+-------------------------------------------------------------+
| id                  | count    | task | operator info                                               |
+---------------------+----------+------+-------------------------------------------------------------+
| TableReader_7       | 3333.33  | root | data:Selection_6                                            |
| └─Selection_6       | 3333.33  | cop  | gt(test.tb.a, 200)                                          |
|   └─TableScan_5     | 10000.00 | cop  | table:tb, range:[-inf,+inf], keep order:false, stats:pseudo |
+---------------------+----------+------+-------------------------------------------------------------+
3 rows in set (0.00 sec)

mysql> Desc select * from tb where a < 200;
+---------------------+----------+------+-------------------------------------------------------------+
| id                  | count    | task | operator info                                               |
+---------------------+----------+------+-------------------------------------------------------------+
| TableReader_7       | 3323.33  | root | data:Selection_6                                            |
| └─Selection_6       | 3323.33  | cop  | lt(test.tb.a, 200)                                          |
|   └─TableScan_5     | 10000.00 | cop  | table:tb, range:[-inf,+inf], keep order:false, stats:pseudo |
+---------------------+----------+------+-------------------------------------------------------------+
3 rows in set (0.00 sec)

Describe the feature you'd like:

The result can be better.

mysql> Desc select * from tb where a > 200;
+-------------+-------+------+---------------+
| id          | count | task | operator info |
+-------------+-------+------+---------------+
| TableDual_6 | 0.00  | root | rows:0        |
+-------------+-------+------+---------------+
1 row in set (0.00 sec)

mysql> Desc select * from tb where a < 200;
+-------------------+----------+------+-------------------------------------------------------------+
| id                | count    | task | operator info                                               |
+-------------------+----------+------+-------------------------------------------------------------+
| TableReader_6     | 10000.00 | root | data:TableScan_5                                            |
| └─TableScan_5     | 10000.00 | cop  | table:tb, range:[-inf,+inf], keep order:false, stats:pseudo |
+-------------------+----------+------+-------------------------------------------------------------+
2 rows in set (0.00 sec)

Describe alternatives you've considered:

No. Teachability, Documentation, Adoption, Migration Strategy:

No.

zz-jason commented 5 years ago

How to decide whether to use TableDual?