-
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
Optimize translation of string.{Starts,Ends}With #14895
Conversation
If the pattern is constant, we now escape it client-side and send a simple LIKE expression - no need for fancy concatenation and an additional LEFT(LEN()) check. Fixes dotnet#14657
@smitpatel take a look, it's nice to be working in your branch for the first time :) Following is a dump of questions/reactions as I was working - a lot of it isn't really actionable or anything, just remarks.
|
Answers in the same order
|
{ | ||
// The pattern is constant. Aside from null or empty, we escape all special characters (%, _, \) | ||
// in C# and send a simple LIKE | ||
if (!(constExpr.Value is string constPattern)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the pattern be non-string? or this is writing null check in fancy way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fancy null check :)
? new LikeExpression( | ||
instance, | ||
new SqlConstantExpression(Expression.Constant(startsWith ? EscapeLikePattern(constPattern) + '%' : '%' + EscapeLikePattern(constPattern)), stringTypeMapping), | ||
new SqlConstantExpression(Expression.Constant(LikeEscapeChar.ToString()), stringTypeMapping), // SQL Server has no char mapping, avoid value conversion warning |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Invalid comment?
Apart from that, if you are passing constant of string, why would you need char type mapping?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I would have preferred to pass a constant of char, but neither SQLServer nor Sqlite support it well (on Sqlite the literal generation of char gives a number...).
Thanks for all the answers, makes sense... I'll leave it to you to think about it, and also to tell me whenever you think an area is mature enough for me to get involved. BTW the build seems to be failing because of an unrelated compilation error |
If the pattern is constant, we now escape it client-side and send a simple LIKE expression - no need for fancy concatenation and an additional LEFT(LEN()) check.
Fixes #14657
Replaces #14820