pingcap / pingcap/tidb

pushdown the correlated column condition to indexScan

Open
#37,097 2 comments 0 reactions 2 assignees Claimed by @Yisaer View on GitHub
sig/planner type/enhancement
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Enhancement
``` sql
CREATE TABLE `t1` (
`a` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL,
KEY `a` (`a`),
KEY `b` (`b`)
);
CREATE TABLE `t2` (
`a` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL
);
CREATE TABLE `t3` (
`a` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL,
KEY `idx` (`b`,`a`)
);
desc select * from t1 where exists (select (select t3.b from t2, t3 where t3.a=t1.a and t2.b=t3.b and t2.a = 123) a) ;
```

The result plan:
![VQ7s5CBSoY](https://user-images.githubusercontent.com/17380469/184602325-86160665-3ae6-4fc9-9c64-5cd3faba4e3d.jpg)

We can see that the selection_28 has `t3.a=t1.a`, which can be used to build the index range in indexRangeScan_27

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.