Partition the package_derivations_by_guix_revision_range table

And create a proper git_branches table in the process.

I'm hoping this will help with slow deletions from the
package_derivations_by_guix_revision_range table in the case where there are
lots of branches, since it'll separate the data for one branch from another.

These migrations will remove the existing data, so
rebuild-package-derivations-table will currently need manually running to
regenerate it.
This commit is contained in:
Christopher Baines 2022-05-23 19:10:25 +01:00
parent 89545caa3f
commit 64be52844e
19 changed files with 442 additions and 167 deletions

View file

@ -90,7 +90,7 @@ WHERE guix_revisions.git_repository_id = "
(number->string git-repository-id) " AND
commits.column1 NOT IN (
SELECT commit
FROM git_branches
FROM git_commits
)")))))
(unless (null? guix-revision-ids)
@ -130,8 +130,10 @@ WHERE id IN ("
AND id NOT IN (
SELECT id FROM guix_revisions
INNER JOIN git_branches ON
git_branches.commit = guix_revisions.commit AND
git_branches.git_repository_id = guix_revisions.git_repository_id
INNER JOIN git_commits ON
git_commits.git_branch_id = git_branches.id AND
git_commits.commit = guix_revisions.commit
)"))
(delete-unreferenced-package-derivations)
@ -176,16 +178,22 @@ WHERE git_repository_id = " (number->string git-repository-id) " AND
", ")
")")))
(define (delete-from-git-branches conn)
(define (delete-from-git-commits conn)
(exec-query
conn
(simple-format
#f
"
DELETE FROM git_branches
WHERE git_repository_id = ~A AND
name = '~A' AND
commit IN (~A)"
DELETE FROM git_commits
WHERE id IN (
SELECT id
FROM git_commits
INNER JOIN git_branches
ON git_branches.id = git_commits.git_branch_id
WHERE git_branches.git_repository_id = ~A
AND git_branches.name = '~A' AND
AND git_commits.commit IN (~A)
)"
git-repository-id
branch-name
(string-join
@ -197,7 +205,7 @@ WHERE git_repository_id = ~A AND
(with-postgresql-transaction
conn
(lambda (conn)
(delete-from-git-branches conn)
(delete-from-git-commits conn)
(delete-jobs conn)
(exec-query
@ -216,9 +224,12 @@ WHERE git_repository_id = $1 AND
(map car
(exec-query conn
"
SELECT commit
SELECT git_commits.commit
FROM git_branches
WHERE git_repository_id = $1 AND name = $2"
INNER JOIN git_commits
ON git_branches.id = git_commits.git_branch_id
WHERE git_repository_id = $1
AND git_branches.name = $2"
(list (number->string git-repository-id)
branch-name))))
@ -236,7 +247,9 @@ WHERE git_repository_id = $1 AND name = $2"
(exec-query conn
"
SELECT commit
FROM git_branches
FROM git_commits
INNER JOIN git_branches
ON git_branches.id = git_commits.git_branch_id
WHERE git_repository_id = $1 AND name = $2
ORDER BY datetime DESC
OFFSET $3"
@ -311,6 +324,8 @@ FROM (
SELECT DISTINCT ON (name, git_repository_id)
name, git_repository_id, commit
FROM git_branches
INNER JOIN git_commits
ON git_commits.git_branch_id = git_branches.id
ORDER BY git_repository_id, name, datetime DESC
) AS git_branches_latest_revision
WHERE commit = ''")))))