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

Translation from Contains to strpos leads to extremely slow queries #3159

Closed
madiganz opened this issue Apr 24, 2024 · 1 comment
Closed

Comments

@madiganz
Copy link

The database I am working with has 10s of millions of rows and we see some major performance projects when querying with out API using contains queries. I noticed that Entity Framework is translating Contains to doing a strpos operation. I also came across a really old issue in Entity Framework and a comment from your team about the translation in npgsql - dotnet/efcore#474 (comment). I found out that I can use a trigram index for ILIKE and LIKE operations and that significantly improved performance. Queries that before would take 30+ seconds would have under 100ms. I understand that trigram indices increase the cost of writes, and I haven't fully tested that aspect yet, but based on initial research the benefit of using a trigram index greatly outweighs the cost. All this being said, the trigram index does not work when strpos is used in the generated query. I was wondering if there was anything in particular that we could do so that we can use LIKE operations instead of strpos.

@NinoFloris NinoFloris transferred this issue from npgsql/npgsql Apr 24, 2024
@madiganz
Copy link
Author

madiganz commented May 9, 2024

I'm closing this as it looks like this was fixed in v8

@madiganz madiganz closed this as completed May 9, 2024
@roji roji closed this as not planned Won't fix, can't repro, duplicate, stale May 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants