tidb icon indicating copy to clipboard operation
tidb copied to clipboard

Enhance access path selection

Open alivxxx opened this issue 7 years ago • 4 comments

Feature Request

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

Suppose there is a table: create table t(a int, b int, c int, index idx1(b, a), index idx2(a));; For queries like select * from t where a = x and b = xx, the optimizer may choose idx2, but it is a very risky path compares to idx1.

Describe the feature you'd like:

If there are multi paths available, and the access conditions of the path a could strictly covers b, then we should never choose b as access condition.

alivxxx avatar Dec 06 '18 05:12 alivxxx

Seems it already works now?

mysql> create table t(a int, b int, c int, index idx1(b, a), index idx2(a));
Query OK, 0 rows affected (0.01 sec)

mysql> explain select * from t where a = 1 and b = 1;
+-------------------+-------+------+----------------------------------------------------------------------+
| id                | count | task | operator info                                                        |
+-------------------+-------+------+----------------------------------------------------------------------+
| IndexLookUp_10    | 0.10  | root |                                                                      |
| ├─IndexScan_8     | 0.10  | cop  | table:t, index:b, a, range:[1 1,1 1], keep order:false, stats:pseudo |
| └─TableScan_9     | 0.10  | cop  | table:t, keep order:false, stats:pseudo                              |
+-------------------+-------+------+----------------------------------------------------------------------+
3 rows in set (0.00 sec)

You mean the stats may result in a wrong choice?

eurekaka avatar Dec 06 '18 06:12 eurekaka

@eurekaka Yes, the stats may result in a wrong choice.

alivxxx avatar Dec 06 '18 06:12 alivxxx

I guess there are many heuristic rules in other database's operators. Could we borrow something?

shenli avatar Dec 06 '18 06:12 shenli

Yes, there are some other interesting rules like skyline pruning, we could learn from them.

alivxxx avatar Dec 06 '18 08:12 alivxxx