pierrejeambrun opened a new pull request, #72811:
URL: https://github.com/apache/airflow/pull/72811

   Follow-up to #72699. That PR bounded the ``get_previous_task_instance`` 
lookup
   with ``.limit(1)``; @kaxil noted in review that the same query also asks for 
an
   eager-load that duplicates work the mapper already does.
   
   ``TaskInstance.dag_run`` is ``lazy="joined"`` 
(``airflow-core/src/airflow/models/taskinstance.py:727``),
   so the explicit ``joinedload(TI.dag_run)`` attaches a parallel ``JOIN 
dag_run AS dag_run_1``
   next to the explicit ``JOIN dag_run`` the query already needs for the
   ``ORDER BY dag_run.logical_date``. Both joins select the same rows over the 
same
   ``(dag_id, run_id)`` FK pair, so every request paid for one extra join.
   
   Switch to ``contains_eager(TI.dag_run)`` so the mapper's eager-load reuses 
the
   explicit join. Compiled SQL drops from ``JOIN dag_run ... JOIN dag_run AS 
dag_run_1 ...``
   to a single ``JOIN dag_run``; the regression test in this PR fails on the old
   shape and passes on the new one.
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes — Claude Code (Opus 4.7)
   
   Generated-by: Claude Code (Opus 4.7) following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)


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