Skip to content

Avoid full table scan on /structure/{dag_id} #60883

Closed

Description

@sortega

Description

The task_instance.dag_version_id column was added in migration 0047_3_0_0_add_dag_versioning.py but no index was created. This causes slow query performance when filtering/joining on this column.

Problem:

  • The column is a FK to dag_version.id and used to filter in some queries
  • Without an index, we get full table scans on task_instance

Affected queries:

  • UI grid endpoint filtering task instances by dag_version_id
  • Any query joining task_instance with dag_version

Proposed solution:
Add index ti_dag_version_id on task_instance.dag_version_id

Use case/motivation

We experienced query timeouts because of this issue in our Airflow deployment.

Related issues

No response

Are you willing to submit a PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. added
    kind:feature
    needs-triage
    on Jan 21, 2026
  2. added
    area:MetaDB
    kind:bug
    on Jan 21, 2026
  3. removed
    needs-triage
    on Jan 31, 2026
  4. potiuk commented on Mar 2, 2026

    @potiuk
    Member

    @sortega We are unassigning you from this issue as part of our updated assignment policy.

    This is not meant to discourage your contribution — quite the opposite! You are still very welcome to work on this issue and submit a PR for it. Simply comment that you are working on it and open a PR when ready.

    We found that formal assignments were not working well, as they often prevented others from contributing when the assignee was not actively working on the issue.

  5. sortega commented on Mar 27, 2026

    @sortega
    ContributorAuthor

    I'm working on it

  6. kir-rin commented on May 17, 2026

    @kir-rin
    Contributor

    Hi @sortega, thanks for the great work on this issue and PR #64311.

    I noticed that PR has been closed due to inactivity for over a month. I'd like to pick this up and address the remaining items.

    If you're still planning to continue working on this, please let me know and I'll defer to you — otherwise, I'll proceed with a new PR that builds on your implementation.

  7. SamWheating commented on Sep 15, 2026

    @SamWheating
    Contributor

    Adding a note here for anyone else looking into these issues - the task_instance.dag_version_id index was added in #64818, and released as a part of 3.3.0.

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

    area:MetaDBarea:corearea:performancekind:bugkind:feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions