This is an automated email from the ASF dual-hosted git repository.

kaxilnaik pushed a commit to branch v3-1-test
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/v3-1-test by this push:
     new a82a0342312 Filter on dag_id when querying task_instance (#62751) 
(#63291)
a82a0342312 is described below

commit a82a0342312173a1de6c74faea8603b3375f49d0
Author: Rahul Vats <[email protected]>
AuthorDate: Wed Mar 11 04:10:46 2026 +0530

    Filter on dag_id when querying task_instance (#62751) (#63291)
    
    (cherry picked from commit 196553468f158d39a76ae204cc11785ec05779e9)
    
    Co-authored-by: Jeff Stein <[email protected]>
---
 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 e714361df9d..401809c5087 100644
--- a/airflow-core/src/airflow/models/serialized_dag.py
+++ b/airflow-core/src/airflow/models/serialized_dag.py
@@ -432,7 +432,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:

Reply via email to