Merge lp:~jkakar/storm/is-empty-strips-order-by into lp:storm

Proposed by Jamu Kakar
Status: Merged
Approved by: Jamu Kakar
Approved revision: 362
Merged at revision: 362
Proposed branch: lp:~jkakar/storm/is-empty-strips-order-by
Merge into: lp:storm
Diff against target: 52 lines (+23/-1)
2 files modified
storm/store.py (+1/-0)
tests/store/base.py (+22/-1)
To merge this branch: bzr merge lp:~jkakar/storm/is-empty-strips-order-by
Reviewer Review Type Date Requested Status
Kevin McDermott (community) Approve
Robert Collins (community) Approve
Storm Developers Pending
Review via email: mp+30677@code.launchpad.net

Description of the change

This branch introduces the following changes:

- ResultSet.is_empty strips order by clauses, since they're
  unnecessary for this operation.

To post a comment you must log in.
Revision history for this message
Robert Collins (lifeless) wrote :

Looks good except for the typo ;)

review: Approve
362. By Jamu Kakar

- Fix a typo in a docstring.
- Unpack the list of captured statements to ensure there is only
  one.

Revision history for this message
Kevin McDermott (bigkevmcd) wrote :

As discussed "ORDER BY" could not appear in a whole load of SQL statements, can we check that there's only one query executed, and that "ORDER BY" doesn't appear.

Oh, and as Robert points out "natching" ;-)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'storm/store.py'
--- storm/store.py 2010-02-10 11:29:39 +0000
+++ storm/store.py 2010-07-22 16:18:43 +0000
@@ -1055,6 +1055,7 @@
1055 """Return true if this L{ResultSet} contains no results."""1055 """Return true if this L{ResultSet} contains no results."""
1056 subselect = self._get_select()1056 subselect = self._get_select()
1057 subselect.limit = 11057 subselect.limit = 1
1058 subselect.order_by = Undef
1058 select = Select(1, tables=Alias(subselect, "_tmp"), limit=1)1059 select = Select(1, tables=Alias(subselect, "_tmp"), limit=1)
1059 result = self._store._connection.execute(select)1060 result = self._store._connection.execute(select)
1060 return (not result.get_one())1061 return (not result.get_one())
10611062
=== modified file 'tests/store/base.py'
--- tests/store/base.py 2010-06-01 08:31:53 +0000
+++ tests/store/base.py 2010-07-22 16:18:43 +0000
@@ -30,7 +30,8 @@
30from storm.properties import PropertyPublisherMeta, Decimal30from storm.properties import PropertyPublisherMeta, Decimal
31from storm.variables import PickleVariable31from storm.variables import PickleVariable
32from storm.expr import (32from storm.expr import (
33 Asc, Desc, Select, LeftJoin, SQL, Count, Sum, Avg, And, Or, Eq, Lower)33 Asc, Desc, Select, LeftJoin, SQL, Count, Sum, Avg, And, Or, Eq, Lower,
34 compile)
34from storm.variables import Variable, UnicodeVariable, IntVariable35from storm.variables import Variable, UnicodeVariable, IntVariable
35from storm.info import get_obj_info, ClassAlias36from storm.info import get_obj_info, ClassAlias
36from storm.exceptions import (37from storm.exceptions import (
@@ -513,6 +514,26 @@
513 result = self.store.find(Foo, id=30)514 result = self.store.find(Foo, id=30)
514 self.assertEquals(result.is_empty(), False)515 self.assertEquals(result.is_empty(), False)
515516
517 def test_wb_is_empty_strips_order_by(self):
518 """
519 L{ResultSet.is_empty} strips the C{ORDER BY} clause, if one is
520 present, since it isn't required to actually determine if a result set
521 has any matching rows. This should provide some performance
522 improvement when the ordered result set would be large.
523 """
524 statements = []
525 original_execute = self.store._connection.execute
526 def execute(expr):
527 statements.append(compile(expr))
528 return original_execute(expr)
529 self.store._connection.execute = execute
530
531 result = self.store.find(Foo, Foo.id == 300)
532 result.order_by(Foo.id)
533 self.assertEqual(True, result.is_empty())
534 [statement] = statements
535 self.assertNotIn("ORDER BY", statement)
536
516 def test_is_empty_with_composed_key(self):537 def test_is_empty_with_composed_key(self):
517 result = self.store.find(Link, foo_id=300, bar_id=3000)538 result = self.store.find(Link, foo_id=300, bar_id=3000)
518 self.assertEquals(result.is_empty(), True)539 self.assertEquals(result.is_empty(), True)

Subscribers

People subscribed via source and target branches

to status/vote changes: