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

reduce cost of various SQL queries #382

Merged
merged 2 commits into from May 13, 2024
Merged

reduce cost of various SQL queries #382

merged 2 commits into from May 13, 2024

Conversation

majewsky
Copy link
Contributor

See commit messages for details.

This is one of the last holdouts of a task clock field that refers to
the last run instead of the next run, so this is a neat little win for
the consistency department.

The main impetus of this change, though, is that the discovering queries
for these tasks rank #3 and #8 on our list of most expensive statements
(i.e. the pg_stat_statements view, ranked by total_exec_time).
The rephrasing from `validated_at` into `next_validation_at` simplifies
these queries considerably.

The actual implementation is sort of a case of "it can't be this hard...
oh no". Most of the diff is in test fixtures, though. The only
significant reworking that was required is in package processor, where
validateAndStoreManifestCommon() needed to be extended to explicitly be
told if the manifest is new or existing, since checking
`PushedAt == ValidatedAt` was not feasible anymore.
The INSERT-first approach with ON CONFLICT DO NOTHING is often neat, but
in this case, it does not even save queries.

And what's worse, the INSERT always advances repo_id_seq even if no
record ends up being inserted, so this always incurs a write in the DB
even if we only read an existing repo.
@coveralls
Copy link

Coverage Status

coverage: 80.576% (-0.03%) from 80.608%
when pulling d08a17b on reduce-query-cost
into 2f80ce2 on master.

@majewsky majewsky merged commit 8048887 into master May 13, 2024
7 of 8 checks passed
@majewsky majewsky deleted the reduce-query-cost branch May 13, 2024 12:20
majewsky added a commit to sapcc/helm-charts that referenced this pull request May 13, 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

Successfully merging this pull request may close these issues.

None yet

3 participants