pingcap / tidb

TiDB - the open-source, cloud-native, distributed SQL database designed for modern applications.
https://pingcap.com
Apache License 2.0
37.2k stars 5.84k forks source link

consider region distribution in optimization phase #19312

Open qw4990 opened 4 years ago

qw4990 commented 4 years ago

Feature Request

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

In the IMDB test, we found a case that two full index scans on different indexes with limitation have a huge gap on performance.

image image

In this case, we only need the first cop-task's data since there is a Limit 100. And because these two indexes have different region distributions, the number of rows need to scan to finish the first cop-task are different.

Describe the feature you'd like:

Consider region distribution in optimization phase for this case.

NOTE: introducing this physical information(region distribution) into the optimizer seems tricky, we need more discussion about this feature.

Describe alternatives you've considered:

No

Teachability, Documentation, Adoption, Migration Strategy:

qw4990 commented 4 years ago

What are your opinions? @zz-jason @eurekaka @winoros

eurekaka commented 4 years ago

That is what I mean in https://github.com/pingcap/tidb/blob/master/planner/core/find_best_task.go#L1577. Would the result change if we use stream coprocessor request?

zz-jason commented 4 years ago

highly recommended to support this in the query optimizer:

qw4990 commented 4 years ago

@tangwz and I will draft a proposal for this feature soon.

tangwz commented 4 years ago

/assign.