- changed status to resolved
a kindler, gentler join()
Issue #1714
resolved
which would simulate a NATURAL JOIN if possible before searching all the FKs.
--- a/lib/sqlalchemy/sql/expression.py
+++ b/lib/sqlalchemy/sql/expression.py
@@ -2820,7 +2820,16 @@
global sql_util
if not sql_util:
from sqlalchemy.sql import util as sql_util
- return sql_util.join_condition(primary, secondary)
+
+ # First try the natural join
+ left = primary
+ while isinstance(left, Join):
+ left = left.right
+
+ try:
+ return sql_util.join_condition(left, secondary)
+ except exc.ArgumentError:
+ return sql_util.join_condition(primary, secondary)
def select(self, whereclause=None, fold_equivalents=False, **kwargs):
"""Create a :class:`Select` from this :class:`Join`.
What I want to do here is basically the same thing but eliminate the ArgumentError throw, to reduce performance overhead, and additionally don't do join_condition()
twice if "left" is the same as "primary".
Comments (2)
-
reporter -
reporter - removed milestone
Removing milestone: 0.6.0 (automated comment)
- Log in to comment
c6fbff56a38e23bfde3bd8d3982c4eb1e944be03