Skip to content

Query: Relational: implement LEFT JOIN LATERAL / OUTER APPLY - #7857

Closed
tuespetre wants to merge 1 commit into
dotnet:devfrom
tuespetre:left-join-lateral
Closed

tuespetre wants to merge 1 commit into
dotnet:devfrom
tuespetre:left-join-lateral

Conversation

@tuespetre

Copy link
Copy Markdown
Contributor

These changes simply pull up the pushed down subquery expression created by the RelationalResultOperatorHandler for the DefaultIfEmptyResultOperator and add it as a LeftJoinLateralExpression instead of a CrossJoinLateralExpression.

Another possible optimization that could be handled later is to re-order subquery result operators to 'float' DefaultIfEmptyResultOperators to the end of the list, e.g. for cases like .DefaultIfEmpty().Distinct() or .DefaultIfEmpty().Take(x).Skip(y). That would allow more queries to become OUTER APPLY instead of CROSS APPLY.

@dnfclas

dnfclas commented Mar 12, 2017

Copy link
Copy Markdown

@tuespetre,
Thanks for having already signed the Contribution License Agreement. Your agreement was validated by .NET Foundation. We will now review your pull request.
Thanks,
.NET Foundation Pull Request Bot

{
Check.NotNull(visitor, nameof(visitor));

var specificVisitor = visitor as ISqlExpressionVisitor;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, C#7 came out since I first wrote this

@tuespetre
tuespetre force-pushed the left-join-lateral branch 3 times, most recently from 1af6773 to b9132a8 Compare March 19, 2017 18:21

@smitpatel smitpatel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

var innerSelectExpression = TryGetQuery(fromClause);

if (innerSelectExpression?.Tables.Count != 1)
if (outerSelectExpression == null || innerSelectExpression == null)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any specific reason to remove check on tables count?


if (finalResultOperator is DefaultIfEmptyResultOperator)
{
innerSelectExpression = (SelectExpression)innerSelectExpression.Tables[0];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value being used in all the paths, store in variable before entering the if blocks.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also use different variable name here. Causes bit of confusion with the table count check above, that how did we end up with 2nd table in innerSelectExpression.

@smitpatel smitpatel self-assigned this Apr 18, 2017
@smitpatel

Copy link
Copy Markdown
Contributor

@anpete @maumar - I am looking to merge this PR. Please review. Especially from translation perspective.

@smitpatel
smitpatel requested review from anpete and maumar May 15, 2017 23:20
}
else
{
outerSelectExpression.AddCrossJoinLateral(

@maumar maumar May 15, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add test for this - similar to SelectMany_Joined_DefaultIfEmpty but with .Distinct() or other result op after DIE (also maybe Distinct and then DIE?)

@smitpatel smitpatel closed this May 26, 2017
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.

4 participants