feat: core/translate: uncorrelated FROM clause subqueries #566
+1,092
−310
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 will warn that this PR is quite big out of necessity, since subqueries are, as the name implies, queries within queries, so everything that works with a regular query should also work with a subquery, roughly speaking.
select sub.renamed from (select name as renamed from products) sub
)select sub.name from (select name from products where name = 'joe') sub
, and,select sub.name from (select name from products) sub where sub.name = 'joe'
)SelectPlan
that never emit ResultRows, instead theyYield
control back to the parent query, and the parent query can copy the subquery result values into a ResultRow. New variantSourceOperator::Subquery
that wraps a subquerySelectPlan
.select p.name from products
) but also subqueries (select sub.foo from (select name as foo from products) sub
. Hence this PR also adds support for column aliases which didn't exist before.Expr::Column
that refers to a regular table will result in anInsn::Column
(i.e. a read from disk/memory) whereas anExpr::Column
that refers to a subquery will result in anInsn::Copy
(from register to register) insteadSELECT * FROM (SELECT * FROM users) sub
the subquery can just be entirely removed)This PR does not add support (yet) for:
SELECT t.foo, (SELECT .......) as column_from_subquery FROM t
SELECT * FROM t1 WHERE t1.foo IN (SELECT ...)
Example bytecode with comments added: