zoukankan      html  css  js  c++  java
  • Oracle deadlock SX/SSX caused by no index on foreign key.

    Example to show the dead lock caused by lack of index on foreign key of child table.

    Session 1:

    create table p ( x int primary key );
    create table c ( x references p );

    insert into p select rownum from all_users where rownum <= 2;
    insert into c select * from p;
    commit;
    delete from c where x = 1;

    Session 2:

    prompt delete from c where x = 2;
    prompt delete from p where x = 2; -- session 2 will be hang.


    Session 1:

    delete from p where x = 1; -- session1 will be hang, deadlock will be detected after a while.

    DEADLOCK DETECTED ( ORA-00060 )

    [Transaction Deadlock]

    The following deadlock is not an ORACLE error. It is a
    deadlock due to user error in the design of an application
    or from issuing incorrect ad-hoc SQL. The following
    information may aid in determining the deadlock:

    Deadlock graph:
    ---------Blocker(s)-------- ---------Waiter(s)---------
    Resource Name process session holds waits process session holds waits
    TM-00012c11-00000000 47 138 SX SSX 45 136 SX SSX
    TM-00012c11-00000000 45 136 SX SSX 47 138 SX SSX

    session 138: DID 0001-002F-00000176 session 136: DID 0001-002D-00000098
    session 136: DID 0001-002D-00000098 session 138: DID 0001-002F-00000176

    Rows waited on:
    Session 138: no row
    Session 136: no row

    ----- Information for the OTHER waiting sessions -----
    Session 136:
    sid: 136 ser: 207 audsid: 384548 user: 100/TEST flags: 0x45
    pid: 45 O/S info: user: SYSTEM, term: PRICNESSD, ospid: 7044
    image: ORACLE.EXE (SHAD)
    client details:
    O/S info: user: PRICNESSDAdministrator, term: PRICNESSD, ospid: 6880:8016
    machine: WORKGROUPPRICNESSD program: sqlplus.exe
    application name: SQL*Plus, hash value=3669949024
    current SQL:
    delete from p where x=2

    ----- End of information for the OTHER waiting sessions -----

    Information for THIS session:

    ----- Current SQL Statement for this session (sql_id=dyg3c78z0ft6g) -----
    delete from p where x=1
    ===================================================

    The typical identifer for this is two SQL waiting on delete statement on one table, both transaction hold SX lock waiting on SSX lock.

    Create on index on the foreign key column will resolve this problem.

    create index c_idx on c(x);

  • 相关阅读:
    hdu 5400 Arithmetic Sequence
    【小超_Android】android上开源的酷炫的交互动画和视觉效果:Interactive-animation
    项目PMO工作
    HDU 3340 Rain in ACStar(线段树+几何)
    再看数据库——(6)连接
    Android 安装应用后点击打开带来的问题
    Notes 和 Domino 已知限制
    去哪网实习总结:JavaWeb配置404页面(JavaWeb)
    Android 怎样实现 焦点图的 无线循环滑动的状态?
    【JNI探索之路系列】之七:JNI要点总结
  • 原文地址:https://www.cnblogs.com/princessd8251/p/3879659.html
Copyright © 2011-2022 走看看