List:MySQL on Win32« Previous MessageNext Message »
From:Bill Easton Date:August 27 2003 10:54am
Subject:Cloning table takes forever
View as plain text  
Sometimes, I want to create a new table with the same columns as an existing table.  I can
do this with:

mysql> create table foo select * from projcomm where 0;
Query OK, 0 rows affected (0.77 sec)
Records: 0  Duplicates: 0  Warnings: 0

However, it takes nearly a second.  If I create several, the delay becomes noticeable.

I don't understand why.  If I do a "show create table..." and then create the table giving
the structure in the create table statement, it only takes 0.02 sec.   (See below.)  I
suppose I can write the code to do this, but I'd rather not.

This happens on Windows 2000, MySQL 4.0.14-max-nt-log, and also on Windows ME.  It does
not appear to happen on Linux.

Any hints as to why it takes so long?

----------

Here are the times when I give the structure explicitly.  I'd think that the "create ...
select" would be doing the same thing.

mysql> select * from project where 0;
Empty set (0.00 sec)

mysql> show create table projcomm\G;
*************************** 1. row ***************************
       Table: projcomm
Create Table: CREATE TABLE `projcomm` (
  `PROJCOMM_ID` int(11) NOT NULL default '0',
  `PROJECT_ID` int(11) NOT NULL default '-1',
  `COMMUNTY_ID` int(11) NOT NULL default '0',
  PRIMARY KEY  (`PROJCOMM_ID`),
  UNIQUE KEY `PROJECT_ID` (`PROJECT_ID`,`COMMUNTY_ID`),
  KEY `COMMUNTY_ID` (`COMMUNTY_ID`)
) TYPE=MyISAM
1 row in set (0.00 sec)

mysql> create table foo (
    ->   `PROJCOMM_ID` int(11) NOT NULL default '0',
    ->   `PROJECT_ID` int(11) NOT NULL default '-1',
    ->   `COMMUNTY_ID` int(11) NOT NULL default '0');
Query OK, 0 rows affected (0.02 sec)

Thread
Cloning table takes foreverBill Easton27 Aug
  • Re: Cloning table takes foreverMichael Ellis27 Aug