I have the following schema in MySQL 5.1
CREATE TABLE `mytest` (
`category` varchar(32) ,
`item_name` varchar(255)
KEY `key1` (`category`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Category Columnfilled in this way
[:parent_parent_cat_id][:parent_cat_id][:leaf_cat_id]
10000200003000
if you can search all categories: parent_parent_category_id
SELECT * FROM mytest WHERE category LIKE "10000%";
using index key1;
but How to use an index when I want to search: parent_cat_id?
SELECT * FROM mytest WHERE category LIKE "%20000%";
Do you have any better solutions?
source
share