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

feat: support subquery in FROM clause #756

Merged
merged 26 commits into from
Jan 7, 2023
Merged

Conversation

MingjiHan99
Copy link
Collaborator

@MingjiHan99 MingjiHan99 commented Dec 30, 2022

This PR introduces alias and output_alias to the binder context.

For table:

create table t(a int, b int);

and query:

select x.a, y.a from 
    (select -a as a from t) as x,
    (select -b as a from t) as y;

After binding from t, the context will be:

[alias]
a = { t: "$t.a" }
b = { t: "$t.b" }
[output_alias]

Later when binding a, it will lookup the alias map and get node $t.a.

After binding select -a as a from t, the context will be:

[alias]
a = { t: "(- $t.a)" }
b = { t: "$t.b" }
[output_alias]
a = "(ref (- $t.a))"

The node ref is used to refer an expression as a whole and prevent optimization.

Then the output_alias will be moved to the upper context:

[alias]
a = { x: "(ref (- $t.a))" }
[output_alias]

Later the binder will get (ref (- $t.a)) when binding select x.a.

The final binding result of this query will be:

(proj (list (ref (- $t.a)) (ref (- $t.b)))
  (join inner true
    (proj (list (- $t.a))
      (scan $t (list $t.a $t.b)))
    (proj (list (- $t.b))
      (scan $t (list $t.a $t.b)))
))

Next it comes to the optimizer. The projection pushdown rules are fixed to properly treat (- $t.a) instead of $t.a as a basic unit above the join node.

Signed-off-by: MingjiHan <mjhan@bu.edu>
Signed-off-by: MingjiHan <mjhan@bu.edu>
Signed-off-by: MingjiHan <mjhan@bu.edu>
Signed-off-by: MingjiHan <mjhan@bu.edu>
Signed-off-by: MingjiHan <mjhan@bu.edu>
MingjiHan99 and others added 14 commits December 30, 2022 20:59
Signed-off-by: MingjiHan <mjhan@bu.edu>
Signed-off-by: MingjiHan <mjhan@bu.edu>
Signed-off-by: MingjiHan <mjhan@bu.edu>
Signed-off-by: MingjiHan <mjhan@bu.edu>
Signed-off-by: MingjiHan <mjhan@bu.edu>
Signed-off-by: MingjiHan <mjhan@bu.edu>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
@wangrunji0408 wangrunji0408 marked this pull request as ready for review January 4, 2023 09:23
@wangrunji0408 wangrunji0408 changed the title Mingji subquery binder feat: support subquery in FROM clause Jan 4, 2023
don't know why the result is different from macOS

Signed-off-by: Runji Wang <wangrunji0408@163.com>
@wangrunji0408 wangrunji0408 enabled auto-merge (squash) January 7, 2023 16:16
@wangrunji0408 wangrunji0408 merged commit 529b408 into main Jan 7, 2023
@wangrunji0408 wangrunji0408 deleted the mingji-subquery-binder branch January 7, 2023 16:24
This was referenced Jan 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants