Add new FK between p_ci_builds and p_ci_pipelines
What does this MR do and why?
For still unknown reasons the FK between the p_ci_builds
and p_ci_pipelines
tables doesn't cascade the deletes anymore and we're accumulating orphaned rows in production. This new FK is intended to stop this from happening while we figure out what is going on with the old FK.
Before
gitlabhq_dblab=# SELECT count(*) FROM p_ci_builds WHERE commit_id = 1443163624;
count
-------
5
(1 row)
gitlabhq_dblab=# DELETE FROM ci_pipelines WHERE id = 1443163624;
DELETE 1
gitlabhq_dblab=# SELECT count(*) FROM p_ci_builds WHERE commit_id = 1443163624;
count
-------
5
(1 row)
After
gitlabhq_dblab=# ALTER TABLE ci_builds ADD CONSTRAINT fk_d3130c9a7f_p_tmp FOREIGN KEY (partition_id, commit_id) REFERENCES p_ci_pipelines (partition_id, id) ON UPDATE CASCADE ON DELETE CASCADE NOT VALID;
ALTER TABLE "gitlab_partitions_dynamic"."ci_builds_101" ADD CONSTRAINT fk_d3130c9a7f_p_tmp FOREIGN KEY (partition_id, commit_id) REFERENCES p_ci_pipelines (partition_id, id) ON UPDATE CASCADE ON DELETE CASCADE NOT VALID;
ALTER TABLE "gitlab_partitions_dynamic"."ci_builds_102" ADD CONSTRAINT fk_d3130c9a7f_p_tmp FOREIGN KEY (partition_id, commit_id) REFERENCES p_ci_pipelines (partition_id, id) ON UPDATE CASCADE ON DELETE CASCADE NOT VALID;
ALTER TABLE
Time: 397.184 ms
ALTER TABLE
Time: 201.444 ms
ALTER TABLE
Time: 201.070 ms
gitlabhq_dblab=# SELECT count(*) FROM p_ci_builds WHERE commit_id = 1443163624;
count
-------
5
(1 row)
Time: 261.522 ms
gitlabhq_dblab=# DELETE FROM ci_pipelines WHERE id = 1443163624;
DELETE 1
Time: 713.154 ms
gitlabhq_dblab=# SELECT count(*) FROM p_ci_builds WHERE commit_id = 1443163624;
count
-------
0
(1 row)
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Screenshots or screen recordings
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
Before | After |
---|---|
How to set up and validate locally
Numbered steps to set up and validate the change are strongly suggested.
Related to #483290 (closed)
Edited by Marius Bobin