它使用雙嵌套子查詢以下MySQL查詢太慢嵌套子查詢太慢
SELECT t.name
FROM creatives AS c
INNER JOIN term_relationships AS tr ON tr.creative_id=c.creative_id
INNER JOIN terms AS t ON t.term_id=tr.term_id
WHERE c.creative_id IN
(SELECT creative_id
FROM term_relationships
WHERE term_id IN
(SELECT offer_term_id
FROM offer_urls))
AND t.taxonomy LIKE 'ad_network';
內部查詢
SELECT creative_id
FROM term_relationships
WHERE term_id IN
(SELECT offer_term_id
FROM offer_urls)
極快(0.04秒),
但完整的查詢不會提供結果。等了5分鐘後我放棄了。
任何方式來優化?
爲什麼不嘗試'LEFT OUTER JOIN'和一個空檢查呢?雖然下一個語句是純粹的猜測,但我假設每個檢索行都執行子查詢(因此,行a,對所有行b執行子查詢,它們針對所有行c單獨執行)。 – Rogue
您的表格是否正確編制索引? –