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

String.CompareTo emits unicode literal against varchar column #13906

Closed
kdblocher opened this issue Nov 7, 2018 · 3 comments · Fixed by #20993
Closed

String.CompareTo emits unicode literal against varchar column #13906

kdblocher opened this issue Nov 7, 2018 · 3 comments · Fixed by #20993
Assignees
Labels
area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported punted-for-3.0 type-bug
Milestone

Comments

@kdblocher
Copy link

Seems related to #4978, #8370, and #4686, but logging it here because it's a different use case.

EF is correctly emitting a unicode or non-unicode literal when used directly like this:
query.Where(x => x.ID == "test")

SELECT [x].[ID]
FROM [Table] AS [x]
WHERE [x].[ID] = 'test'

But not with String.CompareTo, like this:
query.Where(x => x.ID.CompareTo("test") == 0)

SELECT [x].[ID]
FROM [Table] AS [x]
WHERE [x].[ID] = N'test'

This means any inequality comparisons (i.e. paging) off of a string field when it is varchar will not use the index on the column, because it is not possible to write a string comparison with the > operator.

EF Core version: 2.1.4
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10
IDE: Visual Studio 2017 15.9

@ajcvickers ajcvickers added this to the 3.0.0 milestone Nov 7, 2018
@smitpatel smitpatel added the verify-fixed This issue is likely fixed in new query pipeline. label Jun 6, 2019
@ajcvickers ajcvickers modified the milestones: 3.0.0, Backlog Jun 28, 2019
@smitpatel smitpatel removed their assignment Aug 7, 2019
@ajcvickers ajcvickers modified the milestones: Backlog, 3.1.0 Sep 4, 2019
@ajcvickers ajcvickers modified the milestones: 3.1.0, Backlog Oct 11, 2019
@ajcvickers ajcvickers modified the milestones: Backlog, 5.0.0 Nov 13, 2019
@smitpatel
Copy link
Contributor

Generated SQL in 3.1

      SELECT [b].[Id], [b].[Value]
      FROM [Blogs] AS [b]
      WHERE CASE
          WHEN [b].[Value] = 'test' THEN 0
          WHEN [b].[Value] > 'test' THEN 1
          WHEN [b].[Value] < 'test' THEN -1
      END = 0

@smitpatel smitpatel added add-regression-test and removed punted-for-3.1 verify-fixed This issue is likely fixed in new query pipeline. labels Dec 9, 2019
@kdblocher
Copy link
Author

I will send this over to the project team where this bug was discovered and see if they can verify this is fixed.

@ajcvickers ajcvickers added propose-punt good first issue This issue should be relatively straightforward to fix. labels Mar 10, 2020
@maumar
Copy link
Contributor

maumar commented May 13, 2020

simplification of CASE blocks is tracked by #16092

@maumar maumar added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label May 19, 2020
@maumar maumar unassigned roji May 19, 2020
@maumar maumar removed add-regression-test good first issue This issue should be relatively straightforward to fix. poachable labels May 19, 2020
@maumar maumar closed this as completed in e6674cd May 19, 2020
@ajcvickers ajcvickers modified the milestones: 5.0.0, 5.0.0-preview6 Jun 1, 2020
@ajcvickers ajcvickers modified the milestones: 5.0.0-preview6, 5.0.0 Nov 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported punted-for-3.0 type-bug
Projects
None yet
5 participants