summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/compiler.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2019-12-16 17:06:43 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2020-07-03 23:39:51 -0400
commit3dc9a4a2392d033f9d1bd79dd6b6ecea6281a61c (patch)
tree1041bccb37422f526dccb5b1e57ffad1c702549b /lib/sqlalchemy/sql/compiler.py
parent5060043e8e95ab0aab5f63ed288c1426c46da66e (diff)
downloadsqlalchemy-3dc9a4a2392d033f9d1bd79dd6b6ecea6281a61c.tar.gz
introduce deferred lambdas
The coercions system allows us to add in lambdas as arguments to Core and ORM elements without changing them at all. By allowing the lambda to produce a deterministic cache key where we can also cheat and yank out literal parameters means we can move towards having 90% of "baked" functionality in a clearer way right in Core / ORM. As a second step, we can have whole statements inside the lambda, and can then add generation with __add__(), so then we have 100% of "baked" functionality with full support of ad-hoc literal values. Adds some more short_selects tests for the moment for comparison. Other tweaks inside cache key generation as we're trying to approach a certain level of performance such that we can remove the use of "baked" from the loader strategies. As we have not yet closed #4639, however the caching feature has been fully integrated as of b0cfa7379cf8513a821a3dbe3028c4965d9f85bd, we will also add complete caching documentation here and close that issue as well. Closes: #4639 Fixes: #5380 Change-Id: If91f61527236fd4d7ae3cad1f24c38be921c90ba
Diffstat (limited to 'lib/sqlalchemy/sql/compiler.py')
-rw-r--r--lib/sqlalchemy/sql/compiler.py27
1 files changed, 18 insertions, 9 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index 6152a28e7..3a3ce5c45 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -1296,6 +1296,10 @@ class SQLCompiler(Compiled):
"Cannot compile Column object until " "its 'name' is assigned."
)
+ def visit_lambda_element(self, element, **kw):
+ sql_element = element._resolved
+ return self.process(sql_element, **kw)
+
def visit_column(
self,
column,
@@ -1624,7 +1628,7 @@ class SQLCompiler(Compiled):
return func.clause_expr._compiler_dispatch(self, **kwargs)
def visit_compound_select(
- self, cs, asfrom=False, compound_index=0, **kwargs
+ self, cs, asfrom=False, compound_index=None, **kwargs
):
toplevel = not self.stack
@@ -1635,10 +1639,14 @@ class SQLCompiler(Compiled):
entry = self._default_stack_entry if toplevel else self.stack[-1]
need_result_map = toplevel or (
- compound_index == 0
+ not compound_index
and entry.get("need_result_map_for_compound", False)
)
+ # indicates there is already a CompoundSelect in play
+ if compound_index == 0:
+ entry["select_0"] = cs
+
self.stack.append(
{
"correlate_froms": entry["correlate_froms"],
@@ -2654,7 +2662,7 @@ class SQLCompiler(Compiled):
select_stmt,
asfrom=False,
fromhints=None,
- compound_index=0,
+ compound_index=None,
select_wraps_for=None,
lateral=False,
from_linter=None,
@@ -2709,7 +2717,9 @@ class SQLCompiler(Compiled):
or entry.get("need_result_map_for_nested", False)
)
- if compound_index > 0:
+ # indicates there is a CompoundSelect in play and we are not the
+ # first select
+ if compound_index:
populate_result_map = False
# this was first proposed as part of #3372; however, it is not
@@ -2844,11 +2854,10 @@ class SQLCompiler(Compiled):
correlate_froms = entry["correlate_froms"]
asfrom_froms = entry["asfrom_froms"]
- if compound_index > 0:
- # note this is cached
- select_0 = entry["selectable"].selects[0]
- if select_0._is_select_container:
- select_0 = select_0.element
+ if compound_index == 0:
+ entry["select_0"] = select
+ elif compound_index:
+ select_0 = entry["select_0"]
numcols = len(select_0.selected_columns)
if len(compile_state.columns_plus_names) != numcols: