nailo2c commented on code in PR #68012:
URL: https://github.com/apache/airflow/pull/68012#discussion_r3524199693


##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -296,6 +296,11 @@ def ti_run(
             )
             or 0
         )
+        first_task_reschedule_start_date = None
+        if task_reschedule_count > 0:
+            first_task_reschedule_start_date = session.scalar(
+                
select(func.min(TaskReschedule.start_date)).where(TaskReschedule.ti_id == 
task_instance_id)
+            )

Review Comment:
   Would it be better to fetch `task_reschedule_count` and 
`first_task_reschedule_start_date` in a single aggregate query? 
   
   Right now this makes two DB round trips filtering on the same 
`TaskReschedule.ti_id`, which adds an extra query on the startup path this 
change is trying to shorten.
   
   Maybe something like this:
   ```python
   task_reschedule_count, first_task_reschedule_start_date = session.execute(
       select(
           func.count(TaskReschedule.id),
           func.min(TaskReschedule.start_date),
       ).where(TaskReschedule.ti_id == task_instance_id)
   ).one()
   
   ...
   
   if first_task_reschedule_start_date is not None:
       context.first_task_reschedule_start_date = 
first_task_reschedule_start_date
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to