Bug #6607 Create table... LIKE... with Windows Symlinks
Submitted: 13 Nov 2004 16:30 Modified: 8 Feb 2005 19:39
Reporter: Fred Stiening Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:4.1.7 OS:Windows (Windows XP Home)
Assigned to: Reggie Burnett CPU Architecture:Any

[13 Nov 2004 16:30] Fred Stiening
Description:
If you attempt to create a table LIKE an existing table, and the source table is located in a directory using the Windows .sym symlink feature to store the tables outside of the normal data directory, the command returns "Unknown Table: source_table".

How to repeat:
example:

V:\code>mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5924 to server version: 4.1.7-nt

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> use thewww;
Database changed
mysql> show tables;
+---------------------+
| Tables_in_thewww    |
+---------------------+
| category            |
| classificationwords |
| httpservers         |
| ipaddress           |
| links               |
| querylog            |
| serverserverjoin    |
| topleveldomains     |
| urls                |
| urls_in             |
+---------------------+
10 rows in set (0.00 sec)

mysql> create table urls2 like urls;
ERROR 1051 (42S02): Unknown table 'urls'
mysql>

the table thewww is located on a different disk drive:

c:\mysql\data\thewww.sym contains:
z:\mysql\data\thewww\

In all other respects the symlink is working fine.

Suggested fix:
It would appear that the Create LIKE function is misssing the logic to follow Winodws Symlinks - Create LIKE works correctly in the main data directory as well as on *nix.
[13 Nov 2004 17:30] Guilhem Bichot
got a patch
[13 Nov 2004 22:21] Guilhem Bichot
Note that a similar bug exists if the destination table is to be created in the .sym database; one gets:
ERROR 1 (HY000): Can't create/write to file (Errcode: 2)
[19 Nov 2004 9:15] Guilhem Bichot
Apparently this patch works on Linux with -DUSE_SYMDIR but fails on Windows. So I am donating it here to the Windows team for them to make something which works on Windows.
===== sql/sql_table.cc 1.261 vs edited =====
*** /home/guilhem/tmp/bk_sql_table.cc-1.261_zjO5Lc      2004-11-12 09:44:53 +01:00
--- edited/sql/sql_table.cc     2004-11-13 23:14:48 +01:00
***************
*** 2146,2153 ****
      strxmov(src_path, (*tmp_table)->path, reg_ext, NullS);
    else
    {
!     strxmov(src_path, mysql_data_home, "/", src_db, "/", src_table,
!           reg_ext, NullS);
      if (access(src_path, F_OK))
      {
        my_error(ER_BAD_TABLE_ERROR, MYF(0), src_table);
--- 2146,2152 ----
      strxmov(src_path, (*tmp_table)->path, reg_ext, NullS);
    else
    {
!     fn_format(src_path, src_table, src_db, reg_ext, MYF(MY_UNPACK_FILENAME));
      if (access(src_path, F_OK))
      {
        my_error(ER_BAD_TABLE_ERROR, MYF(0), src_table);
***************
*** 2174,2181 ****
    }
    else
    {
!     strxmov(dst_path, mysql_data_home, "/", db, "/", table_name,
!           reg_ext, NullS);
      if (!access(dst_path, F_OK))
        goto table_exists;
    }
--- 2173,2179 ----
    }
    else
    {
!     fn_format(dst_path, table_name, db, reg_ext, MYF(MY_UNPACK_FILENAME));
      if (!access(dst_path, F_OK))
        goto table_exists;
    }
[1 Feb 2005 14:44] Reggie Burnett
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html
[6 Feb 2005 17:00] Reggie Burnett
Fixed in 4.1, merged to 5.0
[8 Feb 2005 19:39] Paul DuBois
Mentioned in 4.1.10 and 5.0.3 change notes.