blob: d5c05d06c8ea8273ea702b2e8d8e4b705c3d4c5b [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001-- Garbage collect LabelDef rows from all projects where:
2-- 1. The label is not currently in use (it does not join to Issue2Label).
3-- 2. The label is not a well-known label (it does not have a rank).
4-- There are currently about 1500 such labels in the prod database.
5
6CREATE TABLE LabelDefToDelete (id INT);
7
8INSERT INTO LabelDefToDelete (id)
9 SELECT id FROM LabelDef
10 LEFT JOIN Issue2Label ON LabelDef.id = Issue2Label.label_id
11 WHERE issue_id IS NULL
12 AND rank IS NULL;
13
14DELETE FROM LabelDef
15 WHERE id IN (SELECT * FROM LabelDefToDelete)
16 LIMIT 2000;
17