Skip to content

Unused let in the LINQ expression changes result of Query #402

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

Closed
SergeiPavlov opened this issue Oct 31, 2024 · 1 comment
Closed

Unused let in the LINQ expression changes result of Query #402

SergeiPavlov opened this issue Oct 31, 2024 · 1 comment

Comments

@SergeiPavlov
Copy link
Contributor

SergeiPavlov commented Oct 31, 2024

(from invoice in Session.Query.All<Invoice>()
    let foo = invoice.InvoiceId.In(nonExistingIds) // This line incorrectly works as additional filter.
                                                                        // Must not have any impact
    where invoice.InvoiceId.In(existingIds)
    select invoice).Count();

The expression:

{All().Select(invoice => new <>f__AnonymousType231`2(invoice = invoice, foo = invoice.InvoiceId.In(value(Xtensive.Orm.Tests.Linq.InTest+
<>c__DisplayClass37_0).nonExistingIds))).Where(<>h__TransparentIdentifier0 => 
<>h__TransparentIdentifier0.invoice.InvoiceId.In(value(Xtensive.Orm.Tests.Linq.InTest+<>c__DisplayClass37_0).existingIds)).Select(<>h__TransparentIdentifier0 => <>h__TransparentIdentifier0.invoice)}

The test to reproduce it:
https://github.com/DataObjects-NET/dataobjects-net/pull/401/files

Looks like let works as where filter.

It is a simlified example.
In the real app we discovered the same effect with used variable in let.

We thought the behavior changed after merging https://github.com/dataObjects-net/dataobjects-net commits for last 7 months.
But after some investigation I see the bug is here for longer time, may be from the beginning.

@SergeiPavlov SergeiPavlov changed the title Unused let in the LINQ expression makes query incorrect Unused let in the LINQ expression changes result of Query Oct 31, 2024
SergeiPavlov added a commit to servicetitan/dataobjects-net that referenced this issue Nov 6, 2024
SergeiPavlov added a commit to servicetitan/dataobjects-net that referenced this issue Nov 6, 2024
SergeiPavlov added a commit to servicetitan/dataobjects-net that referenced this issue Nov 6, 2024
…` bug (#300)

* Fix DataObjects-NET#402:

* Fix typo

* Revert "Fix typo"

This reverts commit 57389e0.

* Remove RedundantColumnOptimizer

* Revert "Fix DataObjects-NET#402:"

This reverts commit 6ac3945.
@alex-kulakov
Copy link
Contributor

Two problems were discovered during investigation of this case

  • incorrect visit of GroupBy key expression
  • wrong mapping of Include provider which lead to incorrect reference to source collection for IN statement.

First issue appeared after changes released in 6.0.13 and traversed to newer branches via merge.

@SergeiPavlov the PR that fixes both of issues, and because root of at least one of problems lied in 6.0 branch I had to resolve it there. Soon these changes will be merged into newer branches

alex-kulakov added a commit that referenced this issue Dec 4, 2024
Resolves several query translation issues declared in #402

Addresses issue which appeared in 6.0.13, which roots to not fully visited of key expression in GroupBy
Addressed issue of incorrect optimization of query with several In() calls within RedundantColumnOptimizer, which could cause wrong source of parameters for IN statement.
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

No branches or pull requests

2 participants