From 6a21f9e328361d5185fd616e7992a183030f9a10 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 14 Aug 2014 20:00:35 -0400 Subject: - The string keys that are used to determine the columns impacted for an INSERT or UPDATE are now sorted when they contribute towards the "compiled cache" cache key. These keys were previously not deterministically ordered, meaning the same statement could be cached multiple times on equivalent keys, costing both in terms of memory as well as performance. fixes #3165 --- lib/sqlalchemy/engine/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/sqlalchemy/engine/base.py') diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py index 2dc4d43f2..65753b6dc 100644 --- a/lib/sqlalchemy/engine/base.py +++ b/lib/sqlalchemy/engine/base.py @@ -805,7 +805,7 @@ class Connection(Connectable): dialect = self.dialect if 'compiled_cache' in self._execution_options: - key = dialect, elem, tuple(keys), len(distilled_params) > 1 + key = dialect, elem, tuple(sorted(keys)), len(distilled_params) > 1 if key in self._execution_options['compiled_cache']: compiled_sql = self._execution_options['compiled_cache'][key] else: -- cgit v1.2.1 From b0411e80df13d347104a60c512aeb18b6479bb12 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 15 Aug 2014 00:19:57 -0400 Subject: - other test fixes --- lib/sqlalchemy/engine/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/sqlalchemy/engine/base.py') diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py index 65753b6dc..3728b59fd 100644 --- a/lib/sqlalchemy/engine/base.py +++ b/lib/sqlalchemy/engine/base.py @@ -799,7 +799,7 @@ class Connection(Connectable): if distilled_params: # note this is usually dict but we support RowProxy # as well; but dict.keys() as an iterator is OK - keys = distilled_params[0].keys() + keys = list(distilled_params[0].keys()) else: keys = [] -- cgit v1.2.1 From 5a68f856daee59caf4c9da7d06880eada9d70302 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 15 Aug 2014 14:57:29 -0400 Subject: - TIL that dict.keys() in py3K is not an iterator, it is an iterable view. So copy collections.OrderedDict and use MutableMapping to set up keys, items, values on our own OrderedDict. Conflicts: lib/sqlalchemy/engine/base.py --- lib/sqlalchemy/engine/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/sqlalchemy/engine/base.py') diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py index 3728b59fd..d2cc8890f 100644 --- a/lib/sqlalchemy/engine/base.py +++ b/lib/sqlalchemy/engine/base.py @@ -798,8 +798,8 @@ class Connection(Connectable): distilled_params = _distill_params(multiparams, params) if distilled_params: # note this is usually dict but we support RowProxy - # as well; but dict.keys() as an iterator is OK - keys = list(distilled_params[0].keys()) + # as well; but dict.keys() as an iterable is OK + keys = distilled_params[0].keys() else: keys = [] -- cgit v1.2.1