Repository navigation
Reduce db clean batch probe overhead - #74455
Merged
vatsrahul1001 merged 1 commit intoOct 18, 2026
Merged
Conversation
Large cleanups repeat the batch probe many times, and counting every row up to the batch size adds unnecessary database work.
Contributor
Backport successfully created: v3-4-testNote: As of Merging PRs targeted for Airflow 3.X In matter of doubt please ask in #release-management Slack channel.
|
vatsrahul1001
pushed a commit
that referenced
this pull request
Oct 18, 2026
vatsrahul1001
pushed a commit
that referenced
this pull request
Oct 20, 2026
SameerMesiah97
pushed a commit
to SameerMesiah97/airflow-oss-sm97
that referenced
this pull request
Oct 27, 2026
Large cleanups repeat the batch probe many times, and counting every row up to the batch size adds unnecessary database work.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
airflow db cleanchecks whether each batch contains rows before creating its archive table and deleting the batch. The result is used only as a boolean, but the current query counts every matching row up to the configured batch size.This changes the per-batch probe from
COUNT(*)toEXISTS. The database still evaluates the cleanup filters, but it can stop the probe after finding the first qualifying row instead of consuming the entire candidate batch. For example, cleaning 1,000,000 rows in 100 batches of 10,000 currently makes the boolean prechecks count up to 1,000,000 rows in total; withEXISTS, the non-empty prechecks need only find one qualifying row per batch. The delete or archive statement still selects each batch, and the final empty probe can still scan all relevant candidates when proving that no rows remain.The batch selection, archive behavior, transaction boundaries, and initial exact count used for dry-run and progress output remain unchanged.
PostgreSQL probe benchmark
On a temporary PostgreSQL table with 1,000,000 rows, 500,000 eligible rows, an indexed cleanup timestamp, and warm buffers,
EXPLAIN ANALYZEshowed the following median results over seven runs:COUNT(*)EXISTSThis isolates the batch-emptiness probe rather than measuring end-to-end cleanup time. The archive/delete work is unchanged, absolute timings are environment-specific, and an empty-result probe may still scan all relevant candidates.
Tests
uv run --project airflow-core pytest airflow-core/tests/unit/utils/test_db_cleanup.py::TestDBCleanup::test_do_delete_checks_batch_existence_without_counting_rows --with-db-init -xvs(passed)uv run --project airflow-core pytest airflow-core/tests/unit/utils/test_db_cleanup.py --with-db-init -xq(SQLite: 113 passed, 3 backend-specific skipped)env -u DOCKER_HOST DOCKER_CONTEXT=colima breeze run --backend sqlite pytest airflow-core/tests/unit/utils/test_db_cleanup.py -xvs(113 passed, 3 backend-specific skipped)env -u DOCKER_HOST DOCKER_CONTEXT=colima breeze run --backend postgres pytest airflow-core/tests/unit/utils/test_db_cleanup.py -xvs(115 passed, 1 MySQL-specific skipped)env -u DOCKER_HOST DOCKER_CONTEXT=colima breeze run --backend mysql pytest airflow-core/tests/unit/utils/test_db_cleanup.py -xvs(114 passed, 2 PostgreSQL-specific skipped)prek run --from-ref upstream/main --stage pre-commit(passed)prek run --from-ref upstream/main --stage manual --skip compile-ui-assets-dev --skip view-skill-eval --skip run-skill-eval-codex(passed)Was generative AI tooling used to co-author this PR?
Generated-by: Codex following the guidelines
{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.Drafted-by: Codex (no human review before posting)