< Day Day Up > |
14.2 MyISAM-Specific OptimizationsSome of the features of MyISAM tables enable you to optimize how you use them. These optimizations include the following:
14.2.1 MyISAM Storage FormatsFor MyISAM tables, the table storage format has an impact on query efficiency. The three allowable formats are static, dynamic, and compressed:
To find out what storage format a table has, use the SHOW TABLE STATUS statement and examine the value of the Row_format field:
mysql> SHOW TABLE STATUS LIKE 'Country'\G
*************************** 1. row ***************************
Name: Country
Type: MyISAM
Row_format: Fixed
Rows: 239
Avg_row_length: 261
Data_length: 62379
Max_data_length: 1120986464255
Index_length: 5120
Data_free: 0
Auto_increment: NULL
Create_time: 2003-06-06 16:44:16
Update_time: 2003-06-06 16:44:16
Check_time: 2003-09-12 17:44:26
Create_options:
Comment:
The Row_format value will be Fixed, Dynamic, or Compressed. 14.2.2 Using Compressed MyISAM TablesA MyISAM table may be converted to compressed form to save storage space. In many cases, compressing a table improves lookup speed as well, because the compression operation optimizes the internal structure of the table to make retrievals faster. A compressed table is read-only, so a MyISAM table should be compressed only if its content will not change after it has been populated. If you must modify a compressed table, you can uncompress it, modify it, and compress it again. But if you have to do this often, the extra processing tends to negate the benefits of using a compressed table, especially because the table is unavailable for querying during the uncompression and recompression operations. To compress a MyISAM table, use the myisampack utility. It's also necessary to use myisamchk afterward to update the indexes. The following example demonstrates how to perform this procedure, using the tables in the world database:
If you want to assess the effectiveness of the packing operation, use SHOW TABLE STATUS before and after packing the tables. (The server must be running when you use this statement.) The Data_length and Index_length values should be smaller afterward, and the Row_format value should change from Fixed or Dynamic to Compressed. The following examples show the results for the City table. Before packing:
mysql> SHOW TABLE STATUS FROM world LIKE 'City'\G
*************************** 1. row ***************************
Name: City
Type: MyISAM
Row_format: Fixed
Rows: 4079
Avg_row_length: 67
Data_length: 273293
Max_data_length: 287762808831
Index_length: 35840
Data_free: 0
Auto_increment: 4080
Create_time: 2002-12-20 17:17:55
Update_time: 2002-12-20 17:17:56
Check_time: NULL
Create_options:
Comment:
mysql> SHOW TABLE STATUS FROM world LIKE 'City'\G
*************************** 1. row ***************************
Name: City
Type: MyISAM
Row_format: Compressed
Rows: 4079
Avg_row_length: 19
Data_length: 79418
Max_data_length: 4294967295
Index_length: 30720
Data_free: 0
Auto_increment: 4080
Create_time: 2002-12-20 17:17:55
Update_time: 2002-12-20 17:17:56
Check_time: 2003-03-17 12:56:53
Create_options:
Comment:
To uncompress a compressed table, use myisamchk in the database directory where the table files are located: shell> myisamchk --unpack table_name A table must not be in use by other programs (including the server) while you compress or uncompress it. The easiest thing to do is to bring down the server while using myisampack or myisamchk. If you do not run myisampack or myisamchk in the database directory where the table files are located, you must specify the pathname to the files, using either absolute pathnames or pathnames relative to your current directory. Another way to uncompress a table is to dump it, drop it, and re-create it. Do this while the server is running. For example, if world.Country is compressed, you can uncompress it with the following commands: shell> mysqldump --opt world Country > dump.sql shell> mysql world < dump.sql The --opt option to mysqldump causes it to include a DROP TABLE statement in the output written to the dump file. When you process the file with mysql, that statement drops the compressed table, and the rest of the dump file re-creates the table in uncompressed form. |
< Day Day Up > |