Chinaunix首页 | 论坛 | 博客
  • 博客访问: 103776973
  • 博文数量: 19283
  • 博客积分: 9968
  • 博客等级: 上将
  • 技术积分: 196062
  • 用 户 组: 普通用户
  • 注册时间: 2007-02-07 14:28
文章分类

全部博文(19283)

文章存档

2011年(1)

2009年(125)

2008年(19094)

2007年(63)

分类:

2008-04-30 22:51:47




Avoiding SQLCODE -746 in CALL in Trigger


Technote (FAQ)

Problem  
When issuing a CALL statement in a trigger, an SQLCODE SQL0746 is issued at runtime.  

Cause
The SQL0746 error prevents procedures called by a trigger to access tables which have previously been modified within the context of the invoking statement. These so called "mutating table conflicts" can cause non deterministic results and must be blocked.  

Solution
In DB2 V8.1 FP 11 (V8.2.4) a new registry variable DB2_RESOLVE_CALL_CONFLICT has been introduced which, when set, eliminates SQLCODE -746 errors in the context of triggers. With this variable set DB2 enforces that all modifications to tables are completed in compliance with the SQL Standard rules for triggers before executing the CALL statement.

Limitations:

Once DB2_RESOLVE_CALL_CONFLICT is set, procedures called directly or indirectly by a trigger must not perform any DDL.

This limitation includes:

* DECLARE GLOBAL TEMPORARY TABLE,

* CREATE/DROP TABLE,

* CREATE/DROP INDEX.

It is recommended for performance reasons to declare temporary tables outside procedures which are executed frequently. Instead of DROP/DECLARE DDL, DELETE statements or the ON COMMIT DELETE ROWS property of temporary tables should be used to re-initialize temporary tables.Following this recommendation will both improve performance and allow procedures using temporary tables to be called from triggers.

Usage:

1. Stop the DB2 instance
2. Execute "db2set DB2_RESOLVE_CALL_CONFLICT=YES" from a shell
3. Start the DB2 instance
4. Rebind any packages which cause invocation of triggers.

To rebind SQL Procedures use:
CALL SYSPROC.REBIND_ROUTINE_PACKAGE
('P','.','CONSERVATIVE');

Performance impact:

DB2_RESOLVE_CALL_CONFLICT causes DB2 to resolve all potential read/write conflicts through the injection of temporary tables as needed. Typically at most one temporary tables is injected which is very small in an OLTP environment because only one or a small number of rows are being modified by the triggering statement.Typically, when following the general recommendation to use SMS (system managed storage) for temporary tablespaces, the performance impact from setting DB2_RESOLVE_CALL_CONFLICT is expected to be low.

阅读(865) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~