Repository navigation
Conversation
kalluripradeep
left a comment
There was a problem hiding this comment.
Good set of indexes. Worth noting that on large deployments, running this migration against a big task_instance table could take a while and potentially lock it. Might be worth a heads-up in the migration notes so operators can plan for it.
00054ac to
3f62158
Compare
|
@kalluripradeep that's a good point. Added the warning to the newsfragment |
3f62158 to
b32d3a8
Compare
b32d3a8 to
79e6a07
Compare
There was a problem hiding this comment.
Pull request overview
Adds missing metadata DB indexes to reduce full table scans and speed up common lookups/joins involving serialized DAGs, DAG code, and task instances.
Changes:
- Adds new Alembic migration to create indexes on
serialized_dag(dag_id, last_updated),dag_code(dag_id), andtask_instance(dag_version_id). - Updates ORM models (
SerializedDagModel,DagCode,TaskInstance) to declare the same indexes. - Updates the migration head mapping for Airflow
3.3.0.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| airflow-core/src/airflow/utils/db.py | Bumps the 3.3.0 migration head to the new revision. |
| airflow-core/src/airflow/models/taskinstance.py | Declares an index on dag_version_id at the ORM level. |
| airflow-core/src/airflow/models/serialized_dag.py | Declares a composite index on (dag_id, last_updated) at the ORM level. |
| airflow-core/src/airflow/models/dagcode.py | Declares an index on dag_id at the ORM level. |
| airflow-core/src/airflow/migrations/versions/0110_3_2_0_add_performance_indexes.py | New migration that creates/drops the indexes (with MySQL downgrade exception for the TI FK index). |
| airflow-core/newsfragments/64311.improvement.rst | Newsfragment documenting the performance improvement. |
4c1c008 to
4c5167f
Compare
hussein-awala
left a comment
There was a problem hiding this comment.
Looks good, thanks @sortega for the improvement!
4c5167f to
f093fb7
Compare
|
@sortega could you please add this index to the ignore list in the |
f093fb7 to
5643f65
Compare
|
Added |
Add missing database indexes to improve query performance: - serialized_dag(dag_id, last_updated): speeds up fetching latest serialized DAG - dag_code(dag_id): speeds up DAG code lookups by dag_id - task_instance(dag_version_id): speeds up joins/filters on dag_version_id FK These indexes resolve full table scan issues observed in production when querying the metadata database under load.
5643f65 to
52e58ad
Compare
|
@sortega A few things need addressing before review — see our Pull Request quality criteria.
No rush. Note: This comment was drafted by an AI-assisted triage tool and may contain mistakes. Once you have addressed the points above, an Apache Airflow maintainer — a real person — will take the next look at your PR. We use this two-stage triage process so that our maintainers' limited time is spent where it matters most: the conversation with you. |
| # MySQL auto-creates an index on FK columns; the migration skips creating this | ||
| # index on MySQL to avoid a duplicate, but the ORM always declares it. | ||
| lambda t: t[0] == "add_index" and t[1].name == "idx_task_instance_dag_version_id", | ||
| ] |
There was a problem hiding this comment.
The new ignore for idx_task_instance_dag_version_id is applied unconditionally, which means this schema-sync test would also ignore a missing/renamed dag_version_id index on non-MySQL backends. Consider only adding this ignore when the active dialect is MySQL (where the migration intentionally skips creating the named index).
| # MySQL auto-creates an index on FK columns; the migration skips creating this | |
| # index on MySQL to avoid a duplicate, but the ORM always declares it. | |
| lambda t: t[0] == "add_index" and t[1].name == "idx_task_instance_dag_version_id", | |
| ] | |
| ] | |
| if settings.engine.dialect.name == "mysql": | |
| # MySQL auto-creates an index on FK columns; the migration skips creating this | |
| # index on MySQL to avoid a duplicate, but the ORM always declares it. | |
| ignores.append(lambda t: t[0] == "add_index" and t[1].name == "idx_task_instance_dag_version_id") |
|
@sortega This PR was triaged 16 days ago with no reply since. Converting to draft — this PR doesn't yet meet our Pull Request quality criteria.
See the linked criteria for how to fix each item, then mark the PR "Ready for review". This is not a rejection — just an invitation to bring the PR up to standard. No rush. Note: This comment was drafted by an AI-assisted triage tool and may contain mistakes. Once you have addressed the points above, an Apache Airflow maintainer — a real person — will take the next look at your PR. We use this two-stage triage process so that our maintainers' limited time is spent where it matters most: the conversation with you. |
|
Quick follow-up to the triage comment above — one clarification on the "Unresolved review comments" item: Once you believe a thread has been addressed — whether by pushing a fix, or by replying in-thread with an explanation of why the suggestion doesn't apply — please mark the thread as resolved yourself by clicking the "Resolve conversation" button at the bottom of each thread. Reviewers don't auto-close their own threads, so an addressed-but-unresolved thread reads as "still waiting on the author" and keeps the PR from moving forward. The author doing the resolve-click is the expected convention on this project. Note: This comment was drafted by an AI-assisted triage tool and may contain mistakes. Once you have addressed the points above, an Apache Airflow maintainer — a real person — will take the next look at your PR. We use this two-stage triage process so that our maintainers' limited time is spent where it matters most: the conversation with you. |
|
Hi @sortega, thanks for picking this up — the fix shape looks right and the maintainer reviews are very encouraging. I noticed the branch hasn't had activity in about a month and there are a few CI failures plus merge conflicts to resolve. Are you still planning to finish this, or would you welcome help? I'm happy to take any of these on. |
|
@sortega This draft PR has been inactive for 13 days since the last triage comment and no response from the author. Closing to keep the queue clean. You are welcome to reopen this PR when you resume work, or to open a new one addressing the issues previously raised. There is no rush — take your time. Note: This comment was drafted by an AI-assisted triage tool and may contain mistakes. Once you have addressed the points above, an Apache Airflow maintainer — a real person — will take the next look at your PR. We use this two-stage triage process so that our maintainers' limited time is spent where it matters most: the conversation with you. |
Add missing database indexes to improve query performance on the metadata DB:
serialized_dag(dag_id, last_updated)— speeds up queries fetching the latest serialized DAG per dag_iddag_code(dag_id)— speeds up DAG code lookups by dag_idtask_instance(dag_version_id)— speeds up joins/filters on the dag_version_id FK (added in migration 0047 without an index)These indexes resolve full table scan issues observed in production under load. Supersedes #60886 which only covered the
task_instance.dag_version_idindex.closes #60883
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Opus 4.6) following the guidelines