Fix scheduler MySQL task instance index hint#66785
Open
8silvergun wants to merge 1 commit into
Open
Conversation
eladkal
reviewed
May 13, 2026
| # Select only rows where row_number <= max_active_tasks. | ||
| query = ( | ||
| select(TI) | ||
| .with_hint(TI, "USE INDEX (ti_state)", dialect_name="mysql") |
Contributor
Contributor
There was a problem hiding this comment.
@eladkal Thanks for pinging me! I'm going to run some tests.
xBis7
reviewed
May 13, 2026
Contributor
xBis7
left a comment
There was a problem hiding this comment.
Generally it looks good. I need to run some benchmark tests just to be sure.
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.
closes: #66763
Summary
SchedulerJobRunner._executable_task_instances_to_queuedappliedUSE INDEX (ti_state)twice on MySQL: once on theinner ranked query that filters by scheduled task instances, and once on the outer rejoin that looks up
task_instanceby(dag_id, task_id, run_id, map_index).The outer query is an exact identity lookup, so forcing
ti_statecan prevent MySQL from usingtask_instance_composite_key. This PR removes only the outer hint and keeps the inner hint that was added for theoriginal MySQL scheduler optimization.
Regression Coverage
Added a regression test that compiles the scheduler selection query with the MySQL dialect and verifies
USE INDEX (ti_state)appears only once.Tests
uv run --python 3.12 --group dev pytest airflow-core/tests/unit/jobs/ -xvsprek run ruff --from-ref mainprek run ruff-format --from-ref mainContext
ti_statehint for the scheduler state lookup.also applied to the outer rejoin.
Was generative AI tooling used to co-author this PR?
Generated-by: OpenAI Codex following [the guidelines](https://github.com/apache/airflow/blob/main/contributing-
docs/05_pull_requests.rst#gen-ai-assisted-contributions)