From 3533e77ec97d89aea2613e39c82b5c63d7a4b50f Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 19 Feb 2023 20:08:43 -0600 Subject: [PATCH] Fix using MariaDB slow range select workaround with Postgresql (#88459) * Mark PostgreSQL range select as fast Currently we were using the slow range select workaround for PostgreSQL that was original developed for MariaDB but its actually slower on PostgreSQ fixes #83253 * Mark PostgreSQL range select as fast Currently we were using the slow range select workaround for PostgreSQL that was original developed for MariaDB but its actually slower on PostgreSQ fixes #83253 --- homeassistant/components/recorder/models.py | 3 --- homeassistant/components/recorder/util.py | 8 +------- tests/components/recorder/test_util.py | 2 +- 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/homeassistant/components/recorder/models.py b/homeassistant/components/recorder/models.py index 1109b1f43c0..acdf61743f9 100644 --- a/homeassistant/components/recorder/models.py +++ b/homeassistant/components/recorder/models.py @@ -480,7 +480,4 @@ class DatabaseOptimizer: # # https://jira.mariadb.org/browse/MDEV-25020 # - # Historically, we have applied this logic to PostgreSQL as well, but - # it may not be necessary. We should revisit this in the future - # when we have more data. slow_range_in_select: bool diff --git a/homeassistant/components/recorder/util.py b/homeassistant/components/recorder/util.py index f8a40972307..4db92030091 100644 --- a/homeassistant/components/recorder/util.py +++ b/homeassistant/components/recorder/util.py @@ -454,9 +454,8 @@ def setup_connection_for_dialect( ) -> DatabaseEngine | None: """Execute statements needed for dialect connection.""" version: AwesomeVersion | None = None - slow_range_in_select = True + slow_range_in_select = False if dialect_name == SupportedDialect.SQLITE: - slow_range_in_select = False if first_connection: old_isolation = dbapi_connection.isolation_level dbapi_connection.isolation_level = None @@ -533,11 +532,6 @@ def setup_connection_for_dialect( # Ensure all times are using UTC to avoid issues with daylight savings execute_on_connection(dbapi_connection, "SET time_zone = '+00:00'") elif dialect_name == SupportedDialect.POSTGRESQL: - # Historically we have marked PostgreSQL as having slow range in select - # but this may not be true for all versions. We should investigate - # this further when we have more data and remove this if possible - # in the future so we can use the simpler purge SQL query for - # _select_unused_attributes_ids and _select_unused_events_ids if first_connection: # server_version_num was added in 2006 result = query_on_connection(dbapi_connection, "SHOW server_version") diff --git a/tests/components/recorder/test_util.py b/tests/components/recorder/test_util.py index 83fed98aa22..609af6c362f 100644 --- a/tests/components/recorder/test_util.py +++ b/tests/components/recorder/test_util.py @@ -460,7 +460,7 @@ def test_supported_pgsql(caplog: pytest.LogCaptureFixture, pgsql_version) -> Non assert "minimum supported version" not in caplog.text assert database_engine is not None - assert database_engine.optimizer.slow_range_in_select is True + assert database_engine.optimizer.slow_range_in_select is False @pytest.mark.parametrize(