summaryrefslogtreecommitdiff
path: root/mysql-test/r/alter_table.result
diff options
context:
space:
mode:
authorunknown <andrey@example.com>2006-12-04 18:22:38 +0100
committerunknown <andrey@example.com>2006-12-04 18:22:38 +0100
commitbaeb335ec76e9925fa8b57599d5ef9722f274878 (patch)
treed2a1ddd6efe00051bea52be22419fff7748a7087 /mysql-test/r/alter_table.result
parent8878c65f0eec860370f80416fc8031c373363bdd (diff)
downloadmariadb-git-baeb335ec76e9925fa8b57599d5ef9722f274878.tar.gz
Fix for bug#22369: Alter table rename combined
with other alterations causes lost tables Using RENAME clause combined with other clauses of ALTER TABLE led to data loss (the data was there but not accessible). This could happen if the changes do not change the table much. Adding and droppping of fields and indices was safe. Renaming a column with MODIFY or CHANGE was unsafe operation, if the actual column didn't change (changing from int to int, which is a noop) Depending on the storage engine (SE) the behavior is different: 1)MyISAM/MEMORY - the ALTER TABLE statement completes without any error but next SELECT against the new table fails. 2)InnoDB (and every other transactional table) - The ALTER TABLE statement fails. There are the the following files in the db dir - `new_table_name.frm` and a temporary table's frm. If the SE is file based, then the data and index files will be present but with the old names. What happens is that for InnoDB the table is not renamed in the internal DDIC. Fixed by adding additional call to mysql_rename_table() method, which should not include FRM file rename, because it has been already done during file names juggling. mysql-test/r/alter_table.result: update result mysql-test/r/grant.result: update result mysql-test/t/alter_table.test: 2006/11/29 11:46:23+01:00 andrey@example.com +44 -9 Error to bug number Added test case for #22369: Alter table rename combined with other alterations causes lost tables mysql-test/t/grant.test: add test for bug#22369 - alter table was missing check for DROP_ACL when ALTER_RENAME clause is specified. Synchronise with RENAME TABLE DDL. sql/mysql_priv.h: Add a new flag for mysql_rename_table() sql/sql_parse.cc: To be consistent with SQLCOM_RENAME_TABLE, SQLCOM_ALTER_TABLE has to check for DROP_ACL if there is ALTER_RENAME flag set. sql/sql_table.cc: ALTER_RENAME, the data and index files weren't renamed in the engine but only the FRM was new, when the tables old and new tables are compatible. In the chain of FRM renames we add a call to mysql_rename_table() which should instruct the engine to rename the table but not rename the FRM. This bug was there only in 5.1 branch. 4.1 and 5.0 always do copy data on RENAME if there are more clauses than just rename.
Diffstat (limited to 'mysql-test/r/alter_table.result')
-rw-r--r--mysql-test/r/alter_table.result42
1 files changed, 42 insertions, 0 deletions
diff --git a/mysql-test/r/alter_table.result b/mysql-test/r/alter_table.result
index f3c94ea5af9..7b8479e6e72 100644
--- a/mysql-test/r/alter_table.result
+++ b/mysql-test/r/alter_table.result
@@ -733,3 +733,45 @@ Table Create Table
`c1` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE `#sql2`, `@0023sql1`;
+DROP TABLE IF EXISTS t1;
+DROP TABLE IF EXISTS t2;
+CREATE TABLE t1 (
+int_field INTEGER UNSIGNED NOT NULL,
+char_field CHAR(10),
+INDEX(`int_field`)
+);
+DESCRIBE t1;
+Field Type Null Key Default Extra
+int_field int(10) unsigned NO MUL
+char_field char(10) YES NULL
+SHOW INDEXES FROM t1;
+Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment
+t1 1 int_field 1 int_field A NULL NULL NULL BTREE
+INSERT INTO t1 VALUES (1, "edno"), (1, "edno"), (2, "dve"), (3, "tri"), (5, "pet");
+"Non-copy data change - new frm, but old data and index files"
+ALTER TABLE t1
+CHANGE int_field unsigned_int_field INTEGER UNSIGNED NOT NULL,
+RENAME t2;
+SELECT * FROM t1 ORDER BY int_field;
+ERROR 42S02: Table 'test.t1' doesn't exist
+SELECT * FROM t2 ORDER BY unsigned_int_field;
+unsigned_int_field char_field
+1 edno
+1 edno
+2 dve
+3 tri
+5 pet
+DESCRIBE t2;
+Field Type Null Key Default Extra
+unsigned_int_field int(10) unsigned NO MUL
+char_field char(10) YES NULL
+DESCRIBE t2;
+Field Type Null Key Default Extra
+unsigned_int_field int(10) unsigned NO MUL
+char_field char(10) YES NULL
+ALTER TABLE t2 MODIFY unsigned_int_field BIGINT UNSIGNED NOT NULL;
+DESCRIBE t2;
+Field Type Null Key Default Extra
+unsigned_int_field bigint(20) unsigned NO MUL
+char_field char(10) YES NULL
+DROP TABLE t2;