~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to database/schema/patch-2208-75-0.sql

[r=stub][bug=793848] Remove rubbish that happens to be harmess valid
 SQL

Show diffs side-by-side

added added

removed removed

Lines of Context:
127
127
        fixed_upstream, milestone;
128
128
 
129
129
 
130
 
 
131
 
 
132
 
 
133
 
 
134
 
WITH
135
 
    -- kill dupes
136
 
    relevant_bug AS (SELECT * FROM bug where duplicateof is NULL),
137
 
 
138
 
    -- (bug.id, tag) for all bug-tag pairs plus (bug.id, NULL) for all bugs
139
 
    bug_tags AS (
140
 
        SELECT relevant_bug.id, NULL::text AS tag FROM relevant_bug
141
 
        UNION
142
 
        SELECT relevant_bug.id, tag
143
 
        FROM relevant_bug INNER JOIN bugtag ON relevant_bug.id=bugtag.bug),
144
 
    -- (bug.id, NULL) for all public bugs + (bug.id, viewer) for all
145
 
    -- (subscribers+assignee) on private bugs
146
 
    bug_viewers AS (
147
 
        SELECT relevant_bug.id, NULL::integer AS person
148
 
        FROM relevant_bug WHERE NOT relevant_bug.private
149
 
        UNION
150
 
        SELECT relevant_bug.id, assignee AS person
151
 
        FROM relevant_bug
152
 
        INNER JOIN bugtask ON relevant_bug.id=bugtask.bug
153
 
        WHERE relevant_bug.private and bugtask.assignee IS NOT NULL
154
 
        UNION
155
 
        SELECT relevant_bug.id, bugsubscription.person
156
 
        FROM relevant_bug INNER JOIN bugsubscription
157
 
            ON bugsubscription.bug=relevant_bug.id WHERE relevant_bug.private),
158
 
 
159
 
    fixed_upstream_tasks AS (
160
 
        SELECT BugTask.id, BugTask.bug FROM BugTask
161
 
        WHERE (
162
 
            (bugwatch IS NOT NULL AND status IN (17, 25, 30))
163
 
            OR (
164
 
                bugwatch IS NULL AND product IS NOT NULL
165
 
                AND status IN (25, 30)))),
166
 
 
167
 
    -- (bugtask.(bug, product, productseries, distribution, distroseries,
168
 
    -- sourcepackagename, status, milestone) for all bugs + the same with
169
 
    -- sourcepackage squashed to NULL)
170
 
    tasks AS (
171
 
        SELECT
172
 
            bug, product, productseries, distribution, distroseries,
173
 
            sourcepackagename, status, milestone, importance,
174
 
            EXISTS (
175
 
                SELECT TRUE FROM fixed_upstream_tasks
176
 
                WHERE 
177
 
                    BugTask.bug = fixed_upstream_tasks.bug
178
 
                    AND BugTask.id <> fixed_upstream_tasks.id
179
 
                    ) AS fixed_upstream
180
 
        FROM bugtask
181
 
        UNION
182
 
        SELECT DISTINCT ON (
183
 
            bug, product, productseries, distribution, distroseries,
184
 
            sourcepackagename, milestone)
185
 
            bug, product, productseries, distribution, distroseries,
186
 
            NULL::integer as sourcepackagename,
187
 
            status, milestone, importance,
188
 
            EXISTS (
189
 
                SELECT TRUE FROM fixed_upstream_tasks
190
 
                WHERE
191
 
                    BugTask.bug = fixed_upstream_tasks.bug
192
 
                    AND BugTask.id <> fixed_upstream_tasks.id
193
 
                    ) AS fixed_upstream
194
 
        FROM bugtask where sourcepackagename IS NOT NULL)
195
 
 
196
 
    -- Now combine
197
 
    SELECT
198
 
        count(*), product, productseries, distribution, distroseries,
199
 
        sourcepackagename, person, tag, status, milestone, importance,
200
 
        latest_patch_uploaded IS NOT NULL AS has_patch, fixed_upstream
201
 
    FROM relevant_bug
202
 
    INNER JOIN bug_tags ON relevant_bug.id=bug_tags.id
203
 
    INNER JOIN bug_viewers ON relevant_bug.id=bug_viewers.id
204
 
    INNER JOIN tasks on tasks.bug=relevant_bug.id
205
 
    GROUP BY
206
 
        product, productseries, distribution, distroseries,
207
 
        sourcepackagename, person, tag, status, milestone,
208
 
        importance, has_patch, fixed_upstream;
209
 
 
210
 
 
211
130
-- Rebuild indexes.
212
131
CREATE INDEX bugsummary__full__idx ON BugSummary (
213
132
    tag, status, product, productseries, distribution,