提交 ff557a58 编写于 作者: O obdev 提交者: ob-robot

[CP] Create table or view from recursive cte not support in mysql mode

上级 63c7ad79
......@@ -825,7 +825,7 @@ int ObSelectStmtPrinter::print_for_update()
int ObSelectStmtPrinter::print_with()
{
int ret = OB_SUCCESS;
DATA_PRINTF(is_oracle_mode() ? "WITH " : "WITH RECURSIVE");
DATA_PRINTF(is_oracle_mode() ? "WITH " : "WITH RECURSIVE ");
if (OB_SUCC(ret)) {
const ObSelectStmt* select_stmt = static_cast<const ObSelectStmt*>(stmt_);
const common::ObIArray<TableItem*>& cte_tables = select_stmt->get_CTE_table_items();
......@@ -869,9 +869,9 @@ int ObSelectStmtPrinter::print_cte_define_title(TableItem* cte_table)
int ret = OB_SUCCESS;
ObSelectStmt* sub_select_stmt = NULL;
PRINT_TABLE_NAME(cte_table);
if (OB_ISNULL(cte_table->node_->children_[1]) && (TableItem::RECURSIVE_CTE == cte_table->cte_type_)) {
if (OB_ISNULL(cte_table) || OB_ISNULL(cte_table->ref_query_)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("the recursive cte must have the colume definition", K(ret));
LOG_WARN("unexpect null params", K(ret));
} else if (OB_NOT_NULL(cte_table->node_->children_[1])) {
DATA_PRINTF("(");
sub_select_stmt = cte_table->ref_query_;
......@@ -892,7 +892,7 @@ int ObSelectStmtPrinter::print_cte_define_title(TableItem* cte_table)
}
DATA_PRINTF(")");
} else {
// do nothing, the normal cte without column alias is OK
//do nothing, the normal cte without column alias is OK
}
DATA_PRINTF(" as ");
return ret;
......
......@@ -528,7 +528,7 @@ create view v1 as
with RECURSIVE qn (foo, bar) as (select 1,1 from dual) select * from qn;
show create view v1;
View Create View character_set_client collation_connection
v1 CREATE VIEW `v1` AS WITH RECURSIVE`qn`(foo, bar) as (select 1 AS `foo`,1 AS `bar`) select `qn`.`foo` AS `foo`,`qn`.`bar` AS `bar` from qn utf8mb4 utf8mb4_general_ci
v1 CREATE VIEW `v1` AS WITH RECURSIVE `qn`(foo, bar) as (select 1 AS `foo`,1 AS `bar`) select `qn`.`foo` AS `foo`,`qn`.`bar` AS `bar` from qn utf8mb4 utf8mb4_general_ci
select * from v1;
+-----+-----+
......@@ -541,7 +541,7 @@ create view v1 as
with RECURSIVE qn (foo, bar) as (select 1,1 from t1) select * from qn;
show create view v1;
View Create View character_set_client collation_connection
v1 CREATE VIEW `v1` AS WITH RECURSIVE`qn`(foo, bar) as (select 1 AS `foo`,1 AS `bar` from `cte_st`.`t1`) select `qn`.`foo` AS `foo`,`qn`.`bar` AS `bar` from qn utf8mb4 utf8mb4_general_ci
v1 CREATE VIEW `v1` AS WITH RECURSIVE `qn`(foo, bar) as (select 1 AS `foo`,1 AS `bar` from `cte_st`.`t1`) select `qn`.`foo` AS `foo`,`qn`.`bar` AS `bar` from qn utf8mb4 utf8mb4_general_ci
select * from v1;
+-----+-----+
| foo | bar |
......@@ -588,7 +588,7 @@ select (with RECURSIVE qn as (select 'with RECURSIVE' from dual) select * from q
from dual;
show create view v;
View Create View character_set_client collation_connection
v CREATE VIEW `v` AS select (WITH RECURSIVE`qn` as (select 'with RECURSIVE' AS `with RECURSIVE`) select `qn`.`with RECURSIVE` from qn) AS `scal_subq` utf8mb4 utf8mb4_general_ci
v CREATE VIEW `v` AS select (WITH RECURSIVE `qn` as (select 'with RECURSIVE' AS `with RECURSIVE`) select `qn`.`with RECURSIVE` from qn) AS `scal_subq` utf8mb4 utf8mb4_general_ci
select * from v;
+----------------+
| scal_subq |
......@@ -599,7 +599,7 @@ drop view v;
create view v as select * from (with RECURSIVE qn as (select 'with RECURSIVE' from dual) select * from qn) dt;
show create view v;
View Create View character_set_client collation_connection
v CREATE VIEW `v` AS select `dt`.`with RECURSIVE` AS `with RECURSIVE` from (WITH RECURSIVE`qn` as (select 'with RECURSIVE' AS `with RECURSIVE`) select `qn`.`with RECURSIVE` AS `with RECURSIVE` from qn) dt utf8mb4 utf8mb4_general_ci
v CREATE VIEW `v` AS select `dt`.`with RECURSIVE` AS `with RECURSIVE` from (WITH RECURSIVE `qn` as (select 'with RECURSIVE' AS `with RECURSIVE`) select `qn`.`with RECURSIVE` AS `with RECURSIVE` from qn) dt utf8mb4 utf8mb4_general_ci
select * from v;
+----------------+
| with RECURSIVE |
......
......@@ -107,4 +107,128 @@ SELECT * FROM employee_paths ORDER BY name;
| 692 | Tarek | 333,692 |
| 333 | Yasmina | 333 |
+------+---------+-----------------+
##bugfix: https://work.aone.alibaba-inc.com/issue/42792696
create table t1_from_cte as (with recursive cte as (select 1 as c union all select c+1 from cte where c < 3) select * from cte);
create table t2_from_cte as (with recursive cte(c) as (select 1 union all select c+1 from cte where c < 3) select * from cte);
create table t3_from_cte as (with recursive cte as (select 1 as c union all select c+1 from cte where c < 3) select c as cc from cte);
select * from t1_from_cte;
+------+
| c |
+------+
| 1 |
| 2 |
| 3 |
+------+
select * from t2_from_cte;
+------+
| c |
+------+
| 1 |
| 2 |
| 3 |
+------+
select * from t3_from_cte;
+------+
| cc |
+------+
| 1 |
| 2 |
| 3 |
+------+
desc t1_from_cte;
+-------+-----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-----------+------+-----+---------+-------+
| c | bigint(1) | YES | | NULL | |
+-------+-----------+------+-----+---------+-------+
desc t2_from_cte;
+-------+-----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-----------+------+-----+---------+-------+
| c | bigint(1) | YES | | NULL | |
+-------+-----------+------+-----+---------+-------+
desc t3_from_cte;
+-------+-----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-----------+------+-----+---------+-------+
| cc | bigint(1) | YES | | NULL | |
+-------+-----------+------+-----+---------+-------+
show create table t1_from_cte;
Table Create Table
t1_from_cte CREATE TABLE `t1_from_cte` (
`c` bigint(1) DEFAULT NULL
) DEFAULT CHARSET = utf8mb4 COMPRESSION = 'lz4_1.0' REPLICA_NUM = NUM BLOCK_SIZE = SIZE USE_BLOOM_FILTER = FALSE TABLET_SIZE = SIZE PCTFREE = 10
show create table t2_from_cte;
Table Create Table
t2_from_cte CREATE TABLE `t2_from_cte` (
`c` bigint(1) DEFAULT NULL
) DEFAULT CHARSET = utf8mb4 COMPRESSION = 'lz4_1.0' REPLICA_NUM = NUM BLOCK_SIZE = SIZE USE_BLOOM_FILTER = FALSE TABLET_SIZE = SIZE PCTFREE = 10
show create table t3_from_cte;
Table Create Table
t3_from_cte CREATE TABLE `t3_from_cte` (
`cc` bigint(1) DEFAULT NULL
) DEFAULT CHARSET = utf8mb4 COMPRESSION = 'lz4_1.0' REPLICA_NUM = NUM BLOCK_SIZE = SIZE USE_BLOOM_FILTER = FALSE TABLET_SIZE = SIZE PCTFREE = 10
create view v1_from_cte as (with recursive cte as (select 1 as c union all select c+1 from cte where c < 3) select * from cte);
create view v2_from_cte as (with recursive cte(c) as (select 1 union all select c+1 from cte where c < 3) select * from cte);
create view v3_from_cte as (with recursive cte as (select 1 as c union all select c+1 from cte where c < 3) select c as cc from cte);
select * from v1_from_cte;
+------+
| c |
+------+
| 1 |
| 2 |
| 3 |
+------+
select * from v2_from_cte;
+------+
| c |
+------+
| 1 |
| 2 |
| 3 |
+------+
select * from v3_from_cte;
+------+
| cc |
+------+
| 1 |
| 2 |
| 3 |
+------+
desc v1_from_cte;
+-------+-----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-----------+------+-----+---------+-------+
| c | bigint(1) | NO | | | |
+-------+-----------+------+-----+---------+-------+
desc v2_from_cte;
+-------+-----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-----------+------+-----+---------+-------+
| c | bigint(1) | NO | | | |
+-------+-----------+------+-----+---------+-------+
desc v3_from_cte;
+-------+-----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-----------+------+-----+---------+-------+
| cc | bigint(1) | NO | | | |
+-------+-----------+------+-----+---------+-------+
show create view v1_from_cte;
View Create View character_set_client collation_connection
v1_from_cte CREATE VIEW `v1_from_cte` AS WITH RECURSIVE `cte` as ((select 1 AS `c`) union all (select (`cte`.`c` + 1) AS `c+1` from `cte` where (`cte`.`c` < 3))) select `cte`.`c` AS `c` from cte utf8mb4 utf8mb4_general_ci
show create view v2_from_cte;
View Create View character_set_client collation_connection
v2_from_cte CREATE VIEW `v2_from_cte` AS WITH RECURSIVE `cte`(c) as ((select 1 AS `1`) union all (select (`cte`.`c` + 1) AS `c+1` from `cte` where (`cte`.`c` < 3))) select `cte`.`c` AS `c` from cte utf8mb4 utf8mb4_general_ci
show create view v3_from_cte;
View Create View character_set_client collation_connection
v3_from_cte CREATE VIEW `v3_from_cte` AS WITH RECURSIVE `cte` as ((select 1 AS `c`) union all (select (`cte`.`c` + 1) AS `c+1` from `cte` where (`cte`.`c` < 3))) select `cte`.`c` AS `cc` from cte utf8mb4 utf8mb4_general_ci
drop database cte_st;
......@@ -81,4 +81,48 @@ WITH RECURSIVE employee_paths (id, name, path) AS
ON ep.id = e.manager_id
)
SELECT * FROM employee_paths ORDER BY name;
--echo ##bugfix: https://work.aone.alibaba-inc.com/issue/42792696
create table t1_from_cte as (with recursive cte as (select 1 as c union all select c+1 from cte where c < 3) select * from cte);
create table t2_from_cte as (with recursive cte(c) as (select 1 union all select c+1 from cte where c < 3) select * from cte);
create table t3_from_cte as (with recursive cte as (select 1 as c union all select c+1 from cte where c < 3) select c as cc from cte);
select * from t1_from_cte;
select * from t2_from_cte;
select * from t3_from_cte;
desc t1_from_cte;
desc t2_from_cte;
desc t3_from_cte;
--source mysql_test/include/show_create_table_old_version_replica2.inc
show create table t1_from_cte;
--source mysql_test/include/show_create_table_old_version_replica2.inc
show create table t2_from_cte;
--source mysql_test/include/show_create_table_old_version_replica2.inc
show create table t3_from_cte;
create view v1_from_cte as (with recursive cte as (select 1 as c union all select c+1 from cte where c < 3) select * from cte);
create view v2_from_cte as (with recursive cte(c) as (select 1 union all select c+1 from cte where c < 3) select * from cte);
create view v3_from_cte as (with recursive cte as (select 1 as c union all select c+1 from cte where c < 3) select c as cc from cte);
select * from v1_from_cte;
select * from v2_from_cte;
select * from v3_from_cte;
desc v1_from_cte;
desc v2_from_cte;
desc v3_from_cte;
--source mysql_test/include/show_create_table_old_version_replica2.inc
show create view v1_from_cte;
--source mysql_test/include/show_create_table_old_version_replica2.inc
show create view v2_from_cte;
--source mysql_test/include/show_create_table_old_version_replica2.inc
show create view v3_from_cte;
drop database cte_st;
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册