我的問題是這樣的:MySQL的子查詢與JOIN性能差
select * from
(
select * from barcodesA
UNION ALL
select * from barcodesB
)
as barcodesTOTAL, boxes
where barcodesTotal.code=boxes.code;
表barcodesA有4000項 表barcodesB有4000項 表盒有一個像180.000項
它需要30秒proccess的查詢。
另一個有問題的查詢:
select * from
viewBarcodesTotal, boxes
where barcodesTotal.code=boxes.code;
viewBarcodesTotal包含UNION ALL從兩個條形碼錶。它也需要永遠。
同時,
select * from barcodesA , boxes where barcodesA.code=boxes.code
UNION ALL
select * from barcodesB , boxes where barcodesB.code=boxes.code
這其中需要<1秒。
問題顯然是爲什麼?是我的代碼被竊聽?是mysql竊聽?
我必須從訪問遷移到MySQL,我將不得不重寫所有我的代碼,如果第一個選項在竊聽。
簡而言之:子查詢很慢,儘可能避免它們。 – Polynomial 2012-01-28 22:22:40
您可能需要在查詢上運行EXPLAIN並在您的問題中包含該輸出。否則,你有代碼字段上的索引嗎?你真的需要獲得所有的數據或一個子集(基於條件)就足夠了嗎? – 2012-01-28 22:33:56