[Date Prev][Date Next][Thread Prev][Thread Next]
[Author Index] [Date Index] [Thread Index]
[SQR-USERS Info] [SQRUG Home Page]

Which statement would be most efficient?



I have an update statement that seems to be taking too much time.
The current statement reads:

UPDATE PS_PROJ_RESOURCE
SET PC_DISTRIB_STATUS = 'D'
WHERE PS_PROJ_RESOURCE.BUSINESS_UNIT     = $BU
AND   PS_PROJ_RESOURCE.PC_DISTRIB_STATUS = 'N'
AND EXISTS (SELECT 1 FROM PS_PC_DIST_LN PC_DIST_LN
            WHERE  PC_DIST_LN.BUSINESS_UNIT = PS_PROJ_RESOURCE.BUSINESS_UNIT
            AND    PC_DIST_LN.PROJECT_ID    = PS_PROJ_RESOURCE.PROJECT_ID
            AND    PC_DIST_LN.ACTIVITY_ID   = PS_PROJ_RESOURCE.ACTIVITY_ID
            AND    PC_DIST_LN.RESOURCE_ID   = PS_PROJ_RESOURCE.RESOURCE_ID)
-----------------------------------------------------------
Here is what I propose:

UPDATE PS_PROJ_RESOURCE
SET PC_DISTRIB_STATUS = 'D'
WHERE PS_PROJ_RESOURCE.BUSINESS_UNIT     = $BU
AND   PS_PROJ_RESOURCE.PC_DISTRIB_STATUS = 'N'
AND   PS_PROJ_RESOURCE.RESOURCE_ID IN
     (SELECT PC_DIST_LN.RESOURCE_ID
      FROM PS_PC_DIST_LN PC_DIST_LN
      WHERE  PC_DIST_LN.BUSINESS_UNIT = PS_PROJ_RESOURCE.BUSINESS_UNIT
      AND    PC_DIST_LN.PROJECT_ID    = PS_PROJ_RESOURCE.PROJECT_ID
      AND    PC_DIST_LN.ACTIVITY_ID   = PS_PROJ_RESOURCE.ACTIVITY_ID
      AND    PC_DIST_LN.RESOURCE_ID   = PS_PROJ_RESOURCE.RESOURCE_ID)
-----------------------------------------------------------
The unique index on both tables contain   BUSINESS_UNIT, PROJECT_ID,
ACTIVITY_ID, RESOURCE_ID
as the first 4 fields.  After that, each table's unique index has other
(different) fields as part of the index.  So that
tells me, at best, I will get partial index usage.

In addition, PS_PROJ_RESOURCE has a non-unique index with BUSINESS_UNIT and
PC_DISTRIB_STATUS as the key items.

I am wondering if using 'IN' is more efficient than using 'EXISTS'??

Anyone have comments or suggestions on this?

Many thanks!