diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-03-23 14:52:05 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-03-24 14:25:41 -0400 |
commit | cadfc608d63f4e0df46c0daaa28902423fd88d71 (patch) | |
tree | 63b05c466c5c0cbebae5515d7790291305e66cc6 /lib/sqlalchemy/sql/schema.py | |
parent | fd74bd8eea3f3696c43ca0336ed4e437036c43c5 (diff) | |
download | sqlalchemy-cadfc608d63f4e0df46c0daaa28902423fd88d71.tar.gz |
Convert schema_translate to a post compile
Revised the :paramref:`.Connection.execution_options.schema_translate_map`
feature such that the processing of the SQL statement to receive a specific
schema name occurs within the execution phase of the statement, rather than
at the compile phase. This is to support the statement being efficiently
cached. Previously, the current schema being rendered into the statement
for a particular run would be considered as part of the cache key itself,
meaning that for a run against hundreds of schemas, there would be hundreds
of cache keys, rendering the cache much less performant. The new behavior
is that the rendering is done in a similar manner as the "post compile"
rendering added in 1.4 as part of :ticket:`4645`, :ticket:`4808`.
Fixes: #5004
Change-Id: Ia5c89eb27cc8dc2c5b8e76d6c07c46290a7901b6
Diffstat (limited to 'lib/sqlalchemy/sql/schema.py')
-rw-r--r-- | lib/sqlalchemy/sql/schema.py | 57 |
1 files changed, 1 insertions, 56 deletions
diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py index 69f60ba24..02c14d751 100644 --- a/lib/sqlalchemy/sql/schema.py +++ b/lib/sqlalchemy/sql/schema.py @@ -31,7 +31,6 @@ as components in SQL expressions. from __future__ import absolute_import import collections -import operator import sqlalchemy from . import coercions @@ -143,8 +142,7 @@ class SchemaItem(SchemaEventTarget, visitors.Visitable): schema_item.dispatch._update(self.dispatch) return schema_item - def _translate_schema(self, effective_schema, map_): - return map_.get(effective_schema, effective_schema) + _use_schema_map = True class Table(DialectKWArgs, SchemaItem, TableClause): @@ -4270,59 +4268,6 @@ class ThreadLocalMetaData(MetaData): e.dispose() -class _SchemaTranslateMap(object): - """Provide translation of schema names based on a mapping. - - Also provides helpers for producing cache keys and optimized - access when no mapping is present. - - Used by the :paramref:`.Connection.execution_options.schema_translate_map` - feature. - - .. versionadded:: 1.1 - - - """ - - __slots__ = "map_", "__call__", "hash_key", "is_default" - - _default_schema_getter = operator.attrgetter("schema") - - def __init__(self, map_): - self.map_ = map_ - if map_ is not None: - - def schema_for_object(obj): - effective_schema = self._default_schema_getter(obj) - effective_schema = obj._translate_schema( - effective_schema, map_ - ) - return effective_schema - - self.__call__ = schema_for_object - self.hash_key = ";".join( - "%s=%s" % (k, map_[k]) for k in sorted(map_, key=str) - ) - self.is_default = False - else: - self.hash_key = 0 - self.__call__ = self._default_schema_getter - self.is_default = True - - @classmethod - def _schema_getter(cls, map_): - if map_ is None: - return _default_schema_map - elif isinstance(map_, _SchemaTranslateMap): - return map_ - else: - return _SchemaTranslateMap(map_) - - -_default_schema_map = _SchemaTranslateMap(None) -_schema_getter = _SchemaTranslateMap._schema_getter - - class Computed(FetchedValue, SchemaItem): """Defines a generated column, i.e. "GENERATED ALWAYS AS" syntax. |