pingcap / tidb

TiDB is an open-source, cloud-native, distributed, MySQL-Compatible database for elastic scale and real-time analytics. Try AI-powered Chat2Query free at : https://www.pingcap.com/tidb-serverless/
https://pingcap.com
Apache License 2.0
36.88k stars 5.8k forks source link

support PointGet plan when table has alias name #11149

Closed zz-jason closed 5 years ago

zz-jason commented 5 years ago

Feature Request

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

drop table if exists t;
create table t(a bigint, b bigint, c bigint, primary key(a, b));

If the table has no alias name, it can be executed with Point_Get plan:

TiDB(root@127.0.0.1:test) > desc select * from t where a = 1 and b = 1;
+-------------+-------+------+--------------------+
| id          | count | task | operator info      |
+-------------+-------+------+--------------------+
| Point_Get_1 | 1.00  | root | table:t, index:a b |
+-------------+-------+------+--------------------+
1 row in set (0.00 sec)

But if we add an alias name for the queried table, it can not be executed by Point_Get plan:

TiDB(root@127.0.0.1:test) > desc select * from t tmp where a = 1 and b = 1;
+-------------------+-------+------+------------------------------------------------------------------------+
| id                | count | task | operator info                                                          |
+-------------------+-------+------+------------------------------------------------------------------------+
| IndexLookUp_7     | 1.25  | root |                                                                        |
| ├─IndexScan_5     | 1.25  | cop  | table:tmp, index:a, b, range:[1 1,1 1], keep order:false, stats:pseudo |
| └─TableScan_6     | 1.25  | cop  | table:t, keep order:false, stats:pseudo                                |
+-------------------+-------+------+------------------------------------------------------------------------+
3 rows in set (0.00 sec)

Describe the feature you'd like:

Be able to use point get plan even when the table has an alias name.

Describe alternatives you've considered:

No

Teachability, Documentation, Adoption, Migration Strategy:

No

sduzh commented 5 years ago

while I am working on it, I found another bug: PointGet does not check the table name in where clause.

mysql> create table t(k int not null primary key);
Query OK, 0 rows affected (0.01 sec)
mysql> insert into t values(1),(2),(3);
Query OK, 3 rows affected (0.01 sec)
Records: 3  Duplicates: 0  Warnings: 0
mysql> select * from t where xxxxxxx.k=1;
+---+
| k |
+---+
| 1 |
+---+
1 row in set (0.00 sec)