-1

我有一个 MySQL 查询,它比较两个表之间的值。查询工作正常,但有点慢。

这是查询

SELECT * FROM questions WHERE questions.id NOT IN (SELECT answers.qid FROM answers where answers.account = 'Account') and FIND_IN_SET(questions.lang,'en,de') and category = 'Cat' order by section

我的结构看起来像这样

表问题

在此处输入图像描述

表答案

在此处输入图像描述

我在查询运行的两个表中都有大约 900 条记录。但查询执行时间为 5.8475 秒。

我想知道我的查询中是否有一些可以优化的东西以使其执行更快。

4

1 回答 1

1

尝试:

SELECT questions.*
FROM questions
    LEFT JOIN answers
        ON questions.id = answers.qid AND answers.account = 'Account'
WHERE answers.id IS NULL AND questions.category = 'Cat' AND questions.lang IN('de', 'en')
ORDER BY questions.section

正如哈克曼在评论中所建议的那样,我猜 aLEFT JOIN而不是 a更快。NOT IN()此外,我认为它IN()比 快FIND_IN_SET,但我没有测试或研究它。

于 2020-01-17T08:37:21.243 回答