houqp commented on a change in pull request #8545:
URL: https://github.com/apache/airflow/pull/8545#discussion_r428389970



##########
File path: airflow/models/dagrun.py
##########
@@ -491,6 +491,25 @@ def is_backfill(self):
             self.run_id.startswith(f"{DagRunType.BACKFILL_JOB.value}")
         )
 
+    @classmethod
+    @provide_session
+    def get_latest_run(cls, dag_id, session):
+        """Returns the latest DagRun for a given dag_id"""
+        subquery = (
+            session
+            .query(func.max(cls.execution_date).label('execution_date'))
+            .filter(cls.dag_id == dag_id)
+            .subquery()
+        )
+        dagrun = (

Review comment:
       ha, ok, i didn't know execution_date column is not indexed, that's 
surprising. in that case, subquery is 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.

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


Reply via email to