Skip to content

planner: part of union stmt can't use index #17154

Closed
@wshwsh12

Description

Feature Request

Please answer these questions before submitting your issue. Thanks!

1. What did you do?

drop table t1;
drop table t2;
create table t1(a int,index idx(a));
create table t2(a bigint,index idx(a));
create view tmp as (select * from t1 union all select * from t2);
desc select * from tmp where a = 1;

2. What did you expect to see?

Both t1 and t2 table can use index.

3. What did you see instead?

tidb> desc select * from tmp where a = 1;
+--------------------------------+----------+-----------+------------------------+----------------------------------------------+
| id                             | estRows  | task      | access object          | operator info                                |
+--------------------------------+----------+-----------+------------------------+----------------------------------------------+
| Union_12                       | 8010.00  | root      |                        |                                              |
| ├─Projection_13                | 8000.00  | root      |                        | cast(test.t1.a, bigint(20) BINARY)->Column#5 |
| │ └─TableReader_16             | 8000.00  | root      |                        | data:Selection_15                            |
| │   └─Selection_15             | 8000.00  | cop[tikv] |                        | eq(cast(test.t1.a), 1)                       |
| │     └─TableFullScan_14       | 10000.00 | cop[tikv] | table:t1               | keep order:false, stats:pseudo               |
| └─IndexReader_22               | 10.00    | root      |                        | index:IndexRangeScan_21                      |
|   └─IndexRangeScan_21          | 10.00    | cop[tikv] | table:t2, index:idx(a) | range:[1,1], keep order:false, stats:pseudo  |
+--------------------------------+----------+-----------+------------------------+----------------------------------------------+
7 rows in set (0.00 sec)

4. What version of TiDB are you using? (tidb-server -V or run select tidb_version(); on TiDB)

master

Metadata

Assignees

Labels

sig/plannerSIG: Plannertype/enhancementThe issue or PR belongs to an enhancement.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions