Unverified 提交 9ce14802 authored 作者: Noel Grandin's avatar Noel Grandin 提交者: GitHub

Merge pull request #1144 from devnied/fix-recursive-schema

Add missing schema name with recursive view
......@@ -13,6 +13,7 @@ import java.util.Map;
import org.h2.api.ErrorCode;
import org.h2.api.Trigger;
import org.h2.command.CommandInterface;
import org.h2.command.Parser;
import org.h2.engine.Constants;
import org.h2.engine.Database;
import org.h2.engine.Session;
......@@ -1158,7 +1159,9 @@ public class Select extends Query {
// since using a with statement will re-create the common table expression
// views.
} else {
buff.append("WITH RECURSIVE ").append(t.getName()).append('(');
buff.append("WITH RECURSIVE ")
.append(t.getSchema().getSQL()).append('.').append(Parser.quoteIdentifier(t.getName()))
.append('(');
buff.resetCount();
for (Column c : t.getColumns()) {
buff.appendExceptFirst(",");
......
......@@ -778,7 +778,7 @@ public class TableFilter implements ColumnResolver {
return buff.toString();
}
if (table.isView() && ((TableView) table).isRecursive()) {
buff.append(table.getName());
buff.append(table.getSchema().getSQL()).append('.').append(Parser.quoteIdentifier(table.getName()));
} else {
buff.append(table.getSQL());
}
......
......@@ -6,7 +6,14 @@ explain with recursive r(n) as (
(select 1) union all (select n+1 from r where n < 3)
)
select n from r;
>> WITH RECURSIVE R(N) AS ( (SELECT 1 FROM SYSTEM_RANGE(1, 1) /* PUBLIC.RANGE_INDEX */) UNION ALL (SELECT (N + 1) FROM PUBLIC.R /* PUBLIC.R.tableScan */ WHERE N < 3) ) SELECT N FROM R R /* null */
>> WITH RECURSIVE PUBLIC.R(N) AS ( (SELECT 1 FROM SYSTEM_RANGE(1, 1) /* PUBLIC.RANGE_INDEX */) UNION ALL (SELECT (N + 1) FROM PUBLIC.R /* PUBLIC.R.tableScan */ WHERE N < 3) ) SELECT N FROM PUBLIC.R R /* null */
explain with recursive "r"(n) as (
(select 1) union all (select n+1 from "r" where n < 3)
)
select n from "r";
>> WITH RECURSIVE PUBLIC."r"(N) AS ( (SELECT 1 FROM SYSTEM_RANGE(1, 1) /* PUBLIC.RANGE_INDEX */) UNION ALL (SELECT (N + 1) FROM PUBLIC."r" /* PUBLIC."r".tableScan */ WHERE N < 3) ) SELECT N FROM PUBLIC."r" "r" /* null */
select sum(n) from (
with recursive r(n) as (
......@@ -16,6 +23,14 @@ select sum(n) from (
);
>> 6
select sum(n) from (
with recursive "r"(n) as (
(select 1) union all (select n+1 from "r" where n < 3)
)
select n from "r"
);
>> 6
select sum(n) from (select 0) join (
with recursive r(n) as (
(select 1) union all (select n+1 from r where n < 3)
......@@ -44,3 +59,26 @@ with
> - -- -- --
> 0 -1 1 10
> rows: 1
CREATE SCHEMA SCH;
> ok
CREATE FORCE VIEW TABLE_EXPRESSION SCH.R1(N) AS
(SELECT 1)
UNION ALL
(SELECT (N + 1) FROM SCH.R1 WHERE N < 3);
> ok
CREATE VIEW SCH.R2(N) AS
(SELECT 1)
UNION ALL
(SELECT (N + 1) FROM SCH.R1 WHERE N < 3);
> ok
SELECT * FROM SCH.R2;
> N
> -
> 1
> 2
> 3
> rows: 3
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论