Merge lp:~akopytov/percona-server/bug812179-5.5 into lp:percona-server/5.5

Proposed by Alexey Kopytov
Status: Merged
Merged at revision: 159
Proposed branch: lp:~akopytov/percona-server/bug812179-5.5
Merge into: lp:percona-server/5.5
Diff against target: 250 lines (+153/-8)
1 file modified
patches/innodb_expand_fast_index_creation.patch (+153/-8)
To merge this branch: bzr merge lp:~akopytov/percona-server/bug812179-5.5
Reviewer Review Type Date Requested Status
Laurynas Biveinis (community) Approve
Review via email: mp+74778@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Laurynas Biveinis (laurynas-biveinis) wrote :

LGTM. I'd write *(leftp+1), *(rightp-1) instead of leftp[1], rightp[-1] for consistency.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'patches/innodb_expand_fast_index_creation.patch'
--- patches/innodb_expand_fast_index_creation.patch 2011-08-09 20:52:20 +0000
+++ patches/innodb_expand_fast_index_creation.patch 2011-09-09 13:14:25 +0000
@@ -55,10 +55,30 @@
55 {"insert-ignore", OPT_INSERT_IGNORE, "Insert rows with INSERT IGNORE.",55 {"insert-ignore", OPT_INSERT_IGNORE, "Insert rows with INSERT IGNORE.",
56 &opt_ignore, &opt_ignore, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,56 &opt_ignore, &opt_ignore, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
57 0, 0},57 0, 0},
58@@ -2238,6 +2248,77 @@58@@ -2238,6 +2248,128 @@
59 }59 }
60 60
61 /*61 /*
62+ Parse the specified key definition string and check if the key indexes
63+ any of the columns from ignored_columns.
64+*/
65+static my_bool contains_ignored_column(HASH *ignored_columns, char *keydef)
66+{
67+ char *leftp, *rightp;
68+
69+ if ((leftp = strchr(keydef, '(')) &&
70+ (rightp = strchr(leftp, ')')) &&
71+ rightp > leftp + 3 && /* (`...`) */
72+ leftp[1] == '`' &&
73+ rightp[-1] == '`' &&
74+ my_hash_search(ignored_columns, (uchar *) leftp + 2, rightp - leftp - 3))
75+ return TRUE;
76+
77+ return FALSE;
78+}
79+
80+
81+/*
62+ Remove secondary/foreign key definitions from a given SHOW CREATE TABLE string82+ Remove secondary/foreign key definitions from a given SHOW CREATE TABLE string
63+ and store them into a temporary list to be used later.83+ and store them into a temporary list to be used later.
64+84+
@@ -79,13 +99,18 @@
79+{99+{
80+ char *ptr, *strend;100+ char *ptr, *strend;
81+ char *last_comma = NULL;101+ char *last_comma = NULL;
102+ HASH ignored_columns;
103+
104+ if (my_hash_init(&ignored_columns, charset_info, 16, 0, 0,
105+ (my_hash_get_key) get_table_key, my_free, 0))
106+ exit(EX_EOM);
82+107+
83+ strend= create_str + strlen(create_str);108+ strend= create_str + strlen(create_str);
84+109+
85+ ptr= create_str;110+ ptr= create_str;
86+ while (*ptr)111+ while (*ptr)
87+ {112+ {
88+ char *tmp, *orig_ptr;113+ char *tmp, *orig_ptr, c;
89+114+
90+ orig_ptr= ptr;115+ orig_ptr= ptr;
91+ /* Skip leading whitespace */116+ /* Skip leading whitespace */
@@ -95,11 +120,15 @@
95+ /* Read the next line */120+ /* Read the next line */
96+ for (tmp= ptr; *tmp != '\n' && *tmp != '\0'; tmp++);121+ for (tmp= ptr; *tmp != '\n' && *tmp != '\0'; tmp++);
97+122+
123+ c= *tmp;
124+ *tmp= '\0'; /* so strstr() only processes the current line */
125+
98+ /* Is it a secondary index definition? */126+ /* Is it a secondary index definition? */
99+ if (*tmp == '\n' &&127+ if (c == '\n' &&
100+ (!strncmp(ptr, "UNIQUE KEY ", sizeof("UNIQUE KEY ") - 1) ||128+ (!strncmp(ptr, "UNIQUE KEY ", sizeof("UNIQUE KEY ") - 1) ||
101+ !strncmp(ptr, "KEY ", sizeof("KEY ") - 1) ||129+ !strncmp(ptr, "KEY ", sizeof("KEY ") - 1) ||
102+ !strncmp(ptr, "CONSTRAINT ", sizeof("CONSTRAINT ") - 1)))130+ !strncmp(ptr, "CONSTRAINT ", sizeof("CONSTRAINT ") - 1)) &&
131+ !contains_ignored_column(&ignored_columns, ptr))
103+ {132+ {
104+ char *data, *end= tmp - 1;133+ char *data, *end= tmp - 1;
105+134+
@@ -122,18 +151,40 @@
122+ }151+ }
123+ else152+ else
124+ {153+ {
154+ char *end;
155+
156+ if (strstr(ptr, "AUTO_INCREMENT") && *ptr == '`')
157+ {
158+ /*
159+ If a secondary key is defined on this column later,
160+ it cannot be skipped, as CREATE TABLE would fail on import.
161+ */
162+ for (end= ptr + 1; *end != '`' && *end != '\0'; end++);
163+ if (*end == '`' && end > ptr + 1 &&
164+ my_hash_insert(&ignored_columns,
165+ (uchar *) my_strndup(ptr + 1,
166+ end - ptr - 1, MYF(0))))
167+ {
168+ exit(EX_EOM);
169+ }
170+ }
171+
172+ *tmp= c;
173+
125+ if (tmp[-1] == ',')174+ if (tmp[-1] == ',')
126+ last_comma= tmp - 1;175+ last_comma= tmp - 1;
127+ ptr= (*tmp == '\0') ? tmp : tmp + 1;176+ ptr= (*tmp == '\0') ? tmp : tmp + 1;
128+ }177+ }
129+ }178+ }
179+
180+ my_hash_free(&ignored_columns);
130+}181+}
131+182+
132+/*183+/*
133 get_table_structure -- retrievs database structure, prints out corresponding184 get_table_structure -- retrievs database structure, prints out corresponding
134 CREATE statement and fills out insert_pat if the table is the type we will185 CREATE statement and fills out insert_pat if the table is the type we will
135 be dumping.186 be dumping.
136@@ -2478,6 +2559,9 @@187@@ -2478,6 +2610,9 @@
137 188
138 row= mysql_fetch_row(result);189 row= mysql_fetch_row(result);
139 190
@@ -143,7 +194,7 @@
143 fprintf(sql_file, (opt_compatible_mode & 3) ? "%s;\n" :194 fprintf(sql_file, (opt_compatible_mode & 3) ? "%s;\n" :
144 "/*!40101 SET @saved_cs_client = @@character_set_client */;\n"195 "/*!40101 SET @saved_cs_client = @@character_set_client */;\n"
145 "/*!40101 SET character_set_client = utf8 */;\n"196 "/*!40101 SET character_set_client = utf8 */;\n"
146@@ -3572,6 +3656,27 @@197@@ -3572,6 +3707,27 @@
147 goto err;198 goto err;
148 }199 }
149 200
@@ -173,7 +224,7 @@
173 {224 {
174--- /dev/null225--- /dev/null
175+++ b/mysql-test/r/percona_mysqldump_innodb_optimize_keys.result226+++ b/mysql-test/r/percona_mysqldump_innodb_optimize_keys.result
176@@ -0,0 +1,109 @@227@@ -0,0 +1,171 @@
177+#228+#
178+# Test the --innodb-optimize-keys option.229+# Test the --innodb-optimize-keys option.
179+#230+#
@@ -283,6 +334,68 @@
283+334+
284+######################################335+######################################
285+DROP TABLE t1, t2;336+DROP TABLE t1, t2;
337+CREATE TABLE t1 (
338+id INT NOT NULL AUTO_INCREMENT,
339+KEY (id)
340+) ENGINE=InnoDB;
341+CREATE TABLE t2 (
342+id INT NOT NULL AUTO_INCREMENT,
343+UNIQUE KEY (id)
344+) ENGINE=InnoDB;
345+INSERT INTO t1 VALUES (), (), ();
346+INSERT INTO t2 VALUES (), (), ();
347+######################################
348+
349+/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
350+/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
351+/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
352+/*!40101 SET NAMES utf8 */;
353+/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
354+/*!40103 SET TIME_ZONE='+00:00' */;
355+/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
356+/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
357+/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
358+/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
359+DROP TABLE IF EXISTS `t1`;
360+/*!40101 SET @saved_cs_client = @@character_set_client */;
361+/*!40101 SET character_set_client = utf8 */;
362+CREATE TABLE `t1` (
363+ `id` int(11) NOT NULL AUTO_INCREMENT,
364+ KEY `id` (`id`)
365+) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;
366+/*!40101 SET character_set_client = @saved_cs_client */;
367+
368+LOCK TABLES `t1` WRITE;
369+/*!40000 ALTER TABLE `t1` DISABLE KEYS */;
370+INSERT INTO `t1` VALUES (1),(2),(3);
371+/*!40000 ALTER TABLE `t1` ENABLE KEYS */;
372+UNLOCK TABLES;
373+DROP TABLE IF EXISTS `t2`;
374+/*!40101 SET @saved_cs_client = @@character_set_client */;
375+/*!40101 SET character_set_client = utf8 */;
376+CREATE TABLE `t2` (
377+ `id` int(11) NOT NULL AUTO_INCREMENT,
378+ UNIQUE KEY `id` (`id`)
379+) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;
380+/*!40101 SET character_set_client = @saved_cs_client */;
381+
382+LOCK TABLES `t2` WRITE;
383+/*!40000 ALTER TABLE `t2` DISABLE KEYS */;
384+INSERT INTO `t2` VALUES (1),(2),(3);
385+/*!40000 ALTER TABLE `t2` ENABLE KEYS */;
386+UNLOCK TABLES;
387+/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
388+
389+/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
390+/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
391+/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
392+/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
393+/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
394+/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
395+/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
396+
397+######################################
398+DROP TABLE t1, t2;
286--- a/mysql-test/suite/innodb/r/innodb.result399--- a/mysql-test/suite/innodb/r/innodb.result
287+++ b/mysql-test/suite/innodb/r/innodb.result400+++ b/mysql-test/suite/innodb/r/innodb.result
288@@ -1673,7 +1673,7 @@401@@ -1673,7 +1673,7 @@
@@ -325,7 +438,7 @@
325 # Save the original values of some variables in order to be able to438 # Save the original values of some variables in order to be able to
326--- /dev/null439--- /dev/null
327+++ b/mysql-test/t/percona_mysqldump_innodb_optimize_keys.test440+++ b/mysql-test/t/percona_mysqldump_innodb_optimize_keys.test
328@@ -0,0 +1,62 @@441@@ -0,0 +1,94 @@
329+# Embedded server doesn't support external clients442+# Embedded server doesn't support external clients
330+--source include/not_embedded.inc443+--source include/not_embedded.inc
331+444+
@@ -386,6 +499,38 @@
386+499+
387+DROP TABLE t1, t2;500+DROP TABLE t1, t2;
388+501+
502+########################################################################
503+# Bug #812179: AUTO_INCREMENT columns must be skipped by the
504+# --innodb-optimize-keys optimization in mysqldump
505+########################################################################
506+
507+CREATE TABLE t1 (
508+ id INT NOT NULL AUTO_INCREMENT,
509+ KEY (id)
510+) ENGINE=InnoDB;
511+
512+CREATE TABLE t2 (
513+ id INT NOT NULL AUTO_INCREMENT,
514+ UNIQUE KEY (id)
515+) ENGINE=InnoDB;
516+
517+INSERT INTO t1 VALUES (), (), ();
518+INSERT INTO t2 VALUES (), (), ();
519+
520+--exec $MYSQL_DUMP --skip-comments --innodb-optimize-keys test t1 t2 >$file
521+
522+--echo ######################################
523+--cat_file $file
524+--echo ######################################
525+
526+# Check that the resulting dump can be imported back
527+
528+--exec $MYSQL test < $file
529+
530+--remove_file $file
531+
532+DROP TABLE t1, t2;
533+
389+# Wait till we reached the initial number of concurrent sessions534+# Wait till we reached the initial number of concurrent sessions
390+--source include/wait_until_count_sessions.inc535+--source include/wait_until_count_sessions.inc
391--- a/sql/sql_lex.cc536--- a/sql/sql_lex.cc

Subscribers

People subscribed via source and target branches