]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- remove OrderedSet usage from a critical area
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 23 Dec 2010 00:07:04 +0000 (19:07 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 23 Dec 2010 00:07:04 +0000 (19:07 -0500)
lib/sqlalchemy/schema.py
lib/sqlalchemy/sql/expression.py
lib/sqlalchemy/sql/util.py
test/aaa_profiling/test_orm.py
test/aaa_profiling/test_resultset.py
test/aaa_profiling/test_zoomark.py
test/aaa_profiling/test_zoomark_orm.py
test/ext/test_declarative.py

index 4eff82333371aafc59ef56fc6272502c1f840215..8fd758d2d4d048568b495a422a883d4fd08594dc 100644 (file)
@@ -229,7 +229,7 @@ class Table(SchemaItem, expression.TableClause):
         self.constraints = set()
         self._columns = expression.ColumnCollection()
         self._set_primary_key(PrimaryKeyConstraint())
-        self.foreign_keys = util.OrderedSet()
+        self.foreign_keys = set()
         self._extra_dependencies = set()
         self.kwargs = {}
         if self.schema is not None:
@@ -708,7 +708,7 @@ class Column(SchemaItem, expression.ColumnClause):
         self.onupdate = kwargs.pop('onupdate', None)
         self.autoincrement = kwargs.pop('autoincrement', True)
         self.constraints = set()
-        self.foreign_keys = util.OrderedSet()
+        self.foreign_keys = set()
         self._table_events = set()
 
         # check if this Column is proxying another column
@@ -815,7 +815,7 @@ class Column(SchemaItem, expression.ColumnClause):
 
         if self.key in table._columns:
             col = table._columns.get(self.key)
-            for fk in col.foreign_keys:
+            for fk in list(col.foreign_keys):
                 col.foreign_keys.remove(fk)
                 table.foreign_keys.remove(fk)
                 if fk.constraint in table.constraints:
index bc36e888c62e49c65432b0753e17768add402171..9e4804349750357971b74e61c0a02cedbab1633f 100644 (file)
@@ -2401,14 +2401,6 @@ class FromClause(Selectable):
         self.primary_key = ColumnSet()
         self.foreign_keys = set()
          
-    def _export_columns(self):
-        """Initialize column collections."""
-
-        self._columns = ColumnCollection()
-        self._primary_key = ColumnSet()
-        self._foreign_keys = set()
-        self._populate_column_collection()
-
     def _populate_column_collection(self):
         pass
 
@@ -3655,9 +3647,6 @@ class TableClause(_Immutable, FromClause):
     def _init_collections(self):
         pass
         
-    def _export_columns(self):
-        raise NotImplementedError()
-
     @util.memoized_property
     def description(self):
         # Py3K
index 757de37c40b0b02f4d9217a127aeedbae9270534..997fedadeba261e87d5ccdb76b41c4694f5a7ba4 100644 (file)
@@ -217,7 +217,9 @@ def join_condition(a, b, ignore_nonexistent_tables=False, a_subset=None):
     for left in (a_subset, a):
         if left is None:
             continue
-        for fk in b.foreign_keys:
+        for fk in sorted(
+                    b.foreign_keys, 
+                    key=lambda fk:fk.parent._creation_order):
             try:
                 col = fk.get_referent(left)
             except exc.NoReferencedTableError:
@@ -230,7 +232,9 @@ def join_condition(a, b, ignore_nonexistent_tables=False, a_subset=None):
                 crit.append(col == fk.parent)
                 constraints.add(fk.constraint)
         if left is not b:
-            for fk in left.foreign_keys:
+            for fk in sorted(
+                        left.foreign_keys, 
+                        key=lambda fk:fk.parent._creation_order):
                 try:
                     col = fk.get_referent(b)
                 except exc.NoReferencedTableError:
@@ -247,7 +251,8 @@ def join_condition(a, b, ignore_nonexistent_tables=False, a_subset=None):
             
     if len(crit) == 0:
         if isinstance(b, expression._FromGrouping):
-            hint = " Perhaps you meant to convert the right side to a subquery using alias()?"
+            hint = " Perhaps you meant to convert the right side to a "\
+                                "subquery using alias()?"
         else:
             hint = ""
         raise exc.ArgumentError(
index 9f03b9cdddeaed13b7da855370c706ba341de46d..519a29c29f61508e9de32b3967f7c4cb1e6918d6 100644 (file)
@@ -79,7 +79,7 @@ class MergeTest(_base.MappedTest):
         # using sqlite3 the C extension took it back up to approx. 1257
         # (py2.6)
 
-        @profiling.function_call_count(1067
+        @profiling.function_call_count(1005
                                 versions={'2.5':1050, '2.6':1050,
                                         '2.6+cextension':1041, 
                                         '2.4': 763}
index e46411bdb1c04d7e75484f815b8d673d72dc4acb..dc4732cb83230c50f8e11155d39655551a461131 100644 (file)
@@ -34,16 +34,16 @@ class ResultSetTest(TestBase, AssertsExecutionResults):
         metadata.drop_all()
 
     @profiling.function_call_count(14416, versions={'2.4': 13214,
-                                   '2.6+cextension': 385,
-                                   '2.7+cextension':401})
+                                   '2.6+cextension': 345,
+                                   '2.7+cextension':345})
     def test_string(self):
         [tuple(row) for row in t.select().execute().fetchall()]
 
     # sqlite3 returns native unicode.  so shouldn't be an increase here.
 
     @profiling.function_call_count(14396, versions={'2.4': 13214,
-                                   '2.6+cextension': 385, 
-                                   '2.7+cextension':385})
+                                   '2.6+cextension': 345, 
+                                   '2.7+cextension':345})
     def test_unicode(self):
         [tuple(row) for row in t2.select().execute().fetchall()]
 
@@ -70,8 +70,9 @@ class ExecutionTest(TestBase):
         # ensure initial connect activities complete
         e.execute("select 1")
 
-        @profiling.function_call_count(59, versions={'2.4':41, '2.5':58, 
-                                                    '2.6':58, '3':57}, 
+        @profiling.function_call_count(56, versions={'2.4':41, '2.5':58, 
+                                                    '2.6':58, '3':57,
+                                                    '2.6+cextension':56}, 
                                             variance=.05)
         def go():
             e.execute("select 1")
index 5fa9e716486d3ec7912d7471110408a787448817..4c579f238f1d22c9becff6e8440c68b5f7b42977 100644 (file)
@@ -369,12 +369,12 @@ class ZooMarkTest(TestBase):
     def test_profile_2_insert(self):
         self.test_baseline_2_insert()
 
-    @profiling.function_call_count(3596, {'2.4': 2158})
+    @profiling.function_call_count(3340, {'2.4': 2158, '2.7':3564, '2.6':3564})
     def test_profile_3_properties(self):
         self.test_baseline_3_properties()
 
     @profiling.function_call_count(11624, {'2.4': 7963, '2.6+cextension'
-                                   : 12447, '2.7+cextension': 12447},
+                                   : 10736, '2.7+cextension': 10736},
                                    variance=0.10)
     def test_profile_4_expressions(self):
         self.test_baseline_4_expressions()
index c4dd0ae9fb22484f6413644c319667c4040bfa20..731d2d4c7e9143d9053f8cbeb0a40286e9a38bf3 100644 (file)
@@ -349,7 +349,7 @@ class ZooMarkTest(TestBase):
         '2.6': 6058,
         '2.7': 5922,
         '2.7+cextension': 5714,
-        '2.6+cextension': 6058,
+        '2.6+cextension': 5714,
         })
     def test_profile_3_properties(self):
         self.test_baseline_3_properties()
index 85692161b6fbaf89b338df459582146fc8a3c68f..3daf8c74aed39261e8e7c76e452930d875d34511 100644 (file)
@@ -1001,7 +1001,7 @@ class DeclarativeTest(DeclarativeTestBase):
         # case
 
         sa.orm.configure_mappers()
-        eq_(str(Address.user_id.property.columns[0].foreign_keys[0]),
+        eq_(str(list(Address.user_id.property.columns[0].foreign_keys)[0]),
             "ForeignKey('users.id')")
         Base.metadata.create_all()
         u1 = User(name='u1', addresses=[Address(email='one'),