Consider the following table:
CREATE TABLE `item` (
`id` bigint(11) unsigned NOT NULL AUTO_INCREMENT,
`category` smallint(11) unsigned NOT NULL,
`description` TEXT(500) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `category` (`category`),
FULLTEXT KEY `fulltextnameindex` (`description`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `item` (`id`, `category`, `description`)
VALUES
(1, 1, 'Nothing here for you'),
(2, 2, 'Still nothing here for you'),
(3, 2, 'this is sometext for you');
To perform a fulltext search to match the string sometext
in the description
field within a category I run the following:
SELECT i.id FROM item i
WHERE MATCH(i.description) AGAINST ('+sometext*' IN BOOLEAN MODE) AND category IN (2);
This works great, until the table gets huge (especially since I need to have the minimum indexed word token size to be 1 or 2).
- There are many categories, and the distribution of rows is fairly equal across categories
- With non-FULLLTEXT indexes you can create composite indexes that would make this more efficient like
CREATE INDEX yippie ON item(category,name)
would work if you were doing something likeSELECT i.id FROM item i WHERE category IN (2) AND name LIKE '%sometext%
(note, I'm not claiming '%sometext%' is efficient in itself, but the query more efficient with the category where clause due to the composite coving index). - The dream would be to have some kind of composite index across both the
category
andname
column like:CREATE FULLTEXT INDEX yippie ON item(category,name)
, but this of course isn't valid
Does anyone know a way to achieve the effect of #3 using FULLTEXT search (without creating separate tables for each category)?