Allow WITH subqueries to take effect immediately

This commit is contained in:
Amos Bird 2020-11-01 00:02:52 +08:00
parent 30325689c4
commit 2a747ce5af
No known key found for this signature in database
GPG Key ID: 80D430DCBECFEDB4
3 changed files with 8 additions and 2 deletions

View File

@ -16,10 +16,9 @@ void ApplyWithSubqueryVisitor::visit(ASTPtr & ast, const Data & data)
std::optional<Data> new_data;
if (auto with = node_select->with())
{
for (auto & child : with->children)
visit(child, data);
for (auto & child : with->children)
{
visit(child, new_data ? *new_data: data);
if (auto * ast_with_elem = child->as<ASTWithElement>())
{
if (!new_data)

View File

@ -70,4 +70,10 @@ SELECT max(n) m FROM test1 where test1.m=43 having max(n)=42;
WITH test1 AS (SELECT n, null b, n+1 m FROM with_test where n = 42 order by n limit 4)
SELECT max(n) m FROM test1 where b is null and test1.m=43 having m=42 limit 4;
with
test1 as (select n, null b, n+1 m from with_test where n = 42 order by n limit 4),
test2 as (select n + 1 as x, n - 1 as y from test1),
test3 as (select x * y as z from test2)
select z + 1 as q from test3;
drop table with_test ;