diff options
author | Nisha Gopalakrishnan <nisha.gopalakrishnan@oracle.com> | 2014-06-25 16:33:04 +0530 |
---|---|---|
committer | Nisha Gopalakrishnan <nisha.gopalakrishnan@oracle.com> | 2014-06-25 16:33:04 +0530 |
commit | d63645c890550cc190416e2c90585c1c6903b529 (patch) | |
tree | 55ad36d837d47f4e164941591c1c1e8afe4feaad /sql | |
parent | 410b1dd86d18b87f95d690b2aa2c4fec6b62166d (diff) | |
download | mariadb-git-d63645c890550cc190416e2c90585c1c6903b529.tar.gz |
BUG#18405221: SHOW CREATE VIEW OUTPUT INCORRECT
Fix:
---
The issue reported is same as the BUG#14117018.
Hence backporting the patch from mysql-trunk
to mysql-5.5 and mysql-5.6
Diffstat (limited to 'sql')
-rw-r--r-- | sql/sql_view.cc | 60 |
1 files changed, 46 insertions, 14 deletions
diff --git a/sql/sql_view.cc b/sql/sql_view.cc index 4a10c397508..6bbc475565b 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -1,4 +1,4 @@ -/* Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -163,27 +163,61 @@ err: Check if auto generated column names are conforming and possibly generate a conforming name for them if not. - @param item_list List of Items which should be checked + @param lex Lex for this thread. + + @retval false Operation was a success. + @retval true An error occurred. */ -static void make_valid_column_names(List<Item> &item_list) +static bool make_valid_column_names(LEX *lex) { Item *item; uint name_len; - List_iterator_fast<Item> it(item_list); char buff[NAME_LEN]; + uint column_no= 1; DBUG_ENTER("make_valid_column_names"); - for (uint column_no= 1; (item= it++); column_no++) + for (SELECT_LEX *sl= &lex->select_lex; sl; sl= sl->next_select()) { - if (!item->is_autogenerated_name || !check_column_name(item->name)) - continue; - name_len= my_snprintf(buff, NAME_LEN, "Name_exp_%u", column_no); - item->orig_name= item->name; - item->set_name(buff, name_len, system_charset_info); + for (List_iterator_fast<Item> it(sl->item_list); (item= it++); column_no++) + { + if (!item->is_autogenerated_name || !check_column_name(item->name)) + continue; + name_len= my_snprintf(buff, NAME_LEN, "Name_exp_%u", column_no); + item->orig_name= item->name; + item->set_name(buff, name_len, system_charset_info); + } + + /* + There is a possibility of generating same name for column in more than + one SELECT_LEX. For Example: + + CREATE TABLE t1 (Name_exp_1 INT, Name_exp_2 INT, Name_exp_3 INT); + CREATE TABLE t2 (Name_exp_1 INT, Name_exp_2 INT, Name_exp_3 INT); + + CREATE VIEW v1 AS SELECT '', t1.Name_exp_2 AS Name_exp_2 FROM t1 + UNION + SELECT '', t2.Name_exp_1 AS Name_exp_1 from t2; + + But, column names of the first SELECT_LEX is considered + for the output. + + mysql> SELECT * FROM v1; + +------------+------------+ + | Name_exp_1 | Name_exp_2 | + +------------+------------+ + | | 2 | + | | 3 | + +------------+------------+ + + So, checking for duplicate names in only "sl", current + SELECT_LEX. + */ + if (check_duplicate_names(sl->item_list, 1)) + DBUG_RETURN(true); } - DBUG_VOID_RETURN; + DBUG_RETURN(false); } @@ -590,9 +624,7 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views, } /* Check if the auto generated column names are conforming. */ - make_valid_column_names(select_lex->item_list); - - if (check_duplicate_names(select_lex->item_list, 1)) + if (make_valid_column_names(lex)) { res= TRUE; goto err; |