我有两个返回相同结果的查询:
1.
SELECT DISTINCT
cvc.object_id
, cvc.object_name
FROM ems.ibo_sm_cvc_rfs cvc,
ems.ibo_alcatel_mse_locale poi,
ems.ibo_nbn_csa csa,
ems.ibo_sm_ean_service_sites_rfs sites,
ems.ibo_sm_ean_service_site_rfs site
WHERE poi.object_name ='testPoi'
AND csa.parent_id = poi.object_id
AND cvc.csa_id = csa.csa_id
AND sites.parent_id = cvc.object_id
AND site.service_site_type = 'testSite'
AND site.object_name IN (SELECT mse_chassis.object_name
FROM ems.ibo_alcatel_mse_chassis mse_chassis
WHERE mse_chassis.parent_id = poi.object_id);
2.:
SELECT cvc.object_id,
cvc.object_name
FROM ems.ibo_sm_cvc_rfs cvc
JOIN ems.ibo_nbn_csa csa
ON cvc.csa_id = csa.csa_id
JOIN ems.ibo_sm_ean_service_sites_rfs sites
ON sites.parent_id = cvc.object_id
WHERE csa.parent_id IN (SELECT poi.object_id
FROM ems.ibo_alcatel_mse_locale poi
WHERE poi.object_id IN (SELECT csa.parent_id FROM ems.ibo_nbn_csa csa)
AND poi.object_name = 'testPoi'
AND poi.object_id IN
(SELECT mse_chassis.parent_id
FROM EMS.ibo_alcatel_mse_chassis mse_chassis
WHERE mse_chassis.object_name IN
(SELECT site.object_name
FROM EMS.ibo_sm_ean_service_site_rfs site
WHERE site.service_site_type = 'testSite')
)
);
对我来说奇怪的是,第一个语句在 0.156 秒内完成,而第二个语句在 0.624 秒内完成。需要提一下,所有 ems.* 对象都是视图,我发现基本上 where 子句中的每一列都被索引了。如果需要,我可以放置视图架构,但我宁愿不要,因为是公司信息。也许一双经验的眼睛可能会看到这两种说法的改进