diff options
author | Igor Babaev <igor@askmonty.org> | 2016-02-17 14:30:25 -0800 |
---|---|---|
committer | Igor Babaev <igor@askmonty.org> | 2016-02-17 14:30:25 -0800 |
commit | f340aaeb52916d028a41ed771dfbbdd9dc4c3f88 (patch) | |
tree | b21ddfef1213a345019fa1835844ae44be420bc5 | |
parent | 22f52f1f09b62534eea139a678c954507bb3e89e (diff) | |
download | mariadb-git-bb-10.2-mdev8789.tar.gz |
Addressed the issues raised in the review for the main patchbb-10.2-mdev8789
of mdev-8789.
Fixed a bug in TABLE_LIST::print.
Fixed another bug for the case when the definition of a
WITH table contained column list while the join in the main
query used two instances of this table.
-rw-r--r-- | mysql-test/r/cte_grant.result | 54 | ||||
-rw-r--r-- | mysql-test/r/cte_nonrecursive.result | 115 | ||||
-rw-r--r-- | mysql-test/t/cte_grant.test | 79 | ||||
-rw-r--r-- | mysql-test/t/cte_nonrecursive.test | 62 | ||||
-rw-r--r-- | sql/share/errmsg-utf8.txt | 8 | ||||
-rw-r--r-- | sql/sql_cte.cc | 34 | ||||
-rw-r--r-- | sql/sql_cte.h | 8 | ||||
-rw-r--r-- | sql/sql_derived.cc | 2 | ||||
-rw-r--r-- | sql/sql_lex.cc | 1 | ||||
-rw-r--r-- | sql/sql_lex.h | 4 | ||||
-rw-r--r-- | sql/sql_select.cc | 5 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 1 |
12 files changed, 334 insertions, 39 deletions
diff --git a/mysql-test/r/cte_grant.result b/mysql-test/r/cte_grant.result new file mode 100644 index 00000000000..4b067f42ff2 --- /dev/null +++ b/mysql-test/r/cte_grant.result @@ -0,0 +1,54 @@ +create database mysqltest; +create user mysqltest_1@localhost; +create table mysqltest.t1 (a int, b int); +insert into mysqltest.t1 values (2,10), (1,30); +create table mysqltest.t2 (c int, d char(32)); +insert into mysqltest.t2 values (1,'xxx'), (1,'zzz'); +grant select on mysqltest.t1 to mysqltest_1@localhost; +grant select (c) on mysqltest.t2 to mysqltest_1@localhost; +with t as (select c from mysqltest.t2 where c < 2) +select t.c,t1.b from t,mysqltest.t1 where t.c=t1.a; +c b +1 30 +1 30 +select t.c,t.d,t1.b +from (select c,d from mysqltest.t2 where c < 2) as t, mysqltest.t1 +where t.c=t1.a; +ERROR 42000: SELECT command denied to user 'mysqltest_1'@'localhost' for column 'd' in table 't2' +with t as (select c,d from mysqltest.t2 where c < 2) +select t.c,t.d,t1.b from t,mysqltest.t1 where t.c=t1.a; +ERROR 42000: SELECT command denied to user 'mysqltest_1'@'localhost' for column 'd' in table 't2' +create view mysqltest.v1(f1,f2) as +with t as (select c from mysqltest.t2 where c < 2) +select t.c,t1.b from t,mysqltest.t1 where t.c=t1.a; +create view mysqltest.v2(c,d) as +with t as (select a from mysqltest.t1 where a>=3) +select t.a,b from t,mysqltest.t1 where mysqltest.t1.a = t.a; +grant select on mysqltest.v1 to mysqltest_1@localhost; +grant select (c) on mysqltest.v2 to mysqltest_1@localhost; +grant create view on mysqltest.* to mysqltest_1@localhost; +create view mysqltest.v3(c,d) as +with t as (select c from mysqltest.t2 where c < 2) +select t.c,t1.b from t,mysqltest.t1 where t.c=t1.a; +create view mysqltest.v4(f1,f2,f3) as +with t as (select c,d from mysqltest.t2 where c < 2) +select t.c,t.d,t1.b from t,mysqltest.t1 where t.c=t1.a; +ERROR 42000: SELECT command denied to user 'mysqltest_1'@'localhost' for column 'd' in table 't2' +select * from mysqltest.v1; +f1 f2 +1 30 +1 30 +select c from mysqltest.v2; +c +select d from mysqltest.v2; +ERROR 42000: SELECT command denied to user 'mysqltest_1'@'localhost' for column 'd' in table 'v2' +select * from mysqltest.v3; +ERROR 42000: SELECT command denied to user 'mysqltest_1'@'localhost' for table 'v3' +grant select on mysqltest.v3 to mysqltest_1@localhost; +select * from mysqltest.v3; +c d +1 30 +1 30 +revoke all privileges on mysqltest.v1 from mysqltest_1@localhost; +drop user mysqltest_1@localhost; +drop database mysqltest; diff --git a/mysql-test/r/cte_nonrecursive.result b/mysql-test/r/cte_nonrecursive.result index 07449bc6486..df641156e61 100644 --- a/mysql-test/r/cte_nonrecursive.result +++ b/mysql-test/r/cte_nonrecursive.result @@ -94,6 +94,47 @@ id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t2 ALL NULL NULL NULL NULL 4 Using where 1 PRIMARY <derived2> ref key0 key0 5 test.t2.c 2 2 DERIVED t1 ALL NULL NULL NULL NULL 8 Using where; Using temporary; Using filesort +# specivication of t contains having +with t as (select a, count(*) from t1 where b >= 'c' + group by a having count(*)=1 ) +select * from t2,t where t2.c=t.a; +c a count(*) +3 3 1 +select * from t2, (select a, count(*) from t1 where b >= 'c' + group by a having count(*)=1) t +where t2.c=t.a; +c a count(*) +3 3 1 +# main query contains having +with t as (select * from t2 where c <= 4) +select a, count(*) from t1,t where t1.a=t.c group by a having count(*)=1; +a count(*) +3 1 +select a, count(*) from t1, (select * from t2 where c <= 4) t +where t1.a=t.c group by a having count(*)=1; +a count(*) +3 1 +# main query contains group by + order by +with t as (select * from t2 where c <= 4 ) +select a, count(*) from t1,t where t1.a=t.c group by a order by count(*); +a count(*) +3 1 +4 3 +select a, count(*) from t1, (select * from t2 where c <= 4 ) t +where t1.a=t.c group by a order by count(*); +a count(*) +3 1 +4 3 +# main query contains group by + order by + limit +with t as (select * from t2 where c <= 4 ) +select a, count(*) from t1,t +where t1.a=t.c group by a order by count(*) desc limit 1; +a count(*) +4 3 +select a, count(*) from t1, (select * from t2 where c <= 4 ) t +where t1.a=t.c group by a order by count(*) desc limit 1; +a count(*) +4 3 # t is used in a subquery with t as (select a from t1 where a<5) select * from t2 where c in (select a from t); @@ -255,6 +296,19 @@ where r1.a=r2.a; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 8 Using where 1 SIMPLE t1 ALL NULL NULL NULL NULL 8 Using where; Using join buffer (flat, BNL join) +# two references to t specifying explicitly column names +with t(c) as (select a from t1 where b >= 'c') +select * from t r1, t r2 where r1.c=r2.c; +c c +1 1 +1 1 +4 4 +4 4 +3 3 +1 1 +1 1 +4 4 +4 4 # specification of t contains union with t as (select a from t1 where b >= 'f' union @@ -480,7 +534,7 @@ with t as (select a from t1 where b >= 'c') select * from t2,t where t2.c=t.a; show create view v1; View Create View character_set_client collation_connection -v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS WITH t AS (select `t1`.`a` AS `a` from `t1` where (`t1`.`b` >= 'c'))select `t2`.`c` AS `c`,`t`.`a` AS `a` from (`t2` join `t`) where (`t2`.`c` = `t`.`a`) latin1 latin1_swedish_ci +v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS WITH t AS (select `t1`.`a` AS `a` from `t1` where (`t1`.`b` >= 'c'))select `t2`.`c` AS `c`,`t`.`a` AS `a` from (`t2` join `t`) where (`t2`.`c` = `t`.`a`) latin1 latin1_swedish_ci select * from v1; c a 4 4 @@ -498,7 +552,7 @@ with t as (select a, count(*) from t1 where b >= 'c' group by a) select * from t2,t where t2.c=t.a; show create view v2; View Create View character_set_client collation_connection -v2 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS WITH t AS (select `t1`.`a` AS `a`,count(0) AS `count(*)` from `t1` where (`t1`.`b` >= 'c') group by `t1`.`a`)select `t2`.`c` AS `c`,`t`.`a` AS `a`,`t`.`count(*)` AS `count(*)` from (`t2` join `t`) where (`t2`.`c` = `t`.`a`) latin1 latin1_swedish_ci +v2 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS WITH t AS (select `t1`.`a` AS `a`,count(0) AS `count(*)` from `t1` where (`t1`.`b` >= 'c') group by `t1`.`a`)select `t2`.`c` AS `c`,`t`.`a` AS `a`,`t`.`count(*)` AS `count(*)` from (`t2` join `t`) where (`t2`.`c` = `t`.`a`) latin1 latin1_swedish_ci select * from v2; c a count(*) 4 4 2 @@ -510,7 +564,46 @@ id select_type table type possible_keys key key_len ref rows Extra 2 DERIVED t2 ALL NULL NULL NULL NULL 4 Using where 2 DERIVED <derived3> ref key0 key0 5 test.t2.c 2 3 SUBQUERY t1 ALL NULL NULL NULL NULL 8 Using where; Using temporary; Using filesort -drop view v1,v2; +# with clause in the specification of a view that whose definition +# table alias for a with table +create view v3 as +with t(c) as (select a from t1 where b >= 'c') +select * from t r1 where r1.c=4; +show create view v3; +View Create View character_set_client collation_connection +v3 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v3` AS WITH t AS (select `t1`.`a` AS `c` from `t1` where (`t1`.`b` >= 'c'))select `r1`.`c` AS `c` from `t` `r1` where (`r1`.`c` = 4) latin1 latin1_swedish_ci +select * from v3; +c +4 +4 +# with clause in the specification of a view that whose definition +# two table aliases for for the same with table +create view v4(c,d) as +with t(c) as (select a from t1 where b >= 'c') +select * from t r1, t r2 where r1.c=r2.c and r2.c=4; +show create view v4; +View Create View character_set_client collation_connection +v4 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v4` AS WITH t AS (select `t1`.`a` AS `c` from `t1` where (`t1`.`b` >= 'c'))select `r1`.`c` AS `c`,`r2`.`c` AS `d` from (`t` `r1` join `t` `r2`) where ((`r1`.`c` = `r2`.`c`) and (`r2`.`c` = 4)) latin1 latin1_swedish_ci +select * from v4; +c d +4 4 +4 4 +4 4 +4 4 +explain +select * from v4; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <derived2> ALL NULL NULL NULL NULL 64 +2 DERIVED t1 ALL NULL NULL NULL NULL 8 Using where +2 DERIVED t1 ALL NULL NULL NULL NULL 8 Using where; Using join buffer (flat, BNL join) +drop view v1,v2,v3,v4; +# currently any views containing with clause are not updatable +create view v1(a) as +with t as (select a from t1 where b >= 'c') +select t.a from t2,t where t2.c=t.a; +update v1 set a=0 where a > 4; +ERROR HY000: The target table v1 of the UPDATE is not updatable +drop view v1; # prepare of a query containing a definition of a with table t prepare stmt1 from " with t as (select a from t1 where b >= 'c') @@ -571,18 +664,18 @@ a b a b deallocate prepare stmt1; with t(f) as (select * from t1 where b >= 'c') select * from t2,t where t2.c=t.f1; -ERROR HY000: With column list and SELECT field list have different column counts +ERROR HY000: WITH column list and SELECT field list have different column counts with t(f1,f1) as (select * from t1 where b >= 'c') select * from t2,t where t2.c=t.f1; ERROR 42S21: Duplicate column name 'f1' with t as (select * from t2 where c>3), t as (select a from t1 where a>2) select * from t,t1 where t1.a=t.c; -ERROR HY000: Duplicate query name in with clause +ERROR HY000: Duplicate query name in WITH clause with t as (select a from s where a<5), s as (select a from t1 where b>='d') select * from t,s where t.a=s.a; -ERROR HY000: The definition of the table 't' refers to the table 's' defined later in a non-recursive with clause +ERROR HY000: The definition of the table 't' refers to the table 's' defined later in a non-recursive WITH clause with recursive t as (select a from s where a<5), s as (select a from t1 where b>='d') @@ -598,24 +691,24 @@ with recursive t as (select * from s where a>2), s as (select a from t1,r where t1.a>r.c), r as (select c from t,t2 where t.a=t2.c) select * from r where r.c<7; -ERROR HY000: Recursive queries in with clause are not supported yet +ERROR HY000: Recursive queries in WITH clause are not supported yet with t as (select * from s where a>2), s as (select a from t1,r where t1.a>r.c), r as (select c from t,t2 where t.a=t2.c) select * from r where r.c<7; -ERROR HY000: Recursive queries in with clause are not supported yet +ERROR HY000: Recursive queries in WITH clause are not supported yet with t as (select * from t1 where a in (select c from s where b<='ccc') and b>'b'), s as (select * from t1,t2 where t1.a=t2.c and t1.c in (select a from t where a<5)) select * from s where s.b>'aaa'; -ERROR HY000: Recursive queries in with clause are not supported yet +ERROR HY000: Recursive queries in WITH clause are not supported yet with t as (select * from t1 where b>'aaa' and b <='d') select t.b from t,t2 where t.a=t2.c and t2.c in (with s as (select t1.a from s,t1 where t1.a=s.a and t1.b<'c') select * from s); -ERROR HY000: Recursive queries in with clause are not supported yet +ERROR HY000: Recursive queries in WITH clause are not supported yet #erroneous definition of unreferenced with table t with t as (select count(*) from t1 where d>='f' group by a) select t1.b from t2,t1 where t1.a = t2.c; @@ -647,7 +740,7 @@ ggg #erroneous definition of unreferenced with table t with t(f) as (select * from t1 where b >= 'c') select t1.b from t2,t1 where t1.a = t2.c; -ERROR HY000: With column list and SELECT field list have different column counts +ERROR HY000: WITH column list and SELECT field list have different column counts #erroneous definition of unreferenced with table t with t(f1,f1) as (select * from t1 where b >= 'c') select t1.b from t2,t1 where t1.a = t2.c; diff --git a/mysql-test/t/cte_grant.test b/mysql-test/t/cte_grant.test new file mode 100644 index 00000000000..44fd4a0bc6e --- /dev/null +++ b/mysql-test/t/cte_grant.test @@ -0,0 +1,79 @@ +# Can't test with embedded server +-- source include/not_embedded.inc + +# Save the initial number of concurrent sessions +--source include/count_sessions.inc + +connect (root,localhost,root,,test); +connection root; + +--disable_warnings +create database mysqltest; +--enable_warnings + +create user mysqltest_1@localhost; +connect (user1,localhost,mysqltest_1,,test); +connection user1; + +connection root; + +create table mysqltest.t1 (a int, b int); +insert into mysqltest.t1 values (2,10), (1,30); +create table mysqltest.t2 (c int, d char(32)); +insert into mysqltest.t2 values (1,'xxx'), (1,'zzz'); + +grant select on mysqltest.t1 to mysqltest_1@localhost; +grant select (c) on mysqltest.t2 to mysqltest_1@localhost; + +connection user1; +with t as (select c from mysqltest.t2 where c < 2) +select t.c,t1.b from t,mysqltest.t1 where t.c=t1.a; +--error ER_COLUMNACCESS_DENIED_ERROR +select t.c,t.d,t1.b +from (select c,d from mysqltest.t2 where c < 2) as t, mysqltest.t1 +where t.c=t1.a; +--error ER_COLUMNACCESS_DENIED_ERROR +with t as (select c,d from mysqltest.t2 where c < 2) +select t.c,t.d,t1.b from t,mysqltest.t1 where t.c=t1.a; + +connection root; + +create view mysqltest.v1(f1,f2) as +with t as (select c from mysqltest.t2 where c < 2) +select t.c,t1.b from t,mysqltest.t1 where t.c=t1.a; +create view mysqltest.v2(c,d) as +with t as (select a from mysqltest.t1 where a>=3) +select t.a,b from t,mysqltest.t1 where mysqltest.t1.a = t.a; + +grant select on mysqltest.v1 to mysqltest_1@localhost; +grant select (c) on mysqltest.v2 to mysqltest_1@localhost; +grant create view on mysqltest.* to mysqltest_1@localhost; + +connection user1; + +create view mysqltest.v3(c,d) as +with t as (select c from mysqltest.t2 where c < 2) +select t.c,t1.b from t,mysqltest.t1 where t.c=t1.a; +--error ER_COLUMNACCESS_DENIED_ERROR +create view mysqltest.v4(f1,f2,f3) as +with t as (select c,d from mysqltest.t2 where c < 2) +select t.c,t.d,t1.b from t,mysqltest.t1 where t.c=t1.a; + +select * from mysqltest.v1; + +select c from mysqltest.v2; +# there are no privileges on column 'd' +--error ER_COLUMNACCESS_DENIED_ERROR +select d from mysqltest.v2; + +--error ER_TABLEACCESS_DENIED_ERROR +select * from mysqltest.v3; +connection root; +grant select on mysqltest.v3 to mysqltest_1@localhost; +connection user1; +select * from mysqltest.v3; + +connection root; +revoke all privileges on mysqltest.v1 from mysqltest_1@localhost; +drop user mysqltest_1@localhost; +drop database mysqltest;
\ No newline at end of file diff --git a/mysql-test/t/cte_nonrecursive.test b/mysql-test/t/cte_nonrecursive.test index 90a0cdcac8c..5a6e07e0c0c 100644 --- a/mysql-test/t/cte_nonrecursive.test +++ b/mysql-test/t/cte_nonrecursive.test @@ -50,6 +50,34 @@ explain select * from t2, (select a, count(*) from t1 where b >= 'c' group by a) as t where t2.c=t.a; +--echo # specivication of t contains having +with t as (select a, count(*) from t1 where b >= 'c' + group by a having count(*)=1 ) + select * from t2,t where t2.c=t.a; +select * from t2, (select a, count(*) from t1 where b >= 'c' + group by a having count(*)=1) t + where t2.c=t.a; + +--echo # main query contains having +with t as (select * from t2 where c <= 4) + select a, count(*) from t1,t where t1.a=t.c group by a having count(*)=1; +select a, count(*) from t1, (select * from t2 where c <= 4) t + where t1.a=t.c group by a having count(*)=1; + +--echo # main query contains group by + order by +with t as (select * from t2 where c <= 4 ) + select a, count(*) from t1,t where t1.a=t.c group by a order by count(*); +select a, count(*) from t1, (select * from t2 where c <= 4 ) t + where t1.a=t.c group by a order by count(*); + +--echo # main query contains group by + order by + limit +with t as (select * from t2 where c <= 4 ) + select a, count(*) from t1,t + where t1.a=t.c group by a order by count(*) desc limit 1; +select a, count(*) from t1, (select * from t2 where c <= 4 ) t + where t1.a=t.c group by a order by count(*) desc limit 1; + + --echo # t is used in a subquery with t as (select a from t1 where a<5) select * from t2 where c in (select a from t); @@ -120,6 +148,10 @@ select * from (select * from t1 where b >= 'c') as r1, (select * from t1 where b >= 'c') as r2 where r1.a=r2.a; +--echo # two references to t specifying explicitly column names +with t(c) as (select a from t1 where b >= 'c') + select * from t r1, t r2 where r1.c=r2.c; + --echo # specification of t contains union with t as (select a from t1 where b >= 'f' union @@ -264,7 +296,35 @@ select * from v2; explain select * from v2; -drop view v1,v2; +--echo # with clause in the specification of a view that whose definition +--echo # table alias for a with table +create view v3 as +with t(c) as (select a from t1 where b >= 'c') +select * from t r1 where r1.c=4; +show create view v3; +select * from v3; + +--echo # with clause in the specification of a view that whose definition +--echo # two table aliases for for the same with table +create view v4(c,d) as +with t(c) as (select a from t1 where b >= 'c') +select * from t r1, t r2 where r1.c=r2.c and r2.c=4; +show create view v4; +select * from v4; +explain +select * from v4; + +drop view v1,v2,v3,v4; + + +--echo # currently any views containing with clause are not updatable +create view v1(a) as +with t as (select a from t1 where b >= 'c') + select t.a from t2,t where t2.c=t.a; +--error ER_NON_UPDATABLE_TABLE +update v1 set a=0 where a > 4; +drop view v1; + --echo # prepare of a query containing a definition of a with table t prepare stmt1 from " diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt index 42a461bf406..cb774e92aab 100644 --- a/sql/share/errmsg-utf8.txt +++ b/sql/share/errmsg-utf8.txt @@ -7137,10 +7137,10 @@ ER_KILL_QUERY_DENIED_ERROR ger "Sie sind nicht Eigentümer von Abfrage %lu" rus "Вы не являетесь владельцем запроса %lu" ER_WITH_COL_WRONG_LIST - eng "With column list and SELECT field list have different column counts" + eng "WITH column list and SELECT field list have different column counts" ER_DUP_QUERY_NAME - eng "Duplicate query name in with clause" + eng "Duplicate query name in WITH clause" ER_WRONG_ORDER_IN_WITH_CLAUSE - eng "The definition of the table '%s' refers to the table '%s' defined later in a non-recursive with clause" + eng "The definition of the table '%s' refers to the table '%s' defined later in a non-recursive WITH clause" ER_RECURSIVE_QUERY_IN_WITH_CLAUSE - eng "Recursive queries in with clause are not supported yet" + eng "Recursive queries in WITH clause are not supported yet" diff --git a/sql/sql_cte.cc b/sql/sql_cte.cc index ef2a0714d41..1203a4ce0c8 100644 --- a/sql/sql_cte.cc +++ b/sql/sql_cte.cc @@ -392,29 +392,32 @@ err: /** @brief - Process optional column list of this with element - - @param thd The context of the statement containing this with element + Rename columns of the unit derived from the spec of this with element + @param thd The context of the statement containing the with element + @param unit The specification of the with element or its clone @details - The method processes the column list in this with element. - It reports an error if the cardinality of this list differs from - the cardinality of the select lists in the specification of the table - defined by this with element. Otherwise it renames the columns - of these select lists and sets the flag column_list_is_processed to true - preventing processing the list for the second time. + The method assumes that the parameter unit is either specification itself + of this with element or a clone of this specification. The looks through + the column list in this with element. It reports an error if the cardinality + of this list differs from the cardinality of select lists in 'unit'. + Otherwise it renames the columns of the first select list and sets the flag + unit->column_list_is_processed to true preventing renaming columns for the + second time. @retval true if an error was reported false otherwise */ -bool With_element::process_column_list(THD *thd) +bool +With_element::rename_columns_of_derived_unit(THD *thd, + st_select_lex_unit *unit) { - if (column_list_is_processed) + if (unit->columns_are_renamed) return false; - st_select_lex *select= spec->first_select(); + st_select_lex *select= unit->first_select(); if (column_list.elements) // The column list is optional { @@ -428,7 +431,7 @@ bool With_element::process_column_list(THD *thd) my_error(ER_WITH_COL_WRONG_LIST, MYF(0)); return true; } - /* Rename the columns of the first select in the specification query */ + /* Rename the columns of the first select in the unit */ while ((item= it++, name= nm++)) { item->set_name(thd, name->str, (uint) name->length, system_charset_info); @@ -438,7 +441,8 @@ bool With_element::process_column_list(THD *thd) make_valid_column_names(thd, select->item_list); - column_list_is_processed= true; + unit->columns_are_renamed= true; + return false; } @@ -473,7 +477,7 @@ bool With_element::prepare_unreferenced(THD *thd) thd->lex->context_analysis_only|= CONTEXT_ANALYSIS_ONLY_DERIVED; if (!spec->prepared && (spec->prepare(thd, 0, 0) || - process_column_list(thd) || + rename_columns_of_derived_unit(thd, spec) || check_duplicate_names(thd, first_sl->item_list, 1))) rc= true; diff --git a/sql/sql_cte.h b/sql/sql_cte.h index 1d572376f46..0cbc9247af9 100644 --- a/sql/sql_cte.h +++ b/sql/sql_cte.h @@ -58,8 +58,6 @@ public: List <LEX_STRING> column_list; /* The query that specifies the table introduced by this with element */ st_select_lex_unit *spec; - /* Set to true after column list has been processed in semantic analysis */ - bool column_list_is_processed; /* Set to true is recursion is used (directly or indirectly) for the definition of this element @@ -71,7 +69,7 @@ public: st_select_lex_unit *unit) : next_elem(NULL), dependency_map(0), references(0), query_name(name), column_list(list), spec(unit), - column_list_is_processed(false), is_recursive(false) {} + is_recursive(false) {} void check_dependencies_in_unit(st_select_lex_unit *unit); @@ -85,12 +83,12 @@ public: st_select_lex_unit *clone_parsed_spec(THD *thd, TABLE_LIST *with_table); - bool process_column_list(THD *thd); - bool is_referenced() { return references != 0; } void inc_references() { references++; } + bool rename_columns_of_derived_unit(THD *thd, st_select_lex_unit *unit); + bool prepare_unreferenced(THD *thd); void print(String *str, enum_query_type query_type); diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc index 978c6a1fdf6..1ef83b3bf1f 100644 --- a/sql/sql_derived.cc +++ b/sql/sql_derived.cc @@ -672,7 +672,7 @@ bool mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *derived) if ((res= unit->prepare(thd, derived->derived_result, 0))) goto exit; if (derived->with && - (res= derived->with->process_column_list(thd))) + (res= derived->with->rename_columns_of_derived_unit(thd, unit))) goto exit; lex->context_analysis_only&= ~CONTEXT_ANALYSIS_ONLY_DERIVED; if ((res= check_duplicate_names(thd, unit->types, 0))) diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 95e1c511738..8fee1370faf 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -1882,6 +1882,7 @@ void st_select_lex_unit::init_query() derived= 0; with_clause= 0; with_element= 0; + columns_are_renamed= false; } void st_select_lex::init_query() diff --git a/sql/sql_lex.h b/sql/sql_lex.h index f6eb5314c3a..1b114ca1838 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -655,7 +655,7 @@ public: */ st_select_lex *fake_select_lex; /** - SELECT_LEX that stores LIMIT and OFFSET for UNION ALL when no + SELECT_LEX that stores LIMIT and OFFSET for UNION ALL when noq fake_select_lex is used. */ st_select_lex *saved_fake_select_lex; @@ -671,6 +671,8 @@ public: */ TABLE *insert_table_with_stored_vcol; + bool columns_are_renamed; + void init_query(); st_select_lex* outer_select(); st_select_lex* first_select() diff --git a/sql/sql_select.cc b/sql/sql_select.cc index e04e2ef2002..da3e054876a 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -24677,6 +24677,11 @@ void TABLE_LIST::print(THD *thd, table_map eliminated_tables, String *str, str->append(')'); cmp_name= ""; // Force printing of alias } + else + { + append_identifier(thd, str, table_name, table_name_length); + cmp_name= table_name; + } } else { diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index ce098084128..515fab53716 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -64,7 +64,6 @@ #include "rpl_mi.h" #include "lex_token.h" - /* this is to get the bison compilation windows warnings out */ #ifdef _MSC_VER /* warning C4065: switch statement contains 'default' but no 'case' labels */ |