Repository navigation
Conversation
find_duplicate queried dag_id = ? AND (run_id = ? OR execution_date = ?). MySQL cannot serve that OR from the (dag_id, run_id) / (dag_id, execution_date) unique indexes and scans every run of the DAG instead. On the US metadb that is 15s per call for lake-chrono-deduplication-dag (2.2M runs); each half on its own is 1ms. Look up run_id first, then execution_date. post_dag_run in the stable API carried its own copy of the OR and now calls find_duplicate too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Draft for team discussion, not ready to merge. Jira: BH-1670
Problem
DagRun.find_duplicaterunsWHERE dag_id = ? AND (run_id = ? OR execution_date = ?)on every trigger: experimental API,TriggerDagRunOperator, and the UI trigger. MySQL can't serve that OR from the(dag_id, run_id)/(dag_id, execution_date)unique indexes. It does arefon thedag_idprefix and filters every run of the DAG.Measured read-only on the US metadb (Aurora MySQL 8.0.42), 2026-10-28:
lake-chrono-deduplication-dag, 2,218,928 runs)(dag_id AND run_id) OR (dag_id AND execution_date)dag_id AND run_id/dag_id AND execution_datealoneThat's ~98% of each ~14s trigger call for the chrono dedup scheduler (~280 triggers/hr), measured from the webserver's
execution_date→queued_attimestamps.Upstream
Unchanged in 2.9.3 and 2.10.5; the stable API's
post_dag_runhas its own copy of the OR. apache#34713 was closed as expected behaviour. Airflow 3.0 changesfind_duplicatetodag_id + run_idonly, so this patch can be dropped once we're on 3.x.Change
find_duplicate: look up byrun_id, and if nothing matches, byexecution_date. Each is a unique-index probe.post_dag_run(stable API) callsfind_duplicateinstead of its own OR query.run_idmatch and anexecution_datematch landing on different runs.Behaviour change (edge case): if
run_idmatches run A andexecution_datematches a different run B, the old code raisedMultipleResultsFound(500 from the API). It now returns A, so callers raiseDagRunAlreadyExists(409). The stable API already used.first(), so nothing changes there.Verification
Patched source run against a fresh SQLite metadb: the existing
test_dagrun_find_duplicateassertions plus the new split-match case all pass, andruff --select Fis clean. I haven't run the full fork test suite or tested on MySQL; CI / a stage deploy should cover that.Open for discussion
+affirm5/+affirm2) and release: not included.lake-chrono-deduplication-dagruns.🤖 Generated with Claude Code