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

Fix to #18808 - Query: incorrect results for query with Join where key selector is anonymous type with a single property #18810

Merged
merged 1 commit into from
Nov 8, 2019

Conversation

maumar
Copy link
Contributor

@maumar maumar commented Nov 7, 2019

Problem was that on c# join predicate behaves differently when it's a regular property (null and null yield false), and where its anonymous type with just a single property (new { A = null } and new { A = null } yields true).
However, we lose that distinction during initial Join predicate translation.

Fix is to add a sentinel true == true condition, if the anonymous type only has one element. This condition can be later optimized out.

Resolves #18808

INNER JOIN [LevelTwo] AS [l2] ON ([l1].[OneToMany_Optional_Self_Inverse1Id] = [l2].[Level1_Optional_Id]) OR ([l1].[OneToMany_Optional_Self_Inverse1Id] IS NULL AND [l2].[Level1_Optional_Id] IS NULL)");
@"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id]
FROM [LevelOne] AS [l]
INNER JOIN [LevelTwo] AS [l0] ON (([l].[OneToMany_Optional_Self_Inverse1Id] = [l0].[Level1_Optional_Id]) OR ([l].[OneToMany_Optional_Self_Inverse1Id] IS NULL AND [l0].[Level1_Optional_Id] IS NULL)) AND (CAST(1 AS bit) = CAST(1 AS bit))");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra condition can be pruned, when/if we fix #18492

Copy link
Member

@smitpatel smitpatel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

…y selector is anonymous type with a single property

Problem was that on c# join predicate behaves differently when it's a regular property (null and null yield false), and where its anonymous type with just a single property (new { A = null } and new { A = null } yields true).
However, we lose that distinction during initial Join predicate translation.

Fix is to add a sentinel true == true condition, if the anonymous type only has one element. This condition can be later optimized out.

Resolves #18808
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.

Query: incorrect results for query with Join where key selector is anonymous type with a single property
2 participants