pierrejeambrun commented on code in PR #62294:
URL: https://github.com/apache/airflow/pull/62294#discussion_r2933165684


##########
airflow-core/src/airflow/utils/db.py:
##########
@@ -1682,11 +1688,47 @@ def get_query_count(query_stmt: Select, *, session: 
Session) -> int:
 
     :meta private:
     """
+    dialect_name = get_dialect_name(session)
+
+    if allow_estimation and dialect_name in ("postgresql", "mysql") and 
_is_simple_select_from(query_stmt):
+        table = getattr(query_stmt.get_final_froms()[0], "name", None)
+        if dialect_name == "postgresql":
+            estimate_stmt = text("SELECT reltuples FROM pg_class WHERE relname 
= :table")
+        elif dialect_name == "mysql":
+            estimate_stmt = text(
+                "SELECT NUM_ROWS FROM INFORMATION_SCHEMA.INNODB_TABLESTATS 
where NAME = 'airflow/:table'"
+            )
+        result = session.scalar(estimate_stmt, {"table": table})
+
+        # If the row count estimate is small, query count(*) to get the exact 
number
+        if result is not None and result > threshold:
+            return result

Review Comment:
   I don't think we can return an estimation for the 'total_entries', this will 
mess up pagination. (More or less pages will be displayed in the UI, some of 
them unreachable, some of them empty)



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