Bug #2985 Table truncated when creating another table name with Spaces
Submitted: 26 Feb 2004 21:19 Modified: 12 Mar 2004 2:07
Reporter: Jason Garber Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S2 (Serious)
Version:4.0.15 OS:Linux (Red Hat Linux 9)
Assigned to: Bugs System CPU Architecture:Any

[26 Feb 2004 21:19] Jason Garber
Description:
I have been running into some very odd behavior when creating a table that has the same name as another table with a space at the end:

`member`
`member `

Any data in `member` gets truncated when `member ` is created.  On the filesystem, a `member .FRM` is created, but `member .MYD` and `member .MYI` are not.

I have run into very irregular errors when attempting to select/drop the tables.  They have included "File does not exist" and "Got error 127 from table handler" and it also worked once.

I have included the exact commandline text that I used to replicate this error.

Thanks,
Jason Garber

How to repeat:
-- Creating the database
mysql> CREATE DATABASE tmp;
Query OK, 1 row affected (0.00 sec)

-- Using it
mysql> USE tmp;
Database changed

-- Creating `member` Table
mysql> CREATE TABLE `member` (x int);
Query OK, 0 rows affected (0.00 sec)

-- Inserting 3 records
mysql> INSERT INTO member VALUES (1),(2),(3);
Query OK, 3 rows affected (0.00 sec)
Records: 3  Duplicates: 0  Warnings: 0

-- Here are the 3 records
mysql> SELECT * FROM `member`;
+------+
| x    |
+------+
|    1 |
|    2 |
|    3 |
+------+
3 rows in set (0.00 sec)

mysql> exit
Bye

----------------------------------------------------------------
-- Here is the database directory
[root@lithium tmp]# cd /var/lib/mysql/tmp
[root@lithium tmp]# ls -l
total 20
-rw-rw----    1 mysql    mysql        8548 Feb 27 00:10 member.frm
-rw-rw----    1 mysql    mysql          15 Feb 27 00:10 member.MYD
-rw-rw----    1 mysql    mysql        1024 Feb 27 00:10 member.MYI
----------------------------------------------------------------

-- Here are the tables
mysql> show tables;
+---------------+
| Tables_in_tmp |
+---------------+
| member        |
+---------------+
1 row in set (0.00 sec)

-- Creating the `member ` table
mysql> CREATE TABLE `member ` (x int);
Query OK, 0 rows affected (0.00 sec)

-- There it is
mysql> SHOW TABLES;
+---------------+
| Tables_in_tmp |
+---------------+
| member        |
| member        |
+---------------+
2 rows in set (0.00 sec)

-- Some errors
mysql> SELECT * FROM `member`;
ERROR 1030: Got error 127 from table handler

mysql> SELECT * FROM `member `;
ERROR 1030: Got error 127 from table handler

----------------------------------------------------------------
-- Here is the database directory
[root@lithium tmp]# ls -l
total 28
-rw-rw----    1 mysql    mysql        8548 Feb 27 00:11 member .frm
-rw-rw----    1 mysql    mysql        8548 Feb 27 00:10 member.frm
-rw-rw----    1 mysql    mysql           0 Feb 27 00:11 member.MYD
-rw-rw----    1 mysql    mysql        1024 Feb 27 00:11 member.MYI
----------------------------------------------------------------

--One more thing:
mysql> show tables;
+---------------+
| Tables_in_tmp |
+---------------+
| member        |
| member        |
+---------------+
2 rows in set (0.00 sec)

-- Dropping the `member ` table
mysql> drop table `member `;
Query OK, 0 rows affected (0.00 sec)

-- More errors
mysql> select * from member;
ERROR 1030: Got error 127 from table handler

----------------------------------------------------------------
-- Here is the database directory
[root@lithium tmp]# ls -l
total 12
-rw-rw----    1 mysql    mysql        8548 Feb 27 00:10 member.frm
[root@lithium tmp]#
----------------------------------------------------------------

Suggested fix:
I believe that some better ` ` handling would do it.  I also think that while this is an important bug that may be indications of deeper logic flaws in that section of the code, it is not that urgent...

Who creates tables with spaces at the end?
[11 Mar 2004 2:22] Victor Vagin
subj: bk commit - 4.0 tree (vva:1.1723)

ChangeSet
  1.1723 04/03/05 22:13:33 vva@eagle.mysql.r18.ru +5 -0
  fixed Bug #2985 
   "Table truncated when creating another table name with Spaces"
  added to check_db_name, check_table_name and check_column_name
  test for end space
[12 Mar 2004 2:07] Victor Vagin
Thank you for your bug report. This issue has already been fixed
in the latest released version of that product, which you can download at 
http://www.mysql.com/downloads/

Additional info:

The fix will be in mysql-4.0.19