]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
omit_join optimization for selectinload on many-to-many relationships
authorbekapono <bsiliezar2@gmail.com>
Mon, 18 May 2026 16:29:50 +0000 (12:29 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 27 May 2026 17:23:10 +0000 (13:23 -0400)
commit808fd28297f36bf932443bae77ca5bb16bcbd4dd
tree748d554ef32839a49c2ed0591627dad603ef768f
parente00937ec549ecc1d2cae49d4fe84fac3d758b6fb
omit_join optimization for selectinload on many-to-many relationships

The :func:`.selectinload` loader strategy now selects the ``omit_join``
optimization for many-to-many non-self-referential relationships, reducing
the number of joins in the secondary SELECT by selecting from the secondary
table directly rather than joining back to the parent entity. ``omit_join``
is enabled automatically when the join condition determines that the
secondary table's foreign keys fully cover the parent's primary key. As
always, ``omit_join`` can be disabled by setting
:paramref:`.relationship.omit_join` to ``False``. Pull request courtesy
bekapono.

Fixes: #5987
Closes: #13278
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/13278
Pull-request-sha: fdd9847e7db041be51160853c075b1427f7be051

Change-Id: Ib68f8e2be1399222383cdd7b55793fe88402212c
doc/build/changelog/unreleased_21/5987.rst [new file with mode: 0644]
lib/sqlalchemy/orm/mapper.py
lib/sqlalchemy/orm/relationships.py
lib/sqlalchemy/orm/strategies.py
test/orm/test_relationships.py
test/orm/test_selectin_relations.py