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

Query: in case of joins, we shouldn't be materializing Inner if the qsre itself is not present in final projection #10210

Closed
maumar opened this issue Nov 2, 2017 · 3 comments · Fixed by #17805
Assignees
Labels
area-perf closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. punted-for-2.1 type-enhancement
Milestone

Comments

@maumar
Copy link
Contributor

maumar commented Nov 2, 2017

Query:

from g in ctx.Gears
join inner in (
     from g2 in ctx.Gears
     select new { g2.Nickname }
     ) on g.Nickname equals inner.Nickname
select g;

produces the following query plan:

(QueryContext queryContext) => IEnumerable<Gear> _InterceptExceptions(
    source: IEnumerable<Gear> _ShapedQuery(
        queryContext: queryContext, 
        shaperCommandContext: SelectExpression: 
            SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOrBirthName], [g].[Discriminator], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], [t].[Nickname]
            FROM [Gears] AS [g]
            INNER JOIN (
                SELECT [g2].[Nickname]
                FROM [Gears] AS [g2]
                WHERE [g2].[Discriminator] IN (N'Officer', N'Gear')
            ) AS [t] ON [g].[Nickname] = [t].[Nickname]
            WHERE [g].[Discriminator] IN (N'Officer', N'Gear'), 
        shaper: (BufferedOffsetEntityShaper<Gear>
        materializer: (TransparentIdentifier<Gear, <>f__AnonymousType227<string>> t0) => t0.Outer)), 
    contextType: TestModels.GearsOfWarModel.GearsOfWarContext, 
    logger: DiagnosticsLogger<Query>, 
    queryContext: queryContext)

We actually don't need to materialize inner, so the materializer could be simplified by stripping the transparent identifier.

Another case that could also be improved, is when element of the inner is present in the final projection, but the inner qsre is not. In that case, we also don't need to materialize the inner and we can directly bind to the value buffer instead:

from g in ctx.Gears
join inner in (
     from g2 in ctx.Gears
     select new { g2.Nickname }
     ) on g.Nickname equals inner.Nickname
select new { g, inner.Nickname };
@smitpatel
Copy link
Member

Also related #9892

@smitpatel
Copy link
Member

        [ConditionalFact]
        public virtual void Anonymous_projection_AsNoTracking_Min()
        {
            AssertQueryScalar<Order>(
                os => os.Select(o => new { A = o.CustomerID, B = o.OrderDate })
                    .AsNoTracking() // Just to cause a subquery
                    .Select(e => e.B));
        }

This causes the selector to be evaluated on client. With aggregate operator like Min/Max causes really bad query. Eliminating anonymous types would be helpful in such cases.

@AndriySvyryd AndriySvyryd added the verify-fixed This issue is likely fixed in new query pipeline. label Aug 22, 2019
@ajcvickers ajcvickers modified the milestones: Backlog, 3.1.0 Sep 4, 2019
@maumar
Copy link
Contributor Author

maumar commented Sep 11, 2019

verified this issue has been fixed in 3.0

@maumar maumar added closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. and removed verify-fixed This issue is likely fixed in new query pipeline. labels Sep 11, 2019
@maumar maumar modified the milestones: 3.1.0, 3.0.0 Sep 11, 2019
maumar added a commit that referenced this issue Sep 12, 2019
Resolves #8723
Resolves #9241
Resolves #10172
Resolves #10210
Resolves #10548
Resolves #11847
Resolves #11933
Resolves #12741
Resolves #15798
@maumar maumar closed this as completed in 36a7bdf Sep 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-perf closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. punted-for-2.1 type-enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants