From d5be2cc1391d0ff4b21557b036eba4713fde7bcf Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 13 Nov 2022 21:48:53 -0500 Subject: perf improvements related to corresponding_column (2) commit two of two. this reorganizes ColumnCollection to build a new index up front that's used to optimize the corresponding_column() method. Additional performance enhancements within ORM-enabled SQL statements, specifically targeting callcounts within the construction of ORM statements, using combinations of :func:`_orm.aliased` with :func:`_sql.union` and similar "compound" constructs, in addition to direct performance improvements to the ``corresponding_column()`` internal method that is used heavily by the ORM by constructs like :func:`_orm.aliased` and similar. Fixes: #8796 Change-Id: I4a76788007d5a802b9a4081e6a0f6e4b52497b50 --- lib/sqlalchemy/sql/schema.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib/sqlalchemy/sql/schema.py') diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py index dde5cd372..cd10d0c4a 100644 --- a/lib/sqlalchemy/sql/schema.py +++ b/lib/sqlalchemy/sql/schema.py @@ -2360,6 +2360,9 @@ class Column(DialectKWArgs, SchemaItem, ColumnClause[_T]): name: Optional[str] = None, key: Optional[str] = None, name_is_truncatable: bool = False, + compound_select_cols: Optional[ + _typing_Sequence[ColumnElement[Any]] + ] = None, **kw: Any, ) -> Tuple[str, ColumnClause[_T]]: """Create a *proxy* for this column. @@ -2401,7 +2404,9 @@ class Column(DialectKWArgs, SchemaItem, ColumnClause[_T]): key=key if key else name if name else self.key, primary_key=self.primary_key, nullable=self.nullable, - _proxies=[self], + _proxies=list(compound_select_cols) + if compound_select_cols + else [self], *fk, ) except TypeError as err: -- cgit v1.2.1