mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
Bug#40277: SHOW CREATE VIEW returns invalid SQL
The problem is that not all column names retrieved from a SELECT statement can be used as view column names due to length and format restrictions. The server failed to properly check the conformity of those automatically generated column names before storing the final view definition on disk. Since columns retrieved from a SELECT statement can be anything ranging from functions to constants values of any format and length, the solution is to rewrite to a pre-defined format any names that are not acceptable as a view column name. The name is rewritten to "Name_exp_%u" where %u translates to the position of the column. To avoid this conversion scheme, define explict names for the view columns via the column_list clause. Also, aliases are now only generated for top level statements.
This commit is contained in:
@ -16950,7 +16950,17 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type)
|
||||
first= 0;
|
||||
else
|
||||
str->append(',');
|
||||
item->print_item_w_name(str, query_type);
|
||||
|
||||
if (master_unit()->item && item->is_autogenerated_name)
|
||||
{
|
||||
/*
|
||||
Do not print auto-generated aliases in subqueries. It has no purpose
|
||||
in a view definition or other contexts where the query is printed.
|
||||
*/
|
||||
item->print(str, query_type);
|
||||
}
|
||||
else
|
||||
item->print_item_w_name(str, query_type);
|
||||
}
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user