Bug #25296 Truncate table converts NDB disk based tables to in-memory tables.
Submitted: 27 Dec 2006 18:05 Modified: 27 Apr 2007 12:24
Reporter: Matthew Montgomery Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Cluster: Disk Data Severity:S2 (Serious)
Version:5.1.14 OS:Linux (Linux 2.6)
Assigned to: Martin Skold CPU Architecture:Any
Tags: cluster, disk-based, ndb, truncate

[27 Dec 2006 18:05] Matthew Montgomery
Description:
If you issue TRUNCATE TABLE to any disk-based NDB table it loses it's tablespace association and becomes an in-memory table.

Perhaps it is related to 24667.
"After ALTER TABLE operation ndb_dd table becomes regular ndb"

How to repeat:
mysql> select * from information_schema.files;
Empty set (0.00 sec)

mysql> CREATE LOGFILE GROUP lg_1
    ->     ADD UNDOFILE 'undo_1.dat'
    ->     INITIAL_SIZE 16M
    ->     UNDO_BUFFER_SIZE 2M
    ->     ENGINE NDB;
Query OK, 0 rows affected (7.90 sec)

mysql> CREATE TABLESPACE ts_1
    ->     ADD DATAFILE 'data_1.dat'
    ->     USE LOGFILE GROUP lg_1
    ->     INITIAL_SIZE 32M
    ->     ENGINE NDB;
Query OK, 0 rows affected (12.88 sec)

mysql> CREATE TABLE dt_1 (
    ->     member_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    ->     last_name VARCHAR(50) NOT NULL,
    ->     first_name VARCHAR(50) NOT NULL,
    ->     dob DATE NOT NULL,
    ->     joined DATE NOT NULL,
    ->     INDEX(last_name, first_name)
    ->     )
    ->     TABLESPACE ts_1 STORAGE DISK
    ->     ENGINE NDB;
Query OK, 0 rows affected (6.59 sec)

mysql> select * from information_schema.files where table_name is not NULL; Empty set (0.09 sec)  mysql> show create table dt_1;
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                          |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| dt_1  | CREATE TABLE `dt_1` (
  `member_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `last_name` varchar(50) NOT NULL,
  `first_name` varchar(50) NOT NULL,
  `dob` date NOT NULL,
  `joined` date NOT NULL,
  PRIMARY KEY (`member_id`),
  KEY `last_name` (`last_name`,`first_name`)
) /*!50100 TABLESPACE ts_1 STORAGE DISK */ ENGINE=ndbcluster DEFAULT CHARSET=latin1 |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.04 sec)

mysql> truncate table dt_1;
Query OK, 0 rows affected (6.70 sec)

mysql> show create table dt_1;
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                 |
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| dt_1  | CREATE TABLE `dt_1` (
  `member_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `last_name` varchar(50) NOT NULL,
  `first_name` varchar(50) NOT NULL,
  `dob` date NOT NULL,
  `joined` date NOT NULL,
  PRIMARY KEY (`member_id`),
  KEY `last_name` (`last_name`,`first_name`)
) ENGINE=ndbcluster DEFAULT CHARSET=latin1 |
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.06 sec)

Suggested fix:
*/* Work Around */*

Following the truncate ALTER TABLE again to include the TABLESPACE definition.

(See Bug 25295)

mysql> alter table `dt_1` TABLESPACE ts_1 STORAGE DISK engine=ndbcluster;
Query OK, 0 rows affected (9.11 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> show create table dt_1;
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                          |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| dt_1  | CREATE TABLE `dt_1` (
  `member_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `last_name` varchar(50) NOT NULL,
  `first_name` varchar(50) NOT NULL,
  `dob` date NOT NULL,
  `joined` date NOT NULL,
  PRIMARY KEY (`member_id`),
  KEY `last_name` (`last_name`,`first_name`)
) /*!50100 TABLESPACE ts_1 STORAGE DISK */ ENGINE=ndbcluster DEFAULT CHARSET=latin1 |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.07 sec)
[29 Dec 2006 17:19] Jonas Oreland
assigning to martin who wrote code...
[2 Jan 2007 21:31] 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/17548

ChangeSet@1.2376, 2007-01-02 22:31:29+01:00, mskold@mysql.com +4 -0
  bug #25296  Truncate table converts NDB disk based tables to in-memory tables: implemented ha_ndbcluster::update_create_info
[3 Jan 2007 9:22] 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/17569

ChangeSet@1.2377, 2007-01-03 10:22:31+01:00, mskold@mysql.com +1 -0
  bug #25296  Truncate table converts NDB disk based tables to in-memory tables: ha_ndbcluster::update_create_infohas to check for explicit STORAGE MEMORY
[4 Jan 2007 8:15] 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/17602

ChangeSet@1.2379, 2007-01-04 09:15:09+01:00, mskold@mysql.com +1 -0
  bug #25296  Truncate table converts NDB disk based tables to in-memory tables: ha_ndbcluster::update_create_info should only update for TRUNCATE since we need to detect change of STORAGE at ALTER TABLE
[4 Jan 2007 16:27] 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/17636

ChangeSet@1.2381, 2007-01-04 17:26:53+01:00, mskold@mysql.com +3 -0
  ha_ndbcluster.h, ndb_dd_alter.result, ha_ndbcluster.cc:
    bug#25296  Truncate table converts NDB disk based tables to in-memory tables: Changed fix to use get_tablespace_name directly instead
[24 Jan 2007 2:01] Tomas Ulin
pushed to 5.1.15
[25 Jan 2007 7:32] Jon Stephens
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 bug fix. More information about accessing the source trees is available at

    http://dev.mysql.com/doc/en/installing-source.html

Documented bugfix in 5.1.15 changelog.
[5 Apr 2007 11:59] Hartmut Holzgraefe
Reopened after bug 27639 came in:

The fix only changes the SHOW CREATE TABLE output, the actual columns 
still change from ST=DISK to ST=MEMORY in ndb_desc output.

So the bug still exists, and even worse it is now "covered" by the
now wrong SHOW CREATE output.

ndb_desc differences before and after truncate:

--- n1  2007-04-05 13:56:25.000000000 +0200
+++ n2  2007-04-05 13:56:32.000000000 +0200
@@ -1,6 +1,6 @@
 > ndb_desc -d test t1
 -- t1 --
-Version: 5
+Version: 6
 Fragment type: 5
 K Value: 6
 Min load factor: 78
@@ -16,8 +16,8 @@
 member_id Unsigned PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
 last_name Varchar(50;latin1_swedish_ci) NOT NULL AT=SHORT_VAR ST=MEMORY
 first_name Varchar(50;latin1_swedish_ci) NOT NULL AT=SHORT_VAR ST=MEMORY
-dob Date NOT NULL AT=FIXED ST=DISK
-joined Date NOT NULL AT=FIXED ST=DISK
+dob Date NOT NULL AT=FIXED ST=MEMORY
+joined Date NOT NULL AT=FIXED ST=MEMORY
 
 -- Indexes -- 
 PRIMARY KEY(member_id) - UniqueHashIndex
[5 Apr 2007 12:01] Hartmut Holzgraefe
Result of this bug not having a reviewer?
[26 Apr 2007 11:36] Bugs System
Pushed into 5.1.18-beta
[27 Apr 2007 12:24] Jon Stephens
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 bug fix. More information about accessing the source trees is available at

    http://dev.mysql.com/doc/en/installing-source.html

Documented fix in 5.1.18 changelog, noted that this supersedes previous fix for same issue in 5.1.15.