summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOleksandr Byelkin <sanja@mariadb.com>2021-10-01 14:46:22 +0200
committerOleksandr Byelkin <sanja@mariadb.com>2021-10-18 23:00:15 +0200
commit27bf57fd6dcfbaf6a116570e861b272eeae0b43c (patch)
tree8c64f54c9c84585ada0a377f4c1989b15d3ed4d7
parent2291f8ef73489fb8ed79768484df1ee4db3583a7 (diff)
downloadmariadb-git-27bf57fd6dcfbaf6a116570e861b272eeae0b43c.tar.gz
MDEV-26299: Some views force server (and mysqldump) to generate invalid SQL for their definitions
Do not print illegal table field names for non-top-level SELECT list, they will not be refered in any case but create problem for parsing of printed result.
-rw-r--r--mysql-test/r/view.result11
-rw-r--r--mysql-test/t/view.test19
-rw-r--r--sql/sql_select.cc23
3 files changed, 51 insertions, 2 deletions
diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result
index bae415c17ea..001d26fc466 100644
--- a/mysql-test/r/view.result
+++ b/mysql-test/r/view.result
@@ -6876,5 +6876,16 @@ SELECT 1 FROM (SELECT count(((SELECT i1 FROM v1))) FROM v1) dt ;
drop view v1;
drop table t1;
#
+# MDEV-26299: Some views force server (and mysqldump) to generate
+# invalid SQL for their definitions
+#
+create view v1 as
+select * from
+(select
+"12345678901234567890123456789012345678901234567890123456789012345") as t1;
+drop view v1;
+CREATE VIEW v1 AS select `t1`.`12345678901234567890123456789012345678901234567890123456789012345` AS `Name_exp_1` from (select '12345678901234567890123456789012345678901234567890123456789012345') `t1`;
+drop view v1;
+#
# End of 10.2 tests
#
diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test
index 128fa853e10..e6e6ccce8bd 100644
--- a/mysql-test/t/view.test
+++ b/mysql-test/t/view.test
@@ -6608,6 +6608,25 @@ SELECT 1 FROM (SELECT count(((SELECT i1 FROM v1))) FROM v1) dt ;
drop view v1;
drop table t1;
+
+--echo #
+--echo # MDEV-26299: Some views force server (and mysqldump) to generate
+--echo # invalid SQL for their definitions
+--echo #
+
+create view v1 as
+ select * from
+ (select
+ "12345678901234567890123456789012345678901234567890123456789012345") as t1;
+
+let $definition=`select VIEW_DEFINITION from information_schema.views where TABLE_NAME="v1"`;
+
+drop view v1;
+
+eval CREATE VIEW v1 AS $definition;
+
+drop view v1;
+
--echo #
--echo # End of 10.2 tests
--echo #
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index bf33623a684..54a2facfe9f 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -25804,6 +25804,11 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type)
//Item List
bool first= 1;
+ /*
+ outer_select() can not be used here because it is for name resolution
+ and will return NULL at any end of name resolution chain (view/derived)
+ */
+ bool top_level= (get_master()->get_master() == 0);
List_iterator_fast<Item> it(item_list);
Item *item;
while ((item= it++))
@@ -25813,7 +25818,8 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type)
else
str->append(',');
- if (is_subquery_function() && item->is_autogenerated_name)
+ if ((is_subquery_function() && item->is_autogenerated_name) ||
+ !item->name)
{
/*
Do not print auto-generated aliases in subqueries. It has no purpose
@@ -25822,7 +25828,20 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type)
item->print(str, query_type);
}
else
- item->print_item_w_name(str, query_type);
+ {
+ /*
+ Do not print illegal names (if it is not top level SELECT).
+ Top level view checked (and correct name are assigned),
+ other cases of top level SELECT are not important, because
+ it is not "table field".
+ */
+ if (top_level ||
+ !item->is_autogenerated_name ||
+ !check_column_name(item->name))
+ item->print_item_w_name(str, query_type);
+ else
+ item->print(str, query_type);
+ }
}
/*