From 247632e67ea49227978cfc50f4df6274ccda4a33 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Fri, 29 Jul 2016 01:10:00 -0700 Subject: [PATCH] Fixed bug mdev-10344. The patch for bug mdev-9937 actually did not fix the problem of name resolution for tables used in views referred in queries with WITH clauses. This fix corrects the patch. --- mysql-test/r/cte_nonrecursive.result | 23 +++++++++++++++++++++++ mysql-test/t/cte_nonrecursive.test | 18 ++++++++++++++++++ sql/sql_view.cc | 2 +- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/cte_nonrecursive.result b/mysql-test/r/cte_nonrecursive.result index 295c7546ca0..713ec4bcec3 100644 --- a/mysql-test/r/cte_nonrecursive.result +++ b/mysql-test/r/cte_nonrecursive.result @@ -780,3 +780,26 @@ a 2 3 DROP TABLE t1,t2,t3; +# +# Bug mdev-10344: the WITH clause of the query refers to a view that uses +# a base table with the same name as a CTE table from the clause +# +create table ten(a int primary key); +insert into ten values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +create table one_k(a int primary key); +insert into one_k select A.a + B.a* 10 + C.a * 100 from ten A, ten B, ten C; +create view v1 as select * from ten; +select * from v1; +a +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +drop view v1; +drop table ten, one_k; diff --git a/mysql-test/t/cte_nonrecursive.test b/mysql-test/t/cte_nonrecursive.test index 9a0e43bf8f7..8caf0832df4 100644 --- a/mysql-test/t/cte_nonrecursive.test +++ b/mysql-test/t/cte_nonrecursive.test @@ -471,3 +471,21 @@ SELECT * FROM (WITH a AS (SELECT * FROM t1) SELECT * FROM t2 NATURAL JOIN t3) AS DROP TABLE t1,t2,t3; +--echo # +--echo # Bug mdev-10344: the WITH clause of the query refers to a view that uses +--echo # a base table with the same name as a CTE table from the clause +--echo # + + +create table ten(a int primary key); +insert into ten values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); + +create table one_k(a int primary key); +insert into one_k select A.a + B.a* 10 + C.a * 100 from ten A, ten B, ten C; + +create view v1 as select * from ten; + +select * from v1; + +drop view v1; +drop table ten, one_k; diff --git a/sql/sql_view.cc b/sql/sql_view.cc index 4fd4fb8dd01..36f5c294663 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -1622,7 +1622,7 @@ 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; + view_select->master_unit()->is_view= true; /* check MERGE algorithm ability