2013-11-04 21:37:29 +01:00
call mtr.add_suppression("Invalid .old.. table or database name");
2019-08-30 15:06:54 +02:00
--source include/not_embedded.inc
2006-02-26 15:03:43 +01:00
2022-06-09 05:32:51 +02:00
#remove this include after fix MDEV-27872
--source include/no_view_protocol.inc
2024-05-28 07:08:51 +02:00
--source include/test_db_charset_latin1.inc
2006-02-17 10:19:26 +01:00
--disable_warnings
2006-02-26 15:03:43 +01:00
drop database if exists `mysqltest1`;
drop database if exists `mysqltest-1`;
drop database if exists `#mysql50#mysqltest-1`;
2006-02-17 10:19:26 +01:00
--enable_warnings
2006-02-26 15:03:43 +01:00
create database `mysqltest1`;
create database `#mysql50#mysqltest-1`;
create table `mysqltest1`.`t1` (a int);
create table `mysqltest1`.`#mysql50#t-1` (a int);
create table `#mysql50#mysqltest-1`.`t1` (a int);
create table `#mysql50#mysqltest-1`.`#mysql50#t-1` (a int);
show create database `mysqltest1`;
2006-02-17 10:19:26 +01:00
--error 1049
2006-02-26 15:03:43 +01:00
show create database `mysqltest-1`;
show create database `#mysql50#mysqltest-1`;
show tables in `mysqltest1`;
show tables in `#mysql50#mysqltest-1`;
2006-02-17 10:19:26 +01:00
--exec $MYSQL_CHECK --all-databases --fix-db-names --fix-table-names
2006-02-26 15:03:43 +01:00
show create database `mysqltest1`;
show create database `mysqltest-1`;
2006-02-17 10:19:26 +01:00
--error 1049
2006-02-26 15:03:43 +01:00
show create database `#mysql50#mysqltest-1`;
show tables in `mysqltest1`;
show tables in `mysqltest-1`;
drop database `mysqltest1`;
drop database `mysqltest-1`;
2006-03-07 10:05:24 +01:00
#
# Bug#17142: Crash if create with encoded name
#
2006-04-12 11:45:37 +02:00
create table `txu#p#p1` (s1 int);
insert into `txu#p#p1` values (1);
2006-03-07 10:05:24 +01:00
--error 1146
2006-04-12 11:45:37 +02:00
select * from `txu@0023p@0023p1`;
create table `txu@0023p@0023p1` (s1 int);
2013-04-09 15:35:07 +02:00
show tables;
2013-07-12 10:21:14 +02:00
insert into `txu@0023p@0023p1` values (2);
select * from `txu@0023p@0023p1`;
2006-04-12 11:45:37 +02:00
select * from `txu#p#p1`;
drop table `txu#p#p1`;
2013-04-09 15:35:07 +02:00
drop table `txu@0023p@0023p1`;
2006-11-21 21:32:58 +01:00
2009-04-30 14:46:49 +02:00
--echo #
--echo # Bug#37631 Incorrect key file for table after upgrading from 5.0 to 5.1
--echo #
--echo # copy table created using mysql4.0 into the data dir
let $MYSQLD_DATADIR= `SELECT @@datadir`;
copy_file std_data/bug37631.frm $MYSQLD_DATADIR/test/t1.frm;
copy_file std_data/bug37631.MYD $MYSQLD_DATADIR/test/t1.MYD;
copy_file std_data/bug37631.MYI $MYSQLD_DATADIR/test/t1.MYI;
--echo # check the table created using mysql 4.0
CHECK TABLE t1;
--echo # query the table created using mysql 4.0
SELECT * FROM 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 algorithm=NOCOPY;
CHECK TABLE t1;
ALTER TABLE t1 FORCE;
CHECK TABLE t1;
2009-04-30 14:46:49 +02:00
DROP TABLE t1;
2006-11-21 21:32:58 +01:00
#
# Check if old tables work
#
2007-12-12 18:19:24 +01:00
let $MYSQLD_DATADIR= `select @@datadir`;
2009-03-26 15:47:58 +01:00
--error 0,1
--remove_file $MYSQLD_DATADIR/test/t1.frm
--copy_file std_data/old_table-323.frm $MYSQLD_DATADIR/test/t1.frm
2006-11-21 21:32:58 +01:00
truncate t1;
drop table t1;
2007-09-11 00:10:37 +02:00
#
# Bug#28360 (RENAME DATABASE destroys routines)
#
--disable_warnings
drop database if exists `tabc`;
drop database if exists `a-b-c`;
--enable_warnings
create database `tabc` default character set latin2;
create table tabc.t1 (a int);
FLUSH TABLES;
# Manually make a 5.0 database from the template
2008-02-28 12:21:44 +01:00
--mkdir $MYSQLD_DATADIR/a-b-c
2007-12-12 18:19:24 +01:00
--copy_file $MYSQLD_DATADIR/tabc/db.opt $MYSQLD_DATADIR/a-b-c/db.opt
--copy_file $MYSQLD_DATADIR/tabc/t1.frm $MYSQLD_DATADIR/a-b-c/t1.frm
--copy_file $MYSQLD_DATADIR/tabc/t1.MYD $MYSQLD_DATADIR/a-b-c/t1.MYD
--copy_file $MYSQLD_DATADIR/tabc/t1.MYI $MYSQLD_DATADIR/a-b-c/t1.MYI
2007-09-11 00:10:37 +02:00
show databases like '%a-b-c%';
ALTER DATABASE `#mysql50#a-b-c` UPGRADE DATA DIRECTORY NAME;
# The physical directory name is now a@002db@002dc, the logical name still a-b-c
show databases like '%a-b-c%';
show create database `a-b-c`;
show tables in `a-b-c`;
show create table `a-b-c`.`t1`;
drop database `a-b-c`;
drop database `tabc`;
2009-04-10 11:25:48 +02:00
#
# Bug#43385 Cannot ALTER DATABASE ... UPGRADE DATA DIRECTORY NAME when Views exist
#
let $MYSQLD_DATADIR= `select @@datadir`;
--mkdir $MYSQLD_DATADIR/a-b-c
use `#mysql50#a-b-c`;
create table t1(f1 char(10));
--write_file $MYSQLD_DATADIR/a-b-c/v1.frm
TYPE=VIEW
query=select `a`.`f1` AS `f1` from `a-b-c`.`t1` `a` join `information_schema`.`tables` `b` where (convert(`a`.`f1` using utf8) = `b`.`TABLE_NAME`)
md5=068271f1c657fe115e497856ca0fa493
updatable=0
algorithm=0
definer_user=root
definer_host=localhost
suid=2
with_check_option=0
timestamp=2009-04-10 11:53:37
create-version=1
source=select f1 from `a-b-c`.t1 a, information_schema.tables b\nwhere a.f1 = b.table_name
2009-08-25 15:56:50 +02:00
client_cs_name=utf8
connection_cl_name=utf8_general_ci
2009-04-10 11:25:48 +02:00
EOF
show databases like '%a-b-c%';
ALTER DATABASE `#mysql50#a-b-c` UPGRADE DATA DIRECTORY NAME;
show databases like '%a-b-c%';
show create view `a-b-c`.v1;
2009-04-13 15:09:10 +02:00
--disable_ps_protocol
2009-04-10 11:25:48 +02:00
select * from `a-b-c`.v1;
2009-04-13 15:09:10 +02:00
--enable_ps_protocol
2009-04-10 11:25:48 +02:00
drop database `a-b-c`;
use test;
2010-05-21 20:47:32 +02:00
--echo # End of 5.0 tests
--echo #
--echo # Bug #53804: serious flaws in the alter database .. upgrade data
--echo # directory name command
--echo #
--error ER_BAD_DB_ERROR
ALTER DATABASE `#mysql50#:` UPGRADE DATA DIRECTORY NAME;
--error ER_WRONG_DB_NAME
ALTER DATABASE `#mysql50#.` UPGRADE DATA DIRECTORY NAME;
--error ER_WRONG_DB_NAME
ALTER DATABASE `#mysql50#../` UPGRADE DATA DIRECTORY NAME;
--error ER_WRONG_DB_NAME
ALTER DATABASE `#mysql50#../..` UPGRADE DATA DIRECTORY NAME;
--error ER_WRONG_DB_NAME
ALTER DATABASE `#mysql50#../../` UPGRADE DATA DIRECTORY NAME;
--error ER_WRONG_DB_NAME
ALTER DATABASE `#mysql50#./blablabla` UPGRADE DATA DIRECTORY NAME;
--error ER_WRONG_DB_NAME
ALTER DATABASE `#mysql50#../blablabla` UPGRADE DATA DIRECTORY NAME;
--error ER_WRONG_DB_NAME
ALTER DATABASE `#mysql50#/` UPGRADE DATA DIRECTORY NAME;
--error ER_WRONG_DB_NAME
ALTER DATABASE `#mysql50#/.` UPGRADE DATA DIRECTORY NAME;
--error ER_WRONG_DB_NAME
USE `#mysql50#.`;
--error ER_WRONG_DB_NAME
USE `#mysql50#../blablabla`;
2010-09-03 18:20:30 +02:00
#
# Test of Bug #56441: mysql_upgrade 5.0->5.1 fails for tables with long names
#
2010-09-20 15:17:59 +02:00
copy_file $MYSQL_TEST_DIR/std_data/long_table_name.MYI $MYSQLD_DATADIR/test/ltoriaeinnovacionendesarrolloempres#9120761097220077376#cio_com.MYI;
copy_file $MYSQL_TEST_DIR/std_data/long_table_name.MYD $MYSQLD_DATADIR/test/ltoriaeinnovacionendesarrolloempres#9120761097220077376#cio_com.MYD;
copy_file $MYSQL_TEST_DIR/std_data/long_table_name.frm $MYSQLD_DATADIR/test/ltoriaeinnovacionendesarrolloempres#9120761097220077376#cio_com.frm;
2010-09-03 18:20:30 +02:00
show full tables;
2010-09-20 15:17:59 +02:00
rename table `#mysql50#ltoriaeinnovacionendesarrolloempres#9120761097220077376#cio_com` to `ltoriaeinnovacionendesarrolloempres#9120761097220077376#cio_com`;
2010-09-03 18:20:30 +02:00
show full tables;
2010-09-20 15:17:59 +02:00
drop table `ltoriaeinnovacionendesarrolloempres#9120761097220077376#cio_com`;
2010-09-03 18:20:30 +02:00
2010-05-21 20:47:32 +02:00
--echo # End of 5.1 tests
2024-05-28 07:08:51 +02:00
--source include/test_db_charset_restore.inc