]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
Uniquify FROMs when traversing through select
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 17 Apr 2021 03:58:48 +0000 (23:58 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 17 Apr 2021 04:10:00 +0000 (00:10 -0400)
commit46f34449f389a8aa994485f36e99f95275a19170
treeed70e4837430c5f2f99d31391607b361b339243e
parentb73fc8f874da94c9c5b2d94feb6b1b45b7f4f02b
Uniquify FROMs when traversing through select

Fixed a critical performance issue where the traversal of a
:func:`_sql.select` construct would traverse a repetitive product of the
represented FROM clauses as they were each referred towards by columns in
the columns clause; for a series of nested subqueries with lots of columns
this could cause a large delay and significant memory growth. This
traversal is used by a wide variety of SQL and ORM functions, including by
the ORM :class:`_orm.Session` when it's configured to have
"table-per-bind", which while this is not a common use case, it seems to be
what Flask-SQLAlchemy is hardcoded as using, so the issue impacts
Flask-SQLAlchemy users. The traversal has been repaired to uniqify on FROM
clauses which was effectively what would happen implicitly with the pre-1.4
architecture.

Fixes: #6304
Change-Id: I43497e943db4065deab0bfc830fbb68c17b80a53
doc/build/changelog/unreleased_14/6304.rst [new file with mode: 0644]
lib/sqlalchemy/sql/selectable.py
test/sql/test_external_traversal.py