早上好。
我想知道它更优化了什么:
SELECT PROD.ID
FROM PRODUCT PROD
INNER JOIN SUBPRODUCT SUB ON PROD.SUBTYPE = SUB.SUBTYPE AND SUB.SOMEFIELD = 1
WHERE PROD.FOO = 2
OR
SELECT PROD.ID
FROM PRODUCT PROD
INNER JOIN
(
SELECT SUB.SUBTYPE FROM SUBPRODUCT SUB WHERE SUB.SOMEFIELD = 1
) PROD.SUBTYPE = SUB.SUBTYPE
WHERE PROD.FOO = 2
非常感谢!!
答案 0 :(得分:1)
只是通过查看查询,我无法分辨哪一个是更优化的形式。但我会选择下面的一个。
SELECT PROD.ID
FROM PRODUCT PROD
INNER JOIN
(
SELECT SUB.SUBTYPE FROM SUBPRODUCT SUB WHERE SUB.SOMEFIELD = 1
) T ON PROD.SUBTYPE = T.SUBTYPE
WHERE PROD.FOO = 2