Bug #21106 Compressed MyISAM table is read only and thus truncate should not be possible
Submitted: 18 Jul 2006 8:08 Modified: 19 Jul 2006 10:12
Reporter: Oli Sennhauser Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Documentation Severity:S2 (Serious)
Version:5.0.22 OS:Any (any)
Assigned to: MC Brown CPU Architecture:Any
Tags: compressed, myisam, read only, table, truncate

[18 Jul 2006 8:08] Oli Sennhauser
Description:
A compressed MyISAM table is according to our documentation read only and thus it should IMHO no be possible to be truncated.

or

At least comment this in our online docu.

This is not what (oracle) users expect?!?

How to repeat:
mysql> flush table test;

# myisampack test.MYI
Compressing test.MYD: (2632928 records)
- Calculating statistics
- Compressing file
73.35%
Remember to run myisamchk -rq on compressed tables

#> myisamchk -rq test.MYI
- check record delete-chain
- recovering (with sort) MyISAM-table 'test.MYI'
Data records: 2632928
- Fixing index 1
- Fixing index 2
- Fixing index 3
- Fixing index 4
- Fixing index 5

mysql> show table status like 'test'\G
*************************** 1. row ***************************
           Name: test
         Engine: MyISAM
        Version: 10
     Row_format: Compressed
           Rows: 2632928
 Avg_row_length: 9
    Data_length: 24554709
Max_data_length: 281474976710655
   Index_length: 107433984
      Data_free: 0
 Auto_increment: NULL
    Create_time: 2006-07-18 09:55:14
    Update_time: 2006-07-18 09:55:26
     Check_time: 2006-07-18 09:58:07
      Collation: latin1_swedish_ci
       Checksum: 2523143152
 Create_options:
        Comment:
1 row in set (0.00 sec)

mysql> truncate table test;

mysql> select * from test;
Empty set (0.38 sec)

Suggested fix:
Eigther fix this (compressed tables are only allowed to drop but not to truncate or delete) or at least write a comment in the docu.
[18 Jul 2006 12:33] Valeriy Kravchuk
Verfified just as described with 50.25-BK on Linux. I think, current behaviour is correct (TRUNCATE is a kind of DDL statement, like DROP), but this specific case should be properly documented (as a note at http://dev.mysql.com/doc/refman/5.0/en/compressed-format.html, I think).
[19 Jul 2006 10:12] MC Brown
I've added a note to the page: 

 While a compressed table is read-only, and you cannot therefore update or add rows in the table, DDL (Data Definition Language) operations are still valid. For example, you may still use <literal>DROP</literal> to drop the table, and <literal>TRUNCATE</literal> to empty the table.