-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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: simplify IndexOf translation #18773
Comments
Also this scenario yields different results between SqlServer and Sqlite, when the argument to IndexOf is empty string, i.e. es.Where(e => e.NullableStringA.IndexOf("") == e.NullableIntA) Sqlite produces: SELECT "e"."Id"
FROM "Entities1" AS "e"
WHERE ((instr("e"."NullableStringA", '') - 1) = "e"."NullableIntA") OR (instr("e"."NullableStringA", '') IS NULL AND "e"."NullableIntA" IS NULL) |
Theoretically, could do fancy parameter snipping to special case empty string. |
Currently the translation for ss.Set<NullSemanticsEntity1>().Where(e => e.NullableStringA.IndexOf("oo") == e.NullableIntA).Select(e => e.Id) (see here) is SELECT [e].[Id]
FROM [Entities1] AS [e]
WHERE CAST(CHARINDEX(N'oo', [e].[NullableStringA]) AS int) - 1 = [e].[NullableIntA]
OR ([e].[NullableStringA] IS NULL AND [e].[NullableIntA] IS NULL) (see here). Is there any further improvement that we should look for? (I see that there is a Regarding the mismatch in the results from SQLite and SQL Server, it was apparently caused by the non-propagation of |
Currently query like:
gets translated to:
This seems too complicated. While it's true that if argument is and empty string we can short circuit and not compute the result of CHARINDEX function it doesn't seem too common (usually queries are on indexof different than emtpy).
Another reason might have been that for cases when target is null, and argument is empty string we return 0, rather than null (i.e. any string starts with empty string - which is consistent with out mental model of null meaning unknown value). However this scenario is invalid on c# already (null ref) and seems like sacrificing 99% scenario for the sake of 1%.
Instead, we could simply translate to:
which, once #18555 is done, can be further optimized to:
The text was updated successfully, but these errors were encountered: