joshowen commented on code in PR #33242:
URL: https://github.com/apache/airflow/pull/33242#discussion_r1456302037


##########
airflow/models/dag.py:
##########
@@ -3068,21 +3068,45 @@ def bulk_write_to_db(
         # Skip these queries entirely if no DAGs can be scheduled to save time.
         if any(dag.timetable.can_be_scheduled for dag in dags):
             # Get the latest automated dag run for each existing dag as a 
single query (avoid n+1 query)
-            last_automated_runs_subq = (
-                select(DagRun.dag_id, 
func.max(DagRun.execution_date).label("max_execution_date"))
-                .where(
-                    DagRun.dag_id.in_(existing_dags),
-                    or_(DagRun.run_type == DagRunType.BACKFILL_JOB, 
DagRun.run_type == DagRunType.SCHEDULED),
+            if len(existing_dags) == 1:
+                # Index optimized fast path to avoid more complicated & slower 
groupby queryplan
+                existing_dag_id = list(existing_dags)[0]

Review Comment:
   `existing_dags` is a dict in this code, so this is grabbing the first key 
which is a dag_id.  
https://github.com/apache/airflow/pull/33242/files#diff-62c8e300ee91e0d59f81e0ea5d30834f04db71ae74f2e155a10b51056b00b59bR3053



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to