-
Notifications
You must be signed in to change notification settings - Fork 29
fix: Improve branch search speed #909
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅ ✅ All tests successful. No failed tests found. 📢 Thoughts on this report? Let us know! |
Codecov ReportAll modified and coverable lines are covered by tests ✅
✅ All tests successful. No failed tests found. Additional details and impacted files@@ Coverage Diff @@
## main #909 +/- ##
=======================================
Coverage 96.26% 96.26%
=======================================
Files 823 823
Lines 19040 19042 +2
=======================================
+ Hits 18329 18331 +2
Misses 711 711
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
|
RE: attempting to adjust the ORM overrides instead of using |
ajay-sentry
left a comment
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.
lgtm!
We run branch search by name on the Configuration page of a repo - it's currently slow (~50 seconds in worst case, median ~10+seconds - Sentry board).
The branch name search is the
GetBranchesgraphQL query and the below db query.I ran some tests against postgres prod and the


EXPLAIN ANALYZEshows significant difference between runningILIKEvs.LIKEfor the search (~10 ms vs. 5 seconds).There is an index on
branches.repoidand one onbranches.repoid, branches.branch. From the query plans it looks like running withLIKEis running a custom columnar scan (full table scan on all 27 million rows ofbranchestable) before then using the repoid index and filtering those rows by name. The query withILIKEjust uses the index then filters, so it's much faster.explain analyze with
LIKE:explain analyze with
ILIKE:So this PR moves over to using
ILIKEin the query. I suspect the reason for the difference between running with LIKE vs. ILIKE has to do with our collation settings for the table but those are risky to alter so I'd rather move to using ILIKE than trying to fix LIKE.Other stuff:
icontainsmethods translates to a query ofILIKE, but it clearly doesn't. Some troubleshooting says maybe it's because our DATABASE ENGINE settings.py is not set to postgres, but everything I checked seems to imply that is done already..extraapi that gets us what we need. Technically the docs say to use it as a last resort, but it seems to be the best solution for this now without restructuring our ORM in bigger ways.Closes codecov/engineering-team#2537