pingcap/tidb

support KV Scan with ranges if possible to speedup queries

Open

#14,907 建立於 2020年2月23日

在 GitHub 查看
 (5 留言) (0 反應) (0 負責人)Go (40,090 star) (6,186 fork)batch import
help wantedsig/plannertype/enhancement

描述

Feature Request

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

consider this case:

create table t(a bigint primary key, b bigint);

The following query can use PointGet to speed up:

TiDB(root@127.0.0.1:test) > desc select * from t where a = 1;
+-------------+-------+------+-------------------+
| id          | count | task | operator info     |
+-------------+-------+------+-------------------+
| Point_Get_1 | 1.00  | root | table:t, handle:1 |
+-------------+-------+------+-------------------+
1 row in set (0.00 sec)

while the following query can not:

TiDB(root@127.0.0.1:test) > desc select * from t where a >= 1 and a <= 100;
+-------------------+--------+-----------+--------------------------------------------------------+
| id                | count  | task      | operator info                                          |
+-------------------+--------+-----------+--------------------------------------------------------+
| TableReader_6     | 123.75 | root      | data:TableScan_5                                       |
| └─TableScan_5     | 123.75 | cop[tikv] | table:t, range:[1,100], keep order:false, stats:pseudo |
+-------------------+--------+-----------+--------------------------------------------------------+
2 rows in set (0.00 sec)

Describe the feature you'd like:

Directly calling KV Scan with ranges may help to speed the above query, the execution plan may look like:

TiDB(root@127.0.0.1:test) > desc select * from t where a = 1;
+---------------+---------+------+------------------------+
| id            | count   | task | operator info          |
+---------------+---------+------+------------------------+
| KVRangeScan_1 | 123.75  | root | table:t, range:[1,100] |
+---------------+---------+------+------------------------+
1 row in set (0.00 sec)

Describe alternatives you've considered:

For discrete values like int, we can convert range queries to in(). take the above query as an example, the equivalent query is:

select * from t where a in(1, 2, ..., 100);

Then this query can benefit from BatchPoint in this case.

Teachability, Documentation, Adoption, Migration Strategy:

No

貢獻者指南