~percona-dev/percona-server/5.1.56-expand_pass_corrupt_table

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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# 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-07-21 22:49:53.660561079 +0900
+++ b/sql/handler.h	2010-07-21 22:50:24.106530090 +0900
@@ -170,6 +170,19 @@
 #define HA_ONLINE_DROP_UNIQUE_INDEX             (1L << 9) /*drop uniq. online*/
 #define HA_ONLINE_ADD_PK_INDEX                  (1L << 10)/*add prim. online*/
 #define HA_ONLINE_DROP_PK_INDEX                 (1L << 11)/*drop prim. online*/
+
+#define HA_ONLINE_ALTER_INDEX_MASK	(HA_ONLINE_ADD_INDEX_NO_WRITES \
+						| HA_ONLINE_DROP_INDEX_NO_WRITES \
+						| HA_ONLINE_ADD_UNIQUE_INDEX_NO_WRITES \
+						| HA_ONLINE_DROP_UNIQUE_INDEX_NO_WRITES \
+						| HA_ONLINE_ADD_PK_INDEX_NO_WRITES \
+						| HA_ONLINE_DROP_PK_INDEX_NO_WRITES \
+						| HA_ONLINE_ADD_INDEX \
+						| HA_ONLINE_DROP_INDEX \
+						| HA_ONLINE_ADD_UNIQUE_INDEX \
+						| HA_ONLINE_DROP_UNIQUE_INDEX \
+						| HA_ONLINE_ADD_PK_INDEX \
+						| HA_ONLINE_DROP_PK_INDEX)
 /*
   HA_PARTITION_FUNCTION_SUPPORTED indicates that the function is
   supported at all.
diff -ruN a/sql/mysqld.cc b/sql/mysqld.cc
--- a/sql/mysqld.cc	2010-07-21 22:49:54.011529414 +0900
+++ b/sql/mysqld.cc	2010-07-21 22:50:24.112527179 +0900
@@ -5892,6 +5892,7 @@
   OPT_USERSTAT_RUNNING,
   OPT_THREAD_STATISTICS,
   OPT_OPTIMIZER_FIX,
+  OPT_ONLINE_ALTER_INDEX,
   OPT_SUPPRESS_LOG_WARNING_1592,
   OPT_QUERY_CACHE_STRIP_COMMENTS,
   OPT_USE_GLOBAL_LONG_QUERY_TIME,
@@ -5923,6 +5924,13 @@
    "from libc.so",
    &opt_allow_suspicious_udfs, &opt_allow_suspicious_udfs,
    0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
+  {"fast_index_creation",
+   OPT_ONLINE_ALTER_INDEX,
+   "If disabled, suppresses online operations for indexes of ALTER TABLE "
+   "(e.g. fast index creation of InnoDB Plugin) for the session.",
+   (uchar**) &global_system_variables.online_alter_index,
+   (uchar**) &global_system_variables.online_alter_index,
+   0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
   {"ansi", 'a', "Use ANSI SQL syntax instead of MySQL syntax. This mode "
    "will also set transaction isolation level 'serializable'.", 0, 0, 0,
    GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
diff -ruN a/sql/set_var.cc b/sql/set_var.cc
--- a/sql/set_var.cc	2010-07-21 22:49:54.019529438 +0900
+++ b/sql/set_var.cc	2010-07-21 22:50:24.122532110 +0900
@@ -748,6 +748,11 @@
 sys_engine_condition_pushdown(&vars, "engine_condition_pushdown",
 			      &SV::engine_condition_pushdown);
 
+/* Control online operations of ALTER TABLE */
+static sys_var_thd_bool
+sys_online_alter_index(&vars, "fast_index_creation",
+			&SV::online_alter_index);
+
 #ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
 /* ndb thread specific variable settings */
 static sys_var_thd_ulong
diff -ruN a/sql/sql_class.h b/sql/sql_class.h
--- a/sql/sql_class.h	2010-07-21 22:49:53.742561560 +0900
+++ b/sql/sql_class.h	2010-07-21 22:50:24.130529404 +0900
@@ -381,6 +381,8 @@
   my_bool ndb_use_transactions;
   my_bool ndb_index_stat_enable;
 
+  my_bool online_alter_index;
+
   my_bool old_alter_table;
   my_bool old_passwords;
 
diff -ruN a/sql/sql_partition.cc b/sql/sql_partition.cc
--- a/sql/sql_partition.cc	2010-06-04 00:50:11.000000000 +0900
+++ b/sql/sql_partition.cc	2010-07-21 22:50:24.140530183 +0900
@@ -4381,7 +4381,12 @@
         alter_info->no_parts= curr_part_no - new_part_no;
       }
     }
-    if (!(flags= table->file->alter_table_flags(alter_info->flags)))
+    flags= table->file->alter_table_flags(alter_info->flags);
+    if (!thd->variables.online_alter_index)
+    {
+      flags&= ~((uint)HA_ONLINE_ALTER_INDEX_MASK);
+    }
+    if (!flags)
     {
       my_error(ER_PARTITION_FUNCTION_FAILURE, MYF(0));
       DBUG_RETURN(1);
diff -ruN a/sql/sql_table.cc b/sql/sql_table.cc
--- a/sql/sql_table.cc	2010-06-04 00:50:11.000000000 +0900
+++ b/sql/sql_table.cc	2010-07-21 22:50:24.146531063 +0900
@@ -6993,6 +6993,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_ONLINE_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;