-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Description
Currently we translate foobar.StartsWith(foo) into:
(foobar like foo +'%' and left(foobar, len(foo)) = foo) or foo = '' -- last term is removed if foo is non-null constant
however @rmacfadyen pointed out that for some scenarios the last term actually makes the query non-sargable.
If the term is removed completely, we return (arguably) incorrect data for case: null.StartsWith("").
We could however use the following translation:
(foobar like foo +'%' and left(foobar, len(foo)) = foo) or (foo = '' and foobar is null)
(and if we know that foobar can't be null we could drop the term as well.
We need to do some more investigation on which scenarios are getting better with this translation (i.e. if its worth complicating the sql)
glen-84 and zdenek-jelinek