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: compilation error (dangling qsre) for queries with SelectMany whose selector is a subquery referencing outer qsre #11941

Closed
maumar opened this issue May 8, 2018 · 8 comments · Fixed by #17812
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. regression type-bug
Milestone

Comments

@maumar
Copy link
Contributor

maumar commented May 8, 2018

Repro:

    class Program
    {
        static void Main(string[] args)
        {
            using (var ctx = new MyContext())
            {
                ctx.Database.EnsureDeleted();
                ctx.Database.EnsureCreated();
            }

            using (var ctx = new MyContext())
            {
                var query = from c in ctx.Customers
                            from g in (from o in ctx.Orders
                                       where c.Id == o.CustomerId
                                       select new { OwnerName = o.Name, CustomerName = c.Name })
                            select g;

                var result = query.ToList();
            }
        }
    }

    public class Customer
    {
        public int Id { get; set; }
        public string Name { get; set; }

        public List<Order> Orders { get; set; }
    }

    public class Order
    {
        public int Id { get; set; }
        public string Name { get; set; }

        public int CustomerId { get; set; }
    }

    public class MyContext : DbContext
    {
        public DbSet<Customer> Customers { get; set; }
        public DbSet<Order> Orders { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseSqlServer(@"Server=.;Database=Repro11941;Trusted_Connection=True;MultipleActiveResultSets=True");
        }
    }

QP:

(QueryContext queryContext) => IEnumerable<<>f__AnonymousType0<string, string>> _InterceptExceptions(
    source: IEnumerable<<>f__AnonymousType0<string, string>> _Select(
        source: IEnumerable<TransparentIdentifier<ValueBuffer, <>f__AnonymousType0<string, string>>> _SelectMany(
            source: IEnumerable<ValueBuffer> _ShapedQuery(
                queryContext: queryContext, 
                shaperCommandContext: SelectExpression: 
                    SELECT [c].[Id], [c].[Name]
                    FROM [Customers] AS [c], 
                shaper: ValueBufferShaper), 
            collectionSelector: (ValueBuffer c) => IEnumerable<<>f__AnonymousType0<string, string>> _Select(
                source: IEnumerable<ValueBuffer> _ShapedQuery(
                    queryContext: queryContext, 
                    shaperCommandContext: SelectExpression: 
                        SELECT [t].[OwnerName], [t].[CustomerName]
                        FROM (
                            SELECT [o].[Name] AS [OwnerName], [c].[Name] AS [CustomerName]
                            FROM [Orders] AS [o]
                            WHERE [c].[Id] = [o].[CustomerId]
                        ) AS [t], 
                    shaper: ValueBufferShaper), 
                selector: (ValueBuffer o) => new <>f__AnonymousType0<string, string>(
                    string TryReadValue(o, 0, Order.Name), 
                     ---> [c] <--- .Name
                )), 
            resultSelector: (ValueBuffer c | <>f__AnonymousType0<string, string> g) => TransparentIdentifier<ValueBuffer, <>f__AnonymousType0<string, string>> CreateTransparentIdentifier(
                outer: c, 
                inner: g)), 
        selector: (TransparentIdentifier<ValueBuffer, <>f__AnonymousType0<string, string>> t0) => t0.Inner), 
    contextType: Repro11933.MyContext, 
    logger: DiagnosticsLogger<Query>, 
    queryContext: queryContext)
@maumar
Copy link
Contributor Author

maumar commented May 9, 2018

This is a regression from 2.0.2.

QP in 2.0.2:

(QueryContext queryContext) => IEnumerable<<>f__AnonymousType0<string, string>> _InterceptExceptions(
          source: IEnumerable<<>f__AnonymousType0<string, string>> _ShapedQuery(
              queryContext: queryContext,
              shaperCommandContext: SelectExpression:
                  SELECT [o].[Name] AS [OwnerName], [c].[Name] AS [CustomerName]
                  FROM [Customers] AS [c]
                  CROSS JOIN [Orders] AS [o]
                  WHERE [c].[Id] = [o].[CustomerId],
              shaper: TypedProjectionShaper<TypedCompositeShaper<ValueBufferShaper, ValueBuffer, ValueBufferShaper, ValueBuffer, TransparentIdentifier<ValueBuffer, ValueBuffer>>, TransparentIdentifier<ValueBuffer, ValueBuffer>, <>f__AnonymousType0<string, string>>),
          contextType: EFSampleApp.MyContext,
          logger: DiagnosticsLogger<Query>,
          queryContext: queryContext)

@maumar
Copy link
Contributor Author

maumar commented May 9, 2018

related to #11933

@maumar
Copy link
Contributor Author

maumar commented May 9, 2018

@ajcvickers
Copy link
Member

@smitpatel Assigned this one to you as a regression in 2.1. It is related to #11933 which @maumar has been investigating. We think that when this is fixed, then it will also fix that issue.

@ajcvickers
Copy link
Member

@maumar to look for workarounds.
@smitpatel to fix before 5PM.

@ajcvickers
Copy link
Member

ajcvickers commented May 11, 2018

@smitpatel / @maumar Can you point to the place (PR, issue, or commit) where we introduced this break?

@maumar
Copy link
Contributor Author

maumar commented May 11, 2018

Workaround:

from c in ctx.Customers
from o in ctx.Orders
where c.Id == o.CustomerId
select new { OwnerName = o.Name, CustomerName = c.Name }

this is essentially what we translated to in 2.0.2

@smitpatel
Copy link
Contributor

@ajcvickers - PR #10647

@smitpatel smitpatel removed this from the 2.1.0 milestone May 11, 2018
@ajcvickers ajcvickers added this to the 2.2.0 milestone May 14, 2018
@ajcvickers ajcvickers modified the milestones: 2.2.0, Backlog Jun 5, 2018
@smitpatel smitpatel removed their assignment Sep 1, 2018
@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
@smitpatel smitpatel self-assigned this Sep 12, 2019
@smitpatel smitpatel 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 12, 2019
@smitpatel smitpatel removed this from the 3.1.0 milestone Sep 12, 2019
@smitpatel smitpatel added this to the 3.0.0 milestone Sep 12, 2019
smitpatel added a commit that referenced this issue Sep 12, 2019
smitpatel added a commit that referenced this issue Sep 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. regression type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants