Skip to content

Query: Include: Second part of new IncludeCompiler - Adds support for single level collection includes. - #7974

Merged
anpete merged 1 commit into
devfrom
inc-collections3
Mar 24, 2017
Merged

anpete merged 1 commit into
devfrom
inc-collections3

Conversation

@anpete

@anpete anpete commented Mar 23, 2017

Copy link
Copy Markdown
Contributor
  • Collection includes now built using QueryModel!
  • Added Task "lifting" capability to core query Select/GroupBy operations enabling async projection, required when enumerating included collections asynchronously.
  • Added family of Conditional -> Coalesce expression optimizations.
  • Added ICloneableQueryAnnotation used to clone query annotations from Include outer QueryModel.
  • Added AssertSql for easier SQL baseline updating.

@smitpatel

Copy link
Copy Markdown
Contributor

:shipit:

.GetDeclaredMethod(nameof(_GroupByAsync));

// ReSharper disable once InconsistentNaming
private static IAsyncEnumerable<IGrouping<TKey, TElement>> _GroupByAsync<TSource, TKey, TElement>(

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.

Can we move these methods into a separate file or in AsyncLinqOperatorProvider ?

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.

+1

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.

@smitpatel @maumar These have no sync counterparts and so would prefer to keep them as impl. detail. I have been pondering using partials more for managing nested classes, thoughts?

) AS [t7]
ORDER BY [t6].[CustomerID]

SELECT [c2.Orders].[OrderID], [c2.Orders].[CustomerID], [c2.Orders].[EmployeeID], [c2.Orders].[OrderDate]

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.

why do we issue this query?

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.

There are a few cases for complex queries where we generate worse queries after this change. Haven't looked deeply into it yet, but something is preventing full lifting for this query.

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.

should we file a bug to track this?

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.

Yep, will do.

{
// Converts '[q] != null ? [q] : [s]' into '[q] ?? [s]'

if (binaryExpression.NodeType == ExpressionType.NotEqual

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.

helper method?

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.

For the whole block? If so, considered it but will take another look


/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.

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.

how is it different from base?

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.

Looks like some stale code, will remove.

return identityMap.CreateIncludeKeyComparer(navigation, (ValueBuffer)boxedValueBuffer);
}

#region Legacy Include

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.

do we still need legacy?

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.

For a little longer.

@smitpatel

Copy link
Copy Markdown
Contributor

4 test failures in SqlServer.FunctionalTests

WHERE EXISTS (
SELECT 1
FROM [Gear] AS [g]
SELECT [g.Weapons].[Id], [g.Weapons].[AmmunitionType], [g.Weapons].[IsAutomatic], [g.Weapons].[Name], [g.Weapons].[OwnerFullName], [g.Weapons].[SynergyWithId]

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.

consider adding a more complex scenario with coalesce :trollface: e.g.

                var query = from g1 in context.Gears.Include(g => g.Weapons)
                            join g2 in context.Gears
                            on g1.LeaderNickname equals g2.Nickname into grouping
                            from g2 in grouping.DefaultIfEmpty()
                            join g3 in context.Gears
                            on g2.LeaderNickname equals g3.Nickname into grouping2
                            from g3 in grouping2.DefaultIfEmpty()
                            select g3 ?? g1 ?? g2;

it actually does work!

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.

@maumar Did you ever doubt it? :trollface:

@anpete anpete mentioned this pull request Mar 23, 2017
8 of 12 tasks
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public static bool IsIncludeMethod([NotNull] MethodCallExpression methodCallExpression)

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.

DRY it up with MethodIsClosedFormOf, or u wanted to avoid the second methodCallExpression.Method.IsGenericMethod?

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.

DRYing is fine

return node;
}

return Expression.Lambda(newBody, node.Name, node.TailCall, newParameters);

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.

node.Update doesn't work for some cases? (the default implementation from ExpressionVisitor)

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.

Checking

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.

The lambda's type may change here, which Update does not allow.


if (binaryExpression.NodeType == ExpressionType.NotEqual
&& binaryExpression.Left is QuerySourceReferenceExpression querySourceReferenceExpression1
&& binaryExpression.Right.RemoveConvert() is ConstantExpression constantExpression1

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.

Could be worthwhile to create extension method IsNullConstantExpression, this pattern is used in other places also (e.g. member access binding, sql translating visitor). Unless we don't want extension on Expression (base type)

}
= (queryModel.SelectClause.Selector as QuerySourceReferenceExpression)?.ReferencedQuerySource
??
// The selector may not have been a QSRE but this query model may still have something that needs adjusted.

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.

nit: move the comment up, so that it's not in the middle of coalesce expression.

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.

But having block comment in the middle of binary operator is awesome! :trollface:

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.

R# 😍

@anpete
anpete force-pushed the inc-collections3 branch from 200fd01 to a0ce95d Compare March 24, 2017 04:13
… single level collection includes.

- Collection includes now built using QueryModel!
- Added Task "lifting" capability to core query Select/GroupBy operations enabling async projection, required when enumerating included collections asynchronously.
- Added family of Conditional -> Coalesce expression optimizations.
- Added ICloneableQueryAnnotation used to clone query annotations from Include outer QueryModel.
- Added AssertSql for easier SQL baseline updating.
@anpete
anpete force-pushed the inc-collections3 branch from a0ce95d to 67b6733 Compare March 24, 2017 05:59
@anpete
anpete merged commit 67b6733 into dev Mar 24, 2017
@anpete
anpete deleted the inc-collections3 branch March 24, 2017 06:12
@joacar

joacar commented Mar 28, 2017

Copy link
Copy Markdown

Looking good, can't wait to try this out. Will this be scheduled for the 1.2.0 release and if so, what date is it expected to be released?

@smitpatel

Copy link
Copy Markdown
Contributor

@joacar - We don't have dates yet. If you want to try this out you can use our nightly builds.

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.

6 participants