-
Notifications
You must be signed in to change notification settings - Fork 769
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(query): support left plan's from clause contains subquery #17621
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ce02c42
to
3b17699
Compare
3b17699
to
790a532
Compare
Docker Image for PR
|
bug reproduce on v1.2.707 CREATE OR REPLACE TABLE employees AS
SELECT * FROM (
VALUES
(1, 1, 50000),
(2, 2, 60000),
(3, 3, 70000)
) AS employees(employee_id, name, salary);
CREATE OR REPLACE TABLE departments AS
SELECT * FROM (
VALUES
(101, 1, 1),
(102, 2, 2),
(103, 3, 3)
) AS departments(department_id, department_name, manager_id);
CREATE OR REPLACE TABLE salaries AS
SELECT * FROM (
VALUES
(1, 50000),
(2, 60000),
(3, 70000),
(4, 80000),
(5, 90000)
) AS salaries(employee_id, salary);
SELECT
e.employee_id,
d.department_name
FROM
employees e
INNER JOIN
departments d
ON
e.employee_id = d.manager_id
WHERE
e.salary > ALL (
SELECT salary
FROM salaries
WHERE employee_id <> e.employee_id
)
ORDER BY employee_id; FIXED |
bug reproduce on v1.2.707 create or replace table tab2 as select * from (values (1, 10), (1, 20), (2, 30)) tab(n, m);
create or replace table tab3 as select * from (values (10, 100), (20, 200), (30, 300)) tab(m, k);
select
t1.n,
t2.m + t3.k as result,
(select count(tab3.k) from tab3 where tab3.k = t1.n * 100 and tab3.m = t2.m) count
from
(values (1), (2), (3)) t1(n),
tab2 t2 , tab3 t3
where t1.n = t2.n and t2.m = t3.m
order by result; FIXED |
sundy-li
approved these changes
Mar 25, 2025
f43fa11
to
b2e2b06
Compare
9a8726d
to
d299698
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/
Summary
SubqueryRewriter::flatten_plan rewrites a correlated subquery as a join. A rewrite involves a subquery plan and an outer plan.
The previous implementation didn't pass in the outer plan but got it indirectly from the metadata, so there were a lot of limitations, but in this PR, it passes in the outer plan directly.
Currently only DummyTableScan, ConstantTableScan, Scan, EvalScalar, Limit, Sort, Filter, Join, Aggregate are supported in outer plan.
#17476 (comment) cc @KKould
Tests
Type of change
This change is