Skip to content

Commit ad7296e

Browse files
author
Mattias Jonsson
committed
Bug#14521864: MYSQL 5.1 TO 5.5 BUGS PARTITIONING
Manual merge into 5.6. Including added a new error for rows in wrong partition. And using ALGORITHM = INPLACE to allow .frm only change of KEY ALGORITHM = N (Still only allowed when KEY ALGORITHM is not yet set).
1 parent eab5dc1 commit ad7296e

File tree

76 files changed

+2380
-1381
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+2380
-1381
lines changed

client/mysqlcheck.c

Lines changed: 62 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
1515
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1616
*/
1717

18-
#define CHECK_VERSION "2.5.0"
18+
#define CHECK_VERSION "2.5.1"
1919

2020
#include "client_priv.h"
2121
#include "my_default.h"
@@ -30,6 +30,10 @@
3030
#define EX_USAGE 1
3131
#define EX_MYSQLERR 2
3232

33+
/* ALTER instead of repair. */
34+
#define MAX_ALTER_STR_SIZE 128 * 1024
35+
#define KEY_PARTITIONING_CHANGED_STR "KEY () partitioning changed"
36+
3337
static MYSQL mysql_connection, *sock = 0;
3438
static my_bool opt_alldbs = 0, opt_check_only_changed = 0, opt_extended = 0,
3539
opt_compress = 0, opt_databases = 0, opt_fast = 0,
@@ -45,7 +49,7 @@ static char *opt_password = 0, *current_user = 0,
4549
*default_charset= 0, *current_host= 0;
4650
static char *opt_plugin_dir= 0, *opt_default_auth= 0;
4751
static int first_error = 0;
48-
DYNAMIC_ARRAY tables4repair, tables4rebuild;
52+
DYNAMIC_ARRAY tables4repair, tables4rebuild, alter_table_cmds;
4953
#ifdef HAVE_SMEM
5054
static char *shared_memory_base_name=0;
5155
#endif
@@ -598,6 +602,17 @@ static int process_all_tables_in_db(char *database)
598602
} /* process_all_tables_in_db */
599603

600604

605+
static int run_query(const char *query)
606+
{
607+
if (mysql_query(sock, query))
608+
{
609+
fprintf(stderr, "Failed to %s\n", query);
610+
fprintf(stderr, "Error: %s\n", mysql_error(sock));
611+
return 1;
612+
}
613+
return 0;
614+
}
615+
601616

602617
static int fix_table_storage_name(const char *name)
603618
{
@@ -606,12 +621,7 @@ static int fix_table_storage_name(const char *name)
606621
if (strncmp(name, "#mysql50#", 9))
607622
return 1;
608623
sprintf(qbuf, "RENAME TABLE `%s` TO `%s`", name, name + 9);
609-
if (mysql_query(sock, qbuf))
610-
{
611-
fprintf(stderr, "Failed to %s\n", qbuf);
612-
fprintf(stderr, "Error: %s\n", mysql_error(sock));
613-
rc= 1;
614-
}
624+
rc= run_query(qbuf);
615625
if (verbose)
616626
printf("%-50s %s\n", name, rc ? "FAILED" : "OK");
617627
return rc;
@@ -624,12 +634,7 @@ static int fix_database_storage_name(const char *name)
624634
if (strncmp(name, "#mysql50#", 9))
625635
return 1;
626636
sprintf(qbuf, "ALTER DATABASE `%s` UPGRADE DATA DIRECTORY NAME", name);
627-
if (mysql_query(sock, qbuf))
628-
{
629-
fprintf(stderr, "Failed to %s\n", qbuf);
630-
fprintf(stderr, "Error: %s\n", mysql_error(sock));
631-
rc= 1;
632-
}
637+
rc= run_query(qbuf);
633638
if (verbose)
634639
printf("%-50s %s\n", name, rc ? "FAILED" : "OK");
635640
return rc;
@@ -692,13 +697,7 @@ static int use_db(char *database)
692697
static int disable_binlog()
693698
{
694699
const char *stmt= "SET SQL_LOG_BIN=0";
695-
if (mysql_query(sock, stmt))
696-
{
697-
fprintf(stderr, "Failed to %s\n", stmt);
698-
fprintf(stderr, "Error: %s\n", mysql_error(sock));
699-
return 1;
700-
}
701-
return 0;
700+
return run_query(stmt);
702701
}
703702

704703
static int handle_request_for_tables(char *tables, uint length)
@@ -768,12 +767,14 @@ static void print_result()
768767
MYSQL_RES *res;
769768
MYSQL_ROW row;
770769
char prev[NAME_LEN*2+2];
770+
char prev_alter[MAX_ALTER_STR_SIZE];
771771
uint i;
772772
my_bool found_error=0, table_rebuild=0;
773773

774774
res = mysql_use_result(sock);
775775

776776
prev[0] = '\0';
777+
prev_alter[0]= 0;
777778
for (i = 0; (row = mysql_fetch_row(res)); i++)
778779
{
779780
int changed = strcmp(prev, row[0]);
@@ -790,12 +791,18 @@ static void print_result()
790791
strcmp(row[3],"OK"))
791792
{
792793
if (table_rebuild)
793-
insert_dynamic(&tables4rebuild, prev);
794+
{
795+
if (prev_alter[0])
796+
insert_dynamic(&alter_table_cmds, (uchar*) prev_alter);
797+
else
798+
insert_dynamic(&tables4rebuild, (uchar*) prev);
799+
}
794800
else
795801
insert_dynamic(&tables4repair, prev);
796802
}
797803
found_error=0;
798804
table_rebuild=0;
805+
prev_alter[0]= 0;
799806
if (opt_silent)
800807
continue;
801808
}
@@ -804,11 +811,30 @@ static void print_result()
804811
else if (!status && changed)
805812
{
806813
printf("%s\n%-9s: %s", row[0], row[2], row[3]);
807-
if (strcmp(row[2],"note"))
814+
if (opt_auto_repair && strcmp(row[2],"note"))
808815
{
809-
found_error=1;
810-
if (opt_auto_repair && strstr(row[3], "ALTER TABLE") != NULL)
816+
const char *alter_txt= strstr(row[3], "ALTER TABLE");
817+
found_error=1;
818+
if (alter_txt)
819+
{
811820
table_rebuild=1;
821+
if (!strncmp(row[3], KEY_PARTITIONING_CHANGED_STR,
822+
strlen(KEY_PARTITIONING_CHANGED_STR)) &&
823+
strstr(alter_txt, "PARTITION BY"))
824+
{
825+
if (strlen(alter_txt) >= MAX_ALTER_STR_SIZE)
826+
{
827+
printf("Error: Alter command too long (>= %d),"
828+
" please do \"%s\" or dump/reload to fix it!\n",
829+
MAX_ALTER_STR_SIZE,
830+
alter_txt);
831+
table_rebuild= 0;
832+
prev_alter[0]= 0;
833+
}
834+
else
835+
strcpy(prev_alter, alter_txt);
836+
}
837+
}
812838
}
813839
}
814840
else
@@ -820,7 +846,12 @@ static void print_result()
820846
if (found_error && opt_auto_repair && what_to_do != DO_REPAIR)
821847
{
822848
if (table_rebuild)
823-
insert_dynamic(&tables4rebuild, prev);
849+
{
850+
if (prev_alter[0])
851+
insert_dynamic(&alter_table_cmds, (uchar*) prev_alter);
852+
else
853+
insert_dynamic(&tables4rebuild, (uchar*) prev);
854+
}
824855
else
825856
insert_dynamic(&tables4repair, prev);
826857
}
@@ -931,7 +962,8 @@ int main(int argc, char **argv)
931962

932963
if (opt_auto_repair &&
933964
(my_init_dynamic_array(&tables4repair, sizeof(char)*(NAME_LEN*2+2),16,64) ||
934-
my_init_dynamic_array(&tables4rebuild, sizeof(char)*(NAME_LEN*2+2),16,64)))
965+
my_init_dynamic_array(&tables4rebuild, sizeof(char)*(NAME_LEN*2+2),16,64) ||
966+
my_init_dynamic_array(&alter_table_cmds, MAX_ALTER_STR_SIZE, 0, 1)))
935967
{
936968
first_error = 1;
937969
goto end;
@@ -959,6 +991,8 @@ int main(int argc, char **argv)
959991
}
960992
for (i = 0; i < tables4rebuild.elements ; i++)
961993
rebuild_table((char*) dynamic_array_ptr(&tables4rebuild, i));
994+
for (i = 0; i < alter_table_cmds.elements ; i++)
995+
run_query((char*) dynamic_array_ptr(&alter_table_cmds, i));
962996
}
963997
end:
964998
dbDisconnect(current_host);

extra/perror.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -136,7 +136,7 @@ static const char *get_ha_error_msg(int code)
136136
/*
137137
If you got compilation error here about compile_time_assert array, check
138138
that every HA_ERR_xxx constant has a corresponding error message in
139-
handler_error_messages[] list (check mysys/ma_handler_errors.h and
139+
handler_error_messages[] list (check mysys/my_handler_errors.h and
140140
include/my_base.h).
141141
*/
142142
compile_time_assert(HA_ERR_FIRST + array_elements(handler_error_messages) ==

include/my_base.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -478,7 +478,8 @@ is the global server default. */
478478
#define HA_ERR_TABLE_IN_FK_CHECK 183 /* Table being used in foreign key check */
479479
#define HA_ERR_TABLESPACE_EXISTS 184 /* The tablespace existed in storage engine */
480480
#define HA_ERR_TOO_MANY_FIELDS 185 /* Table has too many columns */
481-
#define HA_ERR_LAST 185 /* Copy of last error nr */
481+
#define HA_ERR_ROW_IN_WRONG_PARTITION 186 /* Row in wrong partition */
482+
#define HA_ERR_LAST 186 /* Copy of last error nr */
482483

483484
/* Number of different errors */
484485
#define HA_ERR_ERRORS (HA_ERR_LAST - HA_ERR_FIRST + 1)

0 commit comments

Comments
 (0)