mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 16:27:08 +00:00
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
This commit is contained in:
parent
0b311c8c7f
commit
3533e77ec9
@ -480,7 +480,4 @@ class DatabaseOptimizer:
|
|||||||
#
|
#
|
||||||
# https://jira.mariadb.org/browse/MDEV-25020
|
# 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
|
slow_range_in_select: bool
|
||||||
|
@ -454,9 +454,8 @@ def setup_connection_for_dialect(
|
|||||||
) -> DatabaseEngine | None:
|
) -> DatabaseEngine | None:
|
||||||
"""Execute statements needed for dialect connection."""
|
"""Execute statements needed for dialect connection."""
|
||||||
version: AwesomeVersion | None = None
|
version: AwesomeVersion | None = None
|
||||||
slow_range_in_select = True
|
slow_range_in_select = False
|
||||||
if dialect_name == SupportedDialect.SQLITE:
|
if dialect_name == SupportedDialect.SQLITE:
|
||||||
slow_range_in_select = False
|
|
||||||
if first_connection:
|
if first_connection:
|
||||||
old_isolation = dbapi_connection.isolation_level
|
old_isolation = dbapi_connection.isolation_level
|
||||||
dbapi_connection.isolation_level = None
|
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
|
# Ensure all times are using UTC to avoid issues with daylight savings
|
||||||
execute_on_connection(dbapi_connection, "SET time_zone = '+00:00'")
|
execute_on_connection(dbapi_connection, "SET time_zone = '+00:00'")
|
||||||
elif dialect_name == SupportedDialect.POSTGRESQL:
|
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:
|
if first_connection:
|
||||||
# server_version_num was added in 2006
|
# server_version_num was added in 2006
|
||||||
result = query_on_connection(dbapi_connection, "SHOW server_version")
|
result = query_on_connection(dbapi_connection, "SHOW server_version")
|
||||||
|
@ -460,7 +460,7 @@ def test_supported_pgsql(caplog: pytest.LogCaptureFixture, pgsql_version) -> Non
|
|||||||
|
|
||||||
assert "minimum supported version" not in caplog.text
|
assert "minimum supported version" not in caplog.text
|
||||||
assert database_engine is not None
|
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(
|
@pytest.mark.parametrize(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user