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

[NH] Support lateral joins #5990

Closed
jseldess opened this issue Nov 26, 2019 · 2 comments · Fixed by #6425
Closed

[NH] Support lateral joins #5990

jseldess opened this issue Nov 26, 2019 · 2 comments · Fixed by #6425
Assignees
Labels
P-0 Urgent; must be done in next 2 weeks
Milestone

Comments

@jseldess
Copy link
Contributor

jseldess commented Nov 26, 2019

Background: https://airtable.com/tblD3oZPLJgGhCmch/viw1DKmbKhg2MIECH/recueu9RI5gmwC1r3

Description: Similar to a correlated subquery, a lateral inner subquery can refer to fields in rows of the table reference to determine which rows to return. A lateral subquery iterates through each row in the table reference, evaluating the inner subquery for each row, like a foreach loop. The rows returned by the inner subquery are added to the result of the join with the outer query. Without the LATERAL keyword, each subquery is evaluated independently and cannot refer to items in FROM. Note, many queries are implicitly LATERAL even if the keyword is not used.

Many customers, especially those using JSON, want to evaluate data efficiently without independently referring to the FROM clause. Currently, each subquery is evaluated independently and cannot refer to items in FROM which can be slow and complex to implement.

Team: Andrew Woods, Radu Berinde, Justin Jaffray, Chris Seto

Github Tracking Issue: cockroachdb/cockroach#24560 cockroachdb/cockroach#7841 https://github.com/cockroachdb/cockroach/pull/40945/files/aa051269c8ca407f88d1c2418308fa532361ab42..b36223663ee5d2a6a008db25d824773ff1494f06

@jseldess jseldess added this to the 20.1 milestone Nov 26, 2019
@ericharmeling ericharmeling added the P-0 Urgent; must be done in next 2 weeks label Jan 9, 2020
@ericharmeling
Copy link
Contributor

From release note issue:

PR: cockroachdb/cockroach#40945

From release notes:

Added support for the JOIN LATERAL syntax. [#40945][#40945] {% comment %}doc{% endcomment %}

@rytaft
Copy link
Contributor

rytaft commented Jan 9, 2020

Related to this issue, I think we should also have documentation for "apply join". Apply join is the operator that actually executes a lateral join if the optimizer is not able to decorrelate it (i.e., rewrite the query to use a regular join). Most of the time, customers would not need to know about apply joins since the optimizer can decorrelate most queries. However, there are some cases where the optimizer cannot perform this rewrite, and therefore "apply join" would show up in the EXPLAIN output for the query. The optimizer also replaces correlated subqueries with apply joins, and therefore "apply join" may appear in the EXPLAIN output even if LATERAL was not used.

I bring this up because a customer using 19.2 saw "apply join" in their EXPLAIN plan and didn't know what it was.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P-0 Urgent; must be done in next 2 weeks
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants