[Commits] Rev 3506: LPBUG#983285 - incompatibility in frm in case of VIEWs with non-default ALGORITHM option. in file:///H:/bzr/5.3/

Vladislav Vaintroub wlad at montyprogram.com
Fri Apr 20 22:09:43 EEST 2012


At file:///H:/bzr/5.3/

------------------------------------------------------------
revno: 3506
revision-id: wlad at montyprogram.com-20120420190916-o3cee9va71fco62t
parent: sanja at montyprogram.com-20120419061630-gkekk7gpdfggtvmb
fixes bug(s): https://launchpad.net/bugs/983285
committer: Vladislav Vaintroub <wlad at montyprogram.com>
branch nick: 5.3
timestamp: Fri 2012-04-20 21:09:16 +0200
message:
  LPBUG#983285 - incompatibility in frm in case of VIEWs with non-default ALGORITHM option.
  
  As part of derived tables redesign, values for VIEW_ALGORITHM_MERGE and VIEW_ALGORITHM_TMPTABLE have changed from (former values 1 rsp 2 , new values 5 rsp 9).
  
  This lead to the problem that views, created with version 5.2  or earlier would not work in all situations  (e.g "SHOW CREATE VIEW"), or with mysqldump.
  
  The fix is to restore backward compatibility for the from file, and convert algorithm={1,2} in the frm to {5,9} when reading .frm from disk, and store backward compatible values when writing from to disk. 
  
  Also allow processing correct processing for "invalid" .frms created with MariaDB 5.3/5.5 GA releases (where algorithm stored in memory matched the one stored in frm).
-------------- next part --------------
=== modified file 'sql/parse_file.cc'
--- a/sql/parse_file.cc	2011-12-11 09:34:44 +0000
+++ b/sql/parse_file.cc	2012-04-20 19:09:16 +0000
@@ -86,6 +86,40 @@
   return FALSE;
 }
 
+static ulonglong view_algo_to_frm(ulonglong val)
+{
+  switch(val)
+  {
+    case VIEW_ALGORITHM_UNDEFINED:
+      return VIEW_ALGORITHM_UNDEFINED_FRM;
+    case VIEW_ALGORITHM_MERGE:
+      return VIEW_ALGORITHM_MERGE_FRM;
+    case VIEW_ALGORITHM_TMPTABLE:
+      return VIEW_ALGORITHM_TMPTABLE_FRM;
+  }
+  DBUG_ASSERT(0); /* Should never happen */
+  return VIEW_ALGORITHM_UNDEFINED;
+}
+
+static ulonglong view_algo_from_frm(ulonglong val)
+{
+  switch(val)
+  {
+    case VIEW_ALGORITHM_UNDEFINED_FRM:
+      return VIEW_ALGORITHM_UNDEFINED;
+    case VIEW_ALGORITHM_MERGE_FRM:
+      return VIEW_ALGORITHM_MERGE;
+    case VIEW_ALGORITHM_TMPTABLE_FRM:
+      return VIEW_ALGORITHM_TMPTABLE;
+  }
+
+  /*
+    Early versions of MariaDB 5.2/5.3 had identical in-memory and frm values
+    Return input value.
+  */
+  return val;
+}
+
 
 /**
   Write parameter value to IO_CACHE.
@@ -124,8 +158,14 @@
     break;
   }
   case FILE_OPTIONS_ULONGLONG:
+  case FILE_OPTIONS_VIEW_ALGO:
   {
-    num.set(*((ulonglong *)(base + parameter->offset)), &my_charset_bin);
+    ulonglong val= *(ulonglong *)(base + parameter->offset);
+
+    if (parameter->type == FILE_OPTIONS_VIEW_ALGO)
+      val= view_algo_to_frm(val);
+
+    num.set(val, &my_charset_bin);
     if (my_b_append(file, (const uchar *)num.ptr(), num.length()))
       DBUG_RETURN(TRUE);
     break;
@@ -766,6 +806,7 @@
 	  break;
 	}
 	case FILE_OPTIONS_ULONGLONG:
+	case FILE_OPTIONS_VIEW_ALGO:
 	  if (!(eol= strchr(ptr, '\n')))
 	  {
 	    my_error(ER_FPARSER_ERROR_IN_PARAMETER, MYF(0),
@@ -774,8 +815,12 @@
 	  }
           {
             int not_used;
-	    *((ulonglong*)(base + parameter->offset))=
-              my_strtoll10(ptr, 0, &not_used);
+            ulonglong val= (ulonglong)my_strtoll10(ptr, 0, &not_used);
+
+            if (parameter->type == FILE_OPTIONS_VIEW_ALGO)
+              val= view_algo_from_frm(val);
+
+            *((ulonglong*)(base + parameter->offset))= val;
           }
 	  ptr= eol+1;
 	  break;

=== modified file 'sql/parse_file.h'
--- a/sql/parse_file.h	2011-11-24 16:48:58 +0000
+++ b/sql/parse_file.h	2012-04-20 19:09:16 +0000
@@ -26,6 +26,7 @@
   FILE_OPTIONS_STRING,		/**< String (LEX_STRING) */
   FILE_OPTIONS_ESTRING,		/**< Escaped string (LEX_STRING) */
   FILE_OPTIONS_ULONGLONG,	/**< ulonglong parameter (ulonglong) */
+  FILE_OPTIONS_VIEW_ALGO,	/**< Similar to longlong, but needs conversion */
   FILE_OPTIONS_TIMESTAMP,	/**< timestamp (LEX_STRING have to be
 				   allocated with length 20 (19+1) */
   FILE_OPTIONS_STRLIST,         /**< list of escaped strings

=== modified file 'sql/sql_view.cc'
--- a/sql/sql_view.cc	2012-04-05 21:07:18 +0000
+++ b/sql/sql_view.cc	2012-04-20 19:09:16 +0000
@@ -736,7 +736,7 @@
   FILE_OPTIONS_ULONGLONG},
  {{ C_STRING_WITH_LEN("algorithm")},
   my_offsetof(TABLE_LIST, algorithm),
-  FILE_OPTIONS_ULONGLONG},
+  FILE_OPTIONS_VIEW_ALGO},
  {{ C_STRING_WITH_LEN("definer_user")},
   my_offsetof(TABLE_LIST, definer.user),
   FILE_OPTIONS_STRING},

=== modified file 'sql/table.h'
--- a/sql/table.h	2012-04-05 21:07:18 +0000
+++ b/sql/table.h	2012-04-20 19:09:16 +0000
@@ -1150,12 +1150,6 @@
 /*
   Types of derived tables. The ending part is a bitmap of phases that are
   applicable to a derived table of the type.
- * /
-#define VIEW_ALGORITHM_UNDEFINED        0
-#define VIEW_ALGORITHM_MERGE            1 + DT_COMMON + DT_MERGE
-#define DERIVED_ALGORITHM_MERGE         2 + DT_COMMON + DT_MERGE
-#define VIEW_ALGORITHM_TMPTABLE         3 + DT_COMMON + DT_MATERIALIZE
-#define DERIVED_ALGORITHM_MATERIALIZE   4 + DT_COMMON + DT_MATERIALIZE
 */
 #define DTYPE_ALGORITHM_UNDEFINED    0
 #define DTYPE_VIEW                   1
@@ -1188,7 +1182,16 @@
 
 #define VIEW_ALGORITHM_UNDEFINED 0
 #define VIEW_ALGORITHM_MERGE    (DTYPE_VIEW | DTYPE_MERGE)
-#define VIEW_ALGORITHM_TMPTABLE (DTYPE_VIEW + DTYPE_MATERIALIZE )
+#define VIEW_ALGORITHM_TMPTABLE (DTYPE_VIEW | DTYPE_MATERIALIZE)
+
+/*
+  View algorithm values as stored in the FRM. Values differ from in-memory
+  representation for backward compatibility.
+*/
+
+#define VIEW_ALGORITHM_UNDEFINED_FRM  0
+#define VIEW_ALGORITHM_MERGE_FRM      1
+#define VIEW_ALGORITHM_TMPTABLE_FRM   2
 
 #define JOIN_TYPE_LEFT	1
 #define JOIN_TYPE_RIGHT	2



More information about the commits mailing list