Commit 3b6a64c2 authored by Igor Babaev's avatar Igor Babaev

Fixed bug mdev-9937.

When the specification of a WITH table referred to a view
that used a based table with the same name as the WITH table
the server went into an infinite loop because it erroneously
resolved the reference to the base table as the reference to
the WITH table.

With tables used in a view cannot be searched for beyond the
scope the view.
parent 4b8e54bb
......@@ -746,3 +746,16 @@ with t(f1,f1) as (select * from t1 where b >= 'c')
select t1.b from t2,t1 where t1.a = t2.c;
ERROR 42S21: Duplicate column name 'f1'
drop table t1,t2;
#
# Bug mdev-9937: View used in the specification of with table
# refers to the base table with the same name
#
create table t1 (a int);
insert into t1 values (20), (30), (10);
create view v1 as select * from t1 where a > 10;
with t1 as (select * from v1) select * from t1;
a
20
30
drop view v1;
drop table t1;
......@@ -434,3 +434,17 @@ with t(f1,f1) as (select * from t1 where b >= 'c')
select t1.b from t2,t1 where t1.a = t2.c;
drop table t1,t2;
--echo #
--echo # Bug mdev-9937: View used in the specification of with table
--echo # refers to the base table with the same name
--echo #
create table t1 (a int);
insert into t1 values (20), (30), (10);
create view v1 as select * from t1 where a > 10;
with t1 as (select * from v1) select * from t1;
drop view v1;
drop table t1;
......@@ -512,7 +512,10 @@ With_element *st_select_lex::find_table_def_in_with_clauses(TABLE_LIST *table)
{
With_clause *with_clause=sl->get_with_clause();
if (with_clause && (found= with_clause->find_table_def(table)))
return found;
return found;
/* Do not look for the table's definition beyond the scope of the view */
if (sl->master_unit()->is_view)
break;
}
return found;
}
......
......@@ -2078,6 +2078,7 @@ void st_select_lex_unit::init_query()
found_rows_for_union= 0;
insert_table_with_stored_vcol= 0;
derived= 0;
is_view= false;
with_clause= 0;
with_element= 0;
columns_are_renamed= false;
......
......@@ -645,6 +645,7 @@ class st_select_lex_unit: public st_select_lex_node {
derived tables/views handling.
*/
TABLE_LIST *derived;
bool is_view;
/* With clause attached to this unit (if any) */
With_clause *with_clause;
/* With element where this unit is used as the specification (if any) */
......
......@@ -1612,6 +1612,8 @@ bool mysql_make_view(THD *thd, TABLE_SHARE *share, TABLE_LIST *table,
sl->context.error_processor_data= (void *)table;
}
table->select_lex->master_unit()->is_view= true;
/*
check MERGE algorithm ability
- algorithm is not explicit TEMPORARY TABLE
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment