-
Notifications
You must be signed in to change notification settings - Fork 547
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
.StartsWith in .Any uses Cast(CharIndex instead of Like 'TEXT%') which is a lot slower #115
Comments
@NicoJuicy first of all, based on your expectation that this should translate to var productsFromCat = db.Products.Where(el => categories.Any(dl => el.Category.Code.StartsWith(dl))).ToList(); Besides that, the difference between the two queries in your post is that the expression I think it is possible we could do better for cases like this, if it is safe to assume that the Other than that we have considered having a method in |
@divega , yes, the second query is correct. In the referenced project i'm using an new string() {"A"} which actually triggers the ( CAST(CHARINDEX([Project1].[Code], N'A') AS int)) = 1 I have added the generated code in the project, you can see it here: https://github.com/NicoJuicy/EF-ContainsAndStartsWith/blob/master/EF-ContainsAndStartsWith.Test/UnitTest1.cs .
Background information for additional context: I had support for one category on a page, this means:
Now i implemented support for returning products from multiple categories
This led me to the slower query. So the previous example seemed to be correct. When i only used one category, it correctly translated with LIKE 'CatA%'. When i used multiple categories ( in the array), the query translated to usage of CHARINDEX, which caused the slower query. The LIKE filter in DbFunctions would solve my problem,awesome ! Please consider it in the next release. Thanks for the quick reply |
Closing as we plan to take the Like pull request for the next release |
Awesome commit with the 'Like Operator' :), thanks! |
Dupe of #241. |
In case you are reading this to get true
Comparing to |
@dmitry-pavlov FWIW, |
I'm doing this:
And it translates into:
Any ideas why? |
Testing:
Same results:
|
Open new issue on this: #542 |
@proms2018 The first argument must be a reference to a property on the Estatdos object:
|
I have created an example project on : https://github.com/NicoJuicy/EF-ContainsAndStartsWith ( watch out for the generated migration when checking for difference in unit testing time )
The second version is a lot slower, but i believe LIKE 'A%' can be used, which is a lot faster.
I had a generated query which slowed down my performance of loading a page from 1 second to 10 seconds, because of this ( just mentioning the impact).
Could this be altered to be further optimized?
The text was updated successfully, but these errors were encountered: