jason810496 commented on code in PR #58814:
URL: https://github.com/apache/airflow/pull/58814#discussion_r2572837789


##########
airflow-core/tests/unit/api_fastapi/common/db/test_indexes.py:
##########
@@ -0,0 +1,163 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from __future__ import annotations
+
+import uuid
+
+import pytest
+from sqlalchemy import inspect, text
+
+from airflow.api_fastapi.common.db import indexes
+from airflow.settings import get_engine
+
+from tests_common.test_utils.config import conf_vars
+
+pytestmark = pytest.mark.db_test
+
+
+def _backend() -> str:
+    return get_engine().dialect.name
+
+
+class TestParseIndexSpec:
+    def test_valid(self):
+        table, cols = indexes._parse_index_spec("task_instance(dag_id, 
task_id, run_id)")
+        assert table == "task_instance"
+        assert cols == ["dag_id", "task_id", "run_id"]
+
+    def test_invalid(self):
+        with pytest.raises(ValueError, match="Invalid index spec 
'task_instance'. Expected*"):
+            indexes._parse_index_spec("task_instance")
+        with pytest.raises(ValueError, match=r"Invalid index spec 
'task_instance\(,\)'. Table name and"):
+            indexes._parse_index_spec("task_instance(,)")
+
+
+class TestBuildIndexName:
+    @pytest.mark.parametrize(
+        ("table", "cols", "expected"),
+        [
+            ["task_instance", ["dag_id", "run_id", "task_id"], 
"idx_task_instance_dag_id_run_id_task_id"],
+            [
+                "some_table",
+                ["a" * 40, "b" * 40, "c" * 40],
+                
"idx_some_table_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa_e28fa017",
+            ],
+        ],
+    )
+    def test_build_index_names(self, table, cols, expected):
+        name = indexes._build_index_name(table, cols)
+        assert name == expected
+
+
+class TestIndexExists:
+    def test_true_after_creation(self):
+        engine = get_engine()
+        table = f"t_exists_{uuid.uuid4().hex[:8]}"
+        index_name = f"idx_{table}_a_b"
+        with engine.begin() as conn:
+            conn.execute(text(f"CREATE TABLE {table} (a INT, b INT)"))
+        try:
+            with engine.connect() as conn:
+                if _backend() == "postgresql":
+                    indexes._create_index_postgres(conn, table, ["a", "b"], 
index_name)
+                elif _backend() == "mysql":
+                    indexes._create_index_mysql(conn, table, ["a", "b"], 
index_name)
+                else:
+                    indexes._create_index_sqlite(conn, table, ["a", "b"], 
index_name)
+            with engine.connect() as conn:
+                assert indexes._index_exists(conn, table, index_name) is True
+        finally:
+            with engine.begin() as conn:
+                conn.execute(text(f"DROP TABLE IF EXISTS {table}"))
+
+
+class TestCreateIndexPostgres:

Review Comment:
   Would it be better to consolidate the test classes for 
`TestCreateIndexPostgres`, `TestCreateIndexMySQL` and `TestCreateIndexSQLite`, 
as the only difference are `indexes._create_index_<dialect>` callable? 
   
   We could programmatically add `pytest.mark.skipif` if the curret backend 
setup doesn't match the  excepted backend, somehow like common exception 
handler:
   
   
https://github.com/apache/airflow/blob/8ac00cf8924d121f1ed5e9c497026274edb1c8e1/airflow-core/tests/unit/api_fastapi/common/test_exceptions.py#L51-L54



##########
airflow-core/docs/howto/performance.rst:
##########
@@ -0,0 +1,48 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+   or more contributor license agreements.  See the NOTICE file
+   distributed with this work for additional information
+   regarding copyright ownership.  The ASF licenses this file
+   to you under the Apache License, Version 2.0 (the
+   "License"); you may not use this file except in compliance
+   with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+   software distributed under the License is distributed on an
+   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+   KIND, either express or implied.  See the License for the
+   specific language governing permissions and limitations
+   under the License.
+
+Performance tuning (API and UI)
+===============================
+
+This guide collects pragmatic tips that improve Airflow performance for API 
and UI workloads.
+
+Configurable metadata indexes
+-----------------------------
+
+Airflow can create additional database indexes on startup to accelerate common 
queries used by the API and UI.

Review Comment:
   ```suggestion
   Airflow can create additional database indexes on API startup to accelerate 
common queries used by the API and UI.
   ```



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