Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance Issues with parallel FOREIGN KEYS ... ON DELETE CASCADE #8220

Open
jw1u1 opened this issue Mar 29, 2022 · 2 comments
Open

Performance Issues with parallel FOREIGN KEYS ... ON DELETE CASCADE #8220

jw1u1 opened this issue Mar 29, 2022 · 2 comments
Labels

Comments

@jw1u1
Copy link

jw1u1 commented Mar 29, 2022

Summary

DELETE FROM pipelines WHERE id = 1; runs for hours due to too many FOREIGN KEYS ... ON DELETE CASCADE in the Database, some of them are references between the same Tables.

Steps to reproduce

create 1500 builds
explain analyze DELETE FROM pipelines WHERE id = 1;

Expected results

Much faster Execution

Actual results

even after the pipeline_id was deleted from builds, the FK Trigger takes 3.3 seconds of 3.4 total Execution Time:
QUERY PLAN | Trigger for constraint successful_build_outputs_rerun_of_fkey on builds: time=3299.810 calls=1

Additional context

work around:
psql -c " select 'delete from builds where id='||id||';' from builds where pipeline_id in (select id from pipelines where name like 'old%');" concourse -At | psql concourse

PS
trigger based dynamic DDL as in on_pipeline_insert and on_pipeline_delete is a source of performance issues, too.

Triaging info

  • Concourse version: v6.3.0
  • Browser (if applicable):
  • Did this used to work?
@jw1u1 jw1u1 added the bug label Mar 29, 2022
@taylorsilva
Copy link
Member

This is on an old version of Concourse (6.3.0).

Should compare results on v7.0+

Which version of Postgres are you on? That may also be helpful, though I'm not sure how much performance would change between versions of postgres.

@jw1u1
Copy link
Author

jw1u1 commented Oct 5, 2022

concourse is version: v7.8.2 now.
Postgres is stillversion 11.
Still tons of foreign keys with ON DELETE CASCADE.
This isn't how a database schema should look alike, regardless of the DB Version:
Builds for example is referenced by:
TABLE "build_comments" CONSTRAINT "build_comments_build_id_fkey" FOREIGN KEY (build_id) REFERENCES builds(id) ON DELETE CASCADE
TABLE "build_image_resource_caches" CONSTRAINT "build_image_resource_caches_build_id_fkey" FOREIGN KEY (build_id) REFERENCES builds(id) ON DELETE CASCADE
TABLE "build_pipes" CONSTRAINT "build_pipes_from_build_id_fkey" FOREIGN KEY (from_build_id) REFERENCES builds(id) ON DELETE CASCADE
TABLE "build_pipes" CONSTRAINT "build_pipes_to_build_id_fkey" FOREIGN KEY (to_build_id) REFERENCES builds(id) ON DELETE CASCADE
TABLE "build_resource_config_version_inputs" CONSTRAINT "build_resource_config_version_inputs_build_id_fkey" FOREIGN KEY (build_id) REFERENCES builds(id) ON DELETE CASCADE
TABLE "build_resource_config_version_outputs" CONSTRAINT "build_resource_config_version_outputs_build_id_fkey" FOREIGN KEY (build_id) REFERENCES builds(id) ON DELETE CASCADE
TABLE "builds" CONSTRAINT "builds_rerun_of_fkey" FOREIGN KEY (rerun_of) REFERENCES builds(id) ON DELETE CASCADE
TABLE "containers" CONSTRAINT "containers_build_id_fkey" FOREIGN KEY (build_id) REFERENCES builds(id) ON DELETE SET NULL
TABLE "jobs" CONSTRAINT "jobs_latest_completed_build_id_fkey" FOREIGN KEY (latest_completed_build_id) REFERENCES builds(id) ON DELETE SET NULL
TABLE "jobs" CONSTRAINT "jobs_next_build_id_fkey" FOREIGN KEY (next_build_id) REFERENCES builds(id) ON DELETE SET NULL
TABLE "jobs" CONSTRAINT "jobs_transition_build_id_fkey" FOREIGN KEY (transition_build_id) REFERENCES builds(id) ON DELETE SET NULL
TABLE "next_build_pipes" CONSTRAINT "next_build_pipes_from_build_id_fkey" FOREIGN KEY (from_build_id) REFERENCES builds(id) ON DELETE CASCADE
TABLE "resource_cache_uses" CONSTRAINT "resource_cache_uses_build_id_fkey" FOREIGN KEY (build_id) REFERENCES builds(id) ON DELETE CASCADE
TABLE "successful_build_outputs" CONSTRAINT "successful_build_outputs_build_id_fkey" FOREIGN KEY (build_id) REFERENCES builds(id) ON DELETE CASCADE
TABLE "successful_build_outputs" CONSTRAINT "successful_build_outputs_rerun_of_fkey1" FOREIGN KEY (rerun_of) REFERENCES builds(id)
TABLE "worker_artifacts" CONSTRAINT "worker_artifacts_build_id_fkey" FOREIGN KEY (build_id) REFERENCES builds(id) ON DELETE SET NULL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants