Merge ~cjwatson/launchpad:db-oci-git-indexes into launchpad:db-devel

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: b27175e23cb7065615542a26f24b4b84981a5cc7
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:db-oci-git-indexes
Merge into: launchpad:db-devel
Prerequisite: ~cjwatson/launchpad:db-oci-git
Diff against target: 83 lines (+77/-0)
1 file modified
database/schema/patch-2210-08-2.sql (+77/-0)
Reviewer Review Type Date Requested Status
William Grant db Approve
Review via email: mp+377626@code.launchpad.net

Commit message

Recreate GitRepository indexes for SPN/OCIPN

Description of the change

Previously we had a variety of indexes including (distribution, sourcepackagename) with non-NULL distribution but omitting the condition that sourcepackagename is also non-NULL. Replace each of these with a pair of indexes, one for non-NULL sourcepackagename and one for non-NULL ociprojectname.

This can be applied hot by adding CONCURRENTLY.

LP: #1847444

(I split this out from db-oci-git to allow cold/hot patch splitting.)

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (db)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/database/schema/patch-2210-08-2.sql b/database/schema/patch-2210-08-2.sql
2new file mode 100644
3index 0000000..03ea785
4--- /dev/null
5+++ b/database/schema/patch-2210-08-2.sql
6@@ -0,0 +1,77 @@
7+-- Copyright 2019-2020 Canonical Ltd. This software is licensed under the
8+-- GNU Affero General Public License version 3 (see the file LICENSE).
9+
10+SET client_min_messages=ERROR;
11+
12+-- Create/replace indexes. Previously we had a variety of indexes including
13+-- (distribution, sourcepackagename) with non-NULL distribution but omitting
14+-- the condition that sourcepackagename is also non-NULL. Replace each of
15+-- these with a pair of indexes, one for non-NULL sourcepackagename and one
16+-- for non-NULL ociprojectname.
17+
18+CREATE UNIQUE INDEX gitrepository__owner__distribution__spn__name__key
19+ ON GitRepository (owner, distribution, sourcepackagename, name)
20+ WHERE distribution IS NOT NULL AND sourcepackagename IS NOT NULL;
21+CREATE UNIQUE INDEX gitrepository__owner__distribution__ocipn__name__key
22+ ON GitRepository (owner, distribution, ociprojectname, name)
23+ WHERE distribution IS NOT NULL AND ociprojectname IS NOT NULL;
24+DROP INDEX old__gitrepository__owner__distribution__sourcepackagename__name__key;
25+
26+CREATE UNIQUE INDEX gitrepository__distribution__spn__target_default__key
27+ ON GitRepository (distribution, sourcepackagename)
28+ WHERE
29+ distribution IS NOT NULL AND sourcepackagename IS NOT NULL
30+ AND target_default;
31+CREATE UNIQUE INDEX gitrepository__distribution__ocipn__target_default__key
32+ ON GitRepository (distribution, ociprojectname)
33+ WHERE
34+ distribution IS NOT NULL AND ociprojectname IS NOT NULL
35+ AND target_default;
36+DROP INDEX old__gitrepository__distribution__spn__target_default__key;
37+
38+CREATE UNIQUE INDEX gitrepository__owner__distribution__spn__owner_default__key
39+ ON GitRepository (owner, distribution, sourcepackagename)
40+ WHERE
41+ distribution IS NOT NULL AND sourcepackagename IS NOT NULL
42+ AND owner_default;
43+CREATE UNIQUE INDEX gitrepository__owner__distribution__ocipn__owner_default__key
44+ ON GitRepository (owner, distribution, ociprojectname)
45+ WHERE
46+ distribution IS NOT NULL AND ociprojectname IS NOT NULL
47+ AND owner_default;
48+DROP INDEX old__gitrepository__owner__distribution__spn__owner_default__key;
49+
50+CREATE INDEX gitrepository__distribution__spn__date_last_modified__idx
51+ ON GitRepository (distribution, sourcepackagename, date_last_modified)
52+ WHERE distribution IS NOT NULL AND sourcepackagename IS NOT NULL;
53+CREATE INDEX gitrepository__distribution__ocipn__date_last_modified__idx
54+ ON GitRepository (distribution, ociprojectname, date_last_modified)
55+ WHERE distribution IS NOT NULL AND ociprojectname IS NOT NULL;
56+DROP INDEX old__gitrepository__distribution__spn__date_last_modified__idx;
57+
58+CREATE INDEX gitrepository__distribution__spn__id__idx
59+ ON GitRepository (distribution, sourcepackagename, id)
60+ WHERE distribution IS NOT NULL AND sourcepackagename IS NOT NULL;
61+CREATE INDEX gitrepository__distribution__ocipn__id__idx
62+ ON GitRepository (distribution, ociprojectname, id)
63+ WHERE distribution IS NOT NULL AND ociprojectname IS NOT NULL;
64+DROP INDEX old__gitrepository__distribution__spn__id__idx;
65+
66+CREATE INDEX gitrepository__owner__distribution__spn__date_last_modified__idx
67+ ON GitRepository (
68+ owner, distribution, sourcepackagename, date_last_modified)
69+ WHERE distribution IS NOT NULL AND sourcepackagename IS NOT NULL;
70+CREATE INDEX gitrepository__owner__distribution__ocipn__date_last_modified__idx
71+ ON GitRepository (owner, distribution, ociprojectname, date_last_modified)
72+ WHERE distribution IS NOT NULL AND ociprojectname IS NOT NULL;
73+DROP INDEX old__gitrepository__owner__distribution__spn__date_last_modified__idx;
74+
75+CREATE INDEX gitrepository__owner__distribution__spn__id__idx
76+ ON GitRepository (owner, distribution, sourcepackagename, id)
77+ WHERE distribution IS NOT NULL AND sourcepackagename IS NOT NULL;
78+CREATE INDEX gitrepository__owner__distribution__ocipn__id__idx
79+ ON GitRepository (owner, distribution, ociprojectname, id)
80+ WHERE distribution IS NOT NULL AND ociprojectname IS NOT NULL;
81+DROP INDEX old__gitrepository__owner__distribution__spn__id__idx;
82+
83+INSERT INTO LaunchpadDatabaseRevision VALUES (2210, 08, 2);

Subscribers

People subscribed via source and target branches

to status/vote changes: