-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Drop database views #15876
Drop database views #15876
Conversation
|
Nope, let's try again. I think I found the problem. |
8eac1a1
to
333bbc6
Compare
This looks fine to me, but don't you need to explicitly drop the view in a new migration ? |
@mvdbeek Thank you for looking at these! I've added the revision for dropping the view (I had it in the PR's initial to-dos but then lost it in the edits.. Thanks!) I've rewritten the revision script that edited the view (c39f1de47a04) without the use of alembic_util. I think that's all we need. I've tested it - works both ways. I've also dropped the alembic_util dependency in the next commit - I don't think we need it anymore. |
We need this because the query does not use an outer join (like it did) - which is unnecessary. As a result, the SUM function will return None when there are no rows to sum over. That causes problems, because when there are no jobs, we need 0s. This fixes it.
value.value for value in ...values! Co-authored-by: Nicola Soranzo <[email protected]>
Co-authored-by: Nicola Soranzo <[email protected]>
Co-authored-by: Nicola Soranzo <[email protected]>
Thanks @jdavcs! |
See alternative implementation in #15888
IMPORTANT: I've dropped this code (joinedload option for job_state_summary in
history_contents
manager). I'm not sure if this breaks something (or negatively affects performance). If this needs to be restored, my suggestion is to go with #15888, since this version does not use a mapped class and so it cannot pull these summary counts as a query load option.Why drop views:
Unlike #15888, this is a more intrusive refactoring of
HistoryDatasetCollectionJobStateSummary
's implementation.group by
clause was necessary. More importantly, the previous query could only be used in a join - i.e., the class was ONLY used to define a relationship with a parent class - which added the HDCA.id as the join criteria. Without it the query is ..expensive: cost=20432585 (so using the class as a standalone makes no sense).sum
function returns a null if there are no rows to sum over. We fix this in the code by simply assigning zeros to all counts if the total count is zero.SAME NOTE as in 15888: The part of the query that enumerates the job states (aggregate
sum
columns) is now generated dynamically based on members ofmodel.Job.states
. This was done as a safeguard against missing a state (assertion added) or listing a non-existent state (e.g. the original view's query had a bug: the statedeleted_new
has been replaced withdeleting
, which may have resulted in incorrect counts.)How to test the changes?
(Select all options that apply)
License