Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transform semi join to inner join #7205

Closed
zz-jason opened this issue Jul 31, 2018 · 3 comments
Closed

transform semi join to inner join #7205

zz-jason opened this issue Jul 31, 2018 · 3 comments
Assignees
Labels
sig/planner SIG: Planner type/enhancement The issue or PR belongs to an enhancement.

Comments

@zz-jason
Copy link
Member

Take this query as an example:

select * from t1 where t1.a in (select a from t2);

The plan for this query can be:
2018-07-31 16 36 18

Here the above "semi join" can be transformed to an "inner join":
2018-07-31 16 42 43

This transform is logically equivalent, they can result different physical plans.

In some scenarios, table "t1" has an index on column "t1.a", the transformed "InnerJoin" can be implemented by a "IndexJoin", which uses the result of the "Aggregate" as the outer rows to build the index ranges on "t1.a", directly extract the matched rows on table "t1". That is to say: the physical plan of the later one can be more efficient than the former one.

@zz-jason zz-jason added type/enhancement The issue or PR belongs to an enhancement. sig/planner SIG: Planner labels Jul 31, 2018
@zz-jason zz-jason self-assigned this Jul 31, 2018
@winoros
Copy link
Member

winoros commented Jul 31, 2018

It depends on stats so i think we'd better not add it in the current optimizer.

@zz-jason
Copy link
Member Author

@winoros Yes, it's better after we have supported the volcano or cascades planner model.

@winoros
Copy link
Member

winoros commented Jan 8, 2019

Done by #7531.
It will be controlled by cost in the cascades-like planner.


Why we do this in the current planner?
It's shown that this way can beat unfold in-subquery in most cases.

@winoros winoros closed this as completed Jan 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/planner SIG: Planner type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

No branches or pull requests

2 participants