summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/traversals.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2022-04-12 13:52:31 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2022-04-13 17:19:31 -0400
commit428262a2d5374613f4a4cf925bbd9e94e0e34acc (patch)
tree9f71ec4a09d3ea584b3e399085254fb278049a6f /lib/sqlalchemy/sql/traversals.py
parenta45e2284dad17fbbba3bea9d5e5304aab21c8c94 (diff)
downloadsqlalchemy-428262a2d5374613f4a4cf925bbd9e94e0e34acc.tar.gz
implement multi-element expression constructs
Improved the construction of SQL binary expressions to allow for very long expressions against the same associative operator without special steps needed in order to avoid high memory use and excess recursion depth. A particular binary operation ``A op B`` can now be joined against another element ``op C`` and the resulting structure will be "flattened" so that the representation as well as SQL compilation does not require recursion. To implement this more cleanly, the biggest change here is that column-oriented lists of things are broken away from ClauseList in a new class ExpressionClauseList, that also forms the basis of BooleanClauseList. ClauseList is still used for the generic "comma-separated list" of things such as Tuple and things like ORDER BY, as well as in some API endpoints. Also adds __slots__ to the TypeEngine-bound Comparator classes. Still can't really do __slots__ on ClauseElement. Fixes: #7744 Change-Id: I81a8ceb6f8f3bb0fe52d58f3cb42e4b6c2bc9018
Diffstat (limited to 'lib/sqlalchemy/sql/traversals.py')
-rw-r--r--lib/sqlalchemy/sql/traversals.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/lib/sqlalchemy/sql/traversals.py b/lib/sqlalchemy/sql/traversals.py
index cbc4e9e70..c23cd04dd 100644
--- a/lib/sqlalchemy/sql/traversals.py
+++ b/lib/sqlalchemy/sql/traversals.py
@@ -924,7 +924,7 @@ class TraversalComparatorStrategy(HasTraversalDispatch, util.MemoizedSlots):
):
return COMPARE_FAILED
- def compare_clauselist(self, left, right, **kw):
+ def compare_expression_clauselist(self, left, right, **kw):
if left.operator is right.operator:
if operators.is_associative(left.operator):
if self._compare_unordered_sequences(
@@ -938,6 +938,9 @@ class TraversalComparatorStrategy(HasTraversalDispatch, util.MemoizedSlots):
else:
return COMPARE_FAILED
+ def compare_clauselist(self, left, right, **kw):
+ return self.compare_expression_clauselist(left, right, **kw)
+
def compare_binary(self, left, right, **kw):
if left.operator == right.operator:
if operators.is_commutative(left.operator):