From 20c0f774e5517514da811bc446812baa6b1f32f1 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 1 Apr 2021 17:20:31 -0400 Subject: Default caching to opt-out for 3rd party dialects Added a new flag to the :class:`_engine.Dialect` class called :attr:`_engine.Dialect.supports_statement_cache`. This flag now needs to be present directly on a dialect class in order for SQLAlchemy's :ref:`query cache ` to take effect for that dialect. The rationale is based on discovered issues such as :ticket:`6173` revealing that dialects which hardcode literal values from the compiled statement, often the numerical parameters used for LIMIT / OFFSET, will not be compatible with caching until these dialects are revised to use the parameters present in the statement only. For third party dialects where this flag is not applied, the SQL logging will show the message "dialect does not support caching", indicating the dialect should seek to apply this flag once they have verified that no per-statement literal values are being rendered within the compilation phase. Fixes: #6184 Change-Id: I6fd5b5d94200458d4cb0e14f2f556dbc25e27e22 --- lib/sqlalchemy/dialects/sqlite/aiosqlite.py | 1 + lib/sqlalchemy/dialects/sqlite/base.py | 1 + lib/sqlalchemy/dialects/sqlite/pysqlcipher.py | 1 + lib/sqlalchemy/dialects/sqlite/pysqlite.py | 1 + 4 files changed, 4 insertions(+) (limited to 'lib/sqlalchemy/dialects/sqlite') diff --git a/lib/sqlalchemy/dialects/sqlite/aiosqlite.py b/lib/sqlalchemy/dialects/sqlite/aiosqlite.py index e4b7d1d52..1d09a619d 100644 --- a/lib/sqlalchemy/dialects/sqlite/aiosqlite.py +++ b/lib/sqlalchemy/dialects/sqlite/aiosqlite.py @@ -299,6 +299,7 @@ class SQLiteExecutionContext_aiosqlite(SQLiteExecutionContext): class SQLiteDialect_aiosqlite(SQLiteDialect_pysqlite): driver = "aiosqlite" + supports_statement_cache = True is_async = True diff --git a/lib/sqlalchemy/dialects/sqlite/base.py b/lib/sqlalchemy/dialects/sqlite/base.py index 691ca642d..83c2a8ea7 100644 --- a/lib/sqlalchemy/dialects/sqlite/base.py +++ b/lib/sqlalchemy/dialects/sqlite/base.py @@ -1796,6 +1796,7 @@ class SQLiteDialect(default.DefaultDialect): supports_cast = True supports_multivalues_insert = True tuple_in_values = True + supports_statement_cache = True default_paramstyle = "qmark" execution_ctx_cls = SQLiteExecutionContext diff --git a/lib/sqlalchemy/dialects/sqlite/pysqlcipher.py b/lib/sqlalchemy/dialects/sqlite/pysqlcipher.py index 8f0f46acb..ff02d4dee 100644 --- a/lib/sqlalchemy/dialects/sqlite/pysqlcipher.py +++ b/lib/sqlalchemy/dialects/sqlite/pysqlcipher.py @@ -98,6 +98,7 @@ from ... import util class SQLiteDialect_pysqlcipher(SQLiteDialect_pysqlite): driver = "pysqlcipher" + supports_statement_cache = True pragmas = ("kdf_iter", "cipher", "cipher_page_size", "cipher_use_hmac") diff --git a/lib/sqlalchemy/dialects/sqlite/pysqlite.py b/lib/sqlalchemy/dialects/sqlite/pysqlite.py index c940faf38..0b091e73b 100644 --- a/lib/sqlalchemy/dialects/sqlite/pysqlite.py +++ b/lib/sqlalchemy/dialects/sqlite/pysqlite.py @@ -443,6 +443,7 @@ class _SQLite_pysqliteDate(DATE): class SQLiteDialect_pysqlite(SQLiteDialect): default_paramstyle = "qmark" + supports_statement_cache = True colspecs = util.update_copy( SQLiteDialect.colspecs, -- cgit v1.2.1