Skip to content

Commit dd96d09

Browse files
committed
Merge from mysql-5.5 to mysql-trunk
Text conflict in client/mysqlcheck.c Text conflict in sql/share/errmsg-utf8.txt Text conflict in sql/sql_lex.h
2 parents f5cc069 + 984988c commit dd96d09

File tree

14 files changed

+269
-58
lines changed

14 files changed

+269
-58
lines changed

client/mysqlcheck.c

+48-6
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static char *opt_password = 0, *current_user = 0,
4242
*default_charset= 0, *current_host= 0;
4343
static char *opt_plugin_dir= 0, *opt_default_auth= 0;
4444
static int first_error = 0;
45-
DYNAMIC_ARRAY tables4repair;
45+
DYNAMIC_ARRAY tables4repair, tables4rebuild;
4646
#ifdef HAVE_SMEM
4747
static char *shared_memory_base_name=0;
4848
#endif
@@ -630,6 +630,27 @@ static int fix_database_storage_name(const char *name)
630630
return rc;
631631
}
632632

633+
static int rebuild_table(char *name)
634+
{
635+
char *query, *ptr;
636+
int rc= 0;
637+
query= (char*)my_malloc(sizeof(char) * (12 + fixed_name_length(name) + 6 + 1),
638+
MYF(MY_WME));
639+
if (!query)
640+
return 1;
641+
ptr= strmov(query, "ALTER TABLE ");
642+
ptr= fix_table_name(ptr, name);
643+
ptr= strxmov(ptr, " FORCE", NullS);
644+
if (mysql_real_query(sock, query, (uint)(ptr - query)))
645+
{
646+
fprintf(stderr, "Failed to %s\n", query);
647+
fprintf(stderr, "Error: %s\n", mysql_error(sock));
648+
rc= 1;
649+
}
650+
my_free(query);
651+
return rc;
652+
}
653+
633654
static int process_one_db(char *database)
634655
{
635656
if (what_to_do == DO_UPGRADE)
@@ -743,7 +764,7 @@ static void print_result()
743764
MYSQL_ROW row;
744765
char prev[NAME_LEN*2+2];
745766
uint i;
746-
my_bool found_error=0;
767+
my_bool found_error=0, table_rebuild=0;
747768

748769
res = mysql_use_result(sock);
749770

@@ -762,8 +783,14 @@ static void print_result()
762783
*/
763784
if (found_error && opt_auto_repair && what_to_do != DO_REPAIR &&
764785
strcmp(row[3],"OK"))
765-
insert_dynamic(&tables4repair, prev);
786+
{
787+
if (table_rebuild)
788+
insert_dynamic(&tables4rebuild, prev);
789+
else
790+
insert_dynamic(&tables4repair, prev);
791+
}
766792
found_error=0;
793+
table_rebuild=0;
767794
if (opt_silent)
768795
continue;
769796
}
@@ -773,7 +800,11 @@ static void print_result()
773800
{
774801
printf("%s\n%-9s: %s", row[0], row[2], row[3]);
775802
if (strcmp(row[2],"note"))
803+
{
776804
found_error=1;
805+
if (opt_auto_repair && strstr(row[3], "ALTER TABLE") != NULL)
806+
table_rebuild=1;
807+
}
777808
}
778809
else
779810
printf("%-9s: %s", row[2], row[3]);
@@ -782,7 +813,12 @@ static void print_result()
782813
}
783814
/* add the last table to be repaired to the list */
784815
if (found_error && opt_auto_repair && what_to_do != DO_REPAIR)
785-
insert_dynamic(&tables4repair, prev);
816+
{
817+
if (table_rebuild)
818+
insert_dynamic(&tables4rebuild, prev);
819+
else
820+
insert_dynamic(&tables4repair, prev);
821+
}
786822
mysql_free_result(res);
787823
}
788824

@@ -882,7 +918,8 @@ int main(int argc, char **argv)
882918
}
883919

884920
if (opt_auto_repair &&
885-
my_init_dynamic_array(&tables4repair, sizeof(char)*(NAME_LEN*2+2),16,64))
921+
(my_init_dynamic_array(&tables4repair, sizeof(char)*(NAME_LEN*2+2),16,64) ||
922+
my_init_dynamic_array(&tables4rebuild, sizeof(char)*(NAME_LEN*2+2),16,64)))
886923
{
887924
first_error = 1;
888925
goto end;
@@ -900,19 +937,24 @@ int main(int argc, char **argv)
900937
{
901938
uint i;
902939

903-
if (!opt_silent && tables4repair.elements)
940+
if (!opt_silent && (tables4repair.elements || tables4rebuild.elements))
904941
puts("\nRepairing tables");
905942
what_to_do = DO_REPAIR;
906943
for (i = 0; i < tables4repair.elements ; i++)
907944
{
908945
char *name= (char*) dynamic_array_ptr(&tables4repair, i);
909946
handle_request_for_tables(name, fixed_name_length(name));
910947
}
948+
for (i = 0; i < tables4rebuild.elements ; i++)
949+
rebuild_table((char*) dynamic_array_ptr(&tables4rebuild, i));
911950
}
912951
end:
913952
dbDisconnect(current_host);
914953
if (opt_auto_repair)
954+
{
915955
delete_dynamic(&tables4repair);
956+
delete_dynamic(&tables4rebuild);
957+
}
916958
my_free(opt_password);
917959
#ifdef HAVE_SMEM
918960
my_free(shared_memory_base_name);

mysql-test/r/mysqlcheck.result

+77-13
Original file line numberDiff line numberDiff line change
@@ -117,22 +117,22 @@ mysql.time_zone_name Table is already up to date
117117
mysql.time_zone_transition Table is already up to date
118118
mysql.time_zone_transition_type Table is already up to date
119119
mysql.user Table is already up to date
120-
create table t1 (a int);
120+
create table t1 (a int) engine=myisam;
121121
create view v1 as select * from t1;
122122
test.t1 OK
123123
test.t1 Table is already up to date
124124
test.t1 OK
125125
test.t1 Table is already up to date
126126
drop view v1;
127127
drop table t1;
128-
create table `t``1`(a int);
129-
create table `t 1`(a int);
128+
create table `t``1`(a int) engine=myisam;
129+
create table `t 1`(a int) engine=myisam;
130130
test.t 1 OK
131131
test.t`1 OK
132132
drop table `t``1`, `t 1`;
133133
create database d_bug25347;
134134
use d_bug25347;
135-
create table t_bug25347 (a int);
135+
create table t_bug25347 (a int) engine=myisam;
136136
create view v_bug25347 as select * from t_bug25347;
137137
insert into t_bug25347 values (1),(2),(3);
138138
flush tables;
@@ -172,15 +172,15 @@ Table Op Msg_type Msg_text
172172
test.v1 check status OK
173173
information_schema.routines check note The storage engine for the table doesn't support check
174174
drop view v1;
175-
CREATE TABLE t1(a INT);
176-
CREATE TABLE t2(a INT);
175+
CREATE TABLE t1(a INT) engine=myisam;
176+
CREATE TABLE t2(a INT) engine=myisam;
177177
test.t1
178178
Error : Incorrect information in file: './test/t1.frm'
179179
error : Corrupt
180180
test.t2 OK
181181
DROP TABLE t1, t2;
182182
End of 5.0 tests
183-
create table t1(a int);
183+
create table t1(a int) engine=myisam;
184184
create view v1 as select * from t1;
185185
show tables;
186186
Tables_in_test
@@ -200,7 +200,7 @@ v-1
200200
drop view v1, `v-1`;
201201
drop table t1;
202202
SET NAMES utf8;
203-
CREATE TABLE `#mysql50#@` (a INT);
203+
CREATE TABLE `#mysql50#@` (a INT) engine=myisam;
204204
SHOW TABLES;
205205
Tables_in_test
206206
#mysql50#@
@@ -211,7 +211,7 @@ SHOW TABLES;
211211
Tables_in_test
212212
@
213213
DROP TABLE `@`;
214-
CREATE TABLE `я` (a INT);
214+
CREATE TABLE `я` (a INT) engine=myisam;
215215
SET NAMES DEFAULT;
216216
mysqlcheck --default-character-set="latin1" --databases test
217217
test.?
@@ -224,8 +224,8 @@ DROP TABLE `я`;
224224
SET NAMES DEFAULT;
225225
CREATE DATABASE `#mysql50#a@b`;
226226
USE `#mysql50#a@b`;
227-
CREATE TABLE `#mysql50#c@d` (a INT);
228-
CREATE TABLE t1 (a INT);
227+
CREATE TABLE `#mysql50#c@d` (a INT) engine=myisam;
228+
CREATE TABLE t1 (a INT) engine=myisam;
229229
SELECT * FROM INFORMATION_SCHEMA.TRIGGERS
230230
WHERE TRIGGER_SCHEMA="#mysql50#a@b" ORDER BY trigger_name;
231231
TRIGGER_CATALOG TRIGGER_SCHEMA TRIGGER_NAME EVENT_MANIPULATION EVENT_OBJECT_CATALOG EVENT_OBJECT_SCHEMA EVENT_OBJECT_TABLE ACTION_ORDER ACTION_CONDITION ACTION_STATEMENT ACTION_ORIENTATION ACTION_TIMING ACTION_REFERENCE_OLD_TABLE ACTION_REFERENCE_NEW_TABLE ACTION_REFERENCE_OLD_ROW ACTION_REFERENCE_NEW_ROW CREATED SQL_MODE DEFINER CHARACTER_SET_CLIENT COLLATION_CONNECTION DATABASE_COLLATION
@@ -254,12 +254,12 @@ USE test;
254254
# Bug #31821: --all-in-1 and --fix-table-names don't work together
255255
#
256256
drop table if exists `#mysql50#t1-1`;
257-
create table `#mysql50#t1-1` (a int);
257+
create table `#mysql50#t1-1` (a int) engine=myisam;
258258
show tables like 't1-1';
259259
Tables_in_test (t1-1)
260260
t1-1
261261
drop table `t1-1`;
262-
create table `#mysql50#t1-1` (a int);
262+
create table `#mysql50#t1-1` (a int) engine=myisam;
263263
show tables like 't1-1';
264264
Tables_in_test (t1-1)
265265
t1-1
@@ -268,3 +268,67 @@ End of 5.1 tests
268268
#
269269
# Bug #35269: mysqlcheck behaves different depending on order of parameters
270270
#
271+
#
272+
# Bug#11755431 47205: MAP 'REPAIR TABLE' TO RECREATE +ANALYZE FOR
273+
# ENGINES NOT SUPPORTING NATIVE
274+
#
275+
DROP TABLE IF EXISTS bug47205;
276+
#
277+
# Test 1: Check that ALTER TABLE ... rebuilds the table
278+
CREATE TABLE bug47205(a VARCHAR(20) PRIMARY KEY)
279+
DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci engine=innodb;
280+
INSERT INTO bug47205 VALUES ("foobar");
281+
FLUSH TABLE bug47205;
282+
# Replace the FRM with a 5.0 FRM that will require upgrade
283+
# Should indicate that ALTER TABLE ... FORCE is needed
284+
CHECK TABLE bug47205 FOR UPGRADE;
285+
Table Op Msg_type Msg_text
286+
test.bug47205 check error Table rebuild required. Please do "ALTER TABLE `bug47205` FORCE" or dump/reload to fix it!
287+
# ALTER TABLE ... FORCE should rebuild the table
288+
# and therefore output "affected rows: 1"
289+
ALTER TABLE bug47205 FORCE;
290+
affected rows: 1
291+
info: Records: 1 Duplicates: 0 Warnings: 0
292+
# Table should now be ok
293+
CHECK TABLE bug47205 FOR UPGRADE;
294+
Table Op Msg_type Msg_text
295+
test.bug47205 check status OK
296+
DROP TABLE bug47205;
297+
#
298+
# Test 2: InnoDB - REPAIR not supported
299+
CREATE TABLE bug47205(a VARCHAR(20) PRIMARY KEY)
300+
DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci engine=innodb;
301+
FLUSH TABLE bug47205;
302+
# Replace the FRM with a 5.0 FRM that will require upgrade
303+
# Should indicate that ALTER TABLE .. FORCE is needed
304+
CHECK TABLE bug47205 FOR UPGRADE;
305+
Table Op Msg_type Msg_text
306+
test.bug47205 check error Table rebuild required. Please do "ALTER TABLE `bug47205` FORCE" or dump/reload to fix it!
307+
# Running mysqlcheck to check and upgrade
308+
test.bug47205
309+
error : Table rebuild required. Please do "ALTER TABLE `bug47205` FORCE" or dump/reload to fix it!
310+
311+
Repairing tables
312+
# Table should now be ok
313+
CHECK TABLE bug47205 FOR UPGRADE;
314+
Table Op Msg_type Msg_text
315+
test.bug47205 check status OK
316+
DROP TABLE bug47205;
317+
#
318+
# Test 3: MyISAM - REPAIR supported
319+
# Use an old FRM that will require upgrade
320+
# Should indicate that REPAIR TABLE is needed
321+
CHECK TABLE bug47205 FOR UPGRADE;
322+
Table Op Msg_type Msg_text
323+
test.bug47205 check error Table upgrade required. Please do "REPAIR TABLE `bug47205`" or dump/reload to fix it!
324+
# Running mysqlcheck to check and upgrade
325+
test.bug47205
326+
error : Table upgrade required. Please do "REPAIR TABLE `bug47205`" or dump/reload to fix it!
327+
328+
Repairing tables
329+
test.bug47205 OK
330+
# Table should now be ok
331+
CHECK TABLE bug47205 FOR UPGRADE;
332+
Table Op Msg_type Msg_text
333+
test.bug47205 check status OK
334+
DROP TABLE bug47205;

mysql-test/std_data/bug47205.frm

8.35 KB
Binary file not shown.

0 commit comments

Comments
 (0)