1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

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
This commit is contained in:
Nisha Gopalakrishnan
2014-06-25 16:33:04 +05:30
parent 5c4937c101
commit b278384f64
3 changed files with 120 additions and 14 deletions

View File

@ -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;