Bug #28789 Failures in CREATE TABLE AS SELECT don't clean up correctly

Submitted: 30 May 2007 20:02 Modified: 14 Sep 2007 15:40
Reporter: Todd Farmer (OCA) Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.0.41 OS:Any
Assigned to: Martin Hansson CPU Architecture:Any

[30 May 2007 20:02] Todd Farmer
Description:
When a CREATE TABLE AS SELECT statement fails (see http://bugs.mysql.com/bug.php?id=28787 ), some internal clean-up is not performed correctly.  This causes failures in subsequent CREATE TABLE commands.  The error depends on the storage engine:

mysql> USE test;
Database changed
mysql>
mysql> DROP TABLE IF EXISTS t1;
Query OK, 0 rows affected (0.08 sec)

mysql> DROP VIEW IF EXISTS v1;
Query OK, 0 rows affected (0.00 sec)

mysql> DROP TABLE IF EXISTS counts;
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> CREATE TABLE t1 (a INT);
Query OK, 0 rows affected (0.17 sec)

mysql> CREATE DEFINER = 'not_exists'@'no_such_account'
    ->  VIEW v1 AS SELECT * FROM t1;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql>
mysql> # Will fail with unknown error because of bug #28787
mysql>
mysql> CREATE TABLE counts ENGINE = MyISAM AS
    ->  SELECT * FROM information_schema.columns
    ->  WHERE table_schema='test' LIMIT 1;
ERROR 1105 (HY000): Unknown error
mysql>
mysql> CREATE TABLE counts (a INT) ENGINE = MyISAM;
ERROR 1105 (HY000): MyISAM table 'counts' is in use (most likely by a MERGE table). Try FLUSH TABLES.
mysql>
mysql> DROP TABLE IF EXISTS counts;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql>
mysql> SHOW WARNINGS;
+-------+------+------------------------+
| Level | Code | Message                |
+-------+------+------------------------+
| Note  | 1051 | Unknown table 'counts' |
+-------+------+------------------------+
1 row in set (0.00 sec)

mysql>
mysql> CREATE TABLE counts (a INT) ENGINE = MyISAM;
Query OK, 0 rows affected (0.06 sec)

When using InnoDB, the following error is reported, and DROP TABLE IF EXISTS does not clear it:

mysql> CREATE TABLE counts (a INT) ENGINE = InnoDB;
ERROR 1005 (HY000): Can't create table '.\test\counts.frm' (errno: 121)
mysql>
mysql> DROP TABLE IF EXISTS counts;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql>
mysql> SHOW WARNINGS;
+-------+------+------------------------+
| Level | Code | Message                |
+-------+------+------------------------+
| Note  | 1051 | Unknown table 'counts' |
+-------+------+------------------------+
1 row in set (0.00 sec)

mysql>
mysql> CREATE TABLE counts (a INT) ENGINE = InnoDB;
ERROR 1005 (HY000): Can't create table '.\test\counts.frm' (errno: 121)

MEMORY tables are not affected in any way.

How to repeat:
USE test;

DROP TABLE IF EXISTS t1;
DROP VIEW IF EXISTS v1;
DROP TABLE IF EXISTS counts;

CREATE TABLE t1 (a INT);
CREATE DEFINER = 'not_exists'@'no_such_account' 
 VIEW v1 AS SELECT * FROM t1;

SELECT * FROM information_schema.columns 
 WHERE table_schema='test' LIMIT 1;

SHOW WARNINGS;

CREATE TABLE counts ENGINE = MyISAM AS 
 SELECT * FROM information_schema.columns 
 WHERE table_schema='test' LIMIT 1;

DROP VIEW IF EXISTS v1;

CREATE TABLE counts (a INT) ENGINE = MyISAM;

Suggested fix:
Clean up resources that are blocking subsequent table creation when initial CREATE command fails.
[30 May 2007 20:08] Todd Farmer
Because http://bugs.mysql.com/bug.php?id=28787 cannot be replicated on 5.0.42, I was only able to recreate this on 5.0.41, but I suspect that it affects 5.0.42 and other versions as well (but that the precondition of the initial failure of the CREATE TABLE command is difficult to generate).
[30 Jul 2007 15:27] Martin Hansson
I need some feedback in order to reproduce Bug#28787, so this bug needs the same feedback.
[30 Aug 2007 23:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
[14 Sep 2007 15:40] Martin Hansson
Since I can't repeat Bug#28787, I can't repeat this one either.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.042 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.