This is an automated email from the ASF dual-hosted git repository. kaxilnaik pushed a commit to branch v3-0-test in repository https://gitbox.apache.org/repos/asf/airflow.git
commit e76879de5e8ec3ad64cd81ecdd504fc9fa10e52a Author: oboki <[email protected]> AuthorDate: Tue Apr 22 18:48:00 2025 +0900 Add `STRAIGHT_JOIN` prefix for MySQL query optimization in get_sorted_triggers (#46303) This PR adds a STRAIGHT_JOIN hint to prevent an unintended full scan of TaskInstance table in get_sorted_triggers. With MySQL backend, if there are many records in the trigger, it causes the task_instance to be scanned first as the driving table, leading to slow queries. (cherry picked from commit 9f0ac9aeba7c64dc8a950470089c0a6868afc4c7) --- airflow-core/src/airflow/models/trigger.py | 1 + 1 file changed, 1 insertion(+) diff --git a/airflow-core/src/airflow/models/trigger.py b/airflow-core/src/airflow/models/trigger.py index 8bcff1d470e..94d8360edf9 100644 --- a/airflow-core/src/airflow/models/trigger.py +++ b/airflow-core/src/airflow/models/trigger.py @@ -350,6 +350,7 @@ class Trigger(Base): """ query = with_row_locks( select(cls.id) + .prefix_with("STRAIGHT_JOIN", dialect="mysql") .join(TaskInstance, cls.id == TaskInstance.trigger_id, isouter=False) .where(or_(cls.triggerer_id.is_(None), cls.triggerer_id.not_in(alive_triggerer_ids))) .order_by(coalesce(TaskInstance.priority_weight, 0).desc(), cls.created_date)
