Allow unrolling subqueries in cleanup task#1156
Conversation
| # This test factory implicitly creates: | ||
| # - Test with a Repository and an Owner, Upload, CommitReport. | ||
| # - An Upload with a CommitReport, a Commit that has a different Owner and | ||
| # one more Repository with yet another different Owner. | ||
| # And then also a Branch and a Pull via DB triggers because of the Commit. | ||
| remaining = TestInstanceFactory() |
There was a problem hiding this comment.
lol, these damn recursive factories :-D
✅ Sentry found no issues in your recent changes ✅ |
Codecov ReportAttention: Patch coverage is ✅ All tests successful. No failed tests found.
📢 Thoughts on this report? Let us know! |
Codecov ReportAttention: Patch coverage is
✅ All tests successful. No failed tests found.
Additional details and impacted files@@ Coverage Diff @@
## main #1156 +/- ##
==========================================
- Coverage 97.77% 97.76% -0.01%
==========================================
Files 444 443 -1
Lines 36574 36529 -45
==========================================
- Hits 35760 35714 -46
- Misses 814 815 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
giovanni-guidini
left a comment
There was a problem hiding this comment.
That's some very advanced query magic
For some reason, our postgres is unable to properly optimize a delete query on certain tables, which are using a subquery in the where clause. It turns out that unrolling that subquery within Python works just fine however. So lets do just that. As we are building all of the delete queries dynamically based on django relations (or some manually defined ones as well), we have to use some queryset magic as well to reverse those automatically created subqueries. So another method was added which can parse the `IN (...)` subquery out of a queryset, in order to execute that separately, and issue N+1 delete queries on the target table.
78dc751 to
0fec242
Compare
For some reason, our postgres is unable to properly optimize a delete query on certain tables, which are using a subquery in the where clause.
It turns out that unrolling that subquery within Python works just fine however. So lets do just that.
As we are building all of the delete queries dynamically based on django relations (or some manually defined ones as well), we have to use some queryset magic as well to reverse those automatically created subqueries.
So another method was added which can parse the
IN (...)subquery out of a queryset, in order to execute that separately, and issue N+1 delete queries on the target table.