Bug #36897 Falcon: "use tablespace" is possible
Submitted: 22 May 2008 21:31 Modified: 9 Dec 2008 0:06
Reporter: Peter Gulutzan Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: DDL Severity:S3 (Non-critical)
Version:6.0.6-alpha-debug OS:Linux (SUSE 10 | 32-bit)
Assigned to: Magne Mæhre CPU Architecture:Any

[22 May 2008 21:31] Peter Gulutzan
Description:
I create tablespace hh.
Now I can say 'use hh'.
I can even create procedures while my 'database' is hh.
This shouldn't be possible.

How to repeat:
mysql> CREATE TABLESPACE hh add datafile 'hh' engine=falcon;
Query OK, 0 rows affected (0.24 sec)

mysql> USE hh
Database changed
mysql> CREATE PROCEDURE p () SET @a=5;
Query OK, 0 rows affected (0.00 sec)

mysql> BACKUP DATABASE hh to 'hh.bak';
+-----------+
| backup_id |
+-----------+
| 1         |
+-----------+
1 row in set (0.08 sec)
[10 Jun 2008 13:51] Jim Starkey
This is a mind-boggling server bug.

The actual bug is demonstrated by the following:

    mysql> CREATE TABLESPACE hh add datafile 'hh' engine=falcon;
    Query OK, 0 rows affected (0.95 sec)
    mysql> USE hh
    Database changed
    mysql> CREATE TABLE FOO (N INT);
    ERROR 1049 (42000): Unknown database 'hh'

What's happening is this:

    1. Peter creates a Falcon table space file without an extension.
    2. When he does a "use hh", the server sees a file without an
       extension and stupidly assumes it's a directory.
    3. When you try to create a file in the "database", guess what?  The
       frm file creation fails because the "directory" isn't a directory.

Solution: The server should check that prospective database/scheme directory
is actually a directory before using it as such.
[10 Jun 2008 16:10] Ann Harrison
This can be reproduced by creating the file xyzzy in the 
data directory, then asking mysql to "use xyzzy".
[10 Jun 2008 16:32] Kevin Lewis
Lowering the priority to P2 since this problem is limited to directory or 'datafile' names without extensions.  Also, making Kostja the lead since the catagory is now Server:DDL
[10 Jun 2008 19:41] Kevin Lewis
From email;
Hi Ann,

Thanks for the clarification.

>> Omer wrote;
>> The reason for the P1 was that from the (limited?) way we understood 
>> the bug that there are still open 'conceptual' issues with the 
>> behavior of tablespaces and that this bug is a symptom of them. As 
>> such it seems that this issue needs to be resolved as soon as possible 
>> as Falcon is viewed as 'kind of considered to already be in beta' 
>> (sorry but I couldn't find a more technical term).

> Ann W. Harrison wrote:
> The problem is not in Falcon, but in the way the server recognizes
> a database.  The example created a tablespace "hh" contained in a
> file "hh".  The file is created by default in the data directory.
> When the server attempts to open a database, it just validates that
> something with that name exists in the data directory.  Any file
> will do.

Omer wrote;
So it seems this is a 'basic' problem in the way the server operates.
The fix if probably in some old 'code' and might not be trivial.

So it seems that as this can be sensitive, it should be fixed soon so I 
think the P1 is justified.

I understand the problem is not in Falcon, but that is not make it less 
of a problem. If the bug is elsewhere, please change the lead/component 
to the right owners.

Thanks
==Omer
[23 Oct 2008 11:32] 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/56879

2739 Magne Mahre	2008-10-23
      Fixed Bug #36897 Falcon: "use tablespace" is possible
[25 Nov 2008 11:40] 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/59776

2753 Magne Mahre	2008-11-25
      Bug #36897  	Falcon: "use tablespace" is possible
      
      The problem is that the code only checks for the
      existence of the target filename when entering a
      database. Added a check to verify that the target is 
      indeed a directory, and not a tablespace file.
[26 Nov 2008 9:17] 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/59885

2754 Magne Mahre	2008-11-26
      Bug #36897  	Falcon: "use tablespace" is possible
            
      The problem is that the code only checks for the
      existence of the target filename when entering a
      database. Added a check to verify that the target is 
      indeed a directory, and not a tablespace file.
      
      Since the my_access() call only checks for file
      existence, it is removed, since this is already
      ensured with the my_stat() call.
[26 Nov 2008 12:58] 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/59924

2754 Magne Mahre	2008-11-26
      Bug #36897        Falcon: "use tablespace" is possible
      
      The problem is that the code only checks for the
      existence of the target filename when entering a
      database. Added a check to verify that the target is
      indeed a directory, and not a tablespace file.
      
      Since the my_access() call only checks for file
      existence, it is removed, since this is already
      ensured with the my_stat() call.
[8 Dec 2008 21:38] Bugs System
Pushed into 6.0.9-alpha  (revid:magne.mahre@sun.com-20081126125817-pani7dcao46vkpm8) (version source revid:magne.mahre@sun.com-20081126125817-pani7dcao46vkpm8) (pib:5)
[9 Dec 2008 0:06] Paul DuBois
Noted in 6.0.9 changelog.

If a non-directory file f without an extension was created in the
data directory, the server would allow clients to execute a USE f
statement even though f could not be a database. The server now
verifies that that the named database corresponds to a directory.