Skip to content

Add indexes on serialized_dag and dag_code - #69391

Merged
ephraimbuddy merged 1 commit into
apache:mainfrom
justinpakzad:add-indexes-ser-dag-dag-code
Aug 7, 2026
Merged

ephraimbuddy merged 1 commit into
apache:mainfrom
justinpakzad:add-indexes-ser-dag-dag-code

Conversation

@justinpakzad

@justinpakzad justinpakzad commented Jul 4, 2026 •

Copy link
Copy Markdown
Contributor

This PR adds indexes on the dag_id columns of the serialized_dag and dag_code tables. This should avoid full table scans when fetching the latest serialized Dag or Dag code by dag_id.

Note - this a continuation of #64311, which was closed due to inactivity. Thanks to the author for the original implementation.

closes: #60883

Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.

@justinpakzad
justinpakzad marked this pull request as ready for review July 5, 2026 12:26
@justinpakzad
justinpakzad force-pushed the add-indexes-ser-dag-dag-code branch from e897e42 to 95a8040 Compare July 13, 2026 23:42
@justinpakzad

Copy link
Copy Markdown
Contributor Author

Updated the version to 3.3.1. Given there were already a few 3.4.0 migrations, I had to modify/rename some of the other files in order put it between 3.3.0 and 3.4.0. Also added a test as requested.

@justinpakzad
justinpakzad requested a review from ashb July 14, 2026 12:28
@potiuk potiuk added the ready for maintainer review Set by triage when all criteria pass, or by the fork CI reconciler when fork CI is green. label Jul 15, 2026
@justinpakzad
justinpakzad force-pushed the add-indexes-ser-dag-dag-code branch from 95a8040 to d2bce90 Compare July 20, 2026 20:52
@justinpakzad

Copy link
Copy Markdown
Contributor Author

Would appreciate another review on this. Thanks.

@justinpakzad
justinpakzad force-pushed the add-indexes-ser-dag-dag-code branch from d2bce90 to f05d856 Compare July 23, 2026 21:31
@justinpakzad

Copy link
Copy Markdown
Contributor Author

@ephraimbuddy any thoughts on this?

@ephraimbuddy ephraimbuddy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good but I think we should have composite indexes which will be more beneficial in the long run
(dag_id, last_updated) on dagcode and (dag_id, created_at) on serialized_dag

We have queries that actually exercise those paths

@justinpakzad
justinpakzad force-pushed the add-indexes-ser-dag-dag-code branch from f05d856 to 8a14979 Compare July 30, 2026 14:41
@justinpakzad

Copy link
Copy Markdown
Contributor Author

This looks good but I think we should have composite indexes which will be more beneficial in the long run (dag_id, last_updated) on dagcode and (dag_id, created_at) on serialized_dag

We have queries that actually exercise those paths

Good call, I've updated them to composite indexes.

@vatsrahul1001

Copy link
Copy Markdown
Contributor

This change is more suitable for minor release not patch moving to 3.4.0

@justinpakzad
justinpakzad force-pushed the add-indexes-ser-dag-dag-code branch from 8a14979 to a15acd5 Compare August 3, 2026 14:16
@justinpakzad

Copy link
Copy Markdown
Contributor Author

This change is more suitable for minor release not patch moving to 3.4.0

Makes sense. I've updated it to target 3.4.0.

@justinpakzad
justinpakzad force-pushed the add-indexes-ser-dag-dag-code branch from a15acd5 to cef6b45 Compare August 5, 2026 21:11
@ephraimbuddy
ephraimbuddy merged commit e24f529 into apache:main Aug 7, 2026
77 checks passed
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Backport failed to create: v3-3-test. View the failure log Run details

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
❌ v3-3-test Commit Link

You can attempt to backport this manually by running:

cherry_picker e24f529 v3-3-test

This should apply the commit to the v3-3-test branch and leave the commit in conflict state marking
the files that need manual conflict resolution.

After you have resolved the conflicts, you can continue the backport process by running:

cherry_picker --continue

If you don't have cherry-picker installed, see the installation guide.

dabla pushed a commit to dabla/airflow that referenced this pull request Aug 14, 2026
imrichardwu pushed a commit to imrichardwu/airflow that referenced this pull request Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:dag-processor area:db-migrations PRs with DB migration kind:documentation ready for maintainer review Set by triage when all criteria pass, or by the fork CI reconciler when fork CI is green.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid full table scan on /structure/{dag_id}

5 participants