summaryrefslogtreecommitdiff
path: root/test/engine
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2014-08-14 20:00:35 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2014-08-14 20:00:35 -0400
commit6a21f9e328361d5185fd616e7992a183030f9a10 (patch)
treed5d1ae011a914ac582296b7543dfce5d9833b234 /test/engine
parent4a4cccfee5a2eb78380e56eb9476e91658656676 (diff)
downloadsqlalchemy-6a21f9e328361d5185fd616e7992a183030f9a10.tar.gz
- 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
Diffstat (limited to 'test/engine')
-rw-r--r--test/engine/test_execute.py48
1 files changed, 45 insertions, 3 deletions
diff --git a/test/engine/test_execute.py b/test/engine/test_execute.py
index 291aee2f3..f65168552 100644
--- a/test/engine/test_execute.py
+++ b/test/engine/test_execute.py
@@ -688,6 +688,7 @@ class CompiledCacheTest(fixtures.TestBase):
Column('user_id', INT, primary_key=True,
test_needs_autoincrement=True),
Column('user_name', VARCHAR(20)),
+ Column("extra_data", VARCHAR(20))
)
metadata.create_all()
@@ -705,12 +706,53 @@ class CompiledCacheTest(fixtures.TestBase):
cached_conn = conn.execution_options(compiled_cache=cache)
ins = users.insert()
- cached_conn.execute(ins, {'user_name': 'u1'})
- cached_conn.execute(ins, {'user_name': 'u2'})
- cached_conn.execute(ins, {'user_name': 'u3'})
+ with patch.object(
+ ins, "compile",
+ Mock(side_effect=ins.compile)) as compile_mock:
+ cached_conn.execute(ins, {'user_name': 'u1'})
+ cached_conn.execute(ins, {'user_name': 'u2'})
+ cached_conn.execute(ins, {'user_name': 'u3'})
+ eq_(compile_mock.call_count, 1)
assert len(cache) == 1
eq_(conn.execute("select count(*) from users").scalar(), 3)
+ def test_keys_independent_of_ordering(self):
+ conn = testing.db.connect()
+ conn.execute(
+ users.insert(),
+ {"user_id": 1, "user_name": "u1", "extra_data": "e1"})
+ cache = {}
+ cached_conn = conn.execution_options(compiled_cache=cache)
+
+ upd = users.update().where(users.c.user_id == bindparam("b_user_id"))
+
+ with patch.object(
+ upd, "compile",
+ Mock(side_effect=upd.compile)) as compile_mock:
+ cached_conn.execute(
+ upd, util.OrderedDict([
+ ("b_user_id", 1),
+ ("user_name", "u2"),
+ ("extra_data", "e2")
+ ])
+ )
+ cached_conn.execute(
+ upd, util.OrderedDict([
+ ("b_user_id", 1),
+ ("extra_data", "e3"),
+ ("user_name", "u3"),
+ ])
+ )
+ cached_conn.execute(
+ upd, util.OrderedDict([
+ ("extra_data", "e4"),
+ ("user_name", "u4"),
+ ("b_user_id", 1),
+ ])
+ )
+ eq_(compile_mock.call_count, 1)
+ eq_(len(cache), 1)
+
class MockStrategyTest(fixtures.TestBase):