List:Commits« Previous MessageNext Message »
From:Sergey Glukhov Date:March 12 2010 7:33am
Subject:bzr commit into mysql-5.1-bugteam branch (Sergey.Glukhov:3395)
Bug#41788
View as plain text  
#At file:///home/gluh/MySQL/mysql-5.1-bugteam/ based on revid:joro@stripped

 3395 Sergey Glukhov	2010-03-12
      Bug#41788 mysql_fetch_field returns org_table == table by a view
      The problem is that Item_direct_view_ref which is inherited
      from Item_ident updates orig_table_name and table_name with
      the same values. The fix is introduction of new constructor
      into Item_ident and up which updates orig_table_name and
      table_name separately.
     @ mysql-test/r/metadata.result
        test case
     @ mysql-test/t/metadata.test
        test case
     @ sql/item.cc
        new constructor which updates
        orig_table_name and table_name
        separately.
     @ sql/item.h
        new constructor which updates
        orig_table_name and table_name
        separately.
     @ sql/table.cc
        used new constructor

    modified:
      mysql-test/r/metadata.result
      mysql-test/t/metadata.test
      sql/item.cc
      sql/item.h
      sql/table.cc
=== modified file 'mysql-test/r/metadata.result'
--- a/mysql-test/r/metadata.result	2008-10-10 11:44:10 +0000
+++ b/mysql-test/r/metadata.result	2010-03-12 06:33:16 +0000
@@ -198,4 +198,15 @@ def				IF(i, d, d)	IF(i, d, d)	10	10	10	
 def				IFNULL(d, d)	IFNULL(d, d)	10	10	10	Y	128	0	63
 def				LEAST(d, d)	LEAST(d, d)	10	10	10	Y	128	0	63
 DROP TABLE t1;
+#
+# Bug#41788 mysql_fetch_field returns org_table == table by a view
+#
+CREATE TABLE t1 (f1 INT);
+CREATE VIEW v1 AS SELECT f1 FROM t1;
+SELECT f1 FROM v1 va;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def	test	v1	va	f1	f1	3	11	0	Y	32768	0	63
+f1
+DROP VIEW v1;
+DROP TABLE t1;
 End of 5.0 tests

=== modified file 'mysql-test/t/metadata.test'
--- a/mysql-test/t/metadata.test	2008-10-10 10:13:12 +0000
+++ b/mysql-test/t/metadata.test	2010-03-12 06:33:16 +0000
@@ -129,4 +129,17 @@ SELECT COALESCE(d, d), IFNULL(d, d), IF(
 
 DROP TABLE t1;
 
+--echo #
+--echo # Bug#41788 mysql_fetch_field returns org_table == table by a view
+--echo #
+
+CREATE TABLE t1 (f1 INT);
+CREATE VIEW v1 AS SELECT f1 FROM t1;
+--enable_metadata
+SELECT f1 FROM v1 va;
+--disable_metadata
+
+DROP VIEW v1;
+DROP TABLE t1;
+
 --echo End of 5.0 tests

=== modified file 'sql/item.cc'
--- a/sql/item.cc	2010-03-09 21:55:08 +0000
+++ b/sql/item.cc	2010-03-12 06:33:16 +0000
@@ -556,6 +556,18 @@ Item_ident::Item_ident(Name_resolution_c
 }
 
 
+Item_ident::Item_ident(TABLE_LIST *view_arg, const char *field_name_arg)
+  :orig_db_name(NullS), orig_table_name(view_arg->table_name),
+   orig_field_name(field_name_arg), context(&view_arg->view->select_lex.context),
+   db_name(NullS), table_name(view_arg->alias),
+   field_name(field_name_arg),
+   alias_name_used(FALSE), cached_field_index(NO_CACHED_FIELD_INDEX),
+   cached_table(NULL), depended_from(NULL)
+{
+  name = (char*) field_name_arg;
+}
+
+
 /**
   Constructor used by Item_field & Item_*_ref (see Item comment)
 */
@@ -5721,6 +5733,20 @@ Item_ref::Item_ref(Name_resolution_conte
 }
 
 
+Item_ref::Item_ref(TABLE_LIST *view_arg, Item **item,
+                   const char *field_name_arg, bool alias_name_used_arg)
+  :Item_ident(view_arg, field_name_arg),
+   result_field(NULL), ref(item)
+{
+  alias_name_used= alias_name_used_arg;
+  /*
+    This constructor is used to create some internal references over fixed items
+  */
+  if (ref && *ref && (*ref)->fixed)
+    set_properties();
+}
+
+
 /**
   Resolve the name of a reference to a column reference.
 

=== modified file 'sql/item.h'
--- a/sql/item.h	2010-02-06 19:54:30 +0000
+++ b/sql/item.h	2010-03-12 06:33:16 +0000
@@ -1402,6 +1402,7 @@ public:
              const char *db_name_arg, const char *table_name_arg,
              const char *field_name_arg);
   Item_ident(THD *thd, Item_ident *item);
+  Item_ident(TABLE_LIST *view_arg, const char *field_name_arg);
   const char *full_name() const;
   void cleanup();
   bool remove_dependence_processor(uchar * arg);
@@ -2222,6 +2223,8 @@ public:
   Item_ref(Name_resolution_context *context_arg, Item **item,
            const char *table_name_arg, const char *field_name_arg,
            bool alias_name_used_arg= FALSE);
+  Item_ref(TABLE_LIST *view_arg, Item **item,
+           const char *field_name_arg, bool alias_name_used_arg= FALSE);
 
   /* Constructor need to process subselect with temporary tables (see Item) */
   Item_ref(THD *thd, Item_ref *item)
@@ -2337,6 +2340,12 @@ public:
   {}
   /* Constructor need to process subselect with temporary tables (see Item) */
   Item_direct_ref(THD *thd, Item_direct_ref *item) : Item_ref(thd, item) {}
+  Item_direct_ref(TABLE_LIST *view_arg, Item **item,
+                  const char *field_name_arg,
+                  bool alias_name_used_arg= FALSE)
+    :Item_ref(view_arg, item, field_name_arg,
+              alias_name_used_arg)
+  {}
 
   double val_real();
   longlong val_int();
@@ -2362,6 +2371,10 @@ public:
   /* Constructor need to process subselect with temporary tables (see Item) */
   Item_direct_view_ref(THD *thd, Item_direct_ref *item)
     :Item_direct_ref(thd, item) {}
+  Item_direct_view_ref(TABLE_LIST *view_arg, Item **item,
+                       const char *field_name_arg)
+    :Item_direct_ref(view_arg, item, field_name_arg)
+  {}
 
   bool fix_fields(THD *, Item **);
   bool eq(const Item *item, bool binary_cmp) const;

=== modified file 'sql/table.cc'
--- a/sql/table.cc	2010-02-09 11:43:44 +0000
+++ b/sql/table.cc	2010-03-12 06:33:16 +0000
@@ -4023,9 +4023,7 @@ Item *create_view_field(THD *thd, TABLE_
   {
     DBUG_RETURN(field);
   }
-  Item *item= new Item_direct_view_ref(&view->view->select_lex.context,
-                                       field_ref, view->alias,
-                                       name);
+  Item *item= new Item_direct_view_ref(view, field_ref, name);
   DBUG_RETURN(item);
 }
 


Attachment: [text/bzr-bundle] bzr/sergey.glukhov@sun.com-20100312063316-sflh6tc1ldvwdxgn.bundle
Thread
bzr commit into mysql-5.1-bugteam branch (Sergey.Glukhov:3395)Bug#41788Sergey Glukhov12 Mar 2010