Remove per engine max bind vars (#135153)

This commit is contained in:
J. Nick Koston
2025-01-09 12:50:13 -10:00
committed by GitHub
parent 139b747a70
commit 3c6113e37c
4 changed files with 11 additions and 38 deletions

View File

@@ -36,14 +36,7 @@ from homeassistant.helpers.recorder import ( # noqa: F401
)
import homeassistant.util.dt as dt_util
from .const import (
DEFAULT_MAX_BIND_VARS,
DOMAIN,
SQLITE_MAX_BIND_VARS,
SQLITE_MODERN_MAX_BIND_VARS,
SQLITE_URL_PREFIX,
SupportedDialect,
)
from .const import DEFAULT_MAX_BIND_VARS, DOMAIN, SQLITE_URL_PREFIX, SupportedDialect
from .db_schema import (
TABLE_RECORDER_RUNS,
TABLE_SCHEMA_CHANGES,
@@ -96,7 +89,6 @@ MARIADB_WITH_FIXED_IN_QUERIES_108 = _simple_version("10.8.4")
MIN_VERSION_MYSQL = _simple_version("8.0.0")
MIN_VERSION_PGSQL = _simple_version("12.0")
MIN_VERSION_SQLITE = _simple_version("3.40.1")
MIN_VERSION_SQLITE_MODERN_BIND_VARS = _simple_version("3.40.1")
# This is the maximum time after the recorder ends the session
@@ -473,7 +465,6 @@ def setup_connection_for_dialect(
version: AwesomeVersion | None = None
slow_range_in_select = False
if dialect_name == SupportedDialect.SQLITE:
max_bind_vars = SQLITE_MAX_BIND_VARS
if first_connection:
old_isolation = dbapi_connection.isolation_level # type: ignore[attr-defined]
dbapi_connection.isolation_level = None # type: ignore[attr-defined]
@@ -491,9 +482,6 @@ def setup_connection_for_dialect(
version or version_string, "SQLite", MIN_VERSION_SQLITE
)
if version and version > MIN_VERSION_SQLITE_MODERN_BIND_VARS:
max_bind_vars = SQLITE_MODERN_MAX_BIND_VARS
# The upper bound on the cache size is approximately 16MiB of memory
execute_on_connection(dbapi_connection, "PRAGMA cache_size = -16384")
@@ -512,7 +500,6 @@ def setup_connection_for_dialect(
execute_on_connection(dbapi_connection, "PRAGMA foreign_keys=ON")
elif dialect_name == SupportedDialect.MYSQL:
max_bind_vars = DEFAULT_MAX_BIND_VARS
execute_on_connection(dbapi_connection, "SET session wait_timeout=28800")
if first_connection:
result = query_on_connection(dbapi_connection, "SELECT VERSION()")
@@ -553,7 +540,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:
max_bind_vars = DEFAULT_MAX_BIND_VARS
# PostgreSQL does not support a skip/loose index scan so its
# also slow for large distinct queries:
# https://wiki.postgresql.org/wiki/Loose_indexscan
@@ -580,7 +566,7 @@ def setup_connection_for_dialect(
dialect=SupportedDialect(dialect_name),
version=version,
optimizer=DatabaseOptimizer(slow_range_in_select=slow_range_in_select),
max_bind_vars=max_bind_vars,
max_bind_vars=DEFAULT_MAX_BIND_VARS,
)