]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
avoid some often unnecessary method calls. i think we might have squeezed all we...
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 7 Nov 2008 17:08:23 +0000 (17:08 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 7 Nov 2008 17:08:23 +0000 (17:08 +0000)
lib/sqlalchemy/sql/compiler.py
test/profiling/compiler.py
test/profiling/zoomark_orm.py

index 1c7c66f477c7694276a5851d0e699288a939334a..851bc30ac6dbbddcd85ae403dcd4daa72c7bd319 100644 (file)
@@ -459,7 +459,8 @@ class DefaultCompiler(engine.Compiled):
             column.table is not None and \
             not isinstance(column.table, sql.Select):
             return _CompileLabel(column, sql._generated_label(column.name))
-        elif not isinstance(column, (sql._UnaryExpression, sql._TextClause, sql._BindParamClause)) and (not hasattr(column, 'name') or isinstance(column, sql._Function)):
+        elif not isinstance(column, (sql._UnaryExpression, sql._TextClause, sql._BindParamClause)) \
+                and (not hasattr(column, 'name') or isinstance(column, sql._Function)):
             return _CompileLabel(column, column.anon_label)
         else:
             return column
@@ -479,13 +480,13 @@ class DefaultCompiler(engine.Compiled):
         # if existingfroms:
         #     correlate_froms = correlate_froms.union(existingfroms)
 
+        self.stack.append({'from':correlate_froms, 'iswrapper':iswrapper})
+
         if compound_index==1 and not entry or entry.get('iswrapper', False):
             column_clause_args = {'result_map':self.result_map}
         else:
             column_clause_args = {}
 
-        self.stack.append({'from':correlate_froms, 'iswrapper':iswrapper})
-
         # the actual list of columns to print in the SELECT column list.
         inner_columns = util.unique_list(
             c for c in [
@@ -515,18 +516,22 @@ class DefaultCompiler(engine.Compiled):
             if t:
                 text += " \nWHERE " + t
 
-        group_by = self.process(select._group_by_clause)
-        if group_by:
-            text += " GROUP BY " + group_by
+        if select._group_by_clause.clauses:
+            group_by = self.process(select._group_by_clause)
+            if group_by:
+                text += " GROUP BY " + group_by
 
         if select._having is not None:
             t = self.process(select._having)
             if t:
                 text += " \nHAVING " + t
 
-        text += self.order_by_clause(select)
-        text += (select._limit is not None or select._offset is not None) and self.limit_clause(select) or ""
-        text += self.for_update_clause(select)
+        if select._order_by_clause.clauses:
+            text += self.order_by_clause(select)
+        if select._limit is not None or select._offset is not None:
+            text += self.limit_clause(select)
+        if select.for_update:
+            text += self.for_update_clause(select)
 
         self.stack.pop(-1)
 
index 5be8c0f8e2fe713a71a127bc7504a7d1829422d2..2f1cbad5962a9cfcb507512cc486b669c5d3e485 100644 (file)
@@ -23,7 +23,7 @@ class CompileTest(TestBase, AssertsExecutionResults):
     def test_update(self):
         t1.update().compile()
 
-    @profiling.function_call_count(195, versions={'2.4':133})
+    @profiling.function_call_count(185, versions={'2.4':133})
     def test_select(self):
         s = select([t1], t1.c.c2==t2.c.c1)
         s.compile()
index 3fff96e1ab3b8e53a16b518d3a0dc91f73e2d85f..8350fbab4ce713ec4450da41d623faf19240722c 100644 (file)
@@ -310,7 +310,7 @@ class ZooMarkTest(TestBase):
     def test_profile_5_aggregates(self):
         self.test_baseline_5_aggregates()
 
-    @profiling.function_call_count(3752)
+    @profiling.function_call_count(3545)
     def test_profile_6_editing(self):
         self.test_baseline_6_editing()