pingcap/tidb

support KV Scan with ranges if possible to speedup queries

Open

#14 907 ouverte le 23 févr. 2020

Voir sur GitHub
 (5 commentaires) (0 réactions) (0 assignés)Go (6 186 forks)batch import
help wantedsig/plannertype/enhancement

Métriques du dépôt

Stars
 (40 090 stars)
Métriques de merge PR
 (Merge moyen 14j 4h) (346 PRs mergées en 30 j)

Description

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

Guide contributeur