How do I add indices to MySQL tables?
ALTER TABLE `table` ADD INDEX `product_id_index` (`product_id`)
Never compare integer
to strings
in MySQL. If id
is int
, remove the quotes.
You can use this syntax to add an index and control the kind of index (HASH or BTREE).
create index your_index_name on your_table_name(your_column_name) using HASH;
or
create index your_index_name on your_table_name(your_column_name) using BTREE;
You can learn about differences between BTREE and HASH indexes here:http://dev.mysql.com/doc/refman/5.5/en/index-btree-hash.html