Skip to content

build_resource_config_version_inputs table never clean up #9302

Open

Description

@IvanChalukov

Summary

On large database instances, the API endpoint
/api/v1/teams/:team_name/pipelines/:pipeline_name/resources/:resource_name/versions/:resource_config_version_id/input_to
starts to responds extremely slowly, taking 5–10 minutes to complete.

This causes significant delays for clients relying on this endpoint.

Notes

  • The issue seems to occur intermittently, but is more frequent on instances with very large tables.
  • Likely related to inefficient query execution on build_resource_config_version_inputs and related joins.
Table Row count
build_resource_config_version_inputs 9,116,358
resource_config_versions 1,479,136
builds 3,494,769
jobs 869
resources 112
pipelines 19
teams 2
build_comments 1,798

After quick check in code base the slow query:

SELECT
    b.id,
    b.name,
    b.job_id,
    b.resource_id,
    b.resource_type_id,
    b.team_id,
    b.status,
    b.manually_triggered,
    b.created_by,
    b.scheduled,
    b.schema,
    b.private_plan,
    b.public_plan,
    b.create_time,
    b.start_time,
    b.end_time,
    b.reap_time,
    j.name AS job_name,
    r.name AS resource_name,
    b.pipeline_id,
    p.name AS pipeline_name,
    p.instance_vars,
    t.name AS team_name,
    b.nonce,
    b.drained,
    b.aborted,
    b.completed,
    b.inputs_ready,
    b.rerun_of,
    rb.name AS rerun_build_name,
    b.rerun_number,
    b.span_context,
    COALESCE(bc.comment, '') AS comment
FROM builds b
LEFT OUTER JOIN jobs j ON b.job_id = j.id
LEFT OUTER JOIN resources r ON b.resource_id = r.id
LEFT OUTER JOIN pipelines p ON b.pipeline_id = p.id
LEFT OUTER JOIN teams t ON b.team_id = t.id
LEFT OUTER JOIN builds rb ON rb.id = b.rerun_of
LEFT OUTER JOIN build_comments bc ON b.id = bc.build_id
JOIN build_resource_config_version_inputs bi ON bi.build_id = b.id
JOIN resource_config_versions rcv ON rcv.version_md5 = bi.version_md5
WHERE rcv.id = $1
  AND bi.resource_id = $2;

Our suspicion is that the large size of the build_resource_config_version_inputs table, which is never cleaned up, is the main cause of the slow query. We haven’t found a way to optimize the query without introducing new indexes.

We already have a build_log_retention policy configured to keep no more than 1,500 build logs. Given that, we would expect input versions associated with cleaned-up builds to also be removed from build_resource_config_version_inputs, but that doesn’t seem to be happening.

Steps to Reproduce

Create an DB instance with alot of resource_config_version_inputs(over 9 million).

Expected Results

The API call /api/v1/teams/:team_name/pipelines/:pipeline_name/resources/:resource_name/versions/:resource_config_version_id/input_to should execute quickly, and the build_resource_config_version_inputs table should be automatically cleaned up as part of the build log retention process.

Actual Results

The API call /api/v1/teams/:team_name/pipelines/:pipeline_name/resources/:resource_name/versions/:resource_config_version_id/input_to often takes 5–10 minutes to respond on large database instances.
Additionally, the build_resource_config_version_inputs table continues to grow without cleanup, even though a build log retention policy is configured.

Web Node(s) configuration

No response

Worker(s) configuration

No response

Concourse Version

7.14.1

Browser (if applicable)

N/A

Did this use to work?

do not think so

Activity

  1. analytically commented on Sep 30, 2025

    @analytically
    Contributor

    Builds are never deleted, just a 'reap_time' is set. Hence the cascade never triggers. I also think that when we delete the resource version inputs, a rerun of an old successful build isn't possible anymore.

    So we should implement some kind of 90 days + cleanup method that actually deleted builds, triggering the cascade's.

  2. Kump3r commented on Oct 17, 2025

    @Kump3r
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions