Sunday, August 28, 2016

SQL Performance - CA PPM - In vs Exists

IN is typically better when the inner query contains a small result set

SELECT SRMR.FULL_NAME
FROM SRM_RESOURCES SRMR
WHERE SRMR.ID (SELECT TM.PRESOURCEID FROM PRTEAM TM WHERE TM.PRPROJECTID IN (5000,5001)

SELECT SRMR.FULL_NAME
FROM SRM_RESOURCES SRMR
WHERE EXISTS (SELECT 1 FROM PRTEAM TM WHERE TM.PRPROJECID IN(5000,5001) AND TM.PRRESOURCEID=SRMR.ID)

EXISTS is typically better when the inner query contains a large result set

SELECT SRMR.FULL_NAME
FROM SRM_RESOURCES SRMR
WHERE SRMR.ID IN (SELECT TM.PRRESOURCEID FROM PRTEAM TM)


SELECT SRMR.FULL_NAME
FROM SRM_RESOURCES SRMR
WHERE EXISTS (SELECT 1 FROM PRTEAM TM WHERE TM.PRRESOURCEID =SRMR.ID)