diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-04-01 17:20:31 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-04-01 18:59:41 -0400 |
| commit | 20c0f774e5517514da811bc446812baa6b1f32f1 (patch) | |
| tree | 31130474fc5aabcd7143ac5b0ba585c25700169a /lib/sqlalchemy/dialects/postgresql | |
| parent | dc5ade010da55c1158ee7294c9e882cc52cd6e01 (diff) | |
| download | sqlalchemy-20c0f774e5517514da811bc446812baa6b1f32f1.tar.gz | |
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 <sql_caching>` 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
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql')
| -rw-r--r-- | lib/sqlalchemy/dialects/postgresql/asyncpg.py | 1 | ||||
| -rw-r--r-- | lib/sqlalchemy/dialects/postgresql/base.py | 1 | ||||
| -rw-r--r-- | lib/sqlalchemy/dialects/postgresql/pg8000.py | 1 | ||||
| -rw-r--r-- | lib/sqlalchemy/dialects/postgresql/psycopg2.py | 3 | ||||
| -rw-r--r-- | lib/sqlalchemy/dialects/postgresql/psycopg2cffi.py | 1 | ||||
| -rw-r--r-- | lib/sqlalchemy/dialects/postgresql/pygresql.py | 1 | ||||
| -rw-r--r-- | lib/sqlalchemy/dialects/postgresql/pypostgresql.py | 1 |
7 files changed, 9 insertions, 0 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/asyncpg.py b/lib/sqlalchemy/dialects/postgresql/asyncpg.py index 4580421f6..8cd5bee41 100644 --- a/lib/sqlalchemy/dialects/postgresql/asyncpg.py +++ b/lib/sqlalchemy/dialects/postgresql/asyncpg.py @@ -850,6 +850,7 @@ _pg_types = { class PGDialect_asyncpg(PGDialect): driver = "asyncpg" + supports_statement_cache = True supports_unicode_statements = True supports_server_side_cursors = True diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index 97eb07bdb..2c4e316b3 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -3062,6 +3062,7 @@ class PGDeferrableConnectionCharacteristic( class PGDialect(default.DefaultDialect): name = "postgresql" + supports_statement_cache = True supports_alter = True max_identifier_length = 63 supports_sane_rowcount = True diff --git a/lib/sqlalchemy/dialects/postgresql/pg8000.py b/lib/sqlalchemy/dialects/postgresql/pg8000.py index 43df6edea..eaf6ccbb8 100644 --- a/lib/sqlalchemy/dialects/postgresql/pg8000.py +++ b/lib/sqlalchemy/dialects/postgresql/pg8000.py @@ -252,6 +252,7 @@ class PGIdentifierPreparer_pg8000(PGIdentifierPreparer): class PGDialect_pg8000(PGDialect): driver = "pg8000" + supports_statement_cache = True supports_unicode_statements = True diff --git a/lib/sqlalchemy/dialects/postgresql/psycopg2.py b/lib/sqlalchemy/dialects/postgresql/psycopg2.py index 16f9ecefa..c2b679022 100644 --- a/lib/sqlalchemy/dialects/postgresql/psycopg2.py +++ b/lib/sqlalchemy/dialects/postgresql/psycopg2.py @@ -634,6 +634,9 @@ EXECUTEMANY_VALUES_PLUS_BATCH = util.symbol( class PGDialect_psycopg2(PGDialect): driver = "psycopg2" + + supports_statement_cache = True + if util.py2k: # turn off supports_unicode_statements for Python 2. psycopg2 supports # unicode statements in Py2K. But! it does not support unicode *bound diff --git a/lib/sqlalchemy/dialects/postgresql/psycopg2cffi.py b/lib/sqlalchemy/dialects/postgresql/psycopg2cffi.py index a449f9e65..780244be9 100644 --- a/lib/sqlalchemy/dialects/postgresql/psycopg2cffi.py +++ b/lib/sqlalchemy/dialects/postgresql/psycopg2cffi.py @@ -28,6 +28,7 @@ from .psycopg2 import PGDialect_psycopg2 class PGDialect_psycopg2cffi(PGDialect_psycopg2): driver = "psycopg2cffi" supports_unicode_statements = True + supports_statement_cache = True # psycopg2cffi's first release is 2.5.0, but reports # __version__ as 2.4.4. Subsequent releases seem to have diff --git a/lib/sqlalchemy/dialects/postgresql/pygresql.py b/lib/sqlalchemy/dialects/postgresql/pygresql.py index 64dd7262d..718bbf78f 100644 --- a/lib/sqlalchemy/dialects/postgresql/pygresql.py +++ b/lib/sqlalchemy/dialects/postgresql/pygresql.py @@ -193,6 +193,7 @@ class _PGIdentifierPreparer(PGIdentifierPreparer): class PGDialect_pygresql(PGDialect): driver = "pygresql" + supports_statement_cache = True statement_compiler = _PGCompiler preparer = _PGIdentifierPreparer diff --git a/lib/sqlalchemy/dialects/postgresql/pypostgresql.py b/lib/sqlalchemy/dialects/postgresql/pypostgresql.py index 6e4db217d..7d4783867 100644 --- a/lib/sqlalchemy/dialects/postgresql/pypostgresql.py +++ b/lib/sqlalchemy/dialects/postgresql/pypostgresql.py @@ -52,6 +52,7 @@ class PGExecutionContext_pypostgresql(PGExecutionContext): class PGDialect_pypostgresql(PGDialect): driver = "pypostgresql" + supports_statement_cache = True supports_unicode_statements = True supports_unicode_binds = True description_encoding = None |
