Answer the question
In order to leave comments, you need to log in
How to optimize query with ORDER BY and FULLTEXT search?
There is a table on 12 million lines.
CREATE TABLE `shingles` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`shingle` text NOT NULL,
`count` int(11) NOT NULL,
`used` tinyint(1) DEFAULT NULL,
`stop` tinyint(1) DEFAULT NULL,
`date` tinyint(1) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `shingle` (`shingle`(255)) USING BTREE,
KEY `count` (`id`),
FULLTEXT KEY `shingle_fulltext` (`shingle`)
) ENGINE=InnoDB AUTO_INCREMENT=11707635 DEFAULT CHARSET=utf
select `t1`.* from
(select * from `shingles`
where MATCH (shingle) AGAINST ('слово' IN BOOLEAN MODE)) as t2
inner join `shingles` as `t1` on `t1`.`id` = `t2`.`id`
order by `t1`.`count` desc limit 5
Answer the question
In order to leave comments, you need to log in
You can try without a subquery, so there will be no nested loop over a large table:
SELECT t1.*, MATCH (t1.shingle) AGAINST ('word' IN BOOLEAN MODE) AS ind
FROM shingles as t1
ORDER BY t1.ind DESC, t1.count DESC
LIMIT 5
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question