DBAsupport.com Forums - Powered by vBulletin
Results 1 to 8 of 8

Thread: Resolve Deadlock

  1. #1
    Join Date
    Sep 2000
    Location
    VA
    Posts
    343

    Resolve Deadlock

    I have the following deadlock error :
    Code:
    Current SQL Statement:
      UPDATE cum SET sc = :1 , scd = :2  WHERE c_id = :3 AND u_id = :4
    End of information on OTHER waiting sessions.
    Current SQL statement for this session:
    UPDATE cu SET o_id = :1  WHERE u_id = :2
    Here is the index/constraints structures :
    Table cum :
    PK constraint on c_id & u_id combination with index
    FK constraint on c_id without index
    FK constraint on u_id without index
    Nonunique Index on c_id

    Table CU :
    PK constraint on u_id with index
    FK contraint on o_id without index

    What could be the cause ? Would adding an index to the FK constraint cum.u_id help ?

    And this is not reproducible either. How do I verify it ?

    Thanks.

  2. #2
    You only need an index on the parent side of a FK constraint, and it is usually a good idea to prevent locking issues. However, no two statements can cause a deadlock, as one would just wait. You need to look at what those sessions are doing around the time of those two statements.

  3. #3
    Join Date
    Mar 2007
    Location
    Ft. Lauderdale, FL
    Posts
    3,555
    You have either to create indexes on your FK constraints or disable table locks on tables that have indexless FK constraint.
    Pablo (Paul) Berzukov

    Author of Understanding Database Administration available at amazon and other bookstores.

    Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.

  4. #4
    I didn't think it was possible to disable table locks in that situation.

  5. #5
    Join Date
    Sep 2000
    Location
    VA
    Posts
    343
    I cannot disable table locks as that table is being heavily used. So do I need an index on the child side of a FK constraint also ?

  6. #6
    Operations on the parent benefit from a index on the child. Operations on the child benefit from an index on the parent.

  7. #7
    Join Date
    Mar 2007
    Location
    Ft. Lauderdale, FL
    Posts
    3,555
    Metalink Note 15476.1 reads: "...it is recommended to have indexes on the foreign key columns of the child tables in order to avoid this additional locking activity..."

    By the way, "ALTER TABLE TABLE_NAME DISABLE TABLE LOCK" does not disables row level transactional locking.
    Last edited by PAVB; 11-13-2007 at 04:27 PM.
    Pablo (Paul) Berzukov

    Author of Understanding Database Administration available at amazon and other bookstores.

    Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.

  8. #8
    Join Date
    Sep 2000
    Location
    VA
    Posts
    343
    ok. makes sense.
    Thanks everyone.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width