Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 1 | -- 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 | |
| 6 | CREATE TABLE LabelDefToDelete (id INT); |
| 7 | |
| 8 | INSERT 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 | |
| 14 | DELETE FROM LabelDef |
| 15 | WHERE id IN (SELECT * FROM LabelDefToDelete) |
| 16 | LIMIT 2000; |
| 17 | |