diff options
author | Oleksandr Byelkin <sanja@mariadb.com> | 2021-10-01 14:46:22 +0200 |
---|---|---|
committer | Oleksandr Byelkin <sanja@mariadb.com> | 2021-10-18 12:53:22 +0200 |
commit | bdaf94d5a21c3a974d2c7d6d586289d4375dce92 (patch) | |
tree | 817d425cae29b829ae3d51b95fcc554bf4fb5a1f /sql/sql_select.cc | |
parent | 5f63f5dc60a48105d739f606cbf0a575925029d1 (diff) | |
download | mariadb-git-bb-10.2-MDEV-26299.tar.gz |
MDEV-26299: Some views force server (and mysqldump) to generate invalid SQL for their definitionsbb-10.2-MDEV-26299
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.
Diffstat (limited to 'sql/sql_select.cc')
-rw-r--r-- | sql/sql_select.cc | 23 |
1 files changed, 21 insertions, 2 deletions
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); + } } /* |