mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 12:02:42 +01:00
MDEV-27086 "No database selected" when using UNION of CTEs to define table
This bug concerned only CREATE TABLE statements of the form CREATE TABLE <table name> AS <with clause> <union>. For such a statement not all references to CTE used in <union> were resolved. As a result a bogus message was reported for the first unresolved reference. This happened because for such statements the function resolving references to CTEs LEX::check_cte_dependencies_and_resolve_references() was called prematurely in the parser. Approved by Oleksandr Byelkin <sanja@mariadb.com>
This commit is contained in:
parent
e9f171b4fe
commit
0dae41637a
3 changed files with 53 additions and 4 deletions
|
@ -2136,4 +2136,30 @@ drop procedure sp1;
|
|||
drop function g;
|
||||
drop function f;
|
||||
drop table t1;
|
||||
#
|
||||
# MDEV-27086: union using CTEs in CREATE TABLE
|
||||
#
|
||||
create or replace temporary table tmp as
|
||||
with cte1 as (select 1 as a), cte2 as (select 2 as a)
|
||||
select * from cte1 union select * from cte2;
|
||||
select * from tmp;
|
||||
a
|
||||
1
|
||||
2
|
||||
create table t1 as
|
||||
with cte1 as (select 1 as a), cte2 as (select 2 as a)
|
||||
select * from cte1 union select * from cte2;
|
||||
select * from t1;
|
||||
a
|
||||
1
|
||||
2
|
||||
insert into t1 values (3);
|
||||
create table t2 as
|
||||
with cte1 as (select * from t1 where a <2), cte2 as (select * from t1 where a > 2)
|
||||
select * from cte1 union select * from cte2;
|
||||
select * from t2;
|
||||
a
|
||||
1
|
||||
3
|
||||
drop table t1,t2;
|
||||
# End of 10.2 tests
|
||||
|
|
|
@ -1578,4 +1578,27 @@ drop function g;
|
|||
drop function f;
|
||||
drop table t1;
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-27086: union using CTEs in CREATE TABLE
|
||||
--echo #
|
||||
|
||||
create or replace temporary table tmp as
|
||||
with cte1 as (select 1 as a), cte2 as (select 2 as a)
|
||||
select * from cte1 union select * from cte2;
|
||||
select * from tmp;
|
||||
|
||||
create table t1 as
|
||||
with cte1 as (select 1 as a), cte2 as (select 2 as a)
|
||||
select * from cte1 union select * from cte2;
|
||||
select * from t1;
|
||||
|
||||
insert into t1 values (3);
|
||||
|
||||
create table t2 as
|
||||
with cte1 as (select * from t1 where a <2), cte2 as (select * from t1 where a > 2)
|
||||
select * from cte1 union select * from cte2;
|
||||
select * from t2;
|
||||
|
||||
drop table t1,t2;
|
||||
|
||||
--echo # End of 10.2 tests
|
||||
|
|
|
@ -4869,6 +4869,10 @@ create_like:
|
|||
opt_create_select:
|
||||
/* empty */ {}
|
||||
| opt_duplicate opt_as create_select_query_expression
|
||||
{
|
||||
if (Lex->check_cte_dependencies_and_resolve_references())
|
||||
MYSQL_YYABORT;
|
||||
}
|
||||
;
|
||||
|
||||
create_select_query_expression:
|
||||
|
@ -4877,16 +4881,12 @@ create_select_query_expression:
|
|||
{
|
||||
Select->set_braces(0);
|
||||
Select->set_with_clause($1);
|
||||
if (Lex->check_cte_dependencies_and_resolve_references())
|
||||
MYSQL_YYABORT;
|
||||
}
|
||||
union_clause
|
||||
| opt_with_clause SELECT_SYM create_select_part2
|
||||
create_select_part3_union_not_ready create_select_part4
|
||||
{
|
||||
Select->set_with_clause($1);
|
||||
if (Lex->check_cte_dependencies_and_resolve_references())
|
||||
MYSQL_YYABORT;
|
||||
}
|
||||
| '(' create_select_query_specification ')'
|
||||
| '(' create_select_query_specification ')'
|
||||
|
|
Loading…
Reference in a new issue