3

My deletes in Oracle 11 are very slow. The tables are linked by foreign keys and every foreign key constraint has a delete cascade set on it.

If I hit the explain button on a statement like this DELETE FROM TOP_LEVEL_TABLE WHERE SOMETHING = 'whatever' it only shows my the involvment of the TOP_LEVEL_TABLE even if 30 other tables are involved.

How can I get a more realistic result?

2 Answers 2

5

I don't think this is possible.

If I'm not mistaken, the optimizer doesn't even know (or at least doesn't try to know) that the statement will "touch" other tables as well.

It's not explicitely documented, but the following quote from the manual only talks about the tables "referenced" in the SQL statement (emphasis is mine):

The row source tree is the core of the execution plan. It shows the following information:
   -  An ordering of the tables referenced by the statement
   -  An access method for each table mentioned in the statement
...

I think the important part is: "tables referenced by the statement". No mentioning of "dependent" tables.

Edit:
If you need to extract that information, you probably have to trace your session and look at the TKPROF output.

1
1

It's not possible to see the whole involved tables in an execution plan. If the locked objects (by cascade foreign key constraints) is matter of consideration, following query will be helpful.

  1. Execute your query on your schema.
  2. Execute following query on SYSTEM schema simultaneously and refresh that to see which dependent tables are involved and locked (it's easier than check tkprof in some cases).

    SELECT l.OS_USER_NAME,
            sys_context('userenv','ip_address') IP ,
            NVL(l.oracle_username, '(oracle)')  ORACLE_USER_NAME,
            obj.OBJECT_TYPE,
            OBJECT_NAME,
            Decode(l.locked_mode,
                  0, 'None',
                  1, 'Null (NULL)',
                  2, 'Row-S (SS)',
                  3, 'Row-X (SX)',
                  4, 'Share (S)',
                  5, 'S/Row-X (SSX)',
                  6, 'Exclusive (X)',
                  l.locked_mode) locked_mode    ,
            v.SID  "SESSION_ID(SID)" ,
            v.SERIAL# ,
            v.INST_ID ,
            'ALTER SYSTEM KILL SESSION '''||v.SID ||','||v.SERIAL# ||',@'||  v.INST_ID||''' IMMEDIATE; '  KILL_COMMAND
    from v$locked_object l   ,   
        dba_objects obj , 
        gv$session v
    where obj.OBJECT_ID=l.OBJECT_ID
    and v.SID  = l.SESSION_ID
    and obj.OBJECT_NAME not like '%DR$%';
    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.