summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/expression.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2009-12-29 23:20:48 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2009-12-29 23:20:48 +0000
commitd732e7bf261504f34c9b9d5049a9875633c3e4b3 (patch)
treeef497b8dad9036a7a8b1e8c230870555010d8b0f /lib/sqlalchemy/sql/expression.py
parent8c3c2ea508894bc3e18c1df26364a74a4f68107a (diff)
downloadsqlalchemy-d732e7bf261504f34c9b9d5049a9875633c3e4b3.tar.gz
- calling expr.in_([]), i.e. with an empty list, emits a warning
before issuing the usual "expr != expr" clause. The "expr != expr" can be very expensive, and it's preferred that the user not issue in_() if the list is empty, instead simply not querying, or modifying the criterion as appropriate for more complex situations. [ticket:1628]
Diffstat (limited to 'lib/sqlalchemy/sql/expression.py')
-rw-r--r--lib/sqlalchemy/sql/expression.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py
index 2f0ac90af..acfb3d7c4 100644
--- a/lib/sqlalchemy/sql/expression.py
+++ b/lib/sqlalchemy/sql/expression.py
@@ -1498,7 +1498,15 @@ class _CompareMixin(ColumnOperators):
args.append(o)
if len(args) == 0:
- # Special case handling for empty IN's, behave like comparison against zero row selectable
+ # Special case handling for empty IN's, behave like comparison
+ # against zero row selectable. We use != to build the
+ # contradiction as it handles NULL values appropriately, i.e.
+ # "not (x IN ())" should not return NULL values for x.
+ util.warn("The IN-predicate on \"%s\" was invoked with an empty sequence. "
+ "This results in a contradiction, which nonetheless can be "
+ "expensive to evaluate. Consider alternative strategies for "
+ "improved performance." % self)
+
return self != self
return self.__compare(op, ClauseList(*args).self_group(against=op), negate=negate_op)