我在MySQL中有以下查询:
SELECT query.*,
GROUP_CONCAT(COALESCE(query.gene,'None'), '(', query.loc, '|', COALESCE(query.typ,'unknown'), ')') AS outt
FROM (
SELECT genes.loc,
genes.typ, genes.abans, genes.despres, genes.gene,
mutations.id,mutations.chr,mutations.pos,mutations.ref,
mutations.ale,mutations.g001,mutations.g002,mutations.g003,
.... (snipped hundreds of denormalized fields)....
FROM genes
INNER JOIN mutations
ON genes.id=mutations.id
WHERE (mutations.g001>=0.40
AND mutations.g002>=0.40 AND mutations.g003>=0.40
AND mutations.g004>=0.40 AND mutations.g005>=0.40
AND mutations.g006>=0.40 AND mutations.g007>=0.40
AND mutations.g008>=0.40 AND mutations.g011>=0.40
AND mutations.g012>=0.40 AND mutations.g013>=0.40
AND mutations.g014>=0.40 AND mutations.g015>=0.40
AND ....(you get the idea)...
AND mutations.g105>=0.40
) LIMIT 0, 100
) AS query
GROUP BY query.id
我在该查询中执行GROUP_CONCAT
并且它运行良好。问题是我想要100行,而由于GROUP BY
,我得到的行少于100行。尝试将GROUP_CONCAT
直接应用于内部查询时,速度非常慢。你有什么建议吗?