【发布时间】:2020-08-23 21:21:55
【问题描述】:
我正在尝试优化使用 GROUP BY 的查询。但是不能花太长时间吗。
我有一个包含 3 列的虚拟表:
CREATE VIRTUAL TABLE GoiWordsWithSeq
USING FTS5(idseq,sid,body);
我希望组与下面的查询一样,但运行时间太长了。 例如,我首先尝试了这个,效果很好,但我仍然想知道是否可以让它更快:
select
GROUP_CONCAT(body), sid
from GoiWordsWithSeq
GROUP BY sid
HAVING sid IN (
select sid from GoiWordsWithSeq
where GoiWordsWithSeq.body match 'awesome'
)
然后:
select
GROUP_CONCAT(body), GoiWordsWithSeq.sid
from GoiWordsWithSeq
inner join (
select sid from GoiWordsWithSeq
where GoiWordsWithSeq.body match 'awesome'
) GoiMatch ON GoiMatch.sid = GoiWordsWithSeq.sid
GROUP BY GoiWordsWithSeq.sid
但是查询还是需要很长时间。我正在尝试使用 JOIN,因为我听说它通常更快但不能真正成功。任何建议都会有所帮助!
【问题讨论】: