SELECT tmp.question_set_id,
qs.sort_order, qa.type, qa.entities, qa.segment, qa.number_entities, qa.display,
q.content, qa.value, m.title as media_title, m.content as media_content
FROM question_set_answer qsa
LEFT JOIN
(SELECT * FROM question_set_answer ORDER BY RAND()) tmp ON (qsa.id= tmp.id)
JOIN question_set qs ON qs.id = tmp.question_set_id
JOIN question_answer qa ON qa.id = tmp.question_answer_id
JOIN question q ON q.id = qa.question_id
LEFT JOIN
(SELECT component_id, title, content FROM media WHERE component ='question_answer')
m ON m.component_id = tmp.question_answer_id
WHERE qs.component_id = 142
AND qs.component = 'game_level'
GROUP BY tmp.question_set_id
ORDER BY qsa.id
答案 0 :(得分:0)
(SELECT * FROM question_set_answer ORDER BY RAND())
AAAAAAAAAAAAAAAAAAAAAA!
的 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA!强> 的
* ahem *对不起,我在那里失去了镇静。
ORDER BY RAND()
表示必须扫描和排序整个表。即使您的查询的其余部分正确地匹配每个索引,如果表具有任何大量数据,这将是您的瓶颈。从您提出这个问题的事实来看,我认为您遇到了性能问题。
除了这一般建议之外,您能否为该查询发布EXPLAIN
的输出?