Bug #2628 ALTER TABLE destroys table and reports success
Submitted: 3 Feb 2004 10:23 Modified: 9 Feb 2004 6:21
Reporter: Paul DuBois Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:3.23,4.0,4.1,5.0 OS:Tested on Linux/Mac OS X
Assigned to: Konstantin Osipov CPU Architecture:Any

[3 Feb 2004 10:23] Paul DuBois
Description:
Under certain conditions, ALTER TABLE RENAME
can destroy the table to be renamed, and report
success.

Conditions: A table with a given name exists in a
database, and a table with the same name exists
in another database. You attempt to move one
of them to the other database by renaming it.

This should fail, because the destination table already
exists, but it does not.

How to repeat:
Create table t in the first database:

USE test;
DROP TABLE IF EXISTS t;
CREATE TABLE t (c CHAR(10));
INSERT INTO t SET c = 'table 1';
SELECT * FROM t;

Create table t in a second database:

USE some_other_db;
DROP TABLE IF EXISTS t;
CREATE TABLE t (c CHAR(10));
INSERT INTO t SET c = 'table 2';
SELECT * FROM t;
ALTER TABLE t RENAME TO test.t;
SELECT * FROM test.t;

The ALTER TABLE statement should fail, because
test.t already exists.  Instead, it reports success,
and the final SELECT statement retrieves "table 1"
rather than "table 2".  The some_other_db.t table
has been destroyed.

Note: Some cases that are handled correctly:
You attempt to rename a table t to a table with
a different name. This (correctly) fails if a table
with that name already exists, and it fails regardless
of whether the table is in the same or a different
database.  The bug seems specific to the conditions
outlined above.

Suggested fix:
Beats me.
[9 Feb 2004 6:21] Konstantin Osipov
Fixed in 3.23.59 and 4.0.18:  bk commit into 3.23 tree (1.1431)
[14 Mar 2007 17:13] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/21910

ChangeSet@1.2475, 2007-03-14 18:23:29+04:00, gluh@mysql.com +3 -0
  Bug#2628 5electing information_schema crahes server
  The crash happens when 'skip-grant-tables' is enabled.
  We skip the filling of I_S privilege tables 
  if acl_cache is not initialized.