List:Internals« Previous MessageNext Message »
From:eugene Date:August 10 2005 1:45pm
Subject:bk commit into 5.0 tree (evgen:1.1919) BUG#11864
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of evgen. When evgen does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet
  1.1919 05/08/10 17:45:00 evgen@stripped +7 -0
  Fix bug #11864 non unique names are allowed in subquery
  
  Column names weren't checked for uniqueness for subqueries.
  
  Code for names uniqueness checking used for view creation moved into 
  separate function named check_duplicate_names(). It's called on 
  preparation of subqueries to check uniqueness of names. If duplicate names 
  are found then error is raised.

  mysql-test/r/select_safe.result
    1.17 05/08/10 17:38:17 evgen@stripped +1 -1
    Fixed test case results after bug fix #11864

  mysql-test/r/derived.result
    1.54 05/08/10 17:37:36 evgen@stripped +6 -1
    Added test case for bug #11864 non unique names are allowed in subquery.
    Fixed test case results after bug fix #11864

  mysql-test/t/select_safe.test
    1.11 05/08/10 17:37:08 evgen@stripped +1 -1
    Fixed test case results after bug fix #11864

  mysql-test/t/derived.test
    1.50 05/08/10 17:36:09 evgen@stripped +10 -1
    Fixed test case results after bug fix #11864
    Added test case for bug#11864 non unique names are allowed in subquery.

  sql/sql_view.h
    1.8 05/08/10 17:31:12 evgen@stripped +2 -0
     Fix bug #11864 non unique names are allowed in subquery
    Added check_duplicate_names() function prototype.

  sql/sql_view.cc
    1.56 05/08/10 17:28:15 evgen@stripped +67 -29
    Fix bug #11864 non unique names are allowed in subquery
    Code for checking uniqueness of names in item list moved into separate function to make in available for use from other places.

  sql/sql_derived.cc
    1.74 05/08/10 17:25:42 evgen@stripped +5 -0
    Fix bug #11864 non unique names are allowed in subquery
    Added check for names uniqueness in select list.

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	evgen
# Host:	moonbone.local
# Root:	/work/mysql-5.0-bug-11864

--- 1.53/mysql-test/r/derived.result	2005-02-22 16:46:56 +03:00
+++ 1.54/mysql-test/r/derived.result	2005-08-10 17:37:36 +04:00
@@ -111,7 +111,7 @@
 1	a
 2	b
 3	c
-explain select * from (select * from t1,t2 where t1.a=t2.a) t1;
+explain select * from (select t1.*, t2.a as t2a from t1,t2 where t1.a=t2.a) t1;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	PRIMARY	<derived2>	system	NULL	NULL	NULL	NULL	1	
 2	DERIVED	t2	system	NULL	NULL	NULL	NULL	1	
@@ -363,3 +363,8 @@
 3
 3
 drop table t1, t2, t3;
+create table t1 (a int);
+create table t2 (a int);
+select * from (select * from t1,t2) foo;
+ERROR 42S21: Duplicate column name 'a'
+drop table t1,t2;

--- 1.49/mysql-test/t/derived.test	2005-07-28 17:12:32 +04:00
+++ 1.50/mysql-test/t/derived.test	2005-08-10 17:36:09 +04:00
@@ -42,7 +42,7 @@
 insert into t2 values(1);
 select * from (select * from t1 where t1.a=(select a from t2 where t2.a=t1.a)) a;
 select * from (select * from t1 where t1.a=(select t2.a from t2 where t2.a=t1.a) union select t1.a, t1.b from t1) a;
-explain select * from (select * from t1,t2 where t1.a=t2.a) t1;
+explain select * from (select t1.*, t2.a as t2a from t1,t2 where t1.a=t2.a) t1;
 drop table t1, t2;
 create table t1(a int not null, t char(8), index(a));
 disable_query_log;
@@ -248,5 +248,14 @@
 select * from t1 union distinct select * from t2 union all select * from t3;
 select * from (select * from t1 union distinct select * from t2 union all select * from t3) X;
 drop table t1, t2, t3;
+
+#
+# Bug #11864 non unique names are allowed in subquery
+#
+create table t1 (a int);
+create table t2 (a int);
+--error 1060
+select * from (select * from t1,t2) foo;
+drop table t1,t2;
 
 # End of 4.1 tests

--- 1.73/sql/sql_derived.cc	2005-07-01 08:05:35 +04:00
+++ 1.74/sql/sql_derived.cc	2005-08-10 17:25:42 +04:00
@@ -125,6 +125,11 @@
     if ((res= unit->prepare(thd, derived_result, 0, orig_table_list->alias)))
       goto exit;
 
+    if (check_duplicate_names(unit->types, 0))
+    {
+      res= -1;
+      goto exit;
+    }
 
     derived_result->tmp_table_param.init();
     derived_result->tmp_table_param.field_count= unit->types.elements;

--- 1.55/sql/sql_view.cc	2005-07-31 13:51:08 +04:00
+++ 1.56/sql/sql_view.cc	2005-08-10 17:28:15 +04:00
@@ -94,6 +94,71 @@
   target->set_name(buff, name_len, system_charset_info);
 }
 
+
+/*
+  Check if items with same names are present in list and possibly
+  generate unique names for them.
+
+  SYNOPSIS
+    item_list             list of Items which should be checked for duplicates
+    gen_unique_view_name  flag: generate unique name or return with error when
+                          duplicate names are found.
+
+  DESCRIPTION
+    This function is used on view creation and preparation of derived tables.
+    It checks item_list for items with duplicate names. If it founds two
+    items with same name and conversion to unique names isn't allowed, or
+    names for both items are set by user - function fails.
+    Otherwise it generates unique name for one item with autogenerated name
+    using make_unique_view_field_name()
+
+  RETURN VALUE
+    FALSE no duplicate names found, or they are converted to unique ones
+    TRUE  duplicate names are found and they can't be converted or conversion
+          isn't allowed
+*/
+
+bool check_duplicate_names(List<Item> &item_list, bool gen_unique_view_name)
+{
+  DBUG_ENTER("check_duplicate_names");
+  /* Test absence of duplicates names */
+  {
+    Item *item;
+    List_iterator_fast<Item> it(item_list);
+    List_iterator_fast<Item> itc(item_list);
+    while ((item= it++))
+    {
+      Item *check;
+      /* treat underlying fields like set by user names */
+      if (item->real_item()->type() == Item::FIELD_ITEM)
+        item->is_autogenerated_name= FALSE;
+      itc.rewind();
+      while ((check= itc++) && check != item)
+      {
+        if (my_strcasecmp(system_charset_info, item->name, check->name) == 0)
+        {
+          if (!gen_unique_view_name)
+          {
+            my_error(ER_DUP_FIELDNAME, MYF(0), item->name);
+            DBUG_RETURN(TRUE);
+          }
+          else if (item->is_autogenerated_name)
+            make_unique_view_field_name(item, item_list, item);
+          else if (check->is_autogenerated_name)
+            make_unique_view_field_name(check, item_list, item);
+          else
+          {
+            my_error(ER_DUP_FIELDNAME, MYF(0), item->name);
+            DBUG_RETURN(TRUE);
+          }
+        }
+      }
+    }
+  }
+  DBUG_RETURN(FALSE);
+}
+
+
 /*
   Creating/altering VIEW procedure
 
@@ -308,35 +373,8 @@
     }
   }
 
-  /* Test absence of duplicates names */
-  {
-    Item *item;
-    List_iterator_fast<Item> it(select_lex->item_list);
-    List_iterator_fast<Item> itc(select_lex->item_list);
-    while ((item= it++))
-    {
-      Item *check;
-      /* treat underlying fields like set by user names */
-      if (item->real_item()->type() == Item::FIELD_ITEM)
-        item->is_autogenerated_name= FALSE;
-      itc.rewind();
-      while ((check= itc++) && check != item)
-      {
-        if (my_strcasecmp(system_charset_info, item->name, check->name) == 0)
-        {
-          if (item->is_autogenerated_name)
-            make_unique_view_field_name(item, select_lex->item_list, item);
-          else if (check->is_autogenerated_name)
-            make_unique_view_field_name(check, select_lex->item_list, item);
-          else
-          {
-            my_error(ER_DUP_FIELDNAME, MYF(0), item->name);
-            DBUG_RETURN(TRUE);
-          }
-        }
-      }
-    }
-  }
+  if (check_duplicate_names(select_lex->item_list, 1))
+    DBUG_RETURN(TRUE);
 
 #ifndef NO_EMBEDDED_ACCESS_CHECKS
   /*

--- 1.7/sql/sql_view.h	2005-07-01 08:05:36 +04:00
+++ 1.8/sql/sql_view.h	2005-08-10 17:31:12 +04:00
@@ -33,5 +33,7 @@
 
 extern TYPELIB updatable_views_with_limit_typelib;
 
+bool check_duplicate_names(List<Item>& item_list, bool gen_unique_view_names);
+
 #define VIEW_ANY_ACL (SELECT_ACL | UPDATE_ACL | INSERT_ACL | DELETE_ACL)
 

--- 1.16/mysql-test/r/select_safe.result	2005-07-29 05:22:45 +04:00
+++ 1.17/mysql-test/r/select_safe.result	2005-08-10 17:38:17 +04:00
@@ -84,7 +84,7 @@
 select * from (select * from t1) x;
 ERROR 42000: The SELECT would examine more than MAX_JOIN_SIZE rows; check your WHERE and use SET SQL_BIG_SELECTS=1 or SET SQL_MAX_JOIN_SIZE=# if the SELECT is okay
 set local  max_join_size=1;
-select * from (select * from t1 a, t1 b) x;
+select * from (select a.a as aa, b.a as ba from t1 a, t1 b) x;
 ERROR 42000: The SELECT would examine more than MAX_JOIN_SIZE rows; check your WHERE and use SET SQL_BIG_SELECTS=1 or SET SQL_MAX_JOIN_SIZE=# if the SELECT is okay
 set local  max_join_size=1;
 select * from (select 1 union select 2 union select 3) x;

--- 1.10/mysql-test/t/select_safe.test	2005-07-29 20:25:07 +04:00
+++ 1.11/mysql-test/t/select_safe.test	2005-08-10 17:37:08 +04:00
@@ -78,7 +78,7 @@
 
 set local  max_join_size=1;
 --error 1104
-select * from (select * from t1 a, t1 b) x;
+select * from (select a.a as aa, b.a as ba from t1 a, t1 b) x;
 
 set local  max_join_size=1;
 --error 1104
Thread
bk commit into 5.0 tree (evgen:1.1919) BUG#11864eugene10 Aug