有一张1200万行的表格。
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=utf8
以下请求执行20秒
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
全文搜索结果越多,越慢......
我该如何优化?没有“order by”,它很快就会起作用。
答案 0 :(得分:0)
为什么使用子查询?这不是一回事吗?
select s.*
from shingles s
where match (s.shingle) against ('слово' in boolean mode)
order by s.count desc
limit 5;
尽管如此,我认为您无法显着提高查询效果。