~percona-dev/percona-server/release-5.5.11-20.2-fix-bug-764138

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# name       : control_online_alter_index.patch
# introduced : 12
# maintainer : Yasufumi
#
#!!! notice !!!
# Any small change to this file in the main branch
# should be done or reviewed by the maintainer!
diff -ruN a/sql/handler.h b/sql/handler.h
--- a/sql/handler.h	2010-11-03 07:01:14.000000000 +0900
+++ b/sql/handler.h	2010-12-03 13:51:04.727293058 +0900
@@ -197,6 +197,8 @@
 #define HA_INPLACE_DROP_UNIQUE_INDEX_NO_WRITE      (1L << 9)
 #define HA_INPLACE_ADD_PK_INDEX_NO_WRITE           (1L << 10)
 #define HA_INPLACE_DROP_PK_INDEX_NO_WRITE          (1L << 11)
+
+#define HA_INPLACE_ALTER_INDEX_MASK                ((1L << 12) - 1)
 /*
   HA_PARTITION_FUNCTION_SUPPORTED indicates that the function is
   supported at all.
diff -ruN a/sql/sql_class.h b/sql/sql_class.h
--- a/sql/sql_class.h	2010-12-02 20:31:56.200956501 +0900
+++ b/sql/sql_class.h	2010-12-03 13:51:04.744953174 +0900
@@ -481,6 +481,8 @@
   my_bool engine_condition_pushdown;
   my_bool keep_files_on_create;
 
+  my_bool online_alter_index;
+
   my_bool old_alter_table;
   my_bool old_passwords;
   my_bool big_tables;
diff -ruN a/sql/sql_partition.cc b/sql/sql_partition.cc
--- a/sql/sql_partition.cc	2010-11-03 07:01:14.000000000 +0900
+++ b/sql/sql_partition.cc	2010-12-03 13:59:56.444039002 +0900
@@ -4636,7 +4636,12 @@
         alter_info->num_parts= curr_part_no - new_part_no;
       }
     }
-    if (!(flags= new_table->file->alter_table_flags(alter_info->flags)))
+    flags= new_table->file->alter_table_flags(alter_info->flags);
+    if (!thd->variables.online_alter_index)
+    {
+      flags&= ~((uint)HA_INPLACE_ALTER_INDEX_MASK);
+    }
+    if (!flags)
     {
       my_error(ER_PARTITION_FUNCTION_FAILURE, MYF(0));
       goto err;
diff -ruN a/sql/sql_table.cc b/sql/sql_table.cc
--- a/sql/sql_table.cc	2010-11-03 07:01:14.000000000 +0900
+++ b/sql/sql_table.cc	2010-12-03 13:51:04.768955495 +0900
@@ -6117,6 +6117,10 @@
     uint  *idx_end_p;
 
     alter_flags= table->file->alter_table_flags(alter_info->flags);
+    if (!thd->variables.online_alter_index)
+    {
+      alter_flags&= ~((ulong)HA_INPLACE_ALTER_INDEX_MASK);
+    }
     DBUG_PRINT("info", ("alter_flags: %lu", alter_flags));
     /* Check dropped indexes. */
     for (idx_p= index_drop_buffer, idx_end_p= idx_p + index_drop_count;
diff -ruN a/sql/sys_vars.cc b/sql/sys_vars.cc
--- a/sql/sys_vars.cc	2010-12-02 21:23:05.569356468 +0900
+++ b/sql/sys_vars.cc	2010-12-03 14:05:28.857356603 +0900
@@ -2140,6 +2140,13 @@
        GLOBAL_VAR(opt_optimizer_fix),
        NO_CMD_LINE, DEFAULT(TRUE));
 
+static Sys_var_mybool Sys_fast_index_creation(
+       "fast_index_creation",
+       "If disabled, suppresses online operations for indexes of ALTER TABLE "
+       "(e.g. fast index creation of InnoDB Plugin) for the session.",
+       SESSION_VAR(online_alter_index), NO_CMD_LINE,
+       DEFAULT(TRUE));
+
 /** propagates changes to the relevant flag of @@optimizer_switch */
 static bool fix_engine_condition_pushdown(sys_var *self, THD *thd,
                                           enum_var_type type)