pingcap / pingcap/tidb

Support build range scan plan when SQL have comparisons in combined index row

Open
#38,553 0 comments 0 reactions 0 assignees View on GitHub
type/enhancement
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Enhancement

### SQL
```mysql
create table t(a int, b int, c int, primary key(a, b));
explain select * from t where (a, b) > (1, 2) and (a, b) < (3, 0);
```
### Result

```
+-------------------------+----------+-----------+---------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| id | estRows | task | access object | operator info |
+-------------------------+----------+-----------+---------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| TableReader_7 | 8000.00 | root | | data:Selection_6 |
| └─Selection_6 | 8000.00 | cop[tikv] | | if(ne(test.t.a, 1), gt(test.t.a, 1), if(isnull(ne(test.t.a, 1)), NULL, gt(test.t.b, 2))), if(ne(test.t.a, 3), lt(test.t.a, 3), if(isnull(ne(test.t.a, 3)), NULL, lt(test.t.b, 0))) |
| └─TableFullScan_5 | 10000.00 | cop[tikv] | table:t | keep order:false, stats:pseudo |
+-------------------------+----------+-----------+---------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
```
Condition `(a, b) > (1, 2) and (a, b) < (3, 0)` should build to range scan

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the provided MySQL query and EXPLAIN output in TiDB, then trace the planner path that handles row comparisons against the combined primary index. The work is done when `(a, b) > (1, 2) AND (a, b) < (3, 0)` produces a range scan rather than a full scan with a selection filter.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, sql
Domain
databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.