This is an automated email from the ASF dual-hosted git repository.
vincbeck pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 196553468f1 Filter on dag_id when querying task_instance (#62751)
196553468f1 is described below
commit 196553468f158d39a76ae204cc11785ec05779e9
Author: Jeff Stein <[email protected]>
AuthorDate: Tue Mar 3 11:06:24 2026 -0800
Filter on dag_id when querying task_instance (#62751)
---
airflow-core/src/airflow/models/serialized_dag.py | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/airflow-core/src/airflow/models/serialized_dag.py
b/airflow-core/src/airflow/models/serialized_dag.py
index db166637a67..2afa5d353db 100644
--- a/airflow-core/src/airflow/models/serialized_dag.py
+++ b/airflow-core/src/airflow/models/serialized_dag.py
@@ -599,7 +599,15 @@ class SerializedDagModel(Base):
has_task_instances: bool = False
if dag_version:
has_task_instances = bool(
-
session.scalar(select(exists().where(TaskInstance.dag_version_id ==
dag_version.id)))
+ session.scalar(
+ select(
+ exists().where(
+ # Using dag_id filter to speed up query via the
composite index.
+ TaskInstance.dag_id == dag.dag_id,
+ TaskInstance.dag_version_id == dag_version.id,
+ )
+ )
+ )
)
if dag_version and not has_task_instances: