create index インデックス名 on テーブル名 (フィールド名);先頭5文字目までをインデックス化したいならば、
create index title_index on bib_tb (title(5));作成したインデックスを確認する
mysql> show index from bib_tb;[Enter Key]実際にインデックスが使用されているかどうかを確認する
+--------+------------+-------------+--------------+-------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name |
+--------+------------+-------------+--------------+-------------+
| bib_tb | 0 | PRIMARY | 1 | id |
| bib_tb | 1 | title_index | 1 | title |
+--------+------------+-------------+--------------+-------------+
-----------+-------------+----------+--------+---------+
Collation | Cardinality | Sub_part | Packed | Comment |
-----------+-------------+----------+--------+---------+
A | 6595 | NULL | NULL | |
A | 3297 | 5 | NULL | |
-----------+-------------+----------+--------+---------+
2 rows in set (0.00 sec)
explain select * from bib_tb where title like ('日本%');インデックスを削除する
drop index インデックス名 on テーブル名;order byについてorder byはindexを利用できない。my.cnf設定での改善を考えてみる。
http://kapi.jp/kapi_blog/105
2008年01月15日
関連カテゴリ Mysql