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

Bug: In multi-level nested subquery, the field relationships of different tables are wrong. #169

Closed
KKould opened this issue Mar 17, 2024 · 2 comments · Fixed by #173
Closed
Assignees
Labels
bug Something isn't working

Comments

@KKould
Copy link
Member

KKould commented Mar 17, 2024

Bug Report

It seems to project twice on temp table.
And I don't think it can handle more complex situations.

explain SELECT b FROM t1 WHERE a in (SELECT a FROM t2 where (select a from t1));
                               PLAN
-------------------------------------------------------------------
Projection [t1.b] [Project]                                      +
  LeftSemi Join On t1.a = (t2.a) as (_temp_table_2_.a) [HashJoin]+
    Scan t1 -> [a, b] [SeqScan]                                  +
    Projection [(t2.a) as (_temp_table_2_.a)] [Project]          +
      Projection [t2.a] [Project]                                +
        Inner Join Where _temp_table_1_.a [HashJoin]             +
          Scan t2 -> [a] [SeqScan]                               +
          Projection [(t2.a) as (_temp_table_1_.a)] [Project]    +
            Projection [t2.a] [Project]                          +
              Scan t1 -> [] [SeqScan]

I think every query using their own binder context may be a solution, but it may be a big work.

#168 (comment)

@KKould KKould added the bug Something isn't working label Mar 17, 2024
@KKould KKould changed the title [Bug]In multi-level nested subquery, the field relationships of different tables are wrong. Bug: In multi-level nested subquery, the field relationships of different tables are wrong. Mar 17, 2024
@KKould
Copy link
Member Author

KKould commented Mar 17, 2024

Is there a lighter solution? Because in issue: #162, Binder::bind also takes up a considerable part of the performance overhead. Can it be solved by using last_bind_table or something like that?

@crwen
Copy link
Member

crwen commented Mar 17, 2024

Is there a lighter solution? Because in issue: #162, Binder::bind also takes up a considerable part of the performance overhead. Can it be solved by using last_bind_table or something like that?

I'm not familiar with this. I just find duckdb have a parent field for this. It seems to be organized like the plan.

https://github.com/duckdb/duckdb/blob/main/src/include/duckdb/planner/binder.hpp#L188

https://github.com/duckdb/duckdb/blob/main/src/planner/binder/tableref/bind_subqueryref.cpp#L7C1-L31C2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants