MySQL中这个子查询是否有任何开销?

时间:2012-05-29 20:58:30

标签: mysql performance subquery explain

我想知道当我引入子查询时这个查询是否有开销:

SELECT p.id_product
FROM product p
JOIN reservation_product rp ON (p.id_product = rp.id_product)
JOIN reservation r ON (rp.id_reservation = r.id_reservation)

WHERE r.id_company =
-- **Subquery in question**
(SELECT r_inn.id_company FROM reservation r_inn WHERE r_inn.id_reservation = 56)

AND r.status = 'active'
-- Floor
AND r.checkout > '2012-05-30 13:00:00'
-- Ceil
AND r.checkin < '2012-05-30 15:00:00'
AND r.id_reservation <> 56
AND r.release_time IS NULL

我可以要求用户直接设置公司的ID,并且有一个像这样的WHERE:

WHERE r.id_company = 1

我试图通过引入子查询来避免这种情况,就像我在第一个示例中所示,但我担心性能开销。

对于第一个查询,这是EXPLAIN(请帮我这个,我还没有得到它的EXPLAIN子句):

EXPLAIN for the subquery query

对于被诅咒的人的解释:

enter image description here

0 个答案:

没有答案