2002-09-01 20:17:33 +02:00
|
|
|
#
|
|
|
|
# Test of repair table
|
|
|
|
#
|
2022-06-09 05:32:51 +02:00
|
|
|
|
2020-05-13 13:10:35 +02:00
|
|
|
--source include/have_sequence.inc
|
2019-08-30 15:06:54 +02:00
|
|
|
--source include/default_charset.inc
|
MDEV-33449 improving repair of tables
This task is to ensure we have a clear definition and rules of how to
repair or optimize a table.
The rules are:
- REPAIR should be used with tables that are crashed and are
unreadable (hardware issues with not readable blocks, blocks with
'unexpected data' etc)
- OPTIMIZE table should be used to optimize the storage layout for the
table (recover space for delete rows and optimize the index
structure.
- ALTER TABLE table_name FORCE should be used to rebuild the .frm file
(the table definition) and the table (with the original table row
format). If the table is from and older MariaDB/MySQL release with a
different storage format, it will convert the data to the new
format. ALTER TABLE ... FORCE is used as part of mariadb-upgrade
Here follows some more background:
The 3 ways to repair a table are:
1) ALTER TABLE table_name FORCE" (not other options).
As an alias we allow: "ALTER TABLE table_name ENGINE=original_engine"
2) "REPAIR TABLE" (without FORCE)
3) "OPTIMIZE TABLE"
All of the above commands will optimize row space usage (which means that
space will be needed to hold a temporary copy of the table) and
re-generate all indexes. They will also try to replicate the original
table definition as exact as possible.
For ALTER TABLE and "REPAIR TABLE without FORCE", the following will hold:
If the table is from an older MariaDB version and data conversion is
needed (for example for old type HASH columns, MySQL JSON type or new
TIMESTAMP format) "ALTER TABLE table_name FORCE, algorithm=COPY" will be
used.
The differences between the algorithms are
1) Will use the fastest algorithm the engine supports to do a full repair
of the table (except if data conversions are is needed).
2) Will use the storage engine internal REPAIR facility (MyISAM, Aria).
If the engine does not support REPAIR then
"ALTER TABLE FORCE, ALGORITHM=COPY" will be used.
If there was data incompatibilities (which means that FORCE was used)
then there will be a warning after REPAIR that ALTER TABLE FORCE is
still needed.
The reason for this is that REPAIR may be able to go around data
errors (wrong incompatible data, crashed or unreadable sectors) that
ALTER TABLE cannot do.
3) Will use the storage engine internal OPTIMIZE. If engine does not
support optimize, then "ALTER TABLE FORCE" is used.
The above will ensure that ALTER TABLE FORCE is able to
correct almost any errors in the row or index data. In case of
corrupted blocks then REPAIR possible followed by ALTER TABLE is needed.
This is important as mariadb-upgrade executes ALTER TABLE table_name
FORCE for any table that must be re-created.
Bugs fixed with InnoDB tables when using ALTER TABLE FORCE:
- No error for INNODB_DEFAULT_ROW_FORMAT=COMPACT even if row length
would be too wide. (Independent of innodb_strict_mode).
- Tables using symlinks will be symlinked after any of the above commands
(Independent of the setting of --symbolic-links)
If one specifies an algorithm together with ALTER TABLE FORCE, things
will work as before (except if data conversion is required as then
the COPY algorithm is enforced).
ALTER TABLE .. OPTIMIZE ALL PARTITIONS will work as before.
Other things:
- FORCE argument added to REPAIR to allow one to first run internal
repair to fix damaged blocks and then follow it with ALTER TABLE.
- REPAIR will not update frm_version if ha_check_for_upgrade() finds
that table is still incompatible with current version. In this case the
REPAIR will end with an error.
- REPAIR for storage engines that does not have native repair, like InnoDB,
is now using ALTER TABLE FORCE.
- REPAIR csv-table USE_FRM now works.
- It did not work before as CSV tables had extension list in wrong
order.
- Default error messages length for %M increased from 128 to 256 to not
cut information from REPAIR.
- Documented HA_ADMIN_XX variables related to repair.
- Added HA_ADMIN_NEEDS_DATA_CONVERSION to signal that we have to
do data conversions when converting the table (and thus ALTER TABLE
copy algorithm is needed).
- Fixed typo in error message (caused test changes).
2024-01-29 10:52:44 +01:00
|
|
|
--source include/have_innodb.inc
|
2019-08-30 15:06:54 +02:00
|
|
|
|
|
|
|
call mtr.add_suppression("character set is multi-byte");
|
2024-03-12 12:54:30 +01:00
|
|
|
call mtr.add_suppression("exists only for compatibility");
|
2002-09-01 20:17:33 +02:00
|
|
|
|
2003-01-06 00:48:59 +01:00
|
|
|
--disable_warnings
|
2002-09-01 20:17:33 +02:00
|
|
|
drop table if exists t1;
|
2003-01-06 00:48:59 +01:00
|
|
|
--enable_warnings
|
|
|
|
|
2002-09-01 20:17:33 +02:00
|
|
|
create table t1 SELECT 1,"table 1";
|
|
|
|
repair table t1 use_frm;
|
2003-12-10 05:31:42 +01:00
|
|
|
alter table t1 ENGINE=HEAP;
|
2003-04-27 21:12:08 +02:00
|
|
|
repair table t1 use_frm;
|
|
|
|
drop table t1;
|
2003-05-03 15:21:39 +02:00
|
|
|
|
2004-03-22 18:34:36 +01:00
|
|
|
#
|
|
|
|
# disabled keys during repair
|
|
|
|
#
|
|
|
|
create table t1(id int PRIMARY KEY, st varchar(10), KEY st_key(st));
|
|
|
|
insert into t1 values(1, "One");
|
|
|
|
alter table t1 disable keys;
|
|
|
|
show keys from t1;
|
|
|
|
repair table t1 extended;
|
|
|
|
show keys from t1;
|
|
|
|
drop table t1;
|
|
|
|
|
|
|
|
|
2003-05-03 15:21:39 +02:00
|
|
|
# non-existent table
|
|
|
|
repair table t1 use_frm;
|
|
|
|
|
2003-12-10 05:31:42 +01:00
|
|
|
create table t1 engine=myisam SELECT 1,"table 1";
|
2004-04-09 06:12:41 +02:00
|
|
|
flush tables;
|
2007-12-12 18:19:24 +01:00
|
|
|
let $MYSQLD_DATADIR= `select @@datadir`;
|
|
|
|
system echo 1 > $MYSQLD_DATADIR/test/t1.MYI ;
|
2004-04-07 16:04:28 +02:00
|
|
|
repair table t1;
|
|
|
|
repair table t1 use_frm;
|
|
|
|
drop table t1;
|
2005-07-28 02:22:47 +02:00
|
|
|
|
2006-08-14 14:05:02 +02:00
|
|
|
#
|
|
|
|
# BUG#18874 - Setting myisam_repair_threads > 1, index cardinality always 1
|
|
|
|
#
|
|
|
|
CREATE TABLE t1(a INT, KEY(a));
|
|
|
|
INSERT INTO t1 VALUES(1),(2),(3),(4),(5);
|
|
|
|
SET myisam_repair_threads=2;
|
|
|
|
REPAIR TABLE t1;
|
|
|
|
SHOW INDEX FROM t1;
|
|
|
|
SET myisam_repair_threads=@@global.myisam_repair_threads;
|
|
|
|
DROP TABLE t1;
|
|
|
|
|
2006-10-11 17:34:20 +02:00
|
|
|
#
|
|
|
|
# BUG#22562 - REPAIR TABLE .. USE_FRM causes server crash on Windows and
|
|
|
|
# server hangs on Linux
|
|
|
|
#
|
|
|
|
CREATE TABLE t1(a INT);
|
|
|
|
USE mysql;
|
|
|
|
REPAIR TABLE test.t1 USE_FRM;
|
|
|
|
USE test;
|
|
|
|
DROP TABLE t1;
|
|
|
|
|
2006-10-18 14:57:29 +02:00
|
|
|
#
|
|
|
|
# BUG#23175 - MYISAM crash/repair failed during repair
|
|
|
|
#
|
|
|
|
CREATE TABLE t1(a CHAR(255), KEY(a));
|
|
|
|
SET myisam_sort_buffer_size=4096;
|
2013-05-10 11:32:34 +02:00
|
|
|
--replace_regex /Current myisam_sort_buffer_size.*/X/
|
2006-10-18 14:57:29 +02:00
|
|
|
INSERT INTO t1 VALUES
|
|
|
|
('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
|
|
|
|
('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
|
|
|
|
('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
|
|
|
|
('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
|
|
|
|
('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
|
|
|
|
('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
|
|
|
|
('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
|
|
|
|
('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
|
|
|
|
('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
|
|
|
|
('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
|
|
|
|
('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
|
|
|
|
('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
|
|
|
|
('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
|
|
|
|
('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
|
|
|
|
('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
|
|
|
|
('0'),('0'),('0'),('0'),('0'),('0'),('0');
|
|
|
|
SET myisam_repair_threads=2;
|
2013-05-10 11:32:34 +02:00
|
|
|
--replace_regex /Current myisam_sort_buffer_size.*/X/
|
2006-10-18 14:57:29 +02:00
|
|
|
REPAIR TABLE t1;
|
|
|
|
SET myisam_repair_threads=@@global.myisam_repair_threads;
|
|
|
|
SET myisam_sort_buffer_size=@@global.myisam_sort_buffer_size;
|
|
|
|
DROP TABLE t1;
|
|
|
|
|
2007-10-11 12:28:12 +02:00
|
|
|
#
|
|
|
|
# BUG#31174 - "Repair" command on MyISAM crashes with small
|
|
|
|
# myisam_sort_buffer_size
|
|
|
|
#
|
|
|
|
CREATE TABLE t1(a CHAR(255), KEY(a));
|
2007-10-17 08:29:51 +02:00
|
|
|
SET myisam_sort_buffer_size=4496;
|
2007-10-11 12:28:12 +02:00
|
|
|
INSERT INTO t1 VALUES
|
|
|
|
('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
|
|
|
|
('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
|
|
|
|
('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
|
|
|
|
('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
|
|
|
|
('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
|
|
|
|
('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
|
|
|
|
('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
|
|
|
|
('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
|
|
|
|
('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
|
|
|
|
('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
|
|
|
|
('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
|
|
|
|
('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
|
|
|
|
('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
|
|
|
|
('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
|
|
|
|
('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
|
|
|
|
('0'),('0'),('0'),('0'),('0'),('0'),('0');
|
|
|
|
SET myisam_repair_threads=2;
|
|
|
|
REPAIR TABLE t1;
|
|
|
|
SET myisam_repair_threads=@@global.myisam_repair_threads;
|
|
|
|
SET myisam_sort_buffer_size=@@global.myisam_sort_buffer_size;
|
|
|
|
DROP TABLE t1;
|
|
|
|
|
2018-01-23 11:24:53 +01:00
|
|
|
--echo # End of 4.1 tests
|
2008-05-12 18:01:13 +02:00
|
|
|
|
|
|
|
#
|
|
|
|
# BUG#36055 - mysql_upgrade doesn't really 'upgrade' tables
|
|
|
|
#
|
|
|
|
|
|
|
|
--echo # Test with a saved table from 4.1
|
2008-05-30 11:12:07 +02:00
|
|
|
let $MYSQLD_DATADIR= `select @@datadir`;
|
|
|
|
--copy_file std_data/bug36055.frm $MYSQLD_DATADIR/test/t1.frm
|
|
|
|
--copy_file std_data/bug36055.MYD $MYSQLD_DATADIR/test/t1.MYD
|
|
|
|
--copy_file std_data/bug36055.MYI $MYSQLD_DATADIR/test/t1.MYI
|
2008-05-12 18:01:13 +02:00
|
|
|
|
|
|
|
--replace_column 12 # 13 #
|
|
|
|
SHOW TABLE STATUS LIKE 't1';
|
|
|
|
SELECT * FROM t1;
|
|
|
|
|
2023-12-19 16:51:23 +01:00
|
|
|
--echo # Run CHECK TABLE, it should indicate table need a ALTER TABLE
|
2008-05-12 18:01:13 +02:00
|
|
|
CHECK TABLE t1 FOR UPGRADE;
|
|
|
|
|
|
|
|
--echo # REPAIR old table USE_FRM should fail
|
|
|
|
REPAIR TABLE t1 USE_FRM;
|
|
|
|
|
|
|
|
--echo # Run REPAIR TABLE to upgrade .frm file
|
|
|
|
REPAIR TABLE t1;
|
|
|
|
--replace_column 12 # 13 #
|
|
|
|
SHOW TABLE STATUS LIKE 't1';
|
|
|
|
SELECT * FROM t1;
|
|
|
|
|
|
|
|
REPAIR TABLE t1 USE_FRM;
|
|
|
|
SELECT * FROM t1;
|
|
|
|
|
|
|
|
DROP TABLE t1;
|
2018-01-23 11:24:53 +01:00
|
|
|
|
2023-12-19 16:51:23 +01:00
|
|
|
--copy_file std_data/bug36055.frm $MYSQLD_DATADIR/test/t1.frm
|
|
|
|
--copy_file std_data/bug36055.MYD $MYSQLD_DATADIR/test/t1.MYD
|
|
|
|
--copy_file std_data/bug36055.MYI $MYSQLD_DATADIR/test/t1.MYI
|
|
|
|
ALTER TABLE t1 FORCE;
|
|
|
|
CHECK TABLE t1;
|
|
|
|
DROP TABLE t1;
|
|
|
|
|
2018-01-23 11:24:53 +01:00
|
|
|
--echo # End of 5.0 tests
|
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
The intermediate (not temporary) files of the new table
during ALTER TABLE was visible for SHOW TABLES. These
intermediate files are copies of the original table with
the changes done by ALTER TABLE. After all the data is
copied over from the original table, these files are renamed
to the original tables file names. So they are not temporary
files. They persist after ALTER TABLE, but just with another
name.
In 5.0 the intermediate files are invisible for SHOW TABLES
because all file names beginning with "#sql" were suppressed.
This failed since 5.1.6 because even temporary table names were
converted when making file names from them. The prefix became
converted to "@0023sql". Converting the prefix during SHOW TABLES
would suppress the listing of user tables that start with "#sql".
The solution of the problem is to continue the implementation of
the table name to file name conversion feature. One requirement
is to suppress the conversion for temporary table names.
This change is straightforward for real temporary tables as there
is a function that creates temporary file names.
But the generated path names are located in TMPDIR and have no
relation to the internal table name. This cannot be used for
ALTER TABLE. Its intermediate files need to be in the same
directory as the old table files. And it is necessary to be
able to deduce the same path from the same table name repeatedly.
Consequently the intermediate table files must be handled like normal
tables. Their internal names shall start with tmp_file_prefix
(#sql) and they shall not be converted like normal table names.
I added a flags parameter to all relevant functions that are
called from ALTER TABLE. It is used to suppress the conversion
for the intermediate table files.
The outcome is that the suppression of #sql in SHOW TABLES
works again. It does not suppress user tables as these are
converted to @0023sql on file level.
This patch does also fix ALTER TABLE ... RENAME, which could not
rename a table with non-ASCII characters in its name.
It does also fix the problem that a user could create a table like
`#sql-xxxx-yyyy`, where xxxx is mysqld's pid and yyyy is the thread
ID of some other thread, which prevented this thread from running
ALTER TABLE.
Some of the above problems are mentioned in Bug 1405, which can
be closed with this patch.
This patch does also contain some minor fixes for other forgotten
conversions. Still known problems are reported as bugs 21370,
21373, and 21387.
mysql-test/r/alter_table.result:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Added test results.
mysql-test/r/backup.result:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Added test results.
mysql-test/r/repair.result:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Added test results.
mysql-test/t/alter_table.test:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Added test cases.
mysql-test/t/backup.test:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Added test cases.
mysql-test/t/repair.test:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Added a test case.
sql/ha_myisam.cc:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Added missing table name mapping calls to backup() and restore().
sql/ha_myisammrg.cc:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Added an zero argument for the new 'flags' parameter.
sql/ha_ndbcluster.cc:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Added an zero argument for the new 'flags' parameter.
sql/ha_ndbcluster_binlog.cc:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Added an zero argument for the new 'flags' parameter.
sql/ha_ndbcluster_binlog.h:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Removed unnecessary check for wrong temp file prefix.
sql/mysql_priv.h:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Extended quick_rm_table(), mysql_rename_table(), and
build_table_filename() by an flags argument, which can indicate
temporary table names that should not be converted.
Added symbolic flag values.
sql/sql_acl.cc:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Added an zero argument for the new 'flags' parameter.
sql/sql_base.cc:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Fixed a comment.
Added DBUG calls.
sql/sql_db.cc:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Added an zero argument for the new 'flags' parameter.
sql/sql_delete.cc:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Added an zero argument for the new 'flags' parameter.
sql/sql_insert.cc:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Added an zero argument for the new 'flags' parameter.
sql/sql_partition.cc:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Added an zero argument for the new 'flags' parameter.
sql/sql_rename.cc:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Added an zero argument for the new 'flags' parameter.
sql/sql_show.cc:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Reverted the former fix for this bug. tmp_file_prefix is now used
verbatim in the comparison of file names.
sql/sql_table.cc:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Added a check for a tmp_file_prefix file name to
filename_to_tablename(). These names are now accepted without
conversion.
Extended quick_rm_table(), mysql_rename_table(), and
build_table_filename() by an flags argument, which can indicate
temporary table names that should not be converted.
Removed the table to file name conversion from
build_tmptable_filename().
Disabled REPAIR TABLE ... USE_FRM for temporary tables.
Added the forgotten conversion to mysql_alter_table() for the case
of ALTER TABLE ... RENAME.
Added comments and DBUG calls.
sql/sql_trigger.cc:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Added an zero argument for the new 'flags' parameter.
sql/sql_view.cc:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Added an zero argument for the new 'flags' parameter.
sql/table.cc:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Replaced a literal ".frm" by reg_ext.
Added DBUG calls.
storage/innobase/row/row0mysql.c:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Changed back the encoded temp file prefix to #sql.
2006-08-02 17:57:06 +02:00
|
|
|
|
|
|
|
#
|
|
|
|
# Bug#18775 - Temporary table from alter table visible to other threads
|
|
|
|
#
|
|
|
|
# REPAIR TABLE ... USE_FRM on temporary table crashed the table or server.
|
|
|
|
--disable_warnings
|
|
|
|
DROP TABLE IF EXISTS tt1;
|
|
|
|
--enable_warnings
|
|
|
|
CREATE TEMPORARY TABLE tt1 (c1 INT);
|
|
|
|
REPAIR TABLE tt1 USE_FRM;
|
|
|
|
DROP TABLE tt1;
|
|
|
|
|
2009-12-09 14:03:37 +01:00
|
|
|
|
|
|
|
--echo #
|
|
|
|
--echo # Bug #48248 assert in MDL_ticket::upgrade_shared_lock_to_exclusive
|
|
|
|
--echo #
|
|
|
|
|
|
|
|
--disable_warnings
|
|
|
|
DROP TABLE IF EXISTS t1;
|
|
|
|
--enable_warnings
|
|
|
|
|
|
|
|
CREATE TABLE t1(a INT);
|
|
|
|
LOCK TABLES t1 READ;
|
|
|
|
REPAIR TABLE t1;
|
|
|
|
|
|
|
|
UNLOCK TABLES;
|
|
|
|
DROP TABLE t1;
|
2010-02-03 06:32:38 +01:00
|
|
|
|
|
|
|
|
|
|
|
--echo #
|
|
|
|
--echo # Test for bug #50784 "MDL: Assertion `m_tickets.is_empty() ||
|
|
|
|
--echo # m_tickets.front() == m_trans_sentinel'"
|
|
|
|
--echo #
|
|
|
|
--disable_warnings
|
|
|
|
drop tables if exists t1, t2;
|
|
|
|
--enable_warnings
|
|
|
|
create table t1 (i int);
|
|
|
|
create table t2 (j int);
|
|
|
|
set @@autocommit= 0;
|
|
|
|
repair table t1, t2;
|
|
|
|
set @@autocommit= default;
|
|
|
|
drop tables t1, t2;
|
2014-01-22 14:16:57 +01:00
|
|
|
|
|
|
|
--echo #
|
|
|
|
--echo # Check that we have decent error messages when using crashed
|
|
|
|
--echo # .frm file from MySQL 3.23
|
|
|
|
--echo #
|
|
|
|
|
|
|
|
--echo # Test with a saved table from 3.23
|
|
|
|
let $MYSQLD_DATADIR= `select @@datadir`;
|
2019-08-30 15:06:54 +02:00
|
|
|
|
|
|
|
SET @save_global_character_set_server= @@global.character_set_server;
|
|
|
|
set @@global.character_set_server=@@character_set_server;
|
2014-01-22 14:16:57 +01:00
|
|
|
--copy_file std_data/host_old.frm $MYSQLD_DATADIR/test/t1.frm
|
|
|
|
--copy_file std_data/host_old.MYD $MYSQLD_DATADIR/test/t1.MYD
|
|
|
|
--copy_file std_data/host_old.MYI $MYSQLD_DATADIR/test/t1.MYI
|
|
|
|
|
2014-02-01 00:54:03 +01:00
|
|
|
--error ER_GET_ERRNO
|
2014-01-22 14:16:57 +01:00
|
|
|
select count(*) from t1;
|
|
|
|
check table t1;
|
|
|
|
repair table t1;
|
|
|
|
repair table t1 use_frm;
|
|
|
|
select count(*) from t1;
|
|
|
|
check table t1;
|
MDEV-33449 improving repair of tables
This task is to ensure we have a clear definition and rules of how to
repair or optimize a table.
The rules are:
- REPAIR should be used with tables that are crashed and are
unreadable (hardware issues with not readable blocks, blocks with
'unexpected data' etc)
- OPTIMIZE table should be used to optimize the storage layout for the
table (recover space for delete rows and optimize the index
structure.
- ALTER TABLE table_name FORCE should be used to rebuild the .frm file
(the table definition) and the table (with the original table row
format). If the table is from and older MariaDB/MySQL release with a
different storage format, it will convert the data to the new
format. ALTER TABLE ... FORCE is used as part of mariadb-upgrade
Here follows some more background:
The 3 ways to repair a table are:
1) ALTER TABLE table_name FORCE" (not other options).
As an alias we allow: "ALTER TABLE table_name ENGINE=original_engine"
2) "REPAIR TABLE" (without FORCE)
3) "OPTIMIZE TABLE"
All of the above commands will optimize row space usage (which means that
space will be needed to hold a temporary copy of the table) and
re-generate all indexes. They will also try to replicate the original
table definition as exact as possible.
For ALTER TABLE and "REPAIR TABLE without FORCE", the following will hold:
If the table is from an older MariaDB version and data conversion is
needed (for example for old type HASH columns, MySQL JSON type or new
TIMESTAMP format) "ALTER TABLE table_name FORCE, algorithm=COPY" will be
used.
The differences between the algorithms are
1) Will use the fastest algorithm the engine supports to do a full repair
of the table (except if data conversions are is needed).
2) Will use the storage engine internal REPAIR facility (MyISAM, Aria).
If the engine does not support REPAIR then
"ALTER TABLE FORCE, ALGORITHM=COPY" will be used.
If there was data incompatibilities (which means that FORCE was used)
then there will be a warning after REPAIR that ALTER TABLE FORCE is
still needed.
The reason for this is that REPAIR may be able to go around data
errors (wrong incompatible data, crashed or unreadable sectors) that
ALTER TABLE cannot do.
3) Will use the storage engine internal OPTIMIZE. If engine does not
support optimize, then "ALTER TABLE FORCE" is used.
The above will ensure that ALTER TABLE FORCE is able to
correct almost any errors in the row or index data. In case of
corrupted blocks then REPAIR possible followed by ALTER TABLE is needed.
This is important as mariadb-upgrade executes ALTER TABLE table_name
FORCE for any table that must be re-created.
Bugs fixed with InnoDB tables when using ALTER TABLE FORCE:
- No error for INNODB_DEFAULT_ROW_FORMAT=COMPACT even if row length
would be too wide. (Independent of innodb_strict_mode).
- Tables using symlinks will be symlinked after any of the above commands
(Independent of the setting of --symbolic-links)
If one specifies an algorithm together with ALTER TABLE FORCE, things
will work as before (except if data conversion is required as then
the COPY algorithm is enforced).
ALTER TABLE .. OPTIMIZE ALL PARTITIONS will work as before.
Other things:
- FORCE argument added to REPAIR to allow one to first run internal
repair to fix damaged blocks and then follow it with ALTER TABLE.
- REPAIR will not update frm_version if ha_check_for_upgrade() finds
that table is still incompatible with current version. In this case the
REPAIR will end with an error.
- REPAIR for storage engines that does not have native repair, like InnoDB,
is now using ALTER TABLE FORCE.
- REPAIR csv-table USE_FRM now works.
- It did not work before as CSV tables had extension list in wrong
order.
- Default error messages length for %M increased from 128 to 256 to not
cut information from REPAIR.
- Documented HA_ADMIN_XX variables related to repair.
- Added HA_ADMIN_NEEDS_DATA_CONVERSION to signal that we have to
do data conversions when converting the table (and thus ALTER TABLE
copy algorithm is needed).
- Fixed typo in error message (caused test changes).
2024-01-29 10:52:44 +01:00
|
|
|
alter table t1 force;
|
|
|
|
check table t1;
|
2014-01-22 14:16:57 +01:00
|
|
|
drop table t1;
|
2015-05-07 22:18:34 +02:00
|
|
|
|
2019-08-30 15:06:54 +02:00
|
|
|
set @@global.character_set_server=@save_global_character_set_server;
|
|
|
|
|
2015-05-07 22:18:34 +02:00
|
|
|
#
|
|
|
|
# MDEV-8115 mysql_upgrade crashes the server with REPAIR VIEW
|
|
|
|
#
|
|
|
|
create table t1 (a blob);
|
|
|
|
create view v1 as select * from t1;
|
|
|
|
repair view v1;
|
|
|
|
drop view v1;
|
|
|
|
drop table t1;
|
2018-01-23 11:24:53 +01:00
|
|
|
|
|
|
|
--echo # End of 5.5 tests
|
|
|
|
|
|
|
|
#
|
|
|
|
# MDEV-11539 test_if_reopen: Assertion `strcmp(share->unique_file_name,filename) || share->last_version' failed upon select from I_S
|
|
|
|
#
|
2022-06-09 05:32:51 +02:00
|
|
|
--disable_view_protocol
|
2018-01-23 11:24:53 +01:00
|
|
|
CREATE TABLE t1 (i INT) ENGINE=MyISAM;
|
|
|
|
INSERT t1 VALUES (1);
|
|
|
|
LOCK TABLE t1 WRITE;
|
|
|
|
REPAIR TABLE t1;
|
|
|
|
--disable_result_log
|
|
|
|
SELECT * FROM INFORMATION_SCHEMA.TABLES;
|
|
|
|
--enable_result_log
|
|
|
|
SELECT * FROM t1;
|
|
|
|
UNLOCK TABLES;
|
|
|
|
DROP TABLE t1;
|
2022-06-09 05:32:51 +02:00
|
|
|
--enable_view_protocol
|
2018-01-23 11:24:53 +01:00
|
|
|
--echo # End of 10.0 tests
|
2020-05-13 13:10:35 +02:00
|
|
|
|
|
|
|
#
|
|
|
|
# MDEV-17153 server crash on repair table ... use_frm
|
|
|
|
#
|
|
|
|
# Note, this test case doesn't crash, but shows spurios warnings
|
|
|
|
# unless the bug is fixed
|
|
|
|
#
|
|
|
|
create table t1 (a int, b varchar(200));
|
|
|
|
insert t1 select seq, repeat(200, seq) from seq_1_to_30;
|
|
|
|
delete from t1 where a % 13 = 0;
|
|
|
|
repair table t1 use_frm;
|
|
|
|
delete from t1 where a % 11 = 0;
|
|
|
|
repair table t1 extended use_frm;
|
|
|
|
delete from t1 where a % 7 = 0;
|
|
|
|
set myisam_repair_threads = 2;
|
|
|
|
repair table t1 use_frm;
|
|
|
|
set myisam_repair_threads = default;
|
|
|
|
drop table t1;
|
|
|
|
|
|
|
|
--echo # End of 10.2 tests
|
2024-03-12 12:54:30 +01:00
|
|
|
|
|
|
|
--echo #
|
|
|
|
--echo # MDEV-33737 The way of ignoring alter-algorithm is inconsistent with
|
|
|
|
--echo # other options and with itself
|
|
|
|
--echo #
|
|
|
|
|
|
|
|
query_vertical select * from information_schema.system_variables where variable_name = 'ALTER_ALGORITHM';
|
|
|
|
|
|
|
|
set alter_algorithm=COPY;
|
|
|
|
select @@alter_algorithm;
|
|
|
|
set statement alter_algorithm=COPY FOR SELECT @@alter_algorithm;
|
|
|
|
|
|
|
|
--let $restart_parameters= --alter-algorithm=COPY
|
|
|
|
--source include/restart_mysqld.inc
|
|
|
|
|
|
|
|
select @@alter_algorithm;
|
|
|
|
|
MDEV-33449 improving repair of tables
This task is to ensure we have a clear definition and rules of how to
repair or optimize a table.
The rules are:
- REPAIR should be used with tables that are crashed and are
unreadable (hardware issues with not readable blocks, blocks with
'unexpected data' etc)
- OPTIMIZE table should be used to optimize the storage layout for the
table (recover space for delete rows and optimize the index
structure.
- ALTER TABLE table_name FORCE should be used to rebuild the .frm file
(the table definition) and the table (with the original table row
format). If the table is from and older MariaDB/MySQL release with a
different storage format, it will convert the data to the new
format. ALTER TABLE ... FORCE is used as part of mariadb-upgrade
Here follows some more background:
The 3 ways to repair a table are:
1) ALTER TABLE table_name FORCE" (not other options).
As an alias we allow: "ALTER TABLE table_name ENGINE=original_engine"
2) "REPAIR TABLE" (without FORCE)
3) "OPTIMIZE TABLE"
All of the above commands will optimize row space usage (which means that
space will be needed to hold a temporary copy of the table) and
re-generate all indexes. They will also try to replicate the original
table definition as exact as possible.
For ALTER TABLE and "REPAIR TABLE without FORCE", the following will hold:
If the table is from an older MariaDB version and data conversion is
needed (for example for old type HASH columns, MySQL JSON type or new
TIMESTAMP format) "ALTER TABLE table_name FORCE, algorithm=COPY" will be
used.
The differences between the algorithms are
1) Will use the fastest algorithm the engine supports to do a full repair
of the table (except if data conversions are is needed).
2) Will use the storage engine internal REPAIR facility (MyISAM, Aria).
If the engine does not support REPAIR then
"ALTER TABLE FORCE, ALGORITHM=COPY" will be used.
If there was data incompatibilities (which means that FORCE was used)
then there will be a warning after REPAIR that ALTER TABLE FORCE is
still needed.
The reason for this is that REPAIR may be able to go around data
errors (wrong incompatible data, crashed or unreadable sectors) that
ALTER TABLE cannot do.
3) Will use the storage engine internal OPTIMIZE. If engine does not
support optimize, then "ALTER TABLE FORCE" is used.
The above will ensure that ALTER TABLE FORCE is able to
correct almost any errors in the row or index data. In case of
corrupted blocks then REPAIR possible followed by ALTER TABLE is needed.
This is important as mariadb-upgrade executes ALTER TABLE table_name
FORCE for any table that must be re-created.
Bugs fixed with InnoDB tables when using ALTER TABLE FORCE:
- No error for INNODB_DEFAULT_ROW_FORMAT=COMPACT even if row length
would be too wide. (Independent of innodb_strict_mode).
- Tables using symlinks will be symlinked after any of the above commands
(Independent of the setting of --symbolic-links)
If one specifies an algorithm together with ALTER TABLE FORCE, things
will work as before (except if data conversion is required as then
the COPY algorithm is enforced).
ALTER TABLE .. OPTIMIZE ALL PARTITIONS will work as before.
Other things:
- FORCE argument added to REPAIR to allow one to first run internal
repair to fix damaged blocks and then follow it with ALTER TABLE.
- REPAIR will not update frm_version if ha_check_for_upgrade() finds
that table is still incompatible with current version. In this case the
REPAIR will end with an error.
- REPAIR for storage engines that does not have native repair, like InnoDB,
is now using ALTER TABLE FORCE.
- REPAIR csv-table USE_FRM now works.
- It did not work before as CSV tables had extension list in wrong
order.
- Default error messages length for %M increased from 128 to 256 to not
cut information from REPAIR.
- Documented HA_ADMIN_XX variables related to repair.
- Added HA_ADMIN_NEEDS_DATA_CONVERSION to signal that we have to
do data conversions when converting the table (and thus ALTER TABLE
copy algorithm is needed).
- Fixed typo in error message (caused test changes).
2024-01-29 10:52:44 +01:00
|
|
|
--echo #
|
|
|
|
--echo # MDEV-33826 Assertion `tl->table == __null' failed in
|
|
|
|
--echo # THD::open_temporary_table
|
|
|
|
--echo #
|
|
|
|
|
|
|
|
CREATE TABLE t1 (i INT) ENGINE=InnoDB;
|
|
|
|
CREATE TABLE t2 (i INT) ENGINE=InnoDB;
|
|
|
|
CREATE TEMPORARY TABLE t3 (i INT);
|
|
|
|
REPAIR TABLE t1,t2,t3;
|
|
|
|
DROP TABLE t1,t2,t3;
|
|
|
|
|
2024-03-12 12:54:30 +01:00
|
|
|
--echo # End of 11.5 tests
|