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 :: invalid sql generated for query with joins where key selector is a null comparison #4748

Closed
maumar opened this issue Mar 10, 2016 · 4 comments
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@maumar
Copy link
Contributor

maumar commented Mar 10, 2016

query:

from instance in ctx.ExamInstances
join answered in ctx.ExamInstanceQuestions
on true equals answered.AnswerId != null

generated query is:

SELECT [answered].[ExamInstanceQuestionId], [answered].[AnswerId], [answered].[ExamInstanceId], [answered].[QuestionId]
FROM [ExamInstances] AS [instance]
INNER JOIN [ExamInstanceQuestions] AS [answered] ON 1 = [answered].[AnswerId] IS NOT NULL

we should be converting the null check into CASE statement, like we do for projections

@smitpatel
Copy link
Contributor

Ah complex join conditions.

@divega
Copy link
Contributor

divega commented Jun 4, 2016

we should be converting the null check into CASE statement, like we do for projections

Hopefully not in this particular case 😄 The argument for ON is also a search condition, like WHERE, so we shouldn't need to convert from search condition to a Boolean value.

I think this would be a nice translation:

SELECT [answered].[ExamInstanceQuestionId], [answered].[AnswerId], [answered].[ExamInstanceId], [answered].[QuestionId]
FROM [ExamInstances] AS [instance]
INNER JOIN [ExamInstanceQuestions] AS [answered] ON [answered].[AnswerId] IS NOT NULL

And maybe we can arrive to it by first eliminating the redundant true equals?

@smitpatel
Copy link
Contributor

We already have optimizer to remove redundant true equals => PredicateReductionExpressionOptimizer
I guess its just matter of running it on join conditions.

@smitpatel
Copy link
Contributor

[Fact]
public virtual void Complex_join()
{
    using (var db = CreateContext())
    {
        var query = (from customer in db.Customers
                        join order in db.Orders
                            on true equals order.CustomerID != null
                        select customer
        )
            .ToList();

        Assert.Equal(
            @"SELECT [customer].[CustomerID], [customer].[Address], [customer].[City], [customer].[CompanyName], [customer].[ContactName], [customer].[ContactTitle], [customer].[Country], [customer].[Fax], [customer].[Phone], [customer].[PostalCode], [customer].[Region]
FROM [Customers] AS [customer]
INNER JOIN [Orders] AS [order] ON [order].[CustomerID] IS NOT NULL",
            Sql);
    }
}

Above test passes if ApplyOptimizations function in DefaultQuerySqlGenerator which solved #5652 is run on join condition.

@rowanmiller rowanmiller removed the pri0 label Jul 6, 2016
@smitpatel smitpatel added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Aug 4, 2016
@ajcvickers ajcvickers modified the milestones: 1.1.0-preview1, 1.1.0 Oct 15, 2022
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. type-bug
Projects
None yet
Development

No branches or pull requests

5 participants