Merge lp:~sergei.glushchenko/mysql-server/expand_fast_index_creation into lp:mysql-server/5.1
- expand_fast_index_creation
- Merge into 5.1
Proposed by
Sergei Glushchenko
Status: | Needs review |
---|---|
Proposed branch: | lp:~sergei.glushchenko/mysql-server/expand_fast_index_creation |
Merge into: | lp:mysql-server/5.1 |
Diff against target: |
1508 lines (+1160/-2) 20 files modified
client/client_priv.h (+1/-0) client/mysqldump.c (+223/-0) mysql-test/r/percona_innodb_expand_fast_index_creation.result (+67/-0) mysql-test/r/percona_mysqldump_innodb_optimize_keys.result (+367/-0) mysql-test/suite/innodb_plugin/r/percona_bug_999147.result (+8/-0) mysql-test/suite/innodb_plugin/t/percona_bug_999147-master.opt (+1/-0) mysql-test/suite/innodb_plugin/t/percona_bug_999147.test (+29/-0) mysql-test/t/percona_innodb_expand_fast_index_creation.test (+46/-0) mysql-test/t/percona_mysqldump_innodb_optimize_keys.test (+187/-0) sql/mysqld.cc (+9/-1) sql/set_var.cc (+4/-0) sql/sql_class.h (+2/-0) sql/sql_lex.cc (+4/-0) sql/sql_lex.h (+8/-0) sql/sql_table.cc (+171/-0) storage/innodb_plugin/handler/ha_innodb.cc (+15/-0) storage/innodb_plugin/handler/handler0alter.cc (+2/-0) storage/innodb_plugin/include/ha_prototypes.h (+11/-0) storage/innodb_plugin/row/row0merge.c (+4/-0) storage/innodb_plugin/row/row0mysql.c (+1/-1) |
To merge this branch: | bzr merge lp:~sergei.glushchenko/mysql-server/expand_fast_index_creation |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Alexey Kopytov (community) | Approve | ||
Review via email: mp+113247@code.launchpad.net |
Commit message
Description of the change
Patch expand_
Fix for bug #999147.
To post a comment you must log in.
Unmerged revisions
- 3733. By Sergei Glushchenko
-
port expand_
fast_index_ creation patch
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'client/client_priv.h' | |||
2 | --- client/client_priv.h 2011-07-03 15:47:37 +0000 | |||
3 | +++ client/client_priv.h 2012-07-03 16:14:26 +0000 | |||
4 | @@ -94,5 +94,6 @@ | |||
5 | 94 | OPT_WRITE_BINLOG, OPT_DUMP_DATE, | 94 | OPT_WRITE_BINLOG, OPT_DUMP_DATE, |
6 | 95 | OPT_FIRST_SLAVE, | 95 | OPT_FIRST_SLAVE, |
7 | 96 | OPT_ALL, | 96 | OPT_ALL, |
8 | 97 | OPT_INNODB_OPTIMIZE_KEYS, | ||
9 | 97 | OPT_MAX_CLIENT_OPTION | 98 | OPT_MAX_CLIENT_OPTION |
10 | 98 | }; | 99 | }; |
11 | 99 | 100 | ||
12 | === modified file 'client/mysqldump.c' | |||
13 | --- client/mysqldump.c 2012-05-07 11:16:44 +0000 | |||
14 | +++ client/mysqldump.c 2012-07-03 16:14:26 +0000 | |||
15 | @@ -47,6 +47,7 @@ | |||
16 | 47 | #include <m_ctype.h> | 47 | #include <m_ctype.h> |
17 | 48 | #include <hash.h> | 48 | #include <hash.h> |
18 | 49 | #include <stdarg.h> | 49 | #include <stdarg.h> |
19 | 50 | #include <my_list.h> | ||
20 | 50 | 51 | ||
21 | 51 | #include "client_priv.h" | 52 | #include "client_priv.h" |
22 | 52 | #include "mysql.h" | 53 | #include "mysql.h" |
23 | @@ -148,6 +149,8 @@ | |||
24 | 148 | #endif | 149 | #endif |
25 | 149 | static uint opt_protocol= 0; | 150 | static uint opt_protocol= 0; |
26 | 150 | 151 | ||
27 | 152 | static my_bool opt_innodb_optimize_keys= FALSE; | ||
28 | 153 | |||
29 | 151 | /* | 154 | /* |
30 | 152 | Dynamic_string wrapper functions. In this file use these | 155 | Dynamic_string wrapper functions. In this file use these |
31 | 153 | wrappers, they will terminate the process if there is | 156 | wrappers, they will terminate the process if there is |
32 | @@ -193,6 +196,8 @@ | |||
33 | 193 | 196 | ||
34 | 194 | HASH ignore_table; | 197 | HASH ignore_table; |
35 | 195 | 198 | ||
36 | 199 | LIST *skipped_keys_list; | ||
37 | 200 | |||
38 | 196 | static struct my_option my_long_options[] = | 201 | static struct my_option my_long_options[] = |
39 | 197 | { | 202 | { |
40 | 198 | {"all", OPT_ALL, "Deprecated. Use --create-options instead.", | 203 | {"all", OPT_ALL, "Deprecated. Use --create-options instead.", |
41 | @@ -339,6 +344,11 @@ | |||
42 | 339 | "be specified with both database and table names, e.g., " | 344 | "be specified with both database and table names, e.g., " |
43 | 340 | "--ignore-table=database.table.", | 345 | "--ignore-table=database.table.", |
44 | 341 | 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, | 346 | 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, |
45 | 347 | {"innodb-optimize-keys", OPT_INNODB_OPTIMIZE_KEYS, | ||
46 | 348 | "Use InnoDB fast index creation by creating secondary indexes after " | ||
47 | 349 | "dumping the data.", | ||
48 | 350 | &opt_innodb_optimize_keys, &opt_innodb_optimize_keys, 0, GET_BOOL, NO_ARG, | ||
49 | 351 | 0, 0, 0, 0, 0, 0}, | ||
50 | 342 | {"insert-ignore", OPT_INSERT_IGNORE, "Insert rows with INSERT IGNORE.", | 352 | {"insert-ignore", OPT_INSERT_IGNORE, "Insert rows with INSERT IGNORE.", |
51 | 343 | &opt_ignore, &opt_ignore, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, | 353 | &opt_ignore, &opt_ignore, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, |
52 | 344 | 0, 0}, | 354 | 0, 0}, |
53 | @@ -2433,6 +2443,190 @@ | |||
54 | 2433 | } | 2443 | } |
55 | 2434 | 2444 | ||
56 | 2435 | /* | 2445 | /* |
57 | 2446 | Parse the specified key definition string and check if the key indexes | ||
58 | 2447 | any of the columns from ignored_columns. | ||
59 | 2448 | */ | ||
60 | 2449 | static my_bool contains_ignored_column(HASH *ignored_columns, char *keydef) | ||
61 | 2450 | { | ||
62 | 2451 | char *leftp, *rightp; | ||
63 | 2452 | |||
64 | 2453 | if ((leftp = strchr(keydef, '(')) && | ||
65 | 2454 | (rightp = strchr(leftp, ')')) && | ||
66 | 2455 | rightp > leftp + 3 && /* (`...`) */ | ||
67 | 2456 | leftp[1] == '`' && | ||
68 | 2457 | rightp[-1] == '`' && | ||
69 | 2458 | my_hash_search(ignored_columns, (uchar *) leftp + 2, rightp - leftp - 3)) | ||
70 | 2459 | return TRUE; | ||
71 | 2460 | |||
72 | 2461 | return FALSE; | ||
73 | 2462 | } | ||
74 | 2463 | |||
75 | 2464 | |||
76 | 2465 | /* | ||
77 | 2466 | Remove secondary/foreign key definitions from a given SHOW CREATE TABLE string | ||
78 | 2467 | and store them into a temporary list to be used later. | ||
79 | 2468 | |||
80 | 2469 | SYNOPSIS | ||
81 | 2470 | skip_secondary_keys() | ||
82 | 2471 | create_str SHOW CREATE TABLE output | ||
83 | 2472 | has_pk TRUE, if the table has PRIMARY KEY | ||
84 | 2473 | (or UNIQUE key on non-nullable columns) | ||
85 | 2474 | |||
86 | 2475 | |||
87 | 2476 | DESCRIPTION | ||
88 | 2477 | |||
89 | 2478 | Stores all lines starting with "KEY" or "UNIQUE KEY" | ||
90 | 2479 | into skipped_keys_list and removes them from the input string. | ||
91 | 2480 | Ignoring FOREIGN KEYS constraints when creating the table is ok, because | ||
92 | 2481 | mysqldump sets foreign_key_checks to 0 anyway. | ||
93 | 2482 | */ | ||
94 | 2483 | |||
95 | 2484 | static void skip_secondary_keys(char *create_str, my_bool has_pk) | ||
96 | 2485 | { | ||
97 | 2486 | char *ptr, *strend; | ||
98 | 2487 | char *last_comma = NULL; | ||
99 | 2488 | HASH ignored_columns; | ||
100 | 2489 | my_bool pk_processed= FALSE; | ||
101 | 2490 | |||
102 | 2491 | if (hash_init(&ignored_columns, charset_info, 16, 0, 0, | ||
103 | 2492 | (hash_get_key) get_table_key, | ||
104 | 2493 | (hash_free_key) free_table_ent, 0)) | ||
105 | 2494 | exit(EX_EOM); | ||
106 | 2495 | |||
107 | 2496 | strend= create_str + strlen(create_str); | ||
108 | 2497 | |||
109 | 2498 | ptr= create_str; | ||
110 | 2499 | while (*ptr) | ||
111 | 2500 | { | ||
112 | 2501 | char *tmp, *orig_ptr, c; | ||
113 | 2502 | my_bool is_unique= FALSE; | ||
114 | 2503 | |||
115 | 2504 | orig_ptr= ptr; | ||
116 | 2505 | /* Skip leading whitespace */ | ||
117 | 2506 | while (*ptr && my_isspace(charset_info, *ptr)) | ||
118 | 2507 | ptr++; | ||
119 | 2508 | |||
120 | 2509 | /* Read the next line */ | ||
121 | 2510 | for (tmp= ptr; *tmp != '\n' && *tmp != '\0'; tmp++); | ||
122 | 2511 | |||
123 | 2512 | c= *tmp; | ||
124 | 2513 | *tmp= '\0'; /* so strstr() only processes the current line */ | ||
125 | 2514 | |||
126 | 2515 | /* Is it a secondary index definition? */ | ||
127 | 2516 | if (c == '\n' && | ||
128 | 2517 | (((is_unique= !strncmp(ptr, "UNIQUE KEY ", sizeof("UNIQUE KEY ")-1)) && | ||
129 | 2518 | (pk_processed || !has_pk)) || | ||
130 | 2519 | !strncmp(ptr, "KEY ", sizeof("KEY ") - 1)) && | ||
131 | 2520 | !contains_ignored_column(&ignored_columns, ptr)) | ||
132 | 2521 | { | ||
133 | 2522 | char *data, *end= tmp - 1; | ||
134 | 2523 | |||
135 | 2524 | /* Remove the trailing comma */ | ||
136 | 2525 | if (*end == ',') | ||
137 | 2526 | end--; | ||
138 | 2527 | data= my_strndup(ptr, end - ptr + 1, MYF(MY_FAE)); | ||
139 | 2528 | skipped_keys_list= list_cons(data, skipped_keys_list); | ||
140 | 2529 | |||
141 | 2530 | memmove(orig_ptr, tmp + 1, strend - tmp); | ||
142 | 2531 | ptr= orig_ptr; | ||
143 | 2532 | strend-= tmp + 1 - ptr; | ||
144 | 2533 | |||
145 | 2534 | /* Remove the comma on the previos line */ | ||
146 | 2535 | if (last_comma != NULL) | ||
147 | 2536 | { | ||
148 | 2537 | *last_comma= ' '; | ||
149 | 2538 | } | ||
150 | 2539 | } | ||
151 | 2540 | else | ||
152 | 2541 | { | ||
153 | 2542 | char *end; | ||
154 | 2543 | |||
155 | 2544 | if (last_comma != NULL && *ptr != ')') | ||
156 | 2545 | { | ||
157 | 2546 | /* | ||
158 | 2547 | It's not the last line of CREATE TABLE, so we have skipped a key | ||
159 | 2548 | definition. We have to restore the last removed comma. | ||
160 | 2549 | */ | ||
161 | 2550 | *last_comma= ','; | ||
162 | 2551 | } | ||
163 | 2552 | |||
164 | 2553 | if ((has_pk && is_unique && !pk_processed) || | ||
165 | 2554 | !strncmp(ptr, "PRIMARY KEY ", sizeof("PRIMARY KEY ") - 1)) | ||
166 | 2555 | pk_processed= TRUE; | ||
167 | 2556 | |||
168 | 2557 | if (strstr(ptr, "AUTO_INCREMENT") && *ptr == '`') | ||
169 | 2558 | { | ||
170 | 2559 | /* | ||
171 | 2560 | If a secondary key is defined on this column later, | ||
172 | 2561 | it cannot be skipped, as CREATE TABLE would fail on import. | ||
173 | 2562 | */ | ||
174 | 2563 | for (end= ptr + 1; *end != '`' && *end != '\0'; end++); | ||
175 | 2564 | if (*end == '`' && end > ptr + 1 && | ||
176 | 2565 | my_hash_insert(&ignored_columns, | ||
177 | 2566 | (uchar *) my_strndup(ptr + 1, | ||
178 | 2567 | end - ptr - 1, MYF(0)))) | ||
179 | 2568 | { | ||
180 | 2569 | exit(EX_EOM); | ||
181 | 2570 | } | ||
182 | 2571 | } | ||
183 | 2572 | |||
184 | 2573 | *tmp= c; | ||
185 | 2574 | |||
186 | 2575 | if (tmp[-1] == ',') | ||
187 | 2576 | last_comma= tmp - 1; | ||
188 | 2577 | ptr= (*tmp == '\0') ? tmp : tmp + 1; | ||
189 | 2578 | } | ||
190 | 2579 | } | ||
191 | 2580 | |||
192 | 2581 | my_hash_free(&ignored_columns); | ||
193 | 2582 | } | ||
194 | 2583 | |||
195 | 2584 | /* | ||
196 | 2585 | Check if the table has a primary key defined either explicitly or | ||
197 | 2586 | implicitly (i.e. a unique key on non-nullable columns). | ||
198 | 2587 | |||
199 | 2588 | SYNOPSIS | ||
200 | 2589 | my_bool has_primary_key(const char *table_name) | ||
201 | 2590 | |||
202 | 2591 | table_name quoted table name | ||
203 | 2592 | |||
204 | 2593 | RETURNS TRUE if the table has a primary key | ||
205 | 2594 | |||
206 | 2595 | DESCRIPTION | ||
207 | 2596 | */ | ||
208 | 2597 | |||
209 | 2598 | static my_bool has_primary_key(const char *table_name) | ||
210 | 2599 | { | ||
211 | 2600 | MYSQL_RES *res= NULL; | ||
212 | 2601 | MYSQL_ROW row; | ||
213 | 2602 | char query_buff[QUERY_LENGTH]; | ||
214 | 2603 | my_bool has_pk= TRUE; | ||
215 | 2604 | |||
216 | 2605 | my_snprintf(query_buff, sizeof(query_buff), | ||
217 | 2606 | "SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE " | ||
218 | 2607 | "TABLE_SCHEMA=DATABASE() AND TABLE_NAME='%s' AND " | ||
219 | 2608 | "COLUMN_KEY='PRI'", table_name); | ||
220 | 2609 | if (mysql_query(mysql, query_buff) || !(res= mysql_store_result(mysql)) || | ||
221 | 2610 | !(row= mysql_fetch_row(res))) | ||
222 | 2611 | { | ||
223 | 2612 | fprintf(stderr, "Warning: Couldn't determine if table %s has a " | ||
224 | 2613 | "primary key (%s). " | ||
225 | 2614 | "--innodb-optimize-keys may work inefficiently.\n", | ||
226 | 2615 | table_name, mysql_error(mysql)); | ||
227 | 2616 | goto cleanup; | ||
228 | 2617 | } | ||
229 | 2618 | |||
230 | 2619 | has_pk= atoi(row[0]) > 0; | ||
231 | 2620 | |||
232 | 2621 | cleanup: | ||
233 | 2622 | if (res) | ||
234 | 2623 | mysql_free_result(res); | ||
235 | 2624 | |||
236 | 2625 | return has_pk; | ||
237 | 2626 | } | ||
238 | 2627 | |||
239 | 2628 | |||
240 | 2629 | /* | ||
241 | 2436 | get_table_structure -- retrievs database structure, prints out corresponding | 2630 | get_table_structure -- retrievs database structure, prints out corresponding |
242 | 2437 | CREATE statement and fills out insert_pat if the table is the type we will | 2631 | CREATE statement and fills out insert_pat if the table is the type we will |
243 | 2438 | be dumping. | 2632 | be dumping. |
244 | @@ -2470,6 +2664,7 @@ | |||
245 | 2470 | my_bool is_log_table; | 2664 | my_bool is_log_table; |
246 | 2471 | MYSQL_RES *result; | 2665 | MYSQL_RES *result; |
247 | 2472 | MYSQL_ROW row; | 2666 | MYSQL_ROW row; |
248 | 2667 | my_bool has_pk= FALSE; | ||
249 | 2473 | DBUG_ENTER("get_table_structure"); | 2668 | DBUG_ENTER("get_table_structure"); |
250 | 2474 | DBUG_PRINT("enter", ("db: %s table: %s", db, table)); | 2669 | DBUG_PRINT("enter", ("db: %s table: %s", db, table)); |
251 | 2475 | 2670 | ||
252 | @@ -2511,6 +2706,9 @@ | |||
253 | 2511 | result_table= quote_name(table, table_buff, 1); | 2706 | result_table= quote_name(table, table_buff, 1); |
254 | 2512 | opt_quoted_table= quote_name(table, table_buff2, 0); | 2707 | opt_quoted_table= quote_name(table, table_buff2, 0); |
255 | 2513 | 2708 | ||
256 | 2709 | if (opt_innodb_optimize_keys && !strcmp(table_type, "InnoDB")) | ||
257 | 2710 | has_pk= has_primary_key(table); | ||
258 | 2711 | |||
259 | 2514 | if (opt_order_by_primary) | 2712 | if (opt_order_by_primary) |
260 | 2515 | order_by= primary_key_fields(result_table); | 2713 | order_by= primary_key_fields(result_table); |
261 | 2516 | 2714 | ||
262 | @@ -2672,6 +2870,10 @@ | |||
263 | 2672 | is_log_table= general_log_or_slow_log_tables(db, table); | 2870 | is_log_table= general_log_or_slow_log_tables(db, table); |
264 | 2673 | if (is_log_table) | 2871 | if (is_log_table) |
265 | 2674 | row[1]+= 13; /* strlen("CREATE TABLE ")= 13 */ | 2872 | row[1]+= 13; /* strlen("CREATE TABLE ")= 13 */ |
266 | 2873 | |||
267 | 2874 | if (opt_innodb_optimize_keys && !strcmp(table_type, "InnoDB")) | ||
268 | 2875 | skip_secondary_keys(row[1], has_pk); | ||
269 | 2876 | |||
270 | 2675 | if (opt_compatible_mode & 3) | 2877 | if (opt_compatible_mode & 3) |
271 | 2676 | { | 2878 | { |
272 | 2677 | fprintf(sql_file, | 2879 | fprintf(sql_file, |
273 | @@ -3788,6 +3990,27 @@ | |||
274 | 3788 | goto err; | 3990 | goto err; |
275 | 3789 | } | 3991 | } |
276 | 3790 | 3992 | ||
277 | 3993 | /* Perform delayed secondary index creation for --innodb-optimize-keys */ | ||
278 | 3994 | if (skipped_keys_list) | ||
279 | 3995 | { | ||
280 | 3996 | uint keys; | ||
281 | 3997 | skipped_keys_list= list_reverse(skipped_keys_list); | ||
282 | 3998 | fprintf(md_result_file, "ALTER TABLE %s ", opt_quoted_table); | ||
283 | 3999 | for (keys= list_length(skipped_keys_list); keys > 0; keys--) | ||
284 | 4000 | { | ||
285 | 4001 | LIST *node= skipped_keys_list; | ||
286 | 4002 | char *def= node->data; | ||
287 | 4003 | |||
288 | 4004 | fprintf(md_result_file, "ADD %s%s", def, (keys > 1) ? ", " : ";\n"); | ||
289 | 4005 | |||
290 | 4006 | skipped_keys_list= list_delete(skipped_keys_list, node); | ||
291 | 4007 | my_free(def, MYF(0)); | ||
292 | 4008 | my_free(node, MYF(0)); | ||
293 | 4009 | } | ||
294 | 4010 | |||
295 | 4011 | DBUG_ASSERT(skipped_keys_list == NULL); | ||
296 | 4012 | } | ||
297 | 4013 | |||
298 | 3791 | /* Moved enable keys to before unlock per bug 15977 */ | 4014 | /* Moved enable keys to before unlock per bug 15977 */ |
299 | 3792 | if (opt_disable_keys) | 4015 | if (opt_disable_keys) |
300 | 3793 | { | 4016 | { |
301 | 3794 | 4017 | ||
302 | === added file 'mysql-test/r/percona_innodb_expand_fast_index_creation.result' | |||
303 | --- mysql-test/r/percona_innodb_expand_fast_index_creation.result 1970-01-01 00:00:00 +0000 | |||
304 | +++ mysql-test/r/percona_innodb_expand_fast_index_creation.result 2012-07-03 16:14:26 +0000 | |||
305 | @@ -0,0 +1,67 @@ | |||
306 | 1 | SELECT @@expand_fast_index_creation; | ||
307 | 2 | @@expand_fast_index_creation | ||
308 | 3 | 0 | ||
309 | 4 | CREATE TABLE t1( | ||
310 | 5 | id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, | ||
311 | 6 | a CHAR(1) NOT NULL, | ||
312 | 7 | b CHAR(36) NOT NULL) ENGINE=InnoDB; | ||
313 | 8 | INSERT INTO t1(a,b) VALUES ('a','b'); | ||
314 | 9 | INSERT INTO t1(a,b) SELECT a,b FROM t1; | ||
315 | 10 | INSERT INTO t1(a,b) SELECT a,b FROM t1; | ||
316 | 11 | INSERT INTO t1(a,b) SELECT a,b FROM t1; | ||
317 | 12 | INSERT INTO t1(a,b) SELECT a,b FROM t1; | ||
318 | 13 | ALTER TABLE t1 ADD KEY (a); | ||
319 | 14 | affected rows: 0 | ||
320 | 15 | info: Records: 0 Duplicates: 0 Warnings: 0 | ||
321 | 16 | EXPLAIN SELECT COUNT(*) FROM t1, t1 t2 WHERE t1.a = t2.a AND t1.b = t2.b; | ||
322 | 17 | id 1 | ||
323 | 18 | select_type SIMPLE | ||
324 | 19 | table t1 | ||
325 | 20 | type ALL | ||
326 | 21 | possible_keys a | ||
327 | 22 | key NULL | ||
328 | 23 | key_len NULL | ||
329 | 24 | ref NULL | ||
330 | 25 | rows 16 | ||
331 | 26 | Extra | ||
332 | 27 | id 1 | ||
333 | 28 | select_type SIMPLE | ||
334 | 29 | table t2 | ||
335 | 30 | type ref | ||
336 | 31 | possible_keys a | ||
337 | 32 | key a | ||
338 | 33 | key_len 1 | ||
339 | 34 | ref test.t1.a | ||
340 | 35 | rows 1 | ||
341 | 36 | Extra Using where | ||
342 | 37 | ALTER TABLE t1 DROP KEY a; | ||
343 | 38 | SET expand_fast_index_creation = 1; | ||
344 | 39 | SELECT @@expand_fast_index_creation; | ||
345 | 40 | @@expand_fast_index_creation | ||
346 | 41 | 1 | ||
347 | 42 | ALTER TABLE t1 ADD KEY (a); | ||
348 | 43 | affected rows: 0 | ||
349 | 44 | info: Records: 0 Duplicates: 0 Warnings: 0 | ||
350 | 45 | EXPLAIN SELECT COUNT(*) FROM t1, t1 t2 WHERE t1.a = t2.a AND t1.b = t2.b; | ||
351 | 46 | id 1 | ||
352 | 47 | select_type SIMPLE | ||
353 | 48 | table t1 | ||
354 | 49 | type ALL | ||
355 | 50 | possible_keys a | ||
356 | 51 | key NULL | ||
357 | 52 | key_len NULL | ||
358 | 53 | ref NULL | ||
359 | 54 | rows 16 | ||
360 | 55 | Extra | ||
361 | 56 | id 1 | ||
362 | 57 | select_type SIMPLE | ||
363 | 58 | table t2 | ||
364 | 59 | type ALL | ||
365 | 60 | possible_keys a | ||
366 | 61 | key NULL | ||
367 | 62 | key_len NULL | ||
368 | 63 | ref NULL | ||
369 | 64 | rows 16 | ||
370 | 65 | Extra Using where; Using join buffer | ||
371 | 66 | SET expand_fast_index_creation = 0; | ||
372 | 67 | DROP TABLE t1; | ||
373 | 0 | 68 | ||
374 | === added file 'mysql-test/r/percona_mysqldump_innodb_optimize_keys.result' | |||
375 | --- mysql-test/r/percona_mysqldump_innodb_optimize_keys.result 1970-01-01 00:00:00 +0000 | |||
376 | +++ mysql-test/r/percona_mysqldump_innodb_optimize_keys.result 2012-07-03 16:14:26 +0000 | |||
377 | @@ -0,0 +1,367 @@ | |||
378 | 1 | # | ||
379 | 2 | # Test the --innodb-optimize-keys option. | ||
380 | 3 | # | ||
381 | 4 | CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY, b INT, KEY(b)) ENGINE=MyISAM; | ||
382 | 5 | ###################################### | ||
383 | 6 | |||
384 | 7 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; | ||
385 | 8 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; | ||
386 | 9 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; | ||
387 | 10 | /*!40101 SET NAMES utf8 */; | ||
388 | 11 | /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; | ||
389 | 12 | /*!40103 SET TIME_ZONE='+00:00' */; | ||
390 | 13 | /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; | ||
391 | 14 | /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; | ||
392 | 15 | /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; | ||
393 | 16 | /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; | ||
394 | 17 | DROP TABLE IF EXISTS `t1`; | ||
395 | 18 | /*!40101 SET @saved_cs_client = @@character_set_client */; | ||
396 | 19 | /*!40101 SET character_set_client = utf8 */; | ||
397 | 20 | CREATE TABLE `t1` ( | ||
398 | 21 | `a` int(11) NOT NULL, | ||
399 | 22 | `b` int(11) DEFAULT NULL, | ||
400 | 23 | PRIMARY KEY (`a`), | ||
401 | 24 | KEY `b` (`b`) | ||
402 | 25 | ) ENGINE=MyISAM DEFAULT CHARSET=latin1; | ||
403 | 26 | /*!40101 SET character_set_client = @saved_cs_client */; | ||
404 | 27 | |||
405 | 28 | LOCK TABLES `t1` WRITE; | ||
406 | 29 | /*!40000 ALTER TABLE `t1` DISABLE KEYS */; | ||
407 | 30 | /*!40000 ALTER TABLE `t1` ENABLE KEYS */; | ||
408 | 31 | UNLOCK TABLES; | ||
409 | 32 | /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; | ||
410 | 33 | |||
411 | 34 | /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; | ||
412 | 35 | /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; | ||
413 | 36 | /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; | ||
414 | 37 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; | ||
415 | 38 | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; | ||
416 | 39 | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; | ||
417 | 40 | /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; | ||
418 | 41 | |||
419 | 42 | ###################################### | ||
420 | 43 | DROP TABLE t1; | ||
421 | 44 | CREATE TABLE t2 (a INT PRIMARY KEY) ENGINE=InnoDB; | ||
422 | 45 | INSERT INTO t2 VALUES (0), (1), (2); | ||
423 | 46 | CREATE TABLE t1 ( | ||
424 | 47 | id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, | ||
425 | 48 | a INT, b VARCHAR(255), c DECIMAL(10,3), | ||
426 | 49 | KEY (b), | ||
427 | 50 | UNIQUE KEY uniq(c,a), | ||
428 | 51 | FOREIGN KEY (a) REFERENCES t2(a) ON DELETE CASCADE | ||
429 | 52 | ) ENGINE=InnoDB; | ||
430 | 53 | INSERT INTO t1(a,b,c) VALUES (0, "0", 0.0), (1, "1", 1.1), (2, "2", 2.2); | ||
431 | 54 | ###################################### | ||
432 | 55 | |||
433 | 56 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; | ||
434 | 57 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; | ||
435 | 58 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; | ||
436 | 59 | /*!40101 SET NAMES utf8 */; | ||
437 | 60 | /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; | ||
438 | 61 | /*!40103 SET TIME_ZONE='+00:00' */; | ||
439 | 62 | /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; | ||
440 | 63 | /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; | ||
441 | 64 | /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; | ||
442 | 65 | /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; | ||
443 | 66 | DROP TABLE IF EXISTS `t1`; | ||
444 | 67 | /*!40101 SET @saved_cs_client = @@character_set_client */; | ||
445 | 68 | /*!40101 SET character_set_client = utf8 */; | ||
446 | 69 | CREATE TABLE `t1` ( | ||
447 | 70 | `id` int(11) NOT NULL AUTO_INCREMENT, | ||
448 | 71 | `a` int(11) DEFAULT NULL, | ||
449 | 72 | `b` varchar(255) DEFAULT NULL, | ||
450 | 73 | `c` decimal(10,3) DEFAULT NULL, | ||
451 | 74 | PRIMARY KEY (`id`), | ||
452 | 75 | CONSTRAINT `t1_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t2` (`a`) ON DELETE CASCADE | ||
453 | 76 | ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1; | ||
454 | 77 | /*!40101 SET character_set_client = @saved_cs_client */; | ||
455 | 78 | |||
456 | 79 | LOCK TABLES `t1` WRITE; | ||
457 | 80 | /*!40000 ALTER TABLE `t1` DISABLE KEYS */; | ||
458 | 81 | INSERT INTO `t1` VALUES (1,0,'0','0.000'),(2,1,'1','1.100'),(3,2,'2','2.200'); | ||
459 | 82 | ALTER TABLE `t1` ADD UNIQUE KEY `uniq` (`c`,`a`), ADD KEY `b` (`b`), ADD KEY `a` (`a`); | ||
460 | 83 | /*!40000 ALTER TABLE `t1` ENABLE KEYS */; | ||
461 | 84 | UNLOCK TABLES; | ||
462 | 85 | DROP TABLE IF EXISTS `t2`; | ||
463 | 86 | /*!40101 SET @saved_cs_client = @@character_set_client */; | ||
464 | 87 | /*!40101 SET character_set_client = utf8 */; | ||
465 | 88 | CREATE TABLE `t2` ( | ||
466 | 89 | `a` int(11) NOT NULL, | ||
467 | 90 | PRIMARY KEY (`a`) | ||
468 | 91 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; | ||
469 | 92 | /*!40101 SET character_set_client = @saved_cs_client */; | ||
470 | 93 | |||
471 | 94 | LOCK TABLES `t2` WRITE; | ||
472 | 95 | /*!40000 ALTER TABLE `t2` DISABLE KEYS */; | ||
473 | 96 | INSERT INTO `t2` VALUES (0),(1),(2); | ||
474 | 97 | /*!40000 ALTER TABLE `t2` ENABLE KEYS */; | ||
475 | 98 | UNLOCK TABLES; | ||
476 | 99 | /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; | ||
477 | 100 | |||
478 | 101 | /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; | ||
479 | 102 | /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; | ||
480 | 103 | /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; | ||
481 | 104 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; | ||
482 | 105 | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; | ||
483 | 106 | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; | ||
484 | 107 | /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; | ||
485 | 108 | |||
486 | 109 | ###################################### | ||
487 | 110 | DROP TABLE t1, t2; | ||
488 | 111 | CREATE TABLE t1 ( | ||
489 | 112 | id INT NOT NULL AUTO_INCREMENT, | ||
490 | 113 | KEY (id) | ||
491 | 114 | ) ENGINE=InnoDB; | ||
492 | 115 | CREATE TABLE t2 ( | ||
493 | 116 | id INT NOT NULL AUTO_INCREMENT, | ||
494 | 117 | UNIQUE KEY (id) | ||
495 | 118 | ) ENGINE=InnoDB; | ||
496 | 119 | INSERT INTO t1 VALUES (), (), (); | ||
497 | 120 | INSERT INTO t2 VALUES (), (), (); | ||
498 | 121 | ###################################### | ||
499 | 122 | |||
500 | 123 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; | ||
501 | 124 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; | ||
502 | 125 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; | ||
503 | 126 | /*!40101 SET NAMES utf8 */; | ||
504 | 127 | /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; | ||
505 | 128 | /*!40103 SET TIME_ZONE='+00:00' */; | ||
506 | 129 | /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; | ||
507 | 130 | /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; | ||
508 | 131 | /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; | ||
509 | 132 | /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; | ||
510 | 133 | DROP TABLE IF EXISTS `t1`; | ||
511 | 134 | /*!40101 SET @saved_cs_client = @@character_set_client */; | ||
512 | 135 | /*!40101 SET character_set_client = utf8 */; | ||
513 | 136 | CREATE TABLE `t1` ( | ||
514 | 137 | `id` int(11) NOT NULL AUTO_INCREMENT, | ||
515 | 138 | KEY `id` (`id`) | ||
516 | 139 | ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1; | ||
517 | 140 | /*!40101 SET character_set_client = @saved_cs_client */; | ||
518 | 141 | |||
519 | 142 | LOCK TABLES `t1` WRITE; | ||
520 | 143 | /*!40000 ALTER TABLE `t1` DISABLE KEYS */; | ||
521 | 144 | INSERT INTO `t1` VALUES (1),(2),(3); | ||
522 | 145 | /*!40000 ALTER TABLE `t1` ENABLE KEYS */; | ||
523 | 146 | UNLOCK TABLES; | ||
524 | 147 | DROP TABLE IF EXISTS `t2`; | ||
525 | 148 | /*!40101 SET @saved_cs_client = @@character_set_client */; | ||
526 | 149 | /*!40101 SET character_set_client = utf8 */; | ||
527 | 150 | CREATE TABLE `t2` ( | ||
528 | 151 | `id` int(11) NOT NULL AUTO_INCREMENT, | ||
529 | 152 | UNIQUE KEY `id` (`id`) | ||
530 | 153 | ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1; | ||
531 | 154 | /*!40101 SET character_set_client = @saved_cs_client */; | ||
532 | 155 | |||
533 | 156 | LOCK TABLES `t2` WRITE; | ||
534 | 157 | /*!40000 ALTER TABLE `t2` DISABLE KEYS */; | ||
535 | 158 | INSERT INTO `t2` VALUES (1),(2),(3); | ||
536 | 159 | /*!40000 ALTER TABLE `t2` ENABLE KEYS */; | ||
537 | 160 | UNLOCK TABLES; | ||
538 | 161 | /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; | ||
539 | 162 | |||
540 | 163 | /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; | ||
541 | 164 | /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; | ||
542 | 165 | /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; | ||
543 | 166 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; | ||
544 | 167 | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; | ||
545 | 168 | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; | ||
546 | 169 | /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; | ||
547 | 170 | |||
548 | 171 | ###################################### | ||
549 | 172 | DROP TABLE t1, t2; | ||
550 | 173 | CREATE TABLE t1 ( | ||
551 | 174 | a INT NOT NULL, | ||
552 | 175 | UNIQUE KEY (a)) ENGINE=InnoDB; | ||
553 | 176 | CREATE TABLE t2 ( | ||
554 | 177 | a INT NOT NULL, | ||
555 | 178 | b INT NOT NULL, | ||
556 | 179 | UNIQUE KEY (a,b)) ENGINE=InnoDB; | ||
557 | 180 | CREATE TABLE t3 ( | ||
558 | 181 | a INT, | ||
559 | 182 | b INT, | ||
560 | 183 | UNIQUE KEY (a,b)) ENGINE=InnoDB; | ||
561 | 184 | CREATE TABLE t4 ( | ||
562 | 185 | a INT NOT NULL, | ||
563 | 186 | b INT NOT NULL, | ||
564 | 187 | PRIMARY KEY (a,b), | ||
565 | 188 | UNIQUE KEY(b)) ENGINE=InnoDB; | ||
566 | 189 | SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE | ||
567 | 190 | TABLE_SCHEMA=DATABASE() AND | ||
568 | 191 | TABLE_NAME='t1' AND | ||
569 | 192 | COLUMN_KEY='PRI'; | ||
570 | 193 | COUNT(*) | ||
571 | 194 | 1 | ||
572 | 195 | SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE | ||
573 | 196 | TABLE_SCHEMA=DATABASE() AND | ||
574 | 197 | TABLE_NAME='t2' AND | ||
575 | 198 | COLUMN_KEY='PRI'; | ||
576 | 199 | COUNT(*) | ||
577 | 200 | 2 | ||
578 | 201 | SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE | ||
579 | 202 | TABLE_SCHEMA=DATABASE() AND | ||
580 | 203 | TABLE_NAME='t3' AND | ||
581 | 204 | COLUMN_KEY='PRI'; | ||
582 | 205 | COUNT(*) | ||
583 | 206 | 0 | ||
584 | 207 | SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE | ||
585 | 208 | TABLE_SCHEMA=DATABASE() AND | ||
586 | 209 | TABLE_NAME='t4' AND | ||
587 | 210 | COLUMN_KEY='PRI'; | ||
588 | 211 | COUNT(*) | ||
589 | 212 | 2 | ||
590 | 213 | INSERT INTO t1 VALUES (1), (2), (3); | ||
591 | 214 | INSERT INTO t2 VALUES (1,1), (2,2), (3,3); | ||
592 | 215 | INSERT INTO t3 SELECT * FROM t2; | ||
593 | 216 | INSERT INTO t4 SELECT * FROM t2; | ||
594 | 217 | ###################################### | ||
595 | 218 | |||
596 | 219 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; | ||
597 | 220 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; | ||
598 | 221 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; | ||
599 | 222 | /*!40101 SET NAMES utf8 */; | ||
600 | 223 | /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; | ||
601 | 224 | /*!40103 SET TIME_ZONE='+00:00' */; | ||
602 | 225 | /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; | ||
603 | 226 | /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; | ||
604 | 227 | /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; | ||
605 | 228 | /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; | ||
606 | 229 | DROP TABLE IF EXISTS `t1`; | ||
607 | 230 | /*!40101 SET @saved_cs_client = @@character_set_client */; | ||
608 | 231 | /*!40101 SET character_set_client = utf8 */; | ||
609 | 232 | CREATE TABLE `t1` ( | ||
610 | 233 | `a` int(11) NOT NULL, | ||
611 | 234 | UNIQUE KEY `a` (`a`) | ||
612 | 235 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; | ||
613 | 236 | /*!40101 SET character_set_client = @saved_cs_client */; | ||
614 | 237 | |||
615 | 238 | LOCK TABLES `t1` WRITE; | ||
616 | 239 | /*!40000 ALTER TABLE `t1` DISABLE KEYS */; | ||
617 | 240 | INSERT INTO `t1` VALUES (1),(2),(3); | ||
618 | 241 | /*!40000 ALTER TABLE `t1` ENABLE KEYS */; | ||
619 | 242 | UNLOCK TABLES; | ||
620 | 243 | DROP TABLE IF EXISTS `t2`; | ||
621 | 244 | /*!40101 SET @saved_cs_client = @@character_set_client */; | ||
622 | 245 | /*!40101 SET character_set_client = utf8 */; | ||
623 | 246 | CREATE TABLE `t2` ( | ||
624 | 247 | `a` int(11) NOT NULL, | ||
625 | 248 | `b` int(11) NOT NULL, | ||
626 | 249 | UNIQUE KEY `a` (`a`,`b`) | ||
627 | 250 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; | ||
628 | 251 | /*!40101 SET character_set_client = @saved_cs_client */; | ||
629 | 252 | |||
630 | 253 | LOCK TABLES `t2` WRITE; | ||
631 | 254 | /*!40000 ALTER TABLE `t2` DISABLE KEYS */; | ||
632 | 255 | INSERT INTO `t2` VALUES (1,1),(2,2),(3,3); | ||
633 | 256 | /*!40000 ALTER TABLE `t2` ENABLE KEYS */; | ||
634 | 257 | UNLOCK TABLES; | ||
635 | 258 | DROP TABLE IF EXISTS `t3`; | ||
636 | 259 | /*!40101 SET @saved_cs_client = @@character_set_client */; | ||
637 | 260 | /*!40101 SET character_set_client = utf8 */; | ||
638 | 261 | CREATE TABLE `t3` ( | ||
639 | 262 | `a` int(11) DEFAULT NULL, | ||
640 | 263 | `b` int(11) DEFAULT NULL | ||
641 | 264 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; | ||
642 | 265 | /*!40101 SET character_set_client = @saved_cs_client */; | ||
643 | 266 | |||
644 | 267 | LOCK TABLES `t3` WRITE; | ||
645 | 268 | /*!40000 ALTER TABLE `t3` DISABLE KEYS */; | ||
646 | 269 | INSERT INTO `t3` VALUES (1,1),(2,2),(3,3); | ||
647 | 270 | ALTER TABLE `t3` ADD UNIQUE KEY `a` (`a`,`b`); | ||
648 | 271 | /*!40000 ALTER TABLE `t3` ENABLE KEYS */; | ||
649 | 272 | UNLOCK TABLES; | ||
650 | 273 | DROP TABLE IF EXISTS `t4`; | ||
651 | 274 | /*!40101 SET @saved_cs_client = @@character_set_client */; | ||
652 | 275 | /*!40101 SET character_set_client = utf8 */; | ||
653 | 276 | CREATE TABLE `t4` ( | ||
654 | 277 | `a` int(11) NOT NULL, | ||
655 | 278 | `b` int(11) NOT NULL, | ||
656 | 279 | PRIMARY KEY (`a`,`b`) | ||
657 | 280 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; | ||
658 | 281 | /*!40101 SET character_set_client = @saved_cs_client */; | ||
659 | 282 | |||
660 | 283 | LOCK TABLES `t4` WRITE; | ||
661 | 284 | /*!40000 ALTER TABLE `t4` DISABLE KEYS */; | ||
662 | 285 | INSERT INTO `t4` VALUES (1,1),(2,2),(3,3); | ||
663 | 286 | ALTER TABLE `t4` ADD UNIQUE KEY `b` (`b`); | ||
664 | 287 | /*!40000 ALTER TABLE `t4` ENABLE KEYS */; | ||
665 | 288 | UNLOCK TABLES; | ||
666 | 289 | /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; | ||
667 | 290 | |||
668 | 291 | /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; | ||
669 | 292 | /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; | ||
670 | 293 | /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; | ||
671 | 294 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; | ||
672 | 295 | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; | ||
673 | 296 | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; | ||
674 | 297 | /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; | ||
675 | 298 | |||
676 | 299 | ###################################### | ||
677 | 300 | DROP TABLE t1, t2, t3, t4; | ||
678 | 301 | CREATE TABLE t1 ( | ||
679 | 302 | id INT NOT NULL PRIMARY KEY | ||
680 | 303 | ) ENGINE=InnoDB; | ||
681 | 304 | CREATE TABLE t2 ( | ||
682 | 305 | id INT NOT NULL AUTO_INCREMENT, | ||
683 | 306 | a INT NOT NULL, | ||
684 | 307 | PRIMARY KEY (id), | ||
685 | 308 | KEY (a), | ||
686 | 309 | FOREIGN KEY (a) REFERENCES t2 (id) | ||
687 | 310 | ) ENGINE=InnoDB; | ||
688 | 311 | INSERT INTO t1 VALUES (1), (2), (3); | ||
689 | 312 | INSERT INTO t2 VALUES (1, 1), (2, 2), (3, 3); | ||
690 | 313 | ###################################### | ||
691 | 314 | |||
692 | 315 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; | ||
693 | 316 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; | ||
694 | 317 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; | ||
695 | 318 | /*!40101 SET NAMES utf8 */; | ||
696 | 319 | /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; | ||
697 | 320 | /*!40103 SET TIME_ZONE='+00:00' */; | ||
698 | 321 | /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; | ||
699 | 322 | /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; | ||
700 | 323 | /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; | ||
701 | 324 | /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; | ||
702 | 325 | DROP TABLE IF EXISTS `t1`; | ||
703 | 326 | /*!40101 SET @saved_cs_client = @@character_set_client */; | ||
704 | 327 | /*!40101 SET character_set_client = utf8 */; | ||
705 | 328 | CREATE TABLE `t1` ( | ||
706 | 329 | `id` int(11) NOT NULL, | ||
707 | 330 | PRIMARY KEY (`id`) | ||
708 | 331 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; | ||
709 | 332 | /*!40101 SET character_set_client = @saved_cs_client */; | ||
710 | 333 | |||
711 | 334 | LOCK TABLES `t1` WRITE; | ||
712 | 335 | /*!40000 ALTER TABLE `t1` DISABLE KEYS */; | ||
713 | 336 | INSERT INTO `t1` VALUES (1),(2),(3); | ||
714 | 337 | /*!40000 ALTER TABLE `t1` ENABLE KEYS */; | ||
715 | 338 | UNLOCK TABLES; | ||
716 | 339 | DROP TABLE IF EXISTS `t2`; | ||
717 | 340 | /*!40101 SET @saved_cs_client = @@character_set_client */; | ||
718 | 341 | /*!40101 SET character_set_client = utf8 */; | ||
719 | 342 | CREATE TABLE `t2` ( | ||
720 | 343 | `id` int(11) NOT NULL AUTO_INCREMENT, | ||
721 | 344 | `a` int(11) NOT NULL, | ||
722 | 345 | PRIMARY KEY (`id`), | ||
723 | 346 | CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t2` (`id`) | ||
724 | 347 | ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1; | ||
725 | 348 | /*!40101 SET character_set_client = @saved_cs_client */; | ||
726 | 349 | |||
727 | 350 | LOCK TABLES `t2` WRITE; | ||
728 | 351 | /*!40000 ALTER TABLE `t2` DISABLE KEYS */; | ||
729 | 352 | INSERT INTO `t2` VALUES (1,1),(2,2),(3,3); | ||
730 | 353 | ALTER TABLE `t2` ADD KEY `a` (`a`); | ||
731 | 354 | /*!40000 ALTER TABLE `t2` ENABLE KEYS */; | ||
732 | 355 | UNLOCK TABLES; | ||
733 | 356 | /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; | ||
734 | 357 | |||
735 | 358 | /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; | ||
736 | 359 | /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; | ||
737 | 360 | /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; | ||
738 | 361 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; | ||
739 | 362 | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; | ||
740 | 363 | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; | ||
741 | 364 | /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; | ||
742 | 365 | |||
743 | 366 | ###################################### | ||
744 | 367 | DROP TABLE t1, t2; | ||
745 | 0 | 368 | ||
746 | === added file 'mysql-test/suite/innodb_plugin/r/percona_bug_999147.result' | |||
747 | --- mysql-test/suite/innodb_plugin/r/percona_bug_999147.result 1970-01-01 00:00:00 +0000 | |||
748 | +++ mysql-test/suite/innodb_plugin/r/percona_bug_999147.result 2012-07-03 16:14:26 +0000 | |||
749 | @@ -0,0 +1,8 @@ | |||
750 | 1 | DROP TABLE IF EXISTS t1; | ||
751 | 2 | SET SESSION expand_fast_index_creation=ON; | ||
752 | 3 | CREATE TEMPORARY TABLE t1 (a INT, b INT, INDEX(a)) ENGINE=InnoDB; | ||
753 | 4 | SET debug="+d,crash_innodb_add_index_after"; | ||
754 | 5 | ALTER TABLE t1 ADD INDEX (b); | ||
755 | 6 | ERROR HY000: Lost connection to MySQL server during query | ||
756 | 7 | SHOW TABLES; | ||
757 | 8 | Tables_in_test | ||
758 | 0 | 9 | ||
759 | === added file 'mysql-test/suite/innodb_plugin/t/percona_bug_999147-master.opt' | |||
760 | --- mysql-test/suite/innodb_plugin/t/percona_bug_999147-master.opt 1970-01-01 00:00:00 +0000 | |||
761 | +++ mysql-test/suite/innodb_plugin/t/percona_bug_999147-master.opt 2012-07-03 16:14:26 +0000 | |||
762 | @@ -0,0 +1,1 @@ | |||
763 | 1 | --skip-stack-trace --skip-core-file --innodb-file-per-table=1 | ||
764 | 0 | 2 | ||
765 | === added file 'mysql-test/suite/innodb_plugin/t/percona_bug_999147.test' | |||
766 | --- mysql-test/suite/innodb_plugin/t/percona_bug_999147.test 1970-01-01 00:00:00 +0000 | |||
767 | +++ mysql-test/suite/innodb_plugin/t/percona_bug_999147.test 2012-07-03 16:14:26 +0000 | |||
768 | @@ -0,0 +1,29 @@ | |||
769 | 1 | # Test for Percona Server bug 999147 (A crash that leaves behind an | ||
770 | 2 | # InnoDB temporary table with indexes results in an unbootable server) | ||
771 | 3 | # https://bugs.launchpad.net/percona-server/+bug/999147 | ||
772 | 4 | |||
773 | 5 | -- source include/not_embedded.inc | ||
774 | 6 | -- source include/not_valgrind.inc | ||
775 | 7 | -- source include/not_crashrep.inc | ||
776 | 8 | -- source include/have_debug.inc | ||
777 | 9 | -- source include/have_innodb_plugin.inc | ||
778 | 10 | |||
779 | 11 | --disable_warnings | ||
780 | 12 | DROP TABLE IF EXISTS t1; | ||
781 | 13 | --enable_warnings | ||
782 | 14 | |||
783 | 15 | SET SESSION expand_fast_index_creation=ON; | ||
784 | 16 | |||
785 | 17 | CREATE TEMPORARY TABLE t1 (a INT, b INT, INDEX(a)) ENGINE=InnoDB; | ||
786 | 18 | |||
787 | 19 | --exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect | ||
788 | 20 | |||
789 | 21 | SET debug="+d,crash_innodb_add_index_after"; | ||
790 | 22 | --error 2013 | ||
791 | 23 | ALTER TABLE t1 ADD INDEX (b); | ||
792 | 24 | |||
793 | 25 | --enable_reconnect | ||
794 | 26 | |||
795 | 27 | --source include/wait_until_connected_again.inc | ||
796 | 28 | |||
797 | 29 | SHOW TABLES; | ||
798 | 0 | 30 | ||
799 | === added file 'mysql-test/t/percona_innodb_expand_fast_index_creation.test' | |||
800 | --- mysql-test/t/percona_innodb_expand_fast_index_creation.test 1970-01-01 00:00:00 +0000 | |||
801 | +++ mysql-test/t/percona_innodb_expand_fast_index_creation.test 2012-07-03 16:14:26 +0000 | |||
802 | @@ -0,0 +1,46 @@ | |||
803 | 1 | --source include/have_innodb_plugin.inc | ||
804 | 2 | |||
805 | 3 | SELECT @@expand_fast_index_creation; | ||
806 | 4 | |||
807 | 5 | ######################################################################## | ||
808 | 6 | # Bug #857590: Fast index creation does not update index statistics | ||
809 | 7 | ######################################################################## | ||
810 | 8 | |||
811 | 9 | CREATE TABLE t1( | ||
812 | 10 | id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, | ||
813 | 11 | a CHAR(1) NOT NULL, | ||
814 | 12 | b CHAR(36) NOT NULL) ENGINE=InnoDB; | ||
815 | 13 | |||
816 | 14 | INSERT INTO t1(a,b) VALUES ('a','b'); | ||
817 | 15 | INSERT INTO t1(a,b) SELECT a,b FROM t1; | ||
818 | 16 | INSERT INTO t1(a,b) SELECT a,b FROM t1; | ||
819 | 17 | INSERT INTO t1(a,b) SELECT a,b FROM t1; | ||
820 | 18 | INSERT INTO t1(a,b) SELECT a,b FROM t1; | ||
821 | 19 | |||
822 | 20 | # Check that fast index creation is used | ||
823 | 21 | --enable_info | ||
824 | 22 | ALTER TABLE t1 ADD KEY (a); | ||
825 | 23 | --disable_info | ||
826 | 24 | |||
827 | 25 | # The default (wrong) plan due to bogus statistics | ||
828 | 26 | --vertical_results | ||
829 | 27 | EXPLAIN SELECT COUNT(*) FROM t1, t1 t2 WHERE t1.a = t2.a AND t1.b = t2.b; | ||
830 | 28 | --horizontal_results | ||
831 | 29 | |||
832 | 30 | ALTER TABLE t1 DROP KEY a; | ||
833 | 31 | |||
834 | 32 | SET expand_fast_index_creation = 1; | ||
835 | 33 | SELECT @@expand_fast_index_creation; | ||
836 | 34 | |||
837 | 35 | # Check that stats are updated with the option enabled | ||
838 | 36 | |||
839 | 37 | --enable_info | ||
840 | 38 | ALTER TABLE t1 ADD KEY (a); | ||
841 | 39 | --disable_info | ||
842 | 40 | --vertical_results | ||
843 | 41 | EXPLAIN SELECT COUNT(*) FROM t1, t1 t2 WHERE t1.a = t2.a AND t1.b = t2.b; | ||
844 | 42 | --horizontal_results | ||
845 | 43 | |||
846 | 44 | SET expand_fast_index_creation = 0; | ||
847 | 45 | |||
848 | 46 | DROP TABLE t1; | ||
849 | 0 | 47 | ||
850 | === added file 'mysql-test/t/percona_mysqldump_innodb_optimize_keys.test' | |||
851 | --- mysql-test/t/percona_mysqldump_innodb_optimize_keys.test 1970-01-01 00:00:00 +0000 | |||
852 | +++ mysql-test/t/percona_mysqldump_innodb_optimize_keys.test 2012-07-03 16:14:26 +0000 | |||
853 | @@ -0,0 +1,187 @@ | |||
854 | 1 | # Embedded server doesn't support external clients | ||
855 | 2 | --source include/not_embedded.inc | ||
856 | 3 | |||
857 | 4 | # Fast index creation is only available in InnoDB plugin | ||
858 | 5 | --source include/have_innodb_plugin.inc | ||
859 | 6 | |||
860 | 7 | # Save the initial number of concurrent sessions | ||
861 | 8 | --source include/count_sessions.inc | ||
862 | 9 | |||
863 | 10 | --echo # | ||
864 | 11 | --echo # Test the --innodb-optimize-keys option. | ||
865 | 12 | --echo # | ||
866 | 13 | |||
867 | 14 | --let $file=$MYSQLTEST_VARDIR/tmp/t1.sql | ||
868 | 15 | |||
869 | 16 | # First test that the option has no effect on non-InnoDB tables | ||
870 | 17 | |||
871 | 18 | CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY, b INT, KEY(b)) ENGINE=MyISAM; | ||
872 | 19 | |||
873 | 20 | --exec $MYSQL_DUMP --skip-comments --innodb-optimize-keys test t1 >$file | ||
874 | 21 | |||
875 | 22 | --echo ###################################### | ||
876 | 23 | --cat_file $file | ||
877 | 24 | --echo ###################################### | ||
878 | 25 | |||
879 | 26 | --remove_file $file | ||
880 | 27 | |||
881 | 28 | DROP TABLE t1; | ||
882 | 29 | |||
883 | 30 | # Check that for InnoDB tables secondary keys are created after the data is | ||
884 | 31 | # dumped but foreign ones are left in CREATE TABLE | ||
885 | 32 | |||
886 | 33 | CREATE TABLE t2 (a INT PRIMARY KEY) ENGINE=InnoDB; | ||
887 | 34 | INSERT INTO t2 VALUES (0), (1), (2); | ||
888 | 35 | |||
889 | 36 | CREATE TABLE t1 ( | ||
890 | 37 | id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, | ||
891 | 38 | a INT, b VARCHAR(255), c DECIMAL(10,3), | ||
892 | 39 | KEY (b), | ||
893 | 40 | UNIQUE KEY uniq(c,a), | ||
894 | 41 | FOREIGN KEY (a) REFERENCES t2(a) ON DELETE CASCADE | ||
895 | 42 | ) ENGINE=InnoDB; | ||
896 | 43 | |||
897 | 44 | INSERT INTO t1(a,b,c) VALUES (0, "0", 0.0), (1, "1", 1.1), (2, "2", 2.2); | ||
898 | 45 | |||
899 | 46 | --exec $MYSQL_DUMP --skip-comments --innodb-optimize-keys test t1 t2 >$file | ||
900 | 47 | |||
901 | 48 | --echo ###################################### | ||
902 | 49 | --cat_file $file | ||
903 | 50 | --echo ###################################### | ||
904 | 51 | |||
905 | 52 | # Check that the resulting dump can be imported back | ||
906 | 53 | |||
907 | 54 | --exec $MYSQL test < $file | ||
908 | 55 | |||
909 | 56 | --remove_file $file | ||
910 | 57 | |||
911 | 58 | DROP TABLE t1, t2; | ||
912 | 59 | |||
913 | 60 | ######################################################################## | ||
914 | 61 | # Bug #812179: AUTO_INCREMENT columns must be skipped by the | ||
915 | 62 | # --innodb-optimize-keys optimization in mysqldump | ||
916 | 63 | ######################################################################## | ||
917 | 64 | |||
918 | 65 | CREATE TABLE t1 ( | ||
919 | 66 | id INT NOT NULL AUTO_INCREMENT, | ||
920 | 67 | KEY (id) | ||
921 | 68 | ) ENGINE=InnoDB; | ||
922 | 69 | |||
923 | 70 | CREATE TABLE t2 ( | ||
924 | 71 | id INT NOT NULL AUTO_INCREMENT, | ||
925 | 72 | UNIQUE KEY (id) | ||
926 | 73 | ) ENGINE=InnoDB; | ||
927 | 74 | |||
928 | 75 | INSERT INTO t1 VALUES (), (), (); | ||
929 | 76 | INSERT INTO t2 VALUES (), (), (); | ||
930 | 77 | |||
931 | 78 | --exec $MYSQL_DUMP --skip-comments --innodb-optimize-keys test t1 t2 >$file | ||
932 | 79 | |||
933 | 80 | --echo ###################################### | ||
934 | 81 | --cat_file $file | ||
935 | 82 | --echo ###################################### | ||
936 | 83 | |||
937 | 84 | # Check that the resulting dump can be imported back | ||
938 | 85 | |||
939 | 86 | --exec $MYSQL test < $file | ||
940 | 87 | |||
941 | 88 | --remove_file $file | ||
942 | 89 | |||
943 | 90 | DROP TABLE t1, t2; | ||
944 | 91 | |||
945 | 92 | ######################################################################## | ||
946 | 93 | # Bug #851674: --innodb-optimize-keys does not work correctly with table | ||
947 | 94 | # without PRIMARY KEY | ||
948 | 95 | ######################################################################## | ||
949 | 96 | |||
950 | 97 | CREATE TABLE t1 ( | ||
951 | 98 | a INT NOT NULL, | ||
952 | 99 | UNIQUE KEY (a)) ENGINE=InnoDB; | ||
953 | 100 | |||
954 | 101 | CREATE TABLE t2 ( | ||
955 | 102 | a INT NOT NULL, | ||
956 | 103 | b INT NOT NULL, | ||
957 | 104 | UNIQUE KEY (a,b)) ENGINE=InnoDB; | ||
958 | 105 | |||
959 | 106 | CREATE TABLE t3 ( | ||
960 | 107 | a INT, | ||
961 | 108 | b INT, | ||
962 | 109 | UNIQUE KEY (a,b)) ENGINE=InnoDB; | ||
963 | 110 | |||
964 | 111 | CREATE TABLE t4 ( | ||
965 | 112 | a INT NOT NULL, | ||
966 | 113 | b INT NOT NULL, | ||
967 | 114 | PRIMARY KEY (a,b), | ||
968 | 115 | UNIQUE KEY(b)) ENGINE=InnoDB; | ||
969 | 116 | |||
970 | 117 | SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE | ||
971 | 118 | TABLE_SCHEMA=DATABASE() AND | ||
972 | 119 | TABLE_NAME='t1' AND | ||
973 | 120 | COLUMN_KEY='PRI'; | ||
974 | 121 | SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE | ||
975 | 122 | TABLE_SCHEMA=DATABASE() AND | ||
976 | 123 | TABLE_NAME='t2' AND | ||
977 | 124 | COLUMN_KEY='PRI'; | ||
978 | 125 | SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE | ||
979 | 126 | TABLE_SCHEMA=DATABASE() AND | ||
980 | 127 | TABLE_NAME='t3' AND | ||
981 | 128 | COLUMN_KEY='PRI'; | ||
982 | 129 | SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE | ||
983 | 130 | TABLE_SCHEMA=DATABASE() AND | ||
984 | 131 | TABLE_NAME='t4' AND | ||
985 | 132 | COLUMN_KEY='PRI'; | ||
986 | 133 | |||
987 | 134 | INSERT INTO t1 VALUES (1), (2), (3); | ||
988 | 135 | INSERT INTO t2 VALUES (1,1), (2,2), (3,3); | ||
989 | 136 | INSERT INTO t3 SELECT * FROM t2; | ||
990 | 137 | INSERT INTO t4 SELECT * FROM t2; | ||
991 | 138 | |||
992 | 139 | --exec $MYSQL_DUMP --skip-comments --innodb-optimize-keys test t1 t2 t3 t4 >$file | ||
993 | 140 | |||
994 | 141 | --echo ###################################### | ||
995 | 142 | --cat_file $file | ||
996 | 143 | --echo ###################################### | ||
997 | 144 | |||
998 | 145 | # Check that the resulting dump can be imported back | ||
999 | 146 | |||
1000 | 147 | --exec $MYSQL test < $file | ||
1001 | 148 | |||
1002 | 149 | --remove_file $file | ||
1003 | 150 | |||
1004 | 151 | DROP TABLE t1, t2, t3, t4; | ||
1005 | 152 | |||
1006 | 153 | ######################################################################## | ||
1007 | 154 | # Bug #859078: --innodb-optimize-keys should ignore foreign keys | ||
1008 | 155 | ######################################################################## | ||
1009 | 156 | |||
1010 | 157 | CREATE TABLE t1 ( | ||
1011 | 158 | id INT NOT NULL PRIMARY KEY | ||
1012 | 159 | ) ENGINE=InnoDB; | ||
1013 | 160 | |||
1014 | 161 | CREATE TABLE t2 ( | ||
1015 | 162 | id INT NOT NULL AUTO_INCREMENT, | ||
1016 | 163 | a INT NOT NULL, | ||
1017 | 164 | PRIMARY KEY (id), | ||
1018 | 165 | KEY (a), | ||
1019 | 166 | FOREIGN KEY (a) REFERENCES t2 (id) | ||
1020 | 167 | ) ENGINE=InnoDB; | ||
1021 | 168 | |||
1022 | 169 | INSERT INTO t1 VALUES (1), (2), (3); | ||
1023 | 170 | INSERT INTO t2 VALUES (1, 1), (2, 2), (3, 3); | ||
1024 | 171 | |||
1025 | 172 | --exec $MYSQL_DUMP --skip-comments --innodb-optimize-keys test t1 t2 >$file | ||
1026 | 173 | |||
1027 | 174 | --echo ###################################### | ||
1028 | 175 | --cat_file $file | ||
1029 | 176 | --echo ###################################### | ||
1030 | 177 | |||
1031 | 178 | # Check that the resulting dump can be imported back | ||
1032 | 179 | |||
1033 | 180 | --exec $MYSQL test < $file | ||
1034 | 181 | |||
1035 | 182 | --remove_file $file | ||
1036 | 183 | |||
1037 | 184 | DROP TABLE t1, t2; | ||
1038 | 185 | |||
1039 | 186 | # Wait till we reached the initial number of concurrent sessions | ||
1040 | 187 | --source include/wait_until_count_sessions.inc | ||
1041 | 0 | 188 | ||
1042 | === modified file 'sql/mysqld.cc' | |||
1043 | --- sql/mysqld.cc 2012-03-08 15:16:53 +0000 | |||
1044 | +++ sql/mysqld.cc 2012-07-03 16:14:26 +0000 | |||
1045 | @@ -5667,7 +5667,8 @@ | |||
1046 | 5667 | OPT_IGNORE_BUILTIN_INNODB, | 5667 | OPT_IGNORE_BUILTIN_INNODB, |
1047 | 5668 | OPT_BINLOG_DIRECT_NON_TRANS_UPDATE, | 5668 | OPT_BINLOG_DIRECT_NON_TRANS_UPDATE, |
1048 | 5669 | OPT_DEFAULT_CHARACTER_SET_OLD, | 5669 | OPT_DEFAULT_CHARACTER_SET_OLD, |
1050 | 5670 | OPT_MAX_LONG_DATA_SIZE | 5670 | OPT_MAX_LONG_DATA_SIZE, |
1051 | 5671 | OPT_EXPAND_FAST_INDEX_CREATION | ||
1052 | 5671 | }; | 5672 | }; |
1053 | 5672 | 5673 | ||
1054 | 5673 | 5674 | ||
1055 | @@ -5896,6 +5897,13 @@ | |||
1056 | 5896 | each time the SQL thread starts.", | 5897 | each time the SQL thread starts.", |
1057 | 5897 | &opt_init_slave, &opt_init_slave, 0, GET_STR_ALLOC, | 5898 | &opt_init_slave, &opt_init_slave, 0, GET_STR_ALLOC, |
1058 | 5898 | REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, | 5899 | REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, |
1059 | 5900 | {"expand-fast-index-creation", OPT_EXPAND_FAST_INDEX_CREATION, | ||
1060 | 5901 | "Enable/disable improvements to the InnoDB fast index creation functionality. " | ||
1061 | 5902 | "Has no effect when fast index creation is disabled with the " | ||
1062 | 5903 | "fast-index-creation option", | ||
1063 | 5904 | &global_system_variables.expand_fast_index_creation, | ||
1064 | 5905 | &max_system_variables.expand_fast_index_creation, | ||
1065 | 5906 | 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, NULL}, | ||
1066 | 5899 | {"language", 'L', | 5907 | {"language", 'L', |
1067 | 5900 | "Client error messages in given language. May be given as a full path.", | 5908 | "Client error messages in given language. May be given as a full path.", |
1068 | 5901 | &language_ptr, &language_ptr, 0, GET_STR, REQUIRED_ARG, | 5909 | &language_ptr, &language_ptr, 0, GET_STR, REQUIRED_ARG, |
1069 | 5902 | 5910 | ||
1070 | === modified file 'sql/set_var.cc' | |||
1071 | --- sql/set_var.cc 2011-07-03 15:47:37 +0000 | |||
1072 | +++ sql/set_var.cc 2012-07-03 16:14:26 +0000 | |||
1073 | @@ -921,6 +921,10 @@ | |||
1074 | 921 | SHOW_LONGLONG, | 921 | SHOW_LONGLONG, |
1075 | 922 | get_myisam_mmap_size); | 922 | get_myisam_mmap_size); |
1076 | 923 | 923 | ||
1077 | 924 | static sys_var_thd_bool | ||
1078 | 925 | sys_expand_fast_index_creation(&vars, | ||
1079 | 926 | "expand_fast_index_creation", &SV::expand_fast_index_creation); | ||
1080 | 927 | |||
1081 | 924 | 928 | ||
1082 | 925 | bool sys_var::check(THD *thd, set_var *var) | 929 | bool sys_var::check(THD *thd, set_var *var) |
1083 | 926 | { | 930 | { |
1084 | 927 | 931 | ||
1085 | === modified file 'sql/sql_class.h' | |||
1086 | --- sql/sql_class.h 2012-04-20 16:41:20 +0000 | |||
1087 | +++ sql/sql_class.h 2012-07-03 16:14:26 +0000 | |||
1088 | @@ -404,6 +404,8 @@ | |||
1089 | 404 | DATE_TIME_FORMAT *datetime_format; | 404 | DATE_TIME_FORMAT *datetime_format; |
1090 | 405 | DATE_TIME_FORMAT *time_format; | 405 | DATE_TIME_FORMAT *time_format; |
1091 | 406 | my_bool sysdate_is_now; | 406 | my_bool sysdate_is_now; |
1092 | 407 | |||
1093 | 408 | my_bool expand_fast_index_creation; | ||
1094 | 407 | }; | 409 | }; |
1095 | 408 | 410 | ||
1096 | 409 | 411 | ||
1097 | 410 | 412 | ||
1098 | === modified file 'sql/sql_lex.cc' | |||
1099 | --- sql/sql_lex.cc 2012-04-18 11:14:05 +0000 | |||
1100 | +++ sql/sql_lex.cc 2012-07-03 16:14:26 +0000 | |||
1101 | @@ -1498,6 +1498,9 @@ | |||
1102 | 1498 | alter_list(rhs.alter_list, mem_root), | 1498 | alter_list(rhs.alter_list, mem_root), |
1103 | 1499 | key_list(rhs.key_list, mem_root), | 1499 | key_list(rhs.key_list, mem_root), |
1104 | 1500 | create_list(rhs.create_list, mem_root), | 1500 | create_list(rhs.create_list, mem_root), |
1105 | 1501 | delayed_key_list(rhs.delayed_key_list, mem_root), | ||
1106 | 1502 | delayed_key_info(rhs.delayed_key_info), | ||
1107 | 1503 | delayed_key_count(rhs.delayed_key_count), | ||
1108 | 1501 | flags(rhs.flags), | 1504 | flags(rhs.flags), |
1109 | 1502 | keys_onoff(rhs.keys_onoff), | 1505 | keys_onoff(rhs.keys_onoff), |
1110 | 1503 | tablespace_op(rhs.tablespace_op), | 1506 | tablespace_op(rhs.tablespace_op), |
1111 | @@ -1520,6 +1523,7 @@ | |||
1112 | 1520 | list_copy_and_replace_each_value(alter_list, mem_root); | 1523 | list_copy_and_replace_each_value(alter_list, mem_root); |
1113 | 1521 | list_copy_and_replace_each_value(key_list, mem_root); | 1524 | list_copy_and_replace_each_value(key_list, mem_root); |
1114 | 1522 | list_copy_and_replace_each_value(create_list, mem_root); | 1525 | list_copy_and_replace_each_value(create_list, mem_root); |
1115 | 1526 | list_copy_and_replace_each_value(delayed_key_list, mem_root); | ||
1116 | 1523 | /* partition_names are not deeply copied currently */ | 1527 | /* partition_names are not deeply copied currently */ |
1117 | 1524 | } | 1528 | } |
1118 | 1525 | 1529 | ||
1119 | 1526 | 1530 | ||
1120 | === modified file 'sql/sql_lex.h' | |||
1121 | --- sql/sql_lex.h 2012-04-18 11:14:05 +0000 | |||
1122 | +++ sql/sql_lex.h 2012-07-03 16:14:26 +0000 | |||
1123 | @@ -911,6 +911,9 @@ | |||
1124 | 911 | List<Alter_column> alter_list; | 911 | List<Alter_column> alter_list; |
1125 | 912 | List<Key> key_list; | 912 | List<Key> key_list; |
1126 | 913 | List<Create_field> create_list; | 913 | List<Create_field> create_list; |
1127 | 914 | List<Key> delayed_key_list; | ||
1128 | 915 | KEY *delayed_key_info; | ||
1129 | 916 | uint delayed_key_count; | ||
1130 | 914 | uint flags; | 917 | uint flags; |
1131 | 915 | enum enum_enable_or_disable keys_onoff; | 918 | enum enum_enable_or_disable keys_onoff; |
1132 | 916 | enum tablespace_op_type tablespace_op; | 919 | enum tablespace_op_type tablespace_op; |
1133 | @@ -922,6 +925,8 @@ | |||
1134 | 922 | 925 | ||
1135 | 923 | 926 | ||
1136 | 924 | Alter_info() : | 927 | Alter_info() : |
1137 | 928 | delayed_key_info(NULL), | ||
1138 | 929 | delayed_key_count(0), | ||
1139 | 925 | flags(0), | 930 | flags(0), |
1140 | 926 | keys_onoff(LEAVE_AS_IS), | 931 | keys_onoff(LEAVE_AS_IS), |
1141 | 927 | tablespace_op(NO_TABLESPACE_OP), | 932 | tablespace_op(NO_TABLESPACE_OP), |
1142 | @@ -937,6 +942,9 @@ | |||
1143 | 937 | alter_list.empty(); | 942 | alter_list.empty(); |
1144 | 938 | key_list.empty(); | 943 | key_list.empty(); |
1145 | 939 | create_list.empty(); | 944 | create_list.empty(); |
1146 | 945 | delayed_key_list.empty(); | ||
1147 | 946 | delayed_key_info= NULL; | ||
1148 | 947 | delayed_key_count= 0; | ||
1149 | 940 | flags= 0; | 948 | flags= 0; |
1150 | 941 | keys_onoff= LEAVE_AS_IS; | 949 | keys_onoff= LEAVE_AS_IS; |
1151 | 942 | tablespace_op= NO_TABLESPACE_OP; | 950 | tablespace_op= NO_TABLESPACE_OP; |
1152 | 943 | 951 | ||
1153 | === modified file 'sql/sql_table.cc' | |||
1154 | --- sql/sql_table.cc 2012-02-15 16:21:38 +0000 | |||
1155 | +++ sql/sql_table.cc 2012-07-03 16:14:26 +0000 | |||
1156 | @@ -3016,6 +3016,14 @@ | |||
1157 | 3016 | if (!*key_info_buffer || ! key_part_info) | 3016 | if (!*key_info_buffer || ! key_part_info) |
1158 | 3017 | DBUG_RETURN(TRUE); // Out of memory | 3017 | DBUG_RETURN(TRUE); // Out of memory |
1159 | 3018 | 3018 | ||
1160 | 3019 | List_iterator<Key> delayed_key_iterator(alter_info->delayed_key_list); | ||
1161 | 3020 | alter_info->delayed_key_count= 0; | ||
1162 | 3021 | if (alter_info->delayed_key_list.elements > 0) | ||
1163 | 3022 | { | ||
1164 | 3023 | alter_info->delayed_key_info= (KEY *) sql_calloc(sizeof(KEY) * | ||
1165 | 3024 | (*key_count)); | ||
1166 | 3025 | } | ||
1167 | 3026 | |||
1168 | 3019 | key_iterator.rewind(); | 3027 | key_iterator.rewind(); |
1169 | 3020 | key_number=0; | 3028 | key_number=0; |
1170 | 3021 | for (; (key=key_iterator++) ; key_number++) | 3029 | for (; (key=key_iterator++) ; key_number++) |
1171 | @@ -3394,6 +3402,23 @@ | |||
1172 | 3394 | my_error(ER_TOO_LONG_KEY,MYF(0),max_key_length); | 3402 | my_error(ER_TOO_LONG_KEY,MYF(0),max_key_length); |
1173 | 3395 | DBUG_RETURN(TRUE); | 3403 | DBUG_RETURN(TRUE); |
1174 | 3396 | } | 3404 | } |
1175 | 3405 | |||
1176 | 3406 | if (alter_info->delayed_key_list.elements > 0) | ||
1177 | 3407 | { | ||
1178 | 3408 | Key *delayed_key; | ||
1179 | 3409 | |||
1180 | 3410 | delayed_key_iterator.rewind(); | ||
1181 | 3411 | while ((delayed_key= delayed_key_iterator++)) | ||
1182 | 3412 | { | ||
1183 | 3413 | if (delayed_key == key) | ||
1184 | 3414 | { | ||
1185 | 3415 | alter_info->delayed_key_info[alter_info->delayed_key_count++]= | ||
1186 | 3416 | *key_info; | ||
1187 | 3417 | break; | ||
1188 | 3418 | } | ||
1189 | 3419 | } | ||
1190 | 3420 | } | ||
1191 | 3421 | |||
1192 | 3397 | key_info++; | 3422 | key_info++; |
1193 | 3398 | } | 3423 | } |
1194 | 3399 | if (!unique_key && !primary_key && | 3424 | if (!unique_key && !primary_key && |
1195 | @@ -6099,6 +6124,10 @@ | |||
1196 | 6099 | List<Create_field> new_create_list; | 6124 | List<Create_field> new_create_list; |
1197 | 6100 | /* New key definitions are added here */ | 6125 | /* New key definitions are added here */ |
1198 | 6101 | List<Key> new_key_list; | 6126 | List<Key> new_key_list; |
1199 | 6127 | /* List with secondary keys which should be created after copying the data */ | ||
1200 | 6128 | List<Key> delayed_key_list; | ||
1201 | 6129 | /* Foreign key list returned by handler::get_foreign_key_list() */ | ||
1202 | 6130 | List<FOREIGN_KEY_INFO> f_key_list; | ||
1203 | 6102 | List_iterator<Alter_drop> drop_it(alter_info->drop_list); | 6131 | List_iterator<Alter_drop> drop_it(alter_info->drop_list); |
1204 | 6103 | List_iterator<Create_field> def_it(alter_info->create_list); | 6132 | List_iterator<Create_field> def_it(alter_info->create_list); |
1205 | 6104 | List_iterator<Alter_column> alter_it(alter_info->alter_list); | 6133 | List_iterator<Alter_column> alter_it(alter_info->alter_list); |
1206 | @@ -6111,6 +6140,7 @@ | |||
1207 | 6111 | uint used_fields= create_info->used_fields; | 6140 | uint used_fields= create_info->used_fields; |
1208 | 6112 | KEY *key_info=table->key_info; | 6141 | KEY *key_info=table->key_info; |
1209 | 6113 | bool rc= TRUE; | 6142 | bool rc= TRUE; |
1210 | 6143 | bool skip_secondary; | ||
1211 | 6114 | 6144 | ||
1212 | 6115 | DBUG_ENTER("mysql_prepare_alter_table"); | 6145 | DBUG_ENTER("mysql_prepare_alter_table"); |
1213 | 6116 | 6146 | ||
1214 | @@ -6305,8 +6335,26 @@ | |||
1215 | 6305 | /* | 6335 | /* |
1216 | 6306 | Collect all keys which isn't in drop list. Add only those | 6336 | Collect all keys which isn't in drop list. Add only those |
1217 | 6307 | for which some fields exists. | 6337 | for which some fields exists. |
1218 | 6338 | |||
1219 | 6339 | We also store secondary keys in delayed_key_list to make use of | ||
1220 | 6340 | the InnoDB fast index creation. The following conditions must be | ||
1221 | 6341 | met: | ||
1222 | 6342 | |||
1223 | 6343 | - fast_index_creation is enabled for the current session | ||
1224 | 6344 | - expand_fast_index_creation is enabled for the current session; | ||
1225 | 6345 | - we are going to create an InnoDB table (this is checked later when the | ||
1226 | 6346 | target engine is known); | ||
1227 | 6347 | - the key most be a non-UNIQUE one; | ||
1228 | 6348 | - there are no foreign keys. This can be optimized later to exclude only | ||
1229 | 6349 | those keys which are a part of foreign key constraints. Currently we | ||
1230 | 6350 | simply disable this optimization for all keys if there are any foreign | ||
1231 | 6351 | key constraints in the table. | ||
1232 | 6308 | */ | 6352 | */ |
1233 | 6309 | 6353 | ||
1234 | 6354 | skip_secondary= thd->variables.expand_fast_index_creation && | ||
1235 | 6355 | !table->file->get_foreign_key_list(thd, &f_key_list) && | ||
1236 | 6356 | f_key_list.elements == 0; | ||
1237 | 6357 | |||
1238 | 6310 | for (uint i=0 ; i < table->s->keys ; i++,key_info++) | 6358 | for (uint i=0 ; i < table->s->keys ; i++,key_info++) |
1239 | 6311 | { | 6359 | { |
1240 | 6312 | char *key_name= key_info->name; | 6360 | char *key_name= key_info->name; |
1241 | @@ -6408,6 +6456,8 @@ | |||
1242 | 6408 | test(key_info->flags & HA_GENERATED_KEY), | 6456 | test(key_info->flags & HA_GENERATED_KEY), |
1243 | 6409 | key_parts); | 6457 | key_parts); |
1244 | 6410 | new_key_list.push_back(key); | 6458 | new_key_list.push_back(key); |
1245 | 6459 | if (skip_secondary && key_type == Key::MULTIPLE) | ||
1246 | 6460 | delayed_key_list.push_back(key); | ||
1247 | 6411 | } | 6461 | } |
1248 | 6412 | } | 6462 | } |
1249 | 6413 | { | 6463 | { |
1250 | @@ -6415,7 +6465,21 @@ | |||
1251 | 6415 | while ((key=key_it++)) // Add new keys | 6465 | while ((key=key_it++)) // Add new keys |
1252 | 6416 | { | 6466 | { |
1253 | 6417 | if (key->type != Key::FOREIGN_KEY) | 6467 | if (key->type != Key::FOREIGN_KEY) |
1254 | 6468 | { | ||
1255 | 6418 | new_key_list.push_back(key); | 6469 | new_key_list.push_back(key); |
1256 | 6470 | if (skip_secondary && key->type == Key::MULTIPLE) | ||
1257 | 6471 | delayed_key_list.push_back(key); | ||
1258 | 6472 | } | ||
1259 | 6473 | else if (skip_secondary) | ||
1260 | 6474 | { | ||
1261 | 6475 | /* | ||
1262 | 6476 | We are adding a foreign key so disable the secondary keys | ||
1263 | 6477 | optimization. | ||
1264 | 6478 | */ | ||
1265 | 6479 | skip_secondary= FALSE; | ||
1266 | 6480 | delayed_key_list.empty(); | ||
1267 | 6481 | } | ||
1268 | 6482 | |||
1269 | 6419 | if (key->name && | 6483 | if (key->name && |
1270 | 6420 | !my_strcasecmp(system_charset_info,key->name,primary_key_name)) | 6484 | !my_strcasecmp(system_charset_info,key->name,primary_key_name)) |
1271 | 6421 | { | 6485 | { |
1272 | @@ -6464,12 +6528,100 @@ | |||
1273 | 6464 | rc= FALSE; | 6528 | rc= FALSE; |
1274 | 6465 | alter_info->create_list.swap(new_create_list); | 6529 | alter_info->create_list.swap(new_create_list); |
1275 | 6466 | alter_info->key_list.swap(new_key_list); | 6530 | alter_info->key_list.swap(new_key_list); |
1276 | 6531 | alter_info->delayed_key_list.swap(delayed_key_list); | ||
1277 | 6467 | err: | 6532 | err: |
1278 | 6468 | DBUG_RETURN(rc); | 6533 | DBUG_RETURN(rc); |
1279 | 6469 | } | 6534 | } |
1280 | 6470 | 6535 | ||
1281 | 6471 | 6536 | ||
1282 | 6472 | /* | 6537 | /* |
1283 | 6538 | Temporarily remove secondary keys previously stored in | ||
1284 | 6539 | alter_info->delayed_key_info. | ||
1285 | 6540 | */ | ||
1286 | 6541 | static int | ||
1287 | 6542 | remove_secondary_keys(THD *thd, TABLE *table, Alter_info *alter_info) | ||
1288 | 6543 | { | ||
1289 | 6544 | uint *key_numbers; | ||
1290 | 6545 | uint key_counter= 0; | ||
1291 | 6546 | uint i; | ||
1292 | 6547 | int error; | ||
1293 | 6548 | DBUG_ENTER("remove_secondary_keys"); | ||
1294 | 6549 | DBUG_ASSERT(alter_info->delayed_key_count > 0); | ||
1295 | 6550 | |||
1296 | 6551 | key_numbers= (uint *) thd->alloc(sizeof(uint) * | ||
1297 | 6552 | alter_info->delayed_key_count); | ||
1298 | 6553 | for (i= 0; i < alter_info->delayed_key_count; i++) | ||
1299 | 6554 | { | ||
1300 | 6555 | KEY *key= alter_info->delayed_key_info + i; | ||
1301 | 6556 | uint j; | ||
1302 | 6557 | |||
1303 | 6558 | for (j= 0; j < table->s->keys; j++) | ||
1304 | 6559 | { | ||
1305 | 6560 | if (!strcmp(table->key_info[j].name, key->name)) | ||
1306 | 6561 | { | ||
1307 | 6562 | key_numbers[key_counter++]= j; | ||
1308 | 6563 | break; | ||
1309 | 6564 | } | ||
1310 | 6565 | } | ||
1311 | 6566 | } | ||
1312 | 6567 | |||
1313 | 6568 | DBUG_ASSERT(key_counter == alter_info->delayed_key_count); | ||
1314 | 6569 | |||
1315 | 6570 | if ((error= table->file->prepare_drop_index(table, key_numbers, | ||
1316 | 6571 | key_counter)) || | ||
1317 | 6572 | (error= table->file->final_drop_index(table))) | ||
1318 | 6573 | { | ||
1319 | 6574 | table->file->print_error(error, MYF(0)); | ||
1320 | 6575 | } | ||
1321 | 6576 | |||
1322 | 6577 | DBUG_RETURN(error); | ||
1323 | 6578 | } | ||
1324 | 6579 | |||
1325 | 6580 | /* | ||
1326 | 6581 | Restore secondary keys previously removed in remove_secondary_keys. | ||
1327 | 6582 | */ | ||
1328 | 6583 | |||
1329 | 6584 | static int | ||
1330 | 6585 | restore_secondary_keys(THD *thd, TABLE *table, Alter_info *alter_info) | ||
1331 | 6586 | { | ||
1332 | 6587 | uint i; | ||
1333 | 6588 | int error; | ||
1334 | 6589 | DBUG_ENTER("restore_secondary_keys"); | ||
1335 | 6590 | DBUG_ASSERT(alter_info->delayed_key_count > 0); | ||
1336 | 6591 | |||
1337 | 6592 | thd_proc_info(thd, "restoring secondary keys"); | ||
1338 | 6593 | |||
1339 | 6594 | /* Fix the key parts */ | ||
1340 | 6595 | for (i= 0; i < alter_info->delayed_key_count; i++) | ||
1341 | 6596 | { | ||
1342 | 6597 | KEY *key = alter_info->delayed_key_info + i; | ||
1343 | 6598 | KEY_PART_INFO *key_part; | ||
1344 | 6599 | KEY_PART_INFO *part_end; | ||
1345 | 6600 | |||
1346 | 6601 | part_end= key->key_part + key->key_parts; | ||
1347 | 6602 | for (key_part= key->key_part; key_part < part_end; key_part++) | ||
1348 | 6603 | key_part->field= table->field[key_part->fieldnr]; | ||
1349 | 6604 | } | ||
1350 | 6605 | |||
1351 | 6606 | if ((error= table->file->add_index(table, alter_info->delayed_key_info, | ||
1352 | 6607 | alter_info->delayed_key_count))) | ||
1353 | 6608 | { | ||
1354 | 6609 | /* | ||
1355 | 6610 | Exchange the key_info for the error message. If we exchange | ||
1356 | 6611 | key number by key name in the message later, we need correct info. | ||
1357 | 6612 | */ | ||
1358 | 6613 | KEY *save_key_info= table->key_info; | ||
1359 | 6614 | table->key_info= alter_info->delayed_key_info; | ||
1360 | 6615 | table->file->print_error(error, MYF(0)); | ||
1361 | 6616 | table->key_info= save_key_info; | ||
1362 | 6617 | |||
1363 | 6618 | DBUG_RETURN(error); | ||
1364 | 6619 | } | ||
1365 | 6620 | |||
1366 | 6621 | DBUG_RETURN(0); | ||
1367 | 6622 | } | ||
1368 | 6623 | |||
1369 | 6624 | /* | ||
1370 | 6473 | Alter table | 6625 | Alter table |
1371 | 6474 | 6626 | ||
1372 | 6475 | SYNOPSIS | 6627 | SYNOPSIS |
1373 | @@ -7305,15 +7457,34 @@ | |||
1374 | 7305 | */ | 7457 | */ |
1375 | 7306 | if (new_table && !(new_table->file->ha_table_flags() & HA_NO_COPY_ON_ALTER)) | 7458 | if (new_table && !(new_table->file->ha_table_flags() & HA_NO_COPY_ON_ALTER)) |
1376 | 7307 | { | 7459 | { |
1377 | 7460 | /* | ||
1378 | 7461 | Check if we can temporarily remove secondary indexes from the table | ||
1379 | 7462 | before copying the data and recreate them later to utilize InnoDB fast | ||
1380 | 7463 | index creation. | ||
1381 | 7464 | TODO: is there a better way to check for InnoDB? | ||
1382 | 7465 | */ | ||
1383 | 7466 | bool optimize_keys= (alter_info->delayed_key_count > 0) && | ||
1384 | 7467 | !my_strcasecmp(system_charset_info, | ||
1385 | 7468 | new_table->file->table_type(), "InnoDB"); | ||
1386 | 7308 | /* We don't want update TIMESTAMP fields during ALTER TABLE. */ | 7469 | /* We don't want update TIMESTAMP fields during ALTER TABLE. */ |
1387 | 7309 | new_table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET; | 7470 | new_table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET; |
1388 | 7310 | new_table->next_number_field=new_table->found_next_number_field; | 7471 | new_table->next_number_field=new_table->found_next_number_field; |
1389 | 7472 | |||
1390 | 7311 | thd_proc_info(thd, "copy to tmp table"); | 7473 | thd_proc_info(thd, "copy to tmp table"); |
1391 | 7474 | |||
1392 | 7475 | if (optimize_keys) | ||
1393 | 7476 | { | ||
1394 | 7477 | /* ignore the error */ | ||
1395 | 7478 | error= remove_secondary_keys(thd, new_table, alter_info); | ||
1396 | 7479 | } | ||
1397 | 7480 | |||
1398 | 7312 | error= copy_data_between_tables(table, new_table, | 7481 | error= copy_data_between_tables(table, new_table, |
1399 | 7313 | alter_info->create_list, ignore, | 7482 | alter_info->create_list, ignore, |
1400 | 7314 | order_num, order, &copied, &deleted, | 7483 | order_num, order, &copied, &deleted, |
1401 | 7315 | alter_info->keys_onoff, | 7484 | alter_info->keys_onoff, |
1402 | 7316 | alter_info->error_if_not_empty); | 7485 | alter_info->error_if_not_empty); |
1403 | 7486 | if (!error && optimize_keys) | ||
1404 | 7487 | error= restore_secondary_keys(thd, new_table, alter_info); | ||
1405 | 7317 | } | 7488 | } |
1406 | 7318 | else | 7489 | else |
1407 | 7319 | { | 7490 | { |
1408 | 7320 | 7491 | ||
1409 | === modified file 'storage/innodb_plugin/handler/ha_innodb.cc' | |||
1410 | --- storage/innodb_plugin/handler/ha_innodb.cc 2012-05-08 05:19:14 +0000 | |||
1411 | +++ storage/innodb_plugin/handler/ha_innodb.cc 2012-07-03 16:14:26 +0000 | |||
1412 | @@ -43,6 +43,8 @@ | |||
1413 | 43 | #pragma implementation // gcc: Class implementation | 43 | #pragma implementation // gcc: Class implementation |
1414 | 44 | #endif | 44 | #endif |
1415 | 45 | 45 | ||
1416 | 46 | #define MYSQL_SERVER | ||
1417 | 47 | |||
1418 | 46 | #include <mysql_priv.h> | 48 | #include <mysql_priv.h> |
1419 | 47 | 49 | ||
1420 | 48 | #include <m_ctype.h> | 50 | #include <m_ctype.h> |
1421 | @@ -682,6 +684,19 @@ | |||
1422 | 682 | } | 684 | } |
1423 | 683 | 685 | ||
1424 | 684 | /******************************************************************//** | 686 | /******************************************************************//** |
1425 | 687 | Returns true if expand_fast_index_creation is enabled for the current | ||
1426 | 688 | session. | ||
1427 | 689 | @return the value of the server's expand_fast_index_creation variable */ | ||
1428 | 690 | extern "C" | ||
1429 | 691 | ibool | ||
1430 | 692 | thd_expand_fast_index_creation( | ||
1431 | 693 | /*================================*/ | ||
1432 | 694 | void* thd) | ||
1433 | 695 | { | ||
1434 | 696 | return((ibool) (((THD*) thd)->variables.expand_fast_index_creation)); | ||
1435 | 697 | } | ||
1436 | 698 | |||
1437 | 699 | /******************************************************************//** | ||
1438 | 685 | Returns true if the thread supports XA, | 700 | Returns true if the thread supports XA, |
1439 | 686 | global value of innodb_supports_xa if thd is NULL. | 701 | global value of innodb_supports_xa if thd is NULL. |
1440 | 687 | @return true if thd has XA support */ | 702 | @return true if thd has XA support */ |
1441 | 688 | 703 | ||
1442 | === modified file 'storage/innodb_plugin/handler/handler0alter.cc' | |||
1443 | --- storage/innodb_plugin/handler/handler0alter.cc 2012-02-28 12:00:00 +0000 | |||
1444 | +++ storage/innodb_plugin/handler/handler0alter.cc 2012-07-03 16:14:26 +0000 | |||
1445 | @@ -813,6 +813,8 @@ | |||
1446 | 813 | innodb_table, indexed_table, | 813 | innodb_table, indexed_table, |
1447 | 814 | index, num_of_idx, table); | 814 | index, num_of_idx, table); |
1448 | 815 | 815 | ||
1449 | 816 | DBUG_EXECUTE_IF("crash_innodb_add_index_after", DBUG_SUICIDE();); | ||
1450 | 817 | |||
1451 | 816 | error_handling: | 818 | error_handling: |
1452 | 817 | /* After an error, remove all those index definitions from the | 819 | /* After an error, remove all those index definitions from the |
1453 | 818 | dictionary which were defined. */ | 820 | dictionary which were defined. */ |
1454 | 819 | 821 | ||
1455 | === modified file 'storage/innodb_plugin/include/ha_prototypes.h' | |||
1456 | --- storage/innodb_plugin/include/ha_prototypes.h 2010-05-14 13:08:15 +0000 | |||
1457 | +++ storage/innodb_plugin/include/ha_prototypes.h 2012-07-03 16:14:26 +0000 | |||
1458 | @@ -268,4 +268,15 @@ | |||
1459 | 268 | void* thd); /*!< in: thread handle (THD*), or NULL to query | 268 | void* thd); /*!< in: thread handle (THD*), or NULL to query |
1460 | 269 | the global innodb_lock_wait_timeout */ | 269 | the global innodb_lock_wait_timeout */ |
1461 | 270 | 270 | ||
1462 | 271 | /******************************************************************//** | ||
1463 | 272 | Returns true if innodb_expand_fast_index_creation is enabled for the current | ||
1464 | 273 | session. | ||
1465 | 274 | @return the value of the server's innodb_expand_fast_index_creation variable */ | ||
1466 | 275 | |||
1467 | 276 | ibool | ||
1468 | 277 | thd_expand_fast_index_creation( | ||
1469 | 278 | /*==================*/ | ||
1470 | 279 | void* thd); /*!< in: thread handle (THD*) */ | ||
1471 | 280 | |||
1472 | 281 | |||
1473 | 271 | #endif | 282 | #endif |
1474 | 272 | 283 | ||
1475 | === modified file 'storage/innodb_plugin/row/row0merge.c' | |||
1476 | --- storage/innodb_plugin/row/row0merge.c 2012-02-10 03:09:12 +0000 | |||
1477 | +++ storage/innodb_plugin/row/row0merge.c 2012-07-03 16:14:26 +0000 | |||
1478 | @@ -56,6 +56,7 @@ | |||
1479 | 56 | #include "log0log.h" | 56 | #include "log0log.h" |
1480 | 57 | #include "ut0sort.h" | 57 | #include "ut0sort.h" |
1481 | 58 | #include "handler0alter.h" | 58 | #include "handler0alter.h" |
1482 | 59 | #include "ha_prototypes.h" | ||
1483 | 59 | 60 | ||
1484 | 60 | #ifdef UNIV_DEBUG | 61 | #ifdef UNIV_DEBUG |
1485 | 61 | /** Set these in order ot enable debug printout. */ | 62 | /** Set these in order ot enable debug printout. */ |
1486 | @@ -2640,6 +2641,9 @@ | |||
1487 | 2640 | } | 2641 | } |
1488 | 2641 | } | 2642 | } |
1489 | 2642 | 2643 | ||
1490 | 2644 | if (trx->mysql_thd && thd_expand_fast_index_creation(trx->mysql_thd)) | ||
1491 | 2645 | dict_update_statistics(new_table, FALSE); | ||
1492 | 2646 | |||
1493 | 2643 | func_exit: | 2647 | func_exit: |
1494 | 2644 | close(tmpfd); | 2648 | close(tmpfd); |
1495 | 2645 | 2649 | ||
1496 | 2646 | 2650 | ||
1497 | === modified file 'storage/innodb_plugin/row/row0mysql.c' | |||
1498 | --- storage/innodb_plugin/row/row0mysql.c 2012-03-08 15:16:53 +0000 | |||
1499 | +++ storage/innodb_plugin/row/row0mysql.c 2012-07-03 16:14:26 +0000 | |||
1500 | @@ -3512,7 +3512,7 @@ | |||
1501 | 3512 | btr_pcur_store_position(&pcur, &mtr); | 3512 | btr_pcur_store_position(&pcur, &mtr); |
1502 | 3513 | btr_pcur_commit_specify_mtr(&pcur, &mtr); | 3513 | btr_pcur_commit_specify_mtr(&pcur, &mtr); |
1503 | 3514 | 3514 | ||
1505 | 3515 | table = dict_load_table(table_name); | 3515 | table = dict_table_get_low(table_name); |
1506 | 3516 | 3516 | ||
1507 | 3517 | if (table) { | 3517 | if (table) { |
1508 | 3518 | row_drop_table_for_mysql(table_name, trx, FALSE); | 3518 | row_drop_table_for_mysql(table_name, trx, FALSE); |