sunank200 commented on code in PR #51225:
URL: https://github.com/apache/airflow/pull/51225#discussion_r2115285009


##########
airflow-core/src/airflow/api_fastapi/core_api/routes/ui/grid.py:
##########
@@ -133,7 +133,6 @@ def grid_data(
     # Retrieve, sort and encode the Task Instances
     tis_of_dag_runs, _ = paginated_select(
         statement=select(TaskInstance)

Review Comment:
   ```suggestion
       tis_of_dag_runs, _ = paginated_select(
           statement=select(TaskInstance)
           .options(selectinload(TaskInstance.task_instance_note))
   ```
   Instead of dropping the note column entirely, I wonder if we can get back 
most of the performance win by switching from OUTER JOIN to a direct 
`select‐in` load on the note relationship. 
https://docs.sqlalchemy.org/en/13/orm/loading_relationships.html#sqlalchemy.orm.selectinload



##########
airflow-core/src/airflow/api_fastapi/core_api/routes/ui/grid.py:
##########
@@ -133,7 +133,6 @@ def grid_data(
     # Retrieve, sort and encode the Task Instances
     tis_of_dag_runs, _ = paginated_select(
         statement=select(TaskInstance)

Review Comment:
   May be something like this:
   ```
   
   statement = (
       select(TaskInstance)
       .options(selectinload(TaskInstance.task_instance_note))
       .where(TaskInstance.dag_id == dag.dag_id)
       .where(TaskInstance.run_id.in_([dr.run_id for dr in dag_runs]))
   )
   
   tis_of_dag_runs, _ = paginated_select(
       statement=statement,
       filters=[],
       order_by=SortParam(allowed_attrs=["task_id", "run_id"], 
model=TaskInstance).set_value("task_id"),
       offset=offset,
       limit=None,
   )
   ```
   This will emit two smaller queries. One for all TIs, one for their notes, 
rather than one giant join. But we'll still have `ti.note` populated. Can we 
try this as well and see if it improves time better?



-- 
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