我的问题是这样的: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