List:Commits« Previous MessageNext Message »
From:jonas oreland Date:March 23 2011 3:57pm
Subject:bzr commit into mysql-5.1-telco-7.0 branch (jonas:4252)
View as plain text  
#At file:///home/jonas/src/70-deferred/ based on revid:magnus.blaudd@stripped

 4252 jonas oreland	2011-03-23
      ndb - deferred unique indexes - commit to test

    added:
      mysql-test/suite/ndb/r/ndb_index_unique_deferred.result
      mysql-test/suite/ndb/t/ndb_index_unique_deferred.test
      mysql-test/suite/rpl_ndb/r/rpl_ndb_ui.result
      mysql-test/suite/rpl_ndb/r/rpl_ndb_ui2.result
      mysql-test/suite/rpl_ndb/r/rpl_ndb_ui3.result
      mysql-test/suite/rpl_ndb/t/rpl_ndb_ui.test
      mysql-test/suite/rpl_ndb/t/rpl_ndb_ui2.test
      mysql-test/suite/rpl_ndb/t/rpl_ndb_ui3.test
    modified:
      mysql-test/suite/ndb/r/ndb_basic.result
      sql/ha_ndbcluster.cc
      storage/ndb/include/kernel/GlobalSignalNumbers.h
      storage/ndb/include/kernel/signaldata/FireTrigOrd.hpp
      storage/ndb/include/kernel/signaldata/LqhKey.hpp
      storage/ndb/include/kernel/signaldata/PackedSignal.hpp
      storage/ndb/include/kernel/signaldata/TcContinueB.hpp
      storage/ndb/include/kernel/signaldata/TcKeyReq.hpp
      storage/ndb/include/kernel/signaldata/TupKey.hpp
      storage/ndb/include/ndbapi/NdbOperation.hpp
      storage/ndb/src/common/debugger/signaldata/LqhKey.cpp
      storage/ndb/src/common/debugger/signaldata/PackedSignal.cpp
      storage/ndb/src/common/debugger/signaldata/TcKeyReq.cpp
      storage/ndb/src/kernel/blocks/dblqh/Dblqh.hpp
      storage/ndb/src/kernel/blocks/dblqh/DblqhInit.cpp
      storage/ndb/src/kernel/blocks/dblqh/DblqhMain.cpp
      storage/ndb/src/kernel/blocks/dbtc/Dbtc.hpp
      storage/ndb/src/kernel/blocks/dbtc/DbtcMain.cpp
      storage/ndb/src/kernel/blocks/dbtup/Dbtup.hpp
      storage/ndb/src/kernel/blocks/dbtup/DbtupCommit.cpp
      storage/ndb/src/kernel/blocks/dbtup/DbtupExecQuery.cpp
      storage/ndb/src/kernel/blocks/dbtup/DbtupGen.cpp
      storage/ndb/src/kernel/blocks/dbtup/DbtupTrigger.cpp
      storage/ndb/src/ndbapi/NdbOperationDefine.cpp
      storage/ndb/src/ndbapi/NdbOperationExec.cpp
=== modified file 'mysql-test/suite/ndb/r/ndb_basic.result'
--- a/mysql-test/suite/ndb/r/ndb_basic.result	2011-03-02 14:11:26 +0000
+++ b/mysql-test/suite/ndb/r/ndb_basic.result	2011-03-23 15:57:37 +0000
@@ -82,6 +82,7 @@ ndb_blob_write_batch_bytes	#
 ndb_cache_check_time	#
 ndb_cluster_connection_pool	#
 ndb_connectstring	#
+ndb_deferred_constraints	#
 ndb_distribution	#
 ndb_extra_logging	#
 ndb_force_send	#

=== added file 'mysql-test/suite/ndb/r/ndb_index_unique_deferred.result'
--- a/mysql-test/suite/ndb/r/ndb_index_unique_deferred.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/ndb/r/ndb_index_unique_deferred.result	2011-03-23 15:57:37 +0000
@@ -0,0 +1,186 @@
+drop table if exists t1, t2, t3, t4, t5, t6, t7, t8;
+CREATE TABLE t1 (
+a int NOT NULL PRIMARY KEY,
+b int,
+c int,
+UNIQUE (b),
+UNIQUE (c)
+) engine=ndbcluster;
+insert t1 values(1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4), (5,5,5), (6,6,6);
+set ndb_deferred_constraints=1;
+begin;
+update t1 set b = 2 where a = 1;
+update t1 set b = 1 where a = 2;
+commit;
+select * from t1;
+a	b	c
+1	2	1
+2	1	2
+3	3	3
+4	4	4
+5	5	5
+6	6	6
+begin;
+update t1 set b = 1 where a = 1;
+update t1 set b = 2 where a = 2;
+commit;
+select * from t1;
+a	b	c
+1	1	1
+2	2	2
+3	3	3
+4	4	4
+5	5	5
+6	6	6
+begin;
+update t1 set b = 2 where a = 1;
+update t1 set b = 3 where a = 2;
+commit;
+ERROR 23000: Can't write; duplicate key in table ''
+select * from t1;
+a	b	c
+1	1	1
+2	2	2
+3	3	3
+4	4	4
+5	5	5
+6	6	6
+begin;
+update t1 set b = 2 where a = 1;
+update t1 set b = 1 where a = 2;
+update t1 set c = 2 where a = 1;
+update t1 set c = 1 where a = 2;
+commit;
+select * from t1;
+a	b	c
+1	2	2
+2	1	1
+3	3	3
+4	4	4
+5	5	5
+6	6	6
+begin;
+update t1 set b = 1 where a = 1;
+update t1 set b = 2 where a = 2;
+update t1 set c = 1 where a = 1;
+update t1 set c = 2 where a = 2;
+commit;
+select * from t1;
+a	b	c
+1	1	1
+2	2	2
+3	3	3
+4	4	4
+5	5	5
+6	6	6
+begin;
+update t1 set b = 2 where a = 1;
+update t1 set b = 1 where a = 2;
+update t1 set c = 2 where a = 1;
+update t1 set c = 3 where a = 2;
+commit;
+ERROR 23000: Can't write; duplicate key in table ''
+select * from t1;
+a	b	c
+1	1	1
+2	2	2
+3	3	3
+4	4	4
+5	5	5
+6	6	6
+begin;
+update t1 set b = 2 where a = 1;
+update t1 set b = NULL where a = 2;
+commit;
+select * from t1;
+a	b	c
+1	2	1
+2	NULL	2
+3	3	3
+4	4	4
+5	5	5
+6	6	6
+begin;
+update t1 set b = 2 where a = 2;
+update t1 set b = 1 where a = 1;
+commit;
+select * from t1;
+a	b	c
+1	1	1
+2	2	2
+3	3	3
+4	4	4
+5	5	5
+6	6	6
+begin;
+update t1 set b = 2 where a = 1;
+update t1 set b = NULL where a = 2;
+update t1 set c = NULL where a = 1;
+update t1 set c = 1 where a = 2;
+commit;
+select * from t1;
+a	b	c
+1	2	NULL
+2	NULL	1
+3	3	3
+4	4	4
+5	5	5
+6	6	6
+begin;
+update t1 set b = 1 where a = 1;
+update t1 set b = 2 where a = 2;
+update t1 set c = 1 where a = 1;
+update t1 set c = 2 where a = 2;
+commit;
+select * from t1;
+a	b	c
+1	1	1
+2	2	2
+3	3	3
+4	4	4
+5	5	5
+6	6	6
+begin;
+update t1 set b = NULL where a = 1;
+update t1 set b = NULL where a = 2;
+update t1 set c = NULL where a = 1;
+update t1 set c = NULL where a = 2;
+commit;
+select * from t1;
+a	b	c
+1	NULL	NULL
+2	NULL	NULL
+3	3	3
+4	4	4
+5	5	5
+6	6	6
+begin;
+update t1 set b = 1 where a = 1;
+update t1 set b = 2 where a = 2;
+update t1 set c = 1 where a = 1;
+update t1 set c = 2 where a = 2;
+commit;
+select * from t1;
+a	b	c
+1	1	1
+2	2	2
+3	3	3
+4	4	4
+5	5	5
+6	6	6
+begin;
+update t1 set b = NULL where a = 1;
+update t1 set b = 1 where a = 2;
+update t1 set c = 1 where a = 2;
+commit;
+ERROR 23000: Can't write; duplicate key in table ''
+select * from t1;
+a	b	c
+1	1	1
+2	2	2
+3	3	3
+4	4	4
+5	5	5
+6	6	6
+drop table t1;
+set ndb_deferred_constraints=0;

=== added file 'mysql-test/suite/ndb/t/ndb_index_unique_deferred.test'
--- a/mysql-test/suite/ndb/t/ndb_index_unique_deferred.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/ndb/t/ndb_index_unique_deferred.test	2011-03-23 15:57:37 +0000
@@ -0,0 +1,130 @@
+-- source include/have_ndb.inc
+
+--disable_warnings
+drop table if exists t1, t2, t3, t4, t5, t6, t7, t8;
+--enable_warnings
+
+CREATE TABLE t1 (
+  a int NOT NULL PRIMARY KEY,
+  b int,
+  c int,
+  UNIQUE (b),
+  UNIQUE (c)
+) engine=ndbcluster;
+
+insert t1 values(1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4), (5,5,5), (6,6,6);
+set ndb_deferred_constraints=1;
+begin;
+update t1 set b = 2 where a = 1;
+update t1 set b = 1 where a = 2;
+commit;
+--sorted_result
+select * from t1;
+
+begin;
+update t1 set b = 1 where a = 1;
+update t1 set b = 2 where a = 2;
+commit;
+--sorted_result
+select * from t1;
+
+begin;
+update t1 set b = 2 where a = 1;
+update t1 set b = 3 where a = 2;
+--error 1022
+commit;
+--sorted_result
+select * from t1;
+
+begin;
+update t1 set b = 2 where a = 1;
+update t1 set b = 1 where a = 2;
+update t1 set c = 2 where a = 1;
+update t1 set c = 1 where a = 2;
+commit;
+--sorted_result
+select * from t1;
+
+begin;
+update t1 set b = 1 where a = 1;
+update t1 set b = 2 where a = 2;
+update t1 set c = 1 where a = 1;
+update t1 set c = 2 where a = 2;
+commit;
+--sorted_result
+select * from t1;
+
+begin;
+update t1 set b = 2 where a = 1;
+update t1 set b = 1 where a = 2;
+update t1 set c = 2 where a = 1;
+update t1 set c = 3 where a = 2;
+--error 1022
+commit;
+--sorted_result
+select * from t1;
+
+### And now...NULL values!
+begin;
+update t1 set b = 2 where a = 1;
+update t1 set b = NULL where a = 2;
+commit;
+--sorted_result
+select * from t1;
+
+begin;
+update t1 set b = 2 where a = 2;
+update t1 set b = 1 where a = 1;
+commit;
+--sorted_result
+select * from t1;
+
+begin;
+update t1 set b = 2 where a = 1;
+update t1 set b = NULL where a = 2;
+update t1 set c = NULL where a = 1;
+update t1 set c = 1 where a = 2;
+commit;
+--sorted_result
+select * from t1;
+
+begin;
+update t1 set b = 1 where a = 1;
+update t1 set b = 2 where a = 2;
+update t1 set c = 1 where a = 1;
+update t1 set c = 2 where a = 2;
+commit;
+--sorted_result
+select * from t1;
+
+begin;
+update t1 set b = NULL where a = 1;
+update t1 set b = NULL where a = 2;
+update t1 set c = NULL where a = 1;
+update t1 set c = NULL where a = 2;
+commit;
+--sorted_result
+select * from t1;
+
+begin;
+update t1 set b = 1 where a = 1;
+update t1 set b = 2 where a = 2;
+update t1 set c = 1 where a = 1;
+update t1 set c = 2 where a = 2;
+commit;
+--sorted_result
+select * from t1;
+
+begin;
+update t1 set b = NULL where a = 1;
+update t1 set b = 1 where a = 2;
+update t1 set c = 1 where a = 2;
+--error 1022
+commit;
+--sorted_result
+select * from t1;
+
+drop table t1;
+set ndb_deferred_constraints=0;
+
+# end of tests

=== added file 'mysql-test/suite/rpl_ndb/r/rpl_ndb_ui.result'
--- a/mysql-test/suite/rpl_ndb/r/rpl_ndb_ui.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl_ndb/r/rpl_ndb_ui.result	2011-03-23 15:57:37 +0000
@@ -0,0 +1,52 @@
+stop slave;
+drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
+reset master;
+reset slave;
+drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
+start slave;
+CREATE TABLE t1 (pk int primary key, uk int not null, unique(uk)) engine=ndb;
+insert into t1 values (1,1);
+insert into t1 values (2,2);
+insert into t1 values (3,3);
+insert into t1 values (4,4);
+insert into t1 values (5,5);
+select * from t1 where uk in (1,2,3,4,5);
+pk	uk
+1	1
+2	2
+3	3
+4	4
+5	5
+update t1 set uk=uk-1 order by pk;
+select * from t1 where uk in (0,1,2,3,4);
+pk	uk
+1	0
+2	1
+3	2
+4	3
+5	4
+Master table contents
+select * from t1 order by pk;
+pk	uk
+1	0
+2	1
+3	2
+4	3
+5	4
+flush logs;
+Slave table contents
+select * from t1 order by pk;
+pk	uk
+1	0
+2	1
+3	2
+4	3
+5	4
+select * from t1 where uk in (0,1,2,3,4);
+pk	uk
+1	0
+2	1
+3	2
+4	3
+5	4
+drop table t1;

=== added file 'mysql-test/suite/rpl_ndb/r/rpl_ndb_ui2.result'
--- a/mysql-test/suite/rpl_ndb/r/rpl_ndb_ui2.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl_ndb/r/rpl_ndb_ui2.result	2011-03-23 15:57:37 +0000
@@ -0,0 +1,21 @@
+stop slave;
+drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
+reset master;
+reset slave;
+drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
+start slave;
+CREATE TABLE t1 (pk int primary key, uk int not null, unique(uk)) engine=ndb;
+STOP SLAVE;
+insert into t1 values (1,1);
+insert into t1 values (2,2);
+insert into t1 values (1,2);
+insert into t1 values (2,1);
+delete from t1;
+insert into t1 values (1,1);
+insert into t1 values (2,2);
+start slave;
+select * from t1;
+pk	uk
+1	1
+2	2
+drop table t1;

=== added file 'mysql-test/suite/rpl_ndb/r/rpl_ndb_ui3.result'
--- a/mysql-test/suite/rpl_ndb/r/rpl_ndb_ui3.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl_ndb/r/rpl_ndb_ui3.result	2011-03-23 15:57:37 +0000
@@ -0,0 +1,54 @@
+stop slave;
+drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
+reset master;
+reset slave;
+drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
+start slave;
+CREATE TABLE t1 (pk int primary key, uk1 int not null, uk2 int not null,
+unique(uk1), unique(uk2)) engine=ndb;
+insert into t1 values (1,1,1);
+insert into t1 values (2,2,2);
+insert into t1 values (3,3,3);
+insert into t1 values (4,4,4);
+insert into t1 values (5,5,5);
+select * from t1 where uk1 in (1,2,3,4,5);
+pk	uk1	uk2
+1	1	1
+2	2	2
+3	3	3
+4	4	4
+5	5	5
+update t1 set uk1=uk1-1 order by pk;
+update t1 set uk2=uk2+1 order by pk desc;
+select * from t1 where uk1 in (0,1,2,3,4);
+pk	uk1	uk2
+1	0	2
+2	1	3
+3	2	4
+4	3	5
+5	4	6
+Master table contents
+select * from t1 order by pk;
+pk	uk1	uk2
+1	0	2
+2	1	3
+3	2	4
+4	3	5
+5	4	6
+flush logs;
+Slave table contents
+select * from t1 order by pk;
+pk	uk1	uk2
+1	0	2
+2	1	3
+3	2	4
+4	3	5
+5	4	6
+select * from t1 where uk1 in (0,1,2,3,4);
+pk	uk1	uk2
+1	0	2
+2	1	3
+3	2	4
+4	3	5
+5	4	6
+drop table t1;

=== added file 'mysql-test/suite/rpl_ndb/t/rpl_ndb_ui.test'
--- a/mysql-test/suite/rpl_ndb/t/rpl_ndb_ui.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl_ndb/t/rpl_ndb_ui.test	2011-03-23 15:57:37 +0000
@@ -0,0 +1,50 @@
+--source include/have_ndb.inc
+--source include/have_binlog_format_mixed_or_row.inc
+--source suite/rpl_ndb/ndb_master-slave.inc
+
+#
+# Slave behaviour when replicating unique index operations
+#
+#
+
+--connection master
+
+CREATE TABLE t1 (pk int primary key, uk int not null, unique(uk)) engine=ndb;
+
+# Now perform some operations which do not result in uniqueness
+# violations when applied in-order, but which can result in them
+# when applied out-of-order
+# 5 distinct values chosen to increase the chance of different
+# fragments (and therefore potentially different SUMA->Binlog
+# orders) being seen.
+#
+insert into t1 values (1,1);
+insert into t1 values (2,2);
+insert into t1 values (3,3);
+insert into t1 values (4,4);
+insert into t1 values (5,5);
+
+--sorted_result
+select * from t1 where uk in (1,2,3,4,5);
+
+# Do a 'right shift' on the unique key values
+update t1 set uk=uk-1 order by pk;
+
+--sorted_result
+select * from t1 where uk in (0,1,2,3,4);
+
+--echo Master table contents
+select * from t1 order by pk;
+
+flush logs;
+
+--sync_slave_with_master
+
+--connection slave
+
+--echo Slave table contents
+select * from t1 order by pk;
+select * from t1 where uk in (0,1,2,3,4);
+
+--connection master
+drop table t1;

=== added file 'mysql-test/suite/rpl_ndb/t/rpl_ndb_ui2.test'
--- a/mysql-test/suite/rpl_ndb/t/rpl_ndb_ui2.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl_ndb/t/rpl_ndb_ui2.test	2011-03-23 15:57:37 +0000
@@ -0,0 +1,35 @@
+--source include/have_ndb.inc
+--source include/have_binlog_format_mixed_or_row.inc
+--source suite/rpl_ndb/ndb_master-slave.inc
+
+--connection master
+
+CREATE TABLE t1 (pk int primary key, uk int not null, unique(uk)) engine=ndb;
+
+--sync_slave_with_master
+--connection slave
+STOP SLAVE;
+insert into t1 values (1,1);
+insert into t1 values (2,2);
+--connection master
+insert into t1 values (1,2);
+insert into t1 values (2,1);
+--sleep 1
+delete from t1;
+--sleep 1
+insert into t1 values (1,1);
+insert into t1 values (2,2);
+
+--connection slave
+start slave;
+
+--connection master
+--sync_slave_with_master
+--connection slave
+--sorted_result
+select * from t1;
+
+--connection master
+drop table t1;
+--sync_slave_with_master
+

=== added file 'mysql-test/suite/rpl_ndb/t/rpl_ndb_ui3.test'
--- a/mysql-test/suite/rpl_ndb/t/rpl_ndb_ui3.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl_ndb/t/rpl_ndb_ui3.test	2011-03-23 15:57:37 +0000
@@ -0,0 +1,52 @@
+--source include/have_ndb.inc
+--source include/have_binlog_format_mixed_or_row.inc
+--source suite/rpl_ndb/ndb_master-slave.inc
+
+#
+# Slave behaviour when replicating unique index operations
+#
+#
+
+--connection master
+
+CREATE TABLE t1 (pk int primary key, uk1 int not null, uk2 int not null,
+       unique(uk1), unique(uk2)) engine=ndb;
+
+# Now perform some operations which do not result in uniqueness
+# violations when applied in-order, but which can result in them
+# when applied out-of-order
+# 5 distinct values chosen to increase the chance of different
+# fragments (and therefore potentially different SUMA->Binlog
+# orders) being seen.
+#
+insert into t1 values (1,1,1);
+insert into t1 values (2,2,2);
+insert into t1 values (3,3,3);
+insert into t1 values (4,4,4);
+insert into t1 values (5,5,5);
+
+--sorted_result
+select * from t1 where uk1 in (1,2,3,4,5);
+
+# Do a 'right shift' on the unique key values
+update t1 set uk1=uk1-1 order by pk;
+update t1 set uk2=uk2+1 order by pk desc;
+
+--sorted_result
+select * from t1 where uk1 in (0,1,2,3,4);
+
+--echo Master table contents
+select * from t1 order by pk;
+
+flush logs;
+
+--sync_slave_with_master
+
+--connection slave
+
+--echo Slave table contents
+select * from t1 order by pk;
+select * from t1 where uk1 in (0,1,2,3,4);
+
+--connection master
+drop table t1;

=== modified file 'sql/ha_ndbcluster.cc'
--- a/sql/ha_ndbcluster.cc	2011-03-16 06:53:41 +0000
+++ b/sql/ha_ndbcluster.cc	2011-03-23 15:57:37 +0000
@@ -245,7 +245,18 @@ static MYSQL_THDVAR_UINT(
   UINT_MAX,                          /* max */
   0                                  /* block */
 );
-  
+
+static MYSQL_THDVAR_UINT(
+  deferred_constraints,              /* name */
+  PLUGIN_VAR_RQCMDARG,
+  "Specified that constraints should be checked deferred (when supported)",
+  NULL,                              /* check func */
+  NULL,                              /* update func */
+  0,                                 /* default */
+  0,                                 /* min */
+  1,                                 /* max */
+  0                                  /* block */
+);
 
 /*
   Default value for max number of transactions createable against NDB from
@@ -4093,6 +4104,12 @@ int ha_ndbcluster::ndb_write_row(uchar *
     options.extraSetValues= sets;
     options.numExtraSetValues= num_sets;
   }
+  if (thd->slave_thread || THDVAR(thd, deferred_constraints))
+  {
+    options.optionsPresent |=
+      NdbOperation::OperationOptions::OO_DEFERRED_CONSTAINTS;
+  }
+
   if (options.optionsPresent != 0)
     poptions=&options;
 
@@ -4843,6 +4860,12 @@ int ha_ndbcluster::ndb_update_row(const 
   
   bool need_flush= add_row_check_if_batch_full(thd_ndb);
 
+  if (thd->slave_thread || THDVAR(thd, deferred_constraints))
+  {
+    options.optionsPresent |=
+      NdbOperation::OperationOptions::OO_DEFERRED_CONSTAINTS;
+  }
+
   if (cursor)
   {
     /*
@@ -5067,6 +5090,12 @@ int ha_ndbcluster::ndb_delete_row(const 
   uint delete_size= 12 + (m_bytes_per_write >> 2);
   bool need_flush= add_row_check_if_batch_full_size(thd_ndb, delete_size);
 
+  if (thd->slave_thread || THDVAR(thd, deferred_constraints))
+  {
+    options.optionsPresent |=
+      NdbOperation::OperationOptions::OO_DEFERRED_CONSTAINTS;
+  }
+
   if (cursor)
   {
     if (options.optionsPresent != 0)
@@ -15572,7 +15601,7 @@ static struct st_mysql_sys_var* system_v
   MYSQL_SYSVAR(nodeid),
   MYSQL_SYSVAR(blob_read_batch_bytes),
   MYSQL_SYSVAR(blob_write_batch_bytes),
-
+  MYSQL_SYSVAR(deferred_constraints),
   NULL
 };
 

=== modified file 'storage/ndb/include/kernel/GlobalSignalNumbers.h'
--- a/storage/ndb/include/kernel/GlobalSignalNumbers.h	2011-02-01 23:27:25 +0000
+++ b/storage/ndb/include/kernel/GlobalSignalNumbers.h	2011-03-23 15:57:37 +0000
@@ -337,9 +337,11 @@ extern const GlobalSignalNumber NO_OF_SI
 /* 233 unused */
 /* 234 unused */
 #define GSN_DISCONNECT_REP              235
-/* 236 unused */
-/* 237 unused */
-/* 238 unused */
+
+#define GSN_FIRE_TRIG_REQ               236
+#define GSN_FIRE_TRIG_REF               237
+#define GSN_FIRE_TRIG_CONF              238
+
 #define GSN_DIVERIFYCONF                239
 #define GSN_DIVERIFYREF                 240
 #define GSN_DIVERIFYREQ                 241

=== modified file 'storage/ndb/include/kernel/signaldata/FireTrigOrd.hpp'
--- a/storage/ndb/include/kernel/signaldata/FireTrigOrd.hpp	2011-02-01 23:27:25 +0000
+++ b/storage/ndb/include/kernel/signaldata/FireTrigOrd.hpp	2011-03-23 15:57:37 +0000
@@ -225,5 +225,31 @@ void FireTrigOrd::setAnyValue(Uint32 any
   m_any_value = any_value;
 }
 
+struct FireTrigReq
+{
+  STATIC_CONST( SignalLength = 4 );
+
+  Uint32 tcOpRec;
+  Uint32 transId[2];
+  Uint32 pass;
+};
+
+struct FireTrigRef
+{
+  STATIC_CONST( SignalLength = 4 );
+
+  Uint32 tcOpRec;
+  Uint32 transId[2];
+  Uint32 errCode;
+};
+
+struct FireTrigConf
+{
+  STATIC_CONST( SignalLength = 4 );
+
+  Uint32 tcOpRec;
+  Uint32 transId[2];
+  Uint32 noFiredTriggers; // bit 31 defered trigger
+};
 
 #endif

=== modified file 'storage/ndb/include/kernel/signaldata/LqhKey.hpp'
--- a/storage/ndb/include/kernel/signaldata/LqhKey.hpp	2011-02-08 13:55:54 +0000
+++ b/storage/ndb/include/kernel/signaldata/LqhKey.hpp	2011-03-23 15:57:37 +0000
@@ -166,6 +166,12 @@ private:
    */
   static UintR getCorrFactorFlag(const UintR & requestInfo);
   static void setCorrFactorFlag(UintR & requestInfo, UintR val);
+
+  /**
+   * Include corr factor
+   */
+  static UintR getDeferredConstraints(const UintR & requestInfo);
+  static void setDeferredConstraints(UintR & requestInfo, UintR val);
 };
 
 /**
@@ -195,6 +201,7 @@ private:
  * q = Queue on redo problem  - 1  Bit (14)
  * A = CorrFactor flag        - 1  Bit (24)
  * P = Do normal protocol even if dirty-read - 1 Bit (25)
+ * D = Deferred constraints   - 1  Bit (26)
 
  * Short LQHKEYREQ :
  *             1111111111222222222233
@@ -205,7 +212,7 @@ private:
  * Long LQHKEYREQ :
  *             1111111111222222222233
  *   01234567890123456789012345678901
- *             llgnqpdisooorrAP cumxz
+ *             llgnqpdisooorrAPDcumxz
  *
  */
 
@@ -235,6 +242,7 @@ private:
 #define RI_QUEUE_REDO_SHIFT  (14)
 #define RI_CORR_FACTOR_VALUE (24)
 #define RI_NORMAL_DIRTY      (25)
+#define RI_DEFERRED_CONSTAINTS (26)
 
 /**
  * Scan Info
@@ -625,6 +633,19 @@ LqhKeyReq::getCorrFactorFlag(const UintR
 }
 
 inline
+void
+LqhKeyReq::setDeferredConstraints(UintR & requestInfo, UintR val){
+  ASSERT_BOOL(val, "LqhKeyReq::setDeferredConstraints");
+  requestInfo |= (val << RI_DEFERRED_CONSTAINTS);
+}
+
+inline
+UintR
+LqhKeyReq::getDeferredConstraints(const UintR & requestInfo){
+  return (requestInfo >> RI_DEFERRED_CONSTAINTS) & 1;
+}
+
+inline
 Uint32
 table_version_major_lqhkeyreq(Uint32 x)
 {
@@ -688,7 +709,7 @@ private:
   };
   Uint32 transId1;
   Uint32 transId2;
-  Uint32 noFiredTriggers;
+  Uint32 noFiredTriggers; // bit 31 defered trigger
 };
 
 class LqhKeyRef {

=== modified file 'storage/ndb/include/kernel/signaldata/PackedSignal.hpp'
--- a/storage/ndb/include/kernel/signaldata/PackedSignal.hpp	2011-02-01 23:27:25 +0000
+++ b/storage/ndb/include/kernel/signaldata/PackedSignal.hpp	2011-03-23 15:57:37 +0000
@@ -28,6 +28,8 @@
 #define ZCOMPLETED 3
 #define ZLQHKEYCONF 4
 #define ZREMOVE_MARKER 5
+#define ZFIRE_TRIG_REQ 6
+#define ZFIRE_TRIG_CONF 7
 
 class PackedSignal {
 

=== modified file 'storage/ndb/include/kernel/signaldata/TcContinueB.hpp'
--- a/storage/ndb/include/kernel/signaldata/TcContinueB.hpp	2011-02-01 23:27:25 +0000
+++ b/storage/ndb/include/kernel/signaldata/TcContinueB.hpp	2011-03-23 15:57:37 +0000
@@ -46,7 +46,8 @@ private:
     TRIGGER_PENDING                        = 17,
     
     DelayTCKEYCONF = 18,
-    ZNF_CHECK_TRANSACTIONS = 19
+    ZNF_CHECK_TRANSACTIONS = 19,
+    ZSEND_FIRE_TRIG_REQ = 20
   };
 };
 

=== modified file 'storage/ndb/include/kernel/signaldata/TcKeyReq.hpp'
--- a/storage/ndb/include/kernel/signaldata/TcKeyReq.hpp	2011-02-08 13:55:54 +0000
+++ b/storage/ndb/include/kernel/signaldata/TcKeyReq.hpp	2011-03-23 15:57:37 +0000
@@ -207,6 +207,13 @@ private:
 
   static void setQueueOnRedoProblemFlag(UintR & requestInfo, UintR val);
   static UintR getQueueOnRedoProblemFlag(const UintR & requestInfo);
+
+  /**
+   * Check constraints deferred
+   */
+  static UintR getDeferredConstraints(const UintR & requestInfo);
+  static void setDeferredConstraints(UintR & requestInfo, UintR val);
+
   /**
    * Set:ers for scanInfo
    */
@@ -237,11 +244,12 @@ private:
  n = No disk flag          - 1  Bit 1
  r = reorg flag            - 1  Bit 19
  q = Queue on redo problem - 1  Bit 9
+ D = deferred constraint   - 1  Bit 17
 
            1111111111222222222233
  01234567890123456789012345678901
  dnb cooop lsyyeiaaarkkkkkkkkkkkk  (Short TCKEYREQ)
- dnbvcooopqlsyyei   r              (Long TCKEYREQ)
+ dnbvcooopqlsyyei D r              (Long TCKEYREQ)
 */
 
 #define TCKEY_NODISK_SHIFT (1)
@@ -270,6 +278,8 @@ private:
 #define TC_REORG_SHIFT     (19)
 #define QUEUE_ON_REDO_SHIFT (9)
 
+#define TC_DEFERRED_CONSTAINTS_SHIFT (17)
+
 /**
  * Scan Info
  *
@@ -612,4 +622,18 @@ TcKeyReq::setQueueOnRedoProblemFlag(Uint
   requestInfo |= (flag << QUEUE_ON_REDO_SHIFT);
 }
 
+inline
+void
+TcKeyReq::setDeferredConstraints(UintR & requestInfo, UintR val){
+  ASSERT_BOOL(val, "TcKeyReq::setDeferredConstraints");
+  requestInfo |= (val << TC_DEFERRED_CONSTAINTS_SHIFT);
+}
+
+inline
+UintR
+TcKeyReq::getDeferredConstraints(const UintR & requestInfo){
+  return (requestInfo >> TC_DEFERRED_CONSTAINTS_SHIFT) & 1;
+}
+
+
 #endif

=== modified file 'storage/ndb/include/kernel/signaldata/TupKey.hpp'
--- a/storage/ndb/include/kernel/signaldata/TupKey.hpp	2011-02-01 23:27:25 +0000
+++ b/storage/ndb/include/kernel/signaldata/TupKey.hpp	2011-03-23 15:57:37 +0000
@@ -38,7 +38,7 @@ class TupKeyReq {
   friend bool printTUPKEYREQ(FILE * output, const Uint32 * theData, Uint32 len, Uint16 receiverBlockNo);
 
 public:
-  STATIC_CONST( SignalLength = 19 );
+  STATIC_CONST( SignalLength = 20 );
 
 private:
 
@@ -64,6 +64,7 @@ private:
   Uint32 m_row_id_page_no;
   Uint32 m_row_id_page_idx;
   Uint32 attrInfoIVal;
+  Uint32 deferred_constraints;
 };
 
 class TupKeyConf {

=== modified file 'storage/ndb/include/ndbapi/NdbOperation.hpp'
--- a/storage/ndb/include/ndbapi/NdbOperation.hpp	2011-02-09 14:18:53 +0000
+++ b/storage/ndb/include/ndbapi/NdbOperation.hpp	2011-03-23 15:57:37 +0000
@@ -1040,7 +1040,8 @@ public:
                  OO_CUSTOMDATA   = 0x40,
                  OO_LOCKHANDLE   = 0x80,
                  OO_QUEUABLE     = 0x100,
-                 OO_NOT_QUEUABLE = 0x200
+                 OO_NOT_QUEUABLE = 0x200,
+                 OO_DEFERRED_CONSTAINTS = 0x400
     };
 
     /* An operation-specific abort option.
@@ -1439,7 +1440,8 @@ protected:
       word set by setAnyValue().
     */
     OF_USE_ANY_VALUE = 0x2,
-    OF_QUEUEABLE = 0x4
+    OF_QUEUEABLE = 0x4,
+    OF_DEFERRED_CONSTRAINTS = 0x8
   };
   Uint8  m_flags;
 

=== modified file 'storage/ndb/src/common/debugger/signaldata/LqhKey.cpp'
--- a/storage/ndb/src/common/debugger/signaldata/LqhKey.cpp	2011-02-08 13:55:54 +0000
+++ b/storage/ndb/src/common/debugger/signaldata/LqhKey.cpp	2011-03-23 15:57:37 +0000
@@ -65,7 +65,9 @@ printLQHKEYREQ(FILE * output, const Uint
     fprintf(output, "GCI ");
   if(LqhKeyReq::getQueueOnRedoProblemFlag(reqInfo))
     fprintf(output, "Queue ");
-  
+  if(LqhKeyReq::getDeferredConstraints(reqInfo))
+    fprintf(output, "Deferred-constraints ");
+
   fprintf(output, "ScanInfo/noFiredTriggers: H\'%x\n", sig->scanInfo);
   
   fprintf(output,

=== modified file 'storage/ndb/src/common/debugger/signaldata/PackedSignal.cpp'
--- a/storage/ndb/src/common/debugger/signaldata/PackedSignal.cpp	2011-02-01 23:27:25 +0000
+++ b/storage/ndb/src/common/debugger/signaldata/PackedSignal.cpp	2011-03-23 15:57:37 +0000
@@ -97,6 +97,24 @@ printPACKED_SIGNAL(FILE * output, const 
       fprintf(output,"\n");
       break;
     }
+    case ZFIRE_TRIG_REQ: {
+      Uint32 signalLength = 3;
+
+      fprintf(output, "--------------- Signal ----------------\n");
+      fprintf(output, "r.bn: %u \"%s\", length: %u \"FIRE_TRIG_REQ\"\n",
+	      receiverBlockNo, getBlockName(receiverBlockNo,""), signalLength);
+      i += signalLength;
+      break;
+    }
+    case ZFIRE_TRIG_CONF: {
+      Uint32 signalLength = 4;
+
+      fprintf(output, "--------------- Signal ----------------\n");
+      fprintf(output, "r.bn: %u \"%s\", length: %u \"FIRE_TRIG_CONF\"\n",
+	      receiverBlockNo, getBlockName(receiverBlockNo,""), signalLength);
+      i += signalLength;
+      break;
+    }
     default:
       fprintf(output, "Unknown signal type\n");
       i = len; // terminate printing

=== modified file 'storage/ndb/src/common/debugger/signaldata/TcKeyReq.cpp'
--- a/storage/ndb/src/common/debugger/signaldata/TcKeyReq.cpp	2011-02-08 13:55:54 +0000
+++ b/storage/ndb/src/common/debugger/signaldata/TcKeyReq.cpp	2011-03-23 15:57:37 +0000
@@ -79,6 +79,9 @@ printTCKEYREQ(FILE * output, const Uint3
     if(sig->getQueueOnRedoProblemFlag(sig->requestInfo))
       fprintf(output, "Queue ");
 
+    if(sig->getDeferredConstraints(sig->requestInfo))
+      fprintf(output, "Deferred-constraints ");
+
     fprintf(output, "\n");
   }
   

=== modified file 'storage/ndb/src/kernel/blocks/dblqh/Dblqh.hpp'
--- a/storage/ndb/src/kernel/blocks/dblqh/Dblqh.hpp	2011-02-23 19:28:26 +0000
+++ b/storage/ndb/src/kernel/blocks/dblqh/Dblqh.hpp	2011-03-23 15:57:37 +0000
@@ -2112,10 +2112,12 @@ public:
     Uint8 m_disk_table;
     Uint8 m_use_rowid;
     Uint8 m_dealloc;
+    Uint8 m_fire_trig_pass;
     enum op_flags {
       OP_ISLONGREQ              = 0x1,
       OP_SAVEATTRINFO           = 0x2,
-      OP_SCANKEYINFOPOSSAVED    = 0x4
+      OP_SCANKEYINFOPOSSAVED    = 0x4,
+      OP_DEFERRED_CONSTRAINTS   = 0x8
     };
     Uint32 m_flags;
     Uint32 m_log_part_ptr_i;
@@ -2308,6 +2310,8 @@ private:
   void execBUILD_INDX_IMPL_REF(Signal* signal);
   void execBUILD_INDX_IMPL_CONF(Signal* signal);
 
+  void execFIRE_TRIG_REQ(Signal*);
+
   // Statement blocks
 
   void init_acc_ptr_list(ScanRecord*);
@@ -3263,6 +3267,9 @@ public:
   void suspendFile(Signal* signal, Ptr<LogFileRecord> logFile, Uint32 millis);
 
   void send_runredo_event(Signal*, LogPartRecord *, Uint32 currgci);
+
+  void sendFireTrigConfTc(Signal* signal, BlockReference ref, Uint32 Tdata[]);
+  Uint32 cas_fire_trig_pass(Uint32 op, Uint32 oldval, Uint32 newval);
 };
 
 inline

=== modified file 'storage/ndb/src/kernel/blocks/dblqh/DblqhInit.cpp'
--- a/storage/ndb/src/kernel/blocks/dblqh/DblqhInit.cpp	2011-02-15 11:41:27 +0000
+++ b/storage/ndb/src/kernel/blocks/dblqh/DblqhInit.cpp	2011-03-23 15:57:37 +0000
@@ -422,6 +422,8 @@ Dblqh::Dblqh(Block_context& ctx, Uint32 
                &Dblqh::execFSWRITEREQ);
   addRecSignal(GSN_DBINFO_SCANREQ, &Dblqh::execDBINFO_SCANREQ);
 
+  addRecSignal(GSN_FIRE_TRIG_REQ, &Dblqh::execFIRE_TRIG_REQ);
+
   initData();
 
 #ifdef VM_TRACE

=== modified file 'storage/ndb/src/kernel/blocks/dblqh/DblqhMain.cpp'
--- a/storage/ndb/src/kernel/blocks/dblqh/DblqhMain.cpp	2011-02-23 19:28:26 +0000
+++ b/storage/ndb/src/kernel/blocks/dblqh/DblqhMain.cpp	2011-03-23 15:57:37 +0000
@@ -74,6 +74,7 @@
 #include <signaldata/FsReadWriteReq.hpp>
 #include <signaldata/DbinfoScan.hpp>
 #include <signaldata/SystemError.hpp>
+#include <signaldata/FireTrigOrd.hpp>
 #include <NdbEnv.h>
 
 #include "../suma/Suma.hpp"
@@ -3264,6 +3265,21 @@ void Dblqh::execPACKED_SIGNAL(Signal* si
       execREMOVE_MARKER_ORD(signal);
       Tstep += 3;
       break;
+    case ZFIRE_TRIG_REQ:
+      jam();
+      ndbassert(FireTrigReq::SignalLength == 4);
+      sig0 = TpackedData[Tstep + 0] & 0x0FFFFFFF;
+      sig1 = TpackedData[Tstep + 1];
+      sig2 = TpackedData[Tstep + 2];
+      sig3 = TpackedData[Tstep + 3];
+      signal->theData[0] = sig0;
+      signal->theData[1] = sig1;
+      signal->theData[2] = sig2;
+      signal->theData[3] = sig3;
+      signal->header.theLength = FireTrigReq::SignalLength;
+      execFIRE_TRIG_REQ(signal);
+      Tstep += FireTrigReq::SignalLength;
+      break;
     default:
       ndbrequire(false);
       return;
@@ -4537,6 +4553,13 @@ void Dblqh::execLQHKEYREQ(Signal* signal
     nextPos += 2;
   }
 
+  Uint32 Tdeferred = LqhKeyReq::getDeferredConstraints(Treqinfo);
+  if (isLongReq && Tdeferred)
+  {
+    regTcPtr->m_flags |= TcConnectionrec::OP_DEFERRED_CONSTRAINTS;
+    regTcPtr->m_fire_trig_pass = 0;
+  }
+
   UintR TitcKeyLen = 0;
   Uint32 keyLenWithLQHReq = 0;
   UintR TreclenAiLqhkey   = 0;
@@ -5881,6 +5904,7 @@ Dblqh::acckeyconf_tupkeyreq(Signal* sign
   Uint32 page_idx = local_key & MAX_TUPLES_PER_PAGE;
   Uint32 page_no = local_key >> MAX_TUPLES_BITS;
   Uint32 Ttupreq = regTcPtr->dirtyOp;
+  Uint32 flags = regTcPtr->m_flags;
   Ttupreq = Ttupreq + (regTcPtr->opSimple << 1);
   Ttupreq = Ttupreq + (op << 6);
   Ttupreq = Ttupreq + (regTcPtr->opExec << 10);
@@ -5943,6 +5967,8 @@ Dblqh::acckeyconf_tupkeyreq(Signal* sign
   regTcPtr->m_row_id.m_page_idx = page_idx;
   
   tupKeyReq->attrInfoIVal= RNIL;
+  tupKeyReq->deferred_constraints =
+    (flags & TcConnectionrec::OP_DEFERRED_CONSTRAINTS) != 0;
 
   /* Pass AttrInfo section if available in the TupKeyReq signal
    * We are still responsible for releasing it, TUP is just
@@ -7276,6 +7302,101 @@ void Dblqh::errorReport(Signal* signal, 
   return;
 }//Dblqh::errorReport()
 
+void
+Dblqh::execFIRE_TRIG_REQ(Signal* signal)
+{
+  Uint32 tcOprec = signal->theData[0];
+  Uint32 transid1 = signal->theData[1];
+  Uint32 transid2 = signal->theData[2];
+  Uint32 pass = signal->theData[3];
+  jamEntry();
+
+  Uint32 err;
+  if (findTransaction(transid1, transid2, tcOprec, 0) == ZOK)
+  {
+    TcConnectionrec * const regTcPtr = tcConnectptr.p;
+    /**
+     *
+     */
+    signal->theData[0] = regTcPtr->tupConnectrec;
+    signal->theData[1] = regTcPtr->tcBlockref;
+    signal->theData[2] = regTcPtr->tcOprec;
+    signal->theData[3] = transid1;
+    signal->theData[4] = transid2;
+    signal->theData[5] = pass;
+    Uint32 tup = refToMain(regTcPtr->tcTupBlockref);
+    EXECUTE_DIRECT(tup, GSN_FIRE_TRIG_REQ, signal, 6);
+
+    err = signal->theData[0];
+    Uint32 cnt = signal->theData[1];
+    if (err == 0)
+    {
+      jam();
+      Uint32 Tdata[FireTrigConf::SignalLength];
+      FireTrigConf * conf = CAST_PTR(FireTrigConf, Tdata);
+      conf->tcOpRec = tcOprec;
+      conf->transId[0] = transid1;
+      conf->transId[1] = transid2;
+      conf->noFiredTriggers = cnt;
+      sendFireTrigConfTc(signal, regTcPtr->tcBlockref, Tdata);
+      return;
+    }
+  }
+  else
+  {
+    jam();
+  }
+
+  ndbrequire(false);
+
+  return;
+}
+
+void
+Dblqh::sendFireTrigConfTc(Signal* signal,
+                          BlockReference atcBlockref,
+                          Uint32 Tdata[])
+{
+  HostRecordPtr Thostptr;
+  Uint32 len = FireTrigConf::SignalLength;
+
+  Thostptr.i = refToNode(atcBlockref);
+  ptrCheckGuard(Thostptr, chostFileSize, hostRecord);
+
+  if (Thostptr.p->noOfPackedWordsTc > (25 - len))
+  {
+    jam();
+    sendPackedSignalTc(signal, Thostptr.p);
+  }
+  else
+  {
+    jam();
+    updatePackedList(signal, Thostptr.p, Thostptr.i);
+  }
+
+  ndbassert(FireTrigConf::SignalLength == 4);
+  Uint32 * dst = &Thostptr.p->packedWordsTc[Thostptr.p->noOfPackedWordsTc];
+  Thostptr.p->noOfPackedWordsTc += len;
+  dst[0] = Tdata[0] | (ZFIRE_TRIG_CONF << 28);
+  dst[1] = Tdata[1];
+  dst[2] = Tdata[2];
+  dst[3] = Tdata[3];
+}
+
+Uint32
+Dblqh::cas_fire_trig_pass(Uint32 opId, Uint32 oldval, Uint32 newval)
+{
+  TcConnectionrecPtr regTcPtr;
+  regTcPtr.i= opId;
+  ptrCheckGuard(regTcPtr, ctcConnectrecFileSize, tcConnectionrec);
+  Uint32 val = regTcPtr.p->m_fire_trig_pass;
+  if (val == oldval)
+  {
+    regTcPtr.p->m_fire_trig_pass = newval;
+  }
+  return val;
+}
+
 /* ************************************************************************>>
  *  COMMIT: Start commit request from TC. This signal is originally sent as a
  *  packed signal and this function is called from execPACKED_SIGNAL.

=== modified file 'storage/ndb/src/kernel/blocks/dbtc/Dbtc.hpp'
--- a/storage/ndb/src/kernel/blocks/dbtc/Dbtc.hpp	2011-02-23 19:28:26 +0000
+++ b/storage/ndb/src/kernel/blocks/dbtc/Dbtc.hpp	2011-03-23 15:57:37 +0000
@@ -170,7 +170,17 @@ public:
     CS_FAIL_COMMITTING = 22,
     CS_FAIL_COMMITTED = 23,
     CS_FAIL_COMPLETED = 24,
-    CS_START_SCAN = 25
+    CS_START_SCAN = 25,
+
+    /**
+     * Sending FIRE_TRIG_REQ
+     */
+    CS_SEND_FIRE_TRIG_REQ = 26,
+
+    /**
+     * Waiting for FIRE_TRIG_CONF/REF (or operations generated by this)
+     */
+    CS_WAIT_FIRE_TRIG_REQ = 27
   };
 
   enum OperationState {
@@ -191,7 +201,9 @@ public:
     OS_WAIT_COMMIT_CONF = 15,
     OS_WAIT_ABORT_CONF = 16,
     OS_WAIT_COMPLETE_CONF = 17,
-    OS_WAIT_SCAN = 18
+    OS_WAIT_SCAN = 18,
+
+    OS_FIRE_TRIG_REQ = 19,
   };
 
   enum AbortState {
@@ -237,8 +249,7 @@ public:
     IOS_NOOP = 0,
     IOS_INDEX_ACCESS = 1,
     IOS_INDEX_ACCESS_WAIT_FOR_TCKEYCONF = 2,
-    IOS_INDEX_ACCESS_WAIT_FOR_TRANSID_AI = 3,
-    IOS_INDEX_OPERATION = 4
+    IOS_INDEX_ACCESS_WAIT_FOR_TRANSID_AI = 3
   };
   
   enum IndexState {
@@ -694,7 +705,10 @@ public:
     //---------------------------------------------------
     UintR lastTcConnect;
     UintR lqhkeyreqrec;
-    Uint32 buddyPtr;
+    union {
+      Uint32 buddyPtr;
+      Int32 pendingTriggers; // For deferred triggers
+    };
     union {
       UintR apiScanRec;
       UintR commitAckMarker;
@@ -704,15 +718,22 @@ public:
     ReturnSignal returnsignal;
     AbortState abortState;
 
-    Uint8 indexOpReturn;
-    Uint8 triggerPending; // Used to mark waiting for a CONTINUEB
+    enum TransactionFlags
+    {
+      TF_INDEX_OP_RETURN = 1,
+      TF_TRIGGER_PENDING = 2, // Used to mark waiting for a CONTINUEB
+      TF_EXEC_FLAG       = 4,
+      TF_COMMIT_ACK_MARKER_RECEIVED = 8,
+      TF_DEFERRED_CONSTRAINTS = 16, // check constraints in deferred fashion
+      TF_DEFERRED_TRIGGERS = 32, // trans has deferred triggers
+      TF_END = 0
+    };
+    Uint32 m_flags;
 
-    Uint8 m_exec_flag;
     Uint8 m_special_op_flags; // Used to mark on-going TcKeyReq as indx table
 
     Uint8 takeOverRec;
     Uint8 currentReplicaNo;
-    Uint8 m_commit_ack_marker_received;
 
     Uint8 tckeyrec; // Changed from R
 
@@ -775,6 +796,12 @@ public:
 #ifdef ERROR_INSERT
     Uint32 continueBCount;  // ERROR_INSERT 8082
 #endif
+    Uint8 m_pre_commit_pass;
+
+    bool isExecutingDeferredTriggers() const {
+      return apiConnectstate == CS_SEND_FIRE_TRIG_REQ ||
+        apiConnectstate == CS_WAIT_FIRE_TRIG_REQ ;
+    }
   };
   
   typedef Ptr<ApiConnectRecord> ApiConnectRecordPtr;
@@ -839,7 +866,8 @@ public:
       SOF_REORG_MOVING = 8,           // A record that should be moved
       SOF_TRIGGER = 16,               // A trigger
       SOF_REORG_COPY = 32,
-      SOF_REORG_DELETE = 64
+      SOF_REORG_DELETE = 64,
+      SOF_DEFERRED_TRIGGER = 128      // Op has deferred trigger
     };
     
     static inline bool isIndexOp(Uint8 flags) {
@@ -862,12 +890,12 @@ public:
     Uint16 lqhInstanceKey;
     
     // Trigger data
-    FiredTriggerPtr accumulatingTriggerData;
-    UintR noFiredTriggers;
-    UintR noReceivedTriggers;
-    UintR triggerExecutionCount;
-    UintR triggeringOperation;
+    UintR noFiredTriggers;      // As reported by lqhKeyConf
+    UintR noReceivedTriggers;   // FIRE_TRIG_ORD
+    UintR triggerExecutionCount;// No of outstanding op due to triggers
     UintR savedState[LqhKeyConf::SignalLength];
+
+    UintR triggeringOperation;  // Which operation was "cause" of this op
     
     // Index data
     UintR indexOp;
@@ -957,8 +985,6 @@ public:
     UintR packedWordsLqh[26];
     UintR noOfWordsTCKEYCONF;
     UintR packedWordsTCKEYCONF[30];
-    UintR noOfWordsTCINDXCONF;
-    UintR packedWordsTCINDXCONF[30];
     BlockReference hostLqhBlockRef;
 
     enum NodeFailBits
@@ -1372,6 +1398,8 @@ private:
   void execALTER_INDX_IMPL_REQ(Signal* signal);
   void execSIGNAL_DROPPED_REP(Signal* signal);
 
+  void execFIRE_TRIG_REF(Signal*);
+  void execFIRE_TRIG_CONF(Signal*);
 
   // Index table lookup
   void execTCKEYCONF(Signal* signal);
@@ -1406,14 +1434,15 @@ private:
   void sendPackedTCKEYCONF(Signal* signal,
                            HostRecord * ahostptr,
                            UintR hostId);
-  void sendPackedTCINDXCONF(Signal* signal,
-                            HostRecord * ahostptr,
-                            UintR hostId);
   void sendPackedSignalLqh(Signal* signal, HostRecord * ahostptr);
   Uint32 sendCommitLqh(Signal* signal,
                        TcConnectRecord * const regTcPtr);
   Uint32 sendCompleteLqh(Signal* signal,
                          TcConnectRecord * const regTcPtr);
+
+  void sendFireTrigReq(Signal*, Ptr<ApiConnectRecord>, Uint32 firstTcConnect);
+  Uint32 sendFireTrigReqLqh(Signal*, Ptr<TcConnectRecord>, Uint32 pass);
+
   void sendTCKEY_FAILREF(Signal* signal, ApiConnectRecord *);
   void sendTCKEY_FAILCONF(Signal* signal, ApiConnectRecord *);
   void routeTCKEY_FAILREFCONF(Signal* signal, const ApiConnectRecord *, 
@@ -1506,7 +1535,6 @@ private:
                      BlockReference TBRef);
   void sendSystemError(Signal* signal, int line);
   void sendtckeyconf(Signal* signal, UintR TcommitFlag);
-  void sendTcIndxConf(Signal* signal, UintR TcommitFlag);
   void unlinkApiConnect(Ptr<GcpRecord>, Ptr<ApiConnectRecord>);
   void unlinkGcp(Ptr<GcpRecord>);
   void unlinkReadyTcCon(Signal* signal);
@@ -1551,11 +1579,10 @@ private:
 			     TcConnectRecord* trigOp);
   void restoreTriggeringOpState(Signal* signal, 
 				TcConnectRecord* trigOp);
-  void continueTriggeringOp(Signal* signal, 
-			    TcConnectRecord* trigOp);
+  void trigger_op_finished(Signal* signal, ApiConnectRecordPtr,
+                           TcConnectRecord* triggeringOp);
+  void continueTriggeringOp(Signal* signal, TcConnectRecord* trigOp);
 
-  void scheduleFiredTrigger(ApiConnectRecordPtr* transPtr, 
-                            TcConnectRecordPtr* opPtr);
   void executeTriggers(Signal* signal, ApiConnectRecordPtr* transPtr);
   void executeTrigger(Signal* signal,
                       TcFiredTriggerData* firedTriggerData,
@@ -1575,14 +1602,12 @@ private:
                             TcFiredTriggerData* firedTriggerData, 
                             ApiConnectRecordPtr* transPtr,
                             TcConnectRecordPtr* opPtr,
-                            TcIndexData* indexData,
-                            bool holdOperation = false);
+                            TcIndexData* indexData);
   void deleteFromIndexTable(Signal* signal, 
                             TcFiredTriggerData* firedTriggerData, 
                             ApiConnectRecordPtr* transPtr,
                             TcConnectRecordPtr* opPtr,
-                            TcIndexData* indexData,
-                            bool holdOperation = false);
+                            TcIndexData* indexData);
 
   void executeReorgTrigger(Signal* signal,
                            TcDefinedTriggerData* definedTriggerData,

=== modified file 'storage/ndb/src/kernel/blocks/dbtc/DbtcMain.cpp'
--- a/storage/ndb/src/kernel/blocks/dbtc/DbtcMain.cpp	2011-02-23 19:28:26 +0000
+++ b/storage/ndb/src/kernel/blocks/dbtc/DbtcMain.cpp	2011-03-23 15:57:37 +0000
@@ -98,6 +98,22 @@
   
 #define INTERNAL_TRIGGER_TCKEYREQ_JBA 0
 
+static
+inline
+bool
+tc_testbit(Uint32 flags, Uint32 flag)
+{
+  return (flags & flag) != 0;
+}
+
+static
+inline
+void
+tc_clearbit(Uint32 & flags, Uint32 flag)
+{
+  flags &= ~(Uint32)flag;
+}
+
 #ifdef VM_TRACE
 NdbOut &
 operator<<(NdbOut& out, Dbtc::ConnectionState state){
@@ -313,8 +329,9 @@ void Dbtc::execCONTINUEB(Signal* signal)
     if (likely((transPtr.p->transid[0] == Tdata1) &&
                (transPtr.p->transid[1] == Tdata2)))
     {
-      ndbrequire(transPtr.p->triggerPending);
-      transPtr.p->triggerPending = false;
+      ndbrequire(tc_testbit(transPtr.p->m_flags,
+                            ApiConnectRecord::TF_TRIGGER_PENDING));
+      tc_clearbit(transPtr.p->m_flags, ApiConnectRecord::TF_TRIGGER_PENDING);
       /* Try executing triggers now */
       executeTriggers(signal, &transPtr);
     }
@@ -1769,7 +1786,7 @@ start_failure:
   {
     jam();
     initApiConnectRec(signal, apiConnectptr.p, true);
-    apiConnectptr.p->m_exec_flag = 1;
+    apiConnectptr.p->m_flags |= ApiConnectRecord::TF_EXEC_FLAG;
     goto start_failure;
   }
   case 61:
@@ -1904,7 +1921,6 @@ void Dbtc::execKEYINFO(Signal* signal) 
   }//switch
 }//Dbtc::execKEYINFO()
 
-
 /**
  * sendKeyInfoTrain
  * Method to send a KeyInfo signal train from KeyInfo in the supplied
@@ -2304,7 +2320,7 @@ void Dbtc::initApiConnectRec(Signal* sig
   UintR Ttransid0 = tcKeyReq->transId1;
   UintR Ttransid1 = tcKeyReq->transId2;
 
-  regApiPtr->m_exec_flag = 0;
+  tc_clearbit(regApiPtr->m_flags, ApiConnectRecord::TF_EXEC_FLAG);
   regApiPtr->returncode = 0;
   regApiPtr->returnsignal = RS_TCKEYCONF;
   ndbassert(regApiPtr->firstTcConnect == RNIL);
@@ -2315,7 +2331,8 @@ void Dbtc::initApiConnectRec(Signal* sig
   regApiPtr->lqhkeyreqrec = 0;
   regApiPtr->tckeyrec = 0;
   regApiPtr->tcindxrec = 0;
-  regApiPtr->m_commit_ack_marker_received = 0;
+  tc_clearbit(regApiPtr->m_flags,
+              ApiConnectRecord::TF_COMMIT_ACK_MARKER_RECEIVED);
   regApiPtr->no_commit_ack_markers = 0;
   regApiPtr->failureNr = TfailureNr;
   regApiPtr->transid[0] = Ttransid0;
@@ -2325,15 +2342,19 @@ void Dbtc::initApiConnectRec(Signal* sig
   regApiPtr->currSavePointId = 0;
   regApiPtr->m_transaction_nodes.clear();
   regApiPtr->singleUserMode = 0;
+  regApiPtr->m_pre_commit_pass = 0;
   // Trigger data
   releaseFiredTriggerData(&regApiPtr->theFiredTriggers);
   // Index data
-  regApiPtr->indexOpReturn = false;
+  tc_clearbit(regApiPtr->m_flags,
+              ApiConnectRecord::TF_INDEX_OP_RETURN);
   regApiPtr->noIndexOp = 0;
   if(releaseIndexOperations)
     releaseAllSeizedIndexOperations(regApiPtr);
   regApiPtr->immediateTriggerId = RNIL;
 
+  tc_clearbit(regApiPtr->m_flags,
+              ApiConnectRecord::TF_DEFERRED_CONSTRAINTS);
   c_counters.ctransCount++;
 
 #ifdef ERROR_INSERT
@@ -2374,8 +2395,6 @@ Dbtc::seizeTcRecord(Signal* signal)
 
   regTcPtr->prevTcConnect = TlastTcConnect;
   regTcPtr->nextTcConnect = RNIL;
-  regTcPtr->accumulatingTriggerData.i = RNIL;  
-  regTcPtr->accumulatingTriggerData.p = NULL;  
   regTcPtr->noFiredTriggers = 0;
   regTcPtr->noReceivedTriggers = 0;
   regTcPtr->triggerExecutionCount = 0;
@@ -2484,13 +2503,15 @@ void Dbtc::execTCKEYREQ(Signal* signal) 
   apiConnectptr.p = regApiPtr;
 
   Uint32 TstartFlag = TcKeyReq::getStartFlag(Treqinfo);
-  Uint32 TexecFlag = TcKeyReq::getExecuteFlag(Treqinfo);
+  Uint32 TexecFlag =
+    TcKeyReq::getExecuteFlag(Treqinfo) ? ApiConnectRecord::TF_EXEC_FLAG : 0;
 
   Uint8 Tspecial_op_flags = regApiPtr->m_special_op_flags;
-  bool isIndexOpReturn = regApiPtr->indexOpReturn;
+  bool isIndexOpReturn = tc_testbit(regApiPtr->m_flags,
+                                    ApiConnectRecord::TF_INDEX_OP_RETURN);
   bool isExecutingTrigger = Tspecial_op_flags & TcConnectRecord::SOF_TRIGGER;
   regApiPtr->m_special_op_flags = 0; // Reset marker
-  regApiPtr->m_exec_flag |= TexecFlag;
+  regApiPtr->m_flags |= TexecFlag;
   TableRecordPtr localTabptr;
   localTabptr.i = TtabIndex;
   localTabptr.p = &tableRecord[TtabIndex];
@@ -2502,7 +2523,7 @@ void Dbtc::execTCKEYREQ(Signal* signal) 
       //---------------------------------------------------------------------
       jam();
       initApiConnectRec(signal, regApiPtr);
-      regApiPtr->m_exec_flag = TexecFlag;
+      regApiPtr->m_flags |= TexecFlag;
     } else {
       releaseSections(handle);
       if(getAllowStartTransaction(sendersNodeId, localTabptr.p->singleUserMode) == true){
@@ -2541,7 +2562,7 @@ void Dbtc::execTCKEYREQ(Signal* signal) 
         return;
       }
       initApiConnectRec(signal, regApiPtr);
-      regApiPtr->m_exec_flag = TexecFlag;
+      regApiPtr->m_flags |= TexecFlag;
     } else { 
       //----------------------------------------------------------------------
       // Transaction is started already. 
@@ -2572,7 +2593,7 @@ void Dbtc::execTCKEYREQ(Signal* signal) 
 	//--------------------------------------------------------------------
         jam();
         initApiConnectRec(signal, regApiPtr);
-	regApiPtr->m_exec_flag = TexecFlag;
+	regApiPtr->m_flags |= TexecFlag;
       } else if(TexecFlag) {
         releaseSections(handle);
 	TCKEY_abort(signal, 59);
@@ -2613,6 +2634,8 @@ void Dbtc::execTCKEYREQ(Signal* signal) 
     }//if
     break;
   case CS_START_COMMITTING:
+  case CS_SEND_FIRE_TRIG_REQ:
+  case CS_WAIT_FIRE_TRIG_REQ:
     jam();
     if(isIndexOpReturn || isExecutingTrigger){
       break;
@@ -2735,6 +2758,11 @@ void Dbtc::execTCKEYREQ(Signal* signal) 
     SegmentedSectionPtr attrInfoSec;
     if (handle.getSection(attrInfoSec, TcKeyReq::AttrInfoSectionNum))
       TattrLen= attrInfoSec.sz;
+
+    if (TcKeyReq::getDeferredConstraints(Treqinfo))
+    {
+      regApiPtr->m_flags |= ApiConnectRecord::TF_DEFERRED_CONSTRAINTS;
+    }
   }
   else
   {
@@ -2943,7 +2971,8 @@ void Dbtc::execTCKEYREQ(Signal* signal) 
   else
   {
     /* Insert, Update, Write, Delete */
-    if (!regApiPtr->m_commit_ack_marker_received)
+    if (!tc_testbit(regApiPtr->m_flags,
+                    ApiConnectRecord::TF_COMMIT_ACK_MARKER_RECEIVED))
     {
       if(regApiPtr->commitAckMarker != RNIL)
         regTcPtr->commitAckMarker = regApiPtr->commitAckMarker;
@@ -3030,7 +3059,7 @@ void Dbtc::execTCKEYREQ(Signal* signal) 
       jam();
       // Trigger execution at commit
       regApiPtr->apiConnectstate = CS_REC_COMMITTING;
-    } else {
+    } else if (!regApiPtr->isExecutingDeferredTriggers()) {
       jam();
       regApiPtr->apiConnectstate = CS_RECEIVING;
     }//if
@@ -3326,6 +3355,10 @@ void Dbtc::tckeyreq050Lab(Signal* signal
       jam();
       regApiPtr->apiConnectstate = CS_START_COMMITTING;
       break;
+    case CS_SEND_FIRE_TRIG_REQ:
+    case CS_WAIT_FIRE_TRIG_REQ:
+      jam();
+      break;
     default:
       jam();
       systemErrorLab(signal, __LINE__);
@@ -3407,16 +3440,7 @@ void Dbtc::attrinfoDihReceivedLab(Signal
       TcConnectRecordPtr opPtr;
       opPtr.i = trigOp;
       ptrCheckGuard(opPtr, ctcConnectFilesize, tcConnectRecord);
-      opPtr.p->triggerExecutionCount--;
-      if (opPtr.p->triggerExecutionCount == 0)
-      {
-        /**
-         * We have completed current trigger execution
-         * Continue triggering operation
-         */
-        jam();
-        continueTriggeringOp(signal, opPtr.p);
-      }
+      trigger_op_finished(signal, apiConnectptr, opPtr.p);
       return;
     }
     else
@@ -3497,6 +3521,8 @@ void Dbtc::sendlqhkeyreq(Signal* signal,
     }//if
   }//if
 #endif
+  Uint32 Tdeferred = tc_testbit(regApiPtr->m_flags,
+                                ApiConnectRecord::TF_DEFERRED_CONSTRAINTS);
   Uint32 reorg = 0;
   Uint32 Tspecial_op = regTcPtr->m_special_op_flags;
   if (Tspecial_op == 0)
@@ -3563,6 +3589,7 @@ void Dbtc::sendlqhkeyreq(Signal* signal,
   LqhKeyReq::setOperation(Tdata10, sig1);
   LqhKeyReq::setNoDiskFlag(Tdata10, regCachePtr->m_no_disk_flag);
   LqhKeyReq::setQueueOnRedoProblemFlag(Tdata10, regCachePtr->m_op_queue);
+  LqhKeyReq::setDeferredConstraints(Tdata10, Tdeferred);
 
   /* ----------------------------------------------------------------------- 
    * If we are sending a short LQHKEYREQ, then there will be some AttrInfo
@@ -3643,8 +3670,6 @@ void Dbtc::sendlqhkeyreq(Signal* signal,
   }//if
 
   // Reset trigger count
-  regTcPtr->accumulatingTriggerData.i = RNIL;  
-  regTcPtr->accumulatingTriggerData.p = NULL;  
   regTcPtr->noFiredTriggers = 0;
   regTcPtr->triggerExecutionCount = 0;
 
@@ -3968,6 +3993,13 @@ void Dbtc::execPACKED_SIGNAL(Signal* sig
       execLQHKEYCONF(signal);
       Tstep += LqhKeyConf::SignalLength;
       break;
+    case ZFIRE_TRIG_CONF:
+      jam();
+      signal->header.theLength = 4;
+      signal->theData[3] = TpackDataPtr[3];
+      execFIRE_TRIG_CONF(signal);
+      Tstep += 4;
+      break;
     default:
       systemErrorLab(signal, __LINE__);
       return;
@@ -4042,10 +4074,13 @@ void Dbtc::execSIGNAL_DROPPED_REP(Signal
     apiConnectptr.p->returncode = ZGET_DATAREC_ERROR;
 
     /* Set m_exec_flag according to the dropped request */
-    apiConnectptr.p->m_exec_flag = 
-      TcKeyReq::getExecuteFlag(truncatedTcKeyReq->requestInfo);
-
-    DEBUG("  Execute flag set to " << apiConnectptr.p->m_exec_flag);
+    apiConnectptr.p->m_flags |=
+      TcKeyReq::getExecuteFlag(truncatedTcKeyReq->requestInfo) ?
+      ApiConnectRecord::TF_EXEC_FLAG : 0;
+
+    DEBUG(" Execute flag set to " << tc_testbit(apiConnectptr.p->m_flags,
+                                                ApiConnectRecord::TF_EXEC_FLAG)
+          );
 
     abortErrorLab(signal);
 
@@ -4157,7 +4192,8 @@ void Dbtc::execLQHKEYCONF(Signal* signal
   UintR TapiConnectFilesize = capiConnectFilesize;
   UintR Ttrans1 = lqhKeyConf->transId1;
   UintR Ttrans2 = lqhKeyConf->transId2;
-  Uint32 noFired = lqhKeyConf->noFiredTriggers;
+  Uint32 noFired = lqhKeyConf->noFiredTriggers & ~(Uint32(1) << 31);
+  Uint32 deferred =(lqhKeyConf->noFiredTriggers & (Uint32(1) << 31)) != 0;
 
   if (TapiConnectptrIndex >= TapiConnectFilesize) {
     TCKEY_abort(signal, 29);
@@ -4213,6 +4249,10 @@ void Dbtc::execLQHKEYCONF(Signal* signal
   regTcPtr->lastLqhCon = tlastLqhConnect;
   regTcPtr->lastLqhNodeId = refToNode(tlastLqhBlockref);
   regTcPtr->noFiredTriggers = noFired;
+  regTcPtr->m_special_op_flags |= (deferred) ?
+    TcConnectRecord::SOF_DEFERRED_TRIGGER : 0;
+  regApiPtr.p->m_flags |= (deferred) ?
+    ApiConnectRecord::TF_DEFERRED_TRIGGERS : 0;
 
   UintR Ttckeyrec = (UintR)regApiPtr.p->tckeyrec;
   UintR TclientData = regTcPtr->clientData;
@@ -4220,10 +4260,7 @@ void Dbtc::execLQHKEYCONF(Signal* signal
   Uint32 TopSimple = regTcPtr->opSimple;
   Uint32 Toperation = regTcPtr->operation;
   ConnectionState TapiConnectstate = regApiPtr.p->apiConnectstate;
-  if (Ttckeyrec > (ZTCOPCONF_SIZE - 2)) {
-    TCKEY_abort(signal, 30);
-    return;
-  }
+
   if (TapiConnectstate == CS_ABORTING) {
     warningReport(signal, 27);
     return;
@@ -4248,7 +4285,7 @@ void Dbtc::execLQHKEYCONF(Signal* signal
     const Uint32 noOfLqhs = regTcPtr->noOfNodes;
     CommitAckMarker * tmp = m_commitAckMarkerHash.getPtr(commitAckMarker);
     jam();
-    regApiPtr.p->m_commit_ack_marker_received = TRUE;
+    regApiPtr.p->m_flags |= ApiConnectRecord::TF_COMMIT_ACK_MARKER_RECEIVED;
     /**
      * Populate LQH array
      */
@@ -4263,6 +4300,12 @@ void Dbtc::execLQHKEYCONF(Signal* signal
   } else {
     if (noFired == 0 && regTcPtr->triggeringOperation == RNIL) {
       jam();
+
+      if (Ttckeyrec > (ZTCOPCONF_SIZE - 2)) {
+        TCKEY_abort(signal, 30);
+        return;
+      }
+
       /*
        * Skip counting triggering operations the first round
        * since they will enter execLQHKEYCONF a second time
@@ -4376,7 +4419,8 @@ void Dbtc::execLQHKEYCONF(Signal* signal
   /**
    * And now decide what to do next
    */
-  if (regTcPtr->triggeringOperation != RNIL) {
+  if (regTcPtr->triggeringOperation != RNIL &&
+      !regApiPtr.p->isExecutingDeferredTriggers()) {
     jam();
     // This operation was created by a trigger execting operation
     // Restart it if we have executed all it's triggers
@@ -4384,15 +4428,7 @@ void Dbtc::execLQHKEYCONF(Signal* signal
 
     opPtr.i = regTcPtr->triggeringOperation;
     ptrCheckGuard(opPtr, ctcConnectFilesize, localTcConnectRecord);
-    opPtr.p->triggerExecutionCount--;
-    if (opPtr.p->triggerExecutionCount == 0) {
-      /*
-      We have completed current trigger execution
-      Continue triggering operation
-      */
-      jam();
-      continueTriggeringOp(signal, opPtr.p);
-    }
+    trigger_op_finished(signal, regApiPtr, opPtr.p);
   } else if (noFired == 0) {
     // This operation did not fire any triggers, finish operation
     jam();
@@ -4418,7 +4454,7 @@ void Dbtc::execLQHKEYCONF(Signal* signal
 void Dbtc::setupIndexOpReturn(ApiConnectRecord* regApiPtr,
 			      TcConnectRecord* regTcPtr) 
 {
-  regApiPtr->indexOpReturn = true;
+  regApiPtr->m_flags |= ApiConnectRecord::TF_INDEX_OP_RETURN;
   regApiPtr->indexOp = regTcPtr->indexOp;
   regApiPtr->clientData = regTcPtr->clientData;
   regApiPtr->attrInfoLen = regTcPtr->attrInfoLen;
@@ -4449,6 +4485,7 @@ Dbtc::lqhKeyConf_checkTransactionState(S
   UintR Tlqhkeyreqrec = regApiPtr.p->lqhkeyreqrec;
   int TnoOfOutStanding = Tlqhkeyreqrec - Tlqhkeyconfrec;
 
+  apiConnectptr = regApiPtr;
   switch (TapiConnectstate) {
   case CS_START_COMMITTING:
     if (TnoOfOutStanding == 0) {
@@ -4460,7 +4497,10 @@ Dbtc::lqhKeyConf_checkTransactionState(S
         jam();
         sendtckeyconf(signal, 0);
         return;
-      } else if (regApiPtr.p->indexOpReturn) {
+      }
+      else if (tc_testbit(regApiPtr.p->m_flags,
+                          ApiConnectRecord::TF_INDEX_OP_RETURN))
+      {
 	jam();
         sendtckeyconf(signal, 0);
         return;
@@ -4483,11 +4523,14 @@ Dbtc::lqhKeyConf_checkTransactionState(S
         jam();
         sendtckeyconf(signal, 0);
         return;
-      } else if (regApiPtr.p->indexOpReturn) {
+      }
+      else if (tc_testbit(regApiPtr.p->m_flags,
+                          ApiConnectRecord::TF_INDEX_OP_RETURN))
+      {
 	jam();
         sendtckeyconf(signal, 0);
         return;
-	}//if
+      }//if
       jam();
     }//if
     return;
@@ -4497,7 +4540,10 @@ Dbtc::lqhKeyConf_checkTransactionState(S
         jam();
         sendtckeyconf(signal, 0);
         return;
-      } else if (regApiPtr.p->indexOpReturn) {
+      }
+      else if (tc_testbit(regApiPtr.p->m_flags,
+                          ApiConnectRecord::TF_INDEX_OP_RETURN))
+      {
         jam();
         sendtckeyconf(signal, 0);
         return;
@@ -4516,6 +4562,17 @@ Dbtc::lqhKeyConf_checkTransactionState(S
 /*---------------------------------------------------------------*/
     regApiPtr.p->tckeyrec = 0;
     return;
+  case CS_SEND_FIRE_TRIG_REQ:
+    return;
+  case CS_WAIT_FIRE_TRIG_REQ:
+    if (TnoOfOutStanding == 0 && regApiPtr.p->pendingTriggers == 0)
+    {
+      jam();
+      regApiPtr.p->apiConnectstate = CS_START_COMMITTING;
+      diverify010Lab(signal);
+      return;
+    }
+    return;
   default:
     TCKEY_abort(signal, 46);
     return;
@@ -4549,7 +4606,8 @@ void Dbtc::sendtckeyconf(Signal* signal,
   const UintR TpacketLen = 6 + TopWords;
   regApiPtr->tckeyrec = 0;
 
-  if (regApiPtr->indexOpReturn) {
+  if (tc_testbit(regApiPtr->m_flags, ApiConnectRecord::TF_INDEX_OP_RETURN))
+  {
     jam();
     // Return internally generated TCKEY
     TcKeyConf * const tcKeyConf = (TcKeyConf *)signal->getDataPtrSend();
@@ -4566,7 +4624,7 @@ void Dbtc::sendtckeyconf(Signal* signal,
     Uint32 sigLen = 1 /** gci_lo */ +
       TcKeyConf::StaticLength + TcKeyConf::OperationLength;
     EXECUTE_DIRECT(DBTC, GSN_TCKEYCONF, signal, sigLen);
-    regApiPtr->indexOpReturn = false;
+    tc_clearbit(regApiPtr->m_flags, ApiConnectRecord::TF_INDEX_OP_RETURN);
     if (TopWords == 0) {
       jam();
       return; // No queued TcKeyConf
@@ -4574,7 +4632,7 @@ void Dbtc::sendtckeyconf(Signal* signal,
   }//if
   if(TcommitFlag){
     jam();
-    regApiPtr->m_exec_flag = 0;
+    tc_clearbit(regApiPtr->m_flags, ApiConnectRecord::TF_EXEC_FLAG);
   }
   TcKeyConf::setNoOfOperations(confInfo, (TopWords >> 1));
   if ((TpacketLen + 1 /** gci_lo */ > 25) || !is_api){
@@ -4674,7 +4732,6 @@ void Dbtc::execSEND_PACKED(Signal* signa
     arrGuard(Thostptr.i - 1, MAX_NODES - 1);
     UintR TnoOfPackedWordsLqh = Thostptr.p->noOfPackedWordsLqh;
     UintR TnoOfWordsTCKEYCONF = Thostptr.p->noOfWordsTCKEYCONF;
-    UintR TnoOfWordsTCINDXCONF = Thostptr.p->noOfWordsTCINDXCONF;
     jam();
     if (TnoOfPackedWordsLqh > 0) {
       jam();
@@ -4684,10 +4741,6 @@ void Dbtc::execSEND_PACKED(Signal* signa
       jam();
       sendPackedTCKEYCONF(signal, Thostptr.p, (Uint32)Thostptr.i);
     }//if
-    if (TnoOfWordsTCINDXCONF > 0) {
-      jam();
-      sendPackedTCINDXCONF(signal, Thostptr.p, (Uint32)Thostptr.i);
-    }//if
     Thostptr.p->inPackedList = false;
   }//for
   cpackedListIndex = 0;
@@ -4749,27 +4802,6 @@ void Dbtc::sendPackedTCKEYCONF(Signal* s
   sendSignal(TBref, GSN_TCKEYCONF, signal, TnoOfWords, JBB);
 }//Dbtc::sendPackedTCKEYCONF()
 
-void Dbtc::sendPackedTCINDXCONF(Signal* signal,
-                                HostRecord * ahostptr,
-                                UintR hostId)
-{
-  UintR Tj;
-  UintR TnoOfWords = ahostptr->noOfWordsTCINDXCONF;
-  BlockReference TBref = numberToRef(API_PACKED, hostId);
-  for (Tj = 0; Tj < ahostptr->noOfWordsTCINDXCONF; Tj += 4) {
-    UintR sig0 = ahostptr->packedWordsTCINDXCONF[Tj + 0];
-    UintR sig1 = ahostptr->packedWordsTCINDXCONF[Tj + 1];
-    UintR sig2 = ahostptr->packedWordsTCINDXCONF[Tj + 2];
-    UintR sig3 = ahostptr->packedWordsTCINDXCONF[Tj + 3];
-    signal->theData[Tj + 0] = sig0;
-    signal->theData[Tj + 1] = sig1;
-    signal->theData[Tj + 2] = sig2;
-    signal->theData[Tj + 3] = sig3;
-  }//for
-  ahostptr->noOfWordsTCINDXCONF = 0;
-  sendSignal(TBref, GSN_TCINDXCONF, signal, TnoOfWords, JBB);
-}//Dbtc::sendPackedTCINDXCONF()
-
 /*
 4.3.11 DIVERIFY 
 ---------------
@@ -4788,6 +4820,19 @@ void Dbtc::diverify010Lab(Signal* signal
     systemErrorLab(signal, __LINE__);
   }//if
 
+  if (tc_testbit(regApiPtr->m_flags, ApiConnectRecord::TF_DEFERRED_TRIGGERS))
+  {
+    jam();
+    /**
+     * If trans has deferred triggers, let them fire just before
+     *   transaction starts to commit
+     */
+    regApiPtr->pendingTriggers = 0;
+    tc_clearbit(regApiPtr->m_flags, ApiConnectRecord::TF_DEFERRED_TRIGGERS);
+    sendFireTrigReq(signal, apiConnectptr, regApiPtr->firstTcConnect);
+    return;
+  }
+
   if (regApiPtr->lqhkeyreqrec)
   {
     if (TfirstfreeApiConnectCopy != RNIL) {
@@ -4846,7 +4891,8 @@ void Dbtc::seizeApiConnectCopy(Signal* s
   cfirstfreeApiConnectCopy = locApiConnectptr.p->nextApiConnect;
   locApiConnectptr.p->nextApiConnect = RNIL;
   regApiPtr->apiCopyRecord = locApiConnectptr.i;
-  regApiPtr->triggerPending = false;
+  tc_clearbit(regApiPtr->m_flags,
+              ApiConnectRecord::TF_TRIGGER_PENDING);
   regApiPtr->m_special_op_flags = 0;
 }//Dbtc::seizeApiConnectCopy()
 
@@ -5571,6 +5617,170 @@ Dbtc::sendCompleteLqh(Signal* signal,
 }
 
 void
+Dbtc::sendFireTrigReq(Signal* signal,
+                      Ptr<ApiConnectRecord> regApiPtr,
+                      Uint32 TopPtrI)
+{
+  UintR TtcConnectFilesize = ctcConnectFilesize;
+  TcConnectRecord *localTcConnectRecord = tcConnectRecord;
+  TcConnectRecordPtr localTcConnectptr;
+
+  setApiConTimer(regApiPtr.i, ctcTimer, __LINE__);
+  regApiPtr.p->apiConnectstate = CS_SEND_FIRE_TRIG_REQ;
+
+  localTcConnectptr.i = TopPtrI;
+  ndbassert(TopPtrI != RNIL);
+  Uint32 Tlqhkeyreqrec = regApiPtr.p->lqhkeyreqrec;
+  Uint32 pass = regApiPtr.p->m_pre_commit_pass;
+  for (Uint32 i = 0; localTcConnectptr.i != RNIL /* TODO && i < 16 */; i++)
+  {
+    ptrCheckGuard(localTcConnectptr,
+                  TtcConnectFilesize, localTcConnectRecord);
+
+    const Uint32 nextTcConnect = localTcConnectptr.p->nextTcConnect;
+    Uint32 flags = localTcConnectptr.p->m_special_op_flags;
+    if (flags & TcConnectRecord::SOF_DEFERRED_TRIGGER)
+    {
+      jam();
+      tc_clearbit(flags, TcConnectRecord::SOF_DEFERRED_TRIGGER);
+      ndbrequire(localTcConnectptr.p->tcConnectstate == OS_PREPARED);
+      localTcConnectptr.p->tcConnectstate = OS_FIRE_TRIG_REQ;
+      localTcConnectptr.p->m_special_op_flags = flags;
+      i += sendFireTrigReqLqh(signal, localTcConnectptr, pass);
+      Tlqhkeyreqrec++;
+    }
+    localTcConnectptr.i = nextTcConnect;
+  }
+
+  regApiPtr.p->lqhkeyreqrec = Tlqhkeyreqrec;
+  if (localTcConnectptr.i == RNIL)
+  {
+    /**
+     * Now wait for FIRE_TRIG_CONF
+     */
+    jam();
+    regApiPtr.p->apiConnectstate = CS_WAIT_FIRE_TRIG_REQ;
+    ndbrequire(pass < 255);
+    regApiPtr.p->m_pre_commit_pass = (Uint8)(pass + 1);
+    return;
+  }
+  else
+  {
+    jam();
+    abort();
+    signal->theData[0] = TcContinueB::ZSEND_FIRE_TRIG_REQ;
+    signal->theData[1] = regApiPtr.i;
+    signal->theData[2] = localTcConnectptr.i;
+    sendSignal(cownref, GSN_CONTINUEB, signal, 3, JBB);
+  }
+}
+
+Uint32
+Dbtc::sendFireTrigReqLqh(Signal* signal,
+                         Ptr<TcConnectRecord> regTcPtr,
+                         Uint32 pass)
+{
+  HostRecordPtr Thostptr;
+  UintR ThostFilesize = chostFilesize;
+  ApiConnectRecord * const regApiPtr = apiConnectptr.p;
+  Thostptr.i = regTcPtr.p->tcNodedata[0];
+  ptrCheckGuard(Thostptr, ThostFilesize, hostRecord);
+
+  Uint32 Tnode = Thostptr.i;
+  Uint32 self = getOwnNodeId();
+  Uint32 ret = (Tnode == self) ? 4 : 1;
+
+  Uint32 Tdata[FireTrigReq::SignalLength];
+  FireTrigReq * req = CAST_PTR(FireTrigReq, Tdata);
+  req->tcOpRec = regTcPtr.i;
+  req->transId[0] = regApiPtr->transid[0];
+  req->transId[1] = regApiPtr->transid[1];
+  req->pass = pass;
+  Uint32 len = FireTrigReq::SignalLength;
+
+  // currently packed signal cannot address specific instance
+  const bool send_unpacked = getNodeInfo(Thostptr.i).m_lqh_workers > 1;
+  if (send_unpacked) {
+    memcpy(signal->theData, req, len << 2);
+    Uint32 instanceKey = regTcPtr.p->lqhInstanceKey;
+    BlockReference lqhRef = numberToRef(DBLQH, instanceKey, Tnode);
+    sendSignal(lqhRef, GSN_FIRE_TRIG_REQ, signal, len, JBB);
+    return ret;
+  }
+
+  if (Thostptr.p->noOfPackedWordsLqh > 25 - len) {
+    jam();
+    sendPackedSignalLqh(signal, Thostptr.p);
+  } else {
+    jam();
+    ret = 1;
+    updatePackedList(signal, Thostptr.p, Thostptr.i);
+  }
+
+  req->tcOpRec |= (ZFIRE_TRIG_REQ << 28);
+  UintR Tindex = Thostptr.p->noOfPackedWordsLqh;
+  UintR* TDataPtr = &Thostptr.p->packedWordsLqh[Tindex];
+  memcpy(TDataPtr, req, len << 2);
+  Thostptr.p->noOfPackedWordsLqh = Tindex + len;
+  return ret;
+}
+
+void
+Dbtc::execFIRE_TRIG_CONF(Signal* signal)
+{
+  TcConnectRecordPtr localTcConnectptr;
+  ApiConnectRecordPtr regApiPtr;
+
+  UintR TtcConnectFilesize = ctcConnectFilesize;
+  UintR TapiConnectFilesize = capiConnectFilesize;
+  TcConnectRecord *localTcConnectRecord = tcConnectRecord;
+  ApiConnectRecord *localApiConnectRecord = apiConnectRecord;
+
+  const FireTrigConf * conf = CAST_CONSTPTR(FireTrigConf, signal->theData);
+  localTcConnectptr.i = conf->tcOpRec;
+  jamEntry();
+  ptrCheckGuard(localTcConnectptr, TtcConnectFilesize, localTcConnectRecord);
+  regApiPtr.i = localTcConnectptr.p->apiConnect;
+  if (localTcConnectptr.p->tcConnectstate != OS_FIRE_TRIG_REQ)
+  {
+    warningReport(signal, 4);
+    return;
+  }//if
+  ptrCheckGuard(regApiPtr, TapiConnectFilesize,
+                localApiConnectRecord);
+
+  Uint32 Tlqhkeyreqrec = regApiPtr.p->lqhkeyreqrec;
+  ConnectionState TapiConnectstate = regApiPtr.p->apiConnectstate;
+  UintR Tdata1 = regApiPtr.p->transid[0] - conf->transId[0];
+  UintR Tdata2 = regApiPtr.p->transid[1] - conf->transId[1];
+  Tdata1 = Tdata1 | Tdata2;
+  if (Tdata1 != 0) {
+    warningReport(signal, 5);
+    return;
+  }//if
+
+  setApiConTimer(regApiPtr.i, ctcTimer, __LINE__);
+  ndbassert(Tlqhkeyreqrec > 0);
+  regApiPtr.p->lqhkeyreqrec = Tlqhkeyreqrec - 1;
+  localTcConnectptr.p->tcConnectstate = OS_PREPARED;
+
+  Uint32 noFired  = conf->noFiredTriggers & ~(Uint32(1) << 31);
+  Uint32 deferred = (conf->noFiredTriggers & (Uint32(1) << 31)) != 0;
+
+  regApiPtr.p->pendingTriggers += noFired;
+  regApiPtr.p->m_flags |= (deferred) ?
+    ApiConnectRecord::TF_DEFERRED_TRIGGERS : 0;
+  localTcConnectptr.p->m_special_op_flags |= (deferred) ?
+    TcConnectRecord::SOF_DEFERRED_TRIGGER : 0;
+
+  if (regApiPtr.p->pendingTriggers == 0)
+  {
+    jam();
+    lqhKeyConf_checkTransactionState(signal, regApiPtr);
+  }
+}
+
+void
 Dbtc::execTC_COMMIT_ACK(Signal* signal){
   jamEntry();
 
@@ -5954,19 +6164,16 @@ void Dbtc::execLQHKEYREF(Signal* signal)
          */
         regApiPtr->lqhkeyreqrec--;
 
+        /**
+         * An failing op in LQH, never leaves the commit ack marker around
+         * TODO: This can be bug in ordinary code too!!!
+         */
+        clearCommitAckMarker(regApiPtr, regTcPtr);
+
         unlinkReadyTcCon(signal);
         releaseTcCon();
 
-        opPtr.p->triggerExecutionCount--;
-        if (opPtr.p->triggerExecutionCount == 0)
-        {
-          /**
-           * We have completed current trigger execution
-           * Continue triggering operation
-           */
-          jam();
-          continueTriggeringOp(signal, opPtr.p);
-        }
+        trigger_op_finished(signal, apiConnectptr, opPtr.p);
         return;
       }
       
@@ -6031,7 +6238,10 @@ void Dbtc::execLQHKEYREF(Signal* signal)
           jam();
           diverify010Lab(signal);
 	  return;
-	} else if (regApiPtr->tckeyrec > 0 || regApiPtr->m_exec_flag) {
+	}
+        else if (regApiPtr->tckeyrec > 0 ||
+                 tc_testbit(regApiPtr->m_flags, ApiConnectRecord::TF_EXEC_FLAG))
+        {
 	  jam();
 	  sendtckeyconf(signal, 2);
 	  return;
@@ -6067,7 +6277,8 @@ void Dbtc::clearCommitAckMarker(ApiConne
     if (regApiPtr->no_commit_ack_markers == 0)
     {
       regApiPtr->commitAckMarker = RNIL;
-      regApiPtr->m_commit_ack_marker_received = FALSE;
+      tc_clearbit(regApiPtr->m_flags,
+                  ApiConnectRecord::TF_COMMIT_ACK_MARKER_RECEIVED);
       m_commitAckMarkerHash.release(commitAckMarker);
     }
   }
@@ -6115,7 +6326,7 @@ void Dbtc::execTC_COMMITREQ(Signal* sign
     const Uint32 transId2      = regApiPtr->transid[1];
     Uint32 errorCode           = 0;
 
-    regApiPtr->m_exec_flag = 1;
+    regApiPtr->m_flags |= ApiConnectRecord::TF_EXEC_FLAG;
     switch (regApiPtr->apiConnectstate) {
     case CS_STARTED:
       tcConnectptr.i = regApiPtr->firstTcConnect;
@@ -6267,7 +6478,7 @@ void Dbtc::execTCROLLBACKREQ(Signal* sig
     return;
   }//if
 
-  apiConnectptr.p->m_exec_flag = 1;
+  apiConnectptr.p->m_flags |= ApiConnectRecord::TF_EXEC_FLAG;
   switch (apiConnectptr.p->apiConnectstate) {
   case CS_STARTED:
   case CS_RECEIVING:
@@ -6803,6 +7014,8 @@ ABORT020:
     jam();
   case OS_OPERATING:
     jam();
+  case OS_FIRE_TRIG_REQ:
+    jam();
     /*----------------------------------------------------------------------
      * WE HAVE SENT LQHKEYREQ AND ARE IN SOME STATE OF EITHER STILL       
      * SENDING THE OPERATION, WAITING FOR REPLIES, WAITING FOR MORE       
@@ -7121,7 +7334,8 @@ void Dbtc::timeOutFoundLab(Signal* signa
 	<< " H'" << apiConnectptr.p->transid[1] << "] " << dec 
 	<< "Time-out in state = " << apiConnectptr.p->apiConnectstate
 	<< " apiConnectptr.i = " << apiConnectptr.i 
-	<< " - exec: " << apiConnectptr.p->m_exec_flag
+	<< " - exec: "
+        << tc_testbit(apiConnectptr.p->m_flags, ApiConnectRecord::TF_EXEC_FLAG)
 	<< " - place: " << c_apiConTimer_line[apiConnectptr.i]
 	<< " code: " << errCode);
   switch (apiConnectptr.p->apiConnectstate) {
@@ -11759,7 +11973,7 @@ void Dbtc::initApiConnect(Signal* signal
     apiConnectptr.p->commitAckMarker = RNIL;
     apiConnectptr.p->firstTcConnect = RNIL;
     apiConnectptr.p->lastTcConnect = RNIL;
-    apiConnectptr.p->triggerPending = false;
+    apiConnectptr.p->m_flags = 0;
     apiConnectptr.p->m_special_op_flags = 0;
     apiConnectptr.p->accumulatingIndexOp = RNIL;
     apiConnectptr.p->executingIndexOp = RNIL;
@@ -11788,7 +12002,7 @@ void Dbtc::initApiConnect(Signal* signal
       apiConnectptr.p->commitAckMarker = RNIL;
       apiConnectptr.p->firstTcConnect = RNIL;
       apiConnectptr.p->lastTcConnect = RNIL;
-      apiConnectptr.p->triggerPending = false;
+      apiConnectptr.p->m_flags = 0;
       apiConnectptr.p->m_special_op_flags = 0;
       apiConnectptr.p->accumulatingIndexOp = RNIL;
       apiConnectptr.p->executingIndexOp = RNIL;
@@ -11817,7 +12031,7 @@ void Dbtc::initApiConnect(Signal* signal
     apiConnectptr.p->commitAckMarker = RNIL;
     apiConnectptr.p->firstTcConnect = RNIL;
     apiConnectptr.p->lastTcConnect = RNIL;
-    apiConnectptr.p->triggerPending = false;
+    apiConnectptr.p->m_flags = 0;
     apiConnectptr.p->m_special_op_flags = 0;
     apiConnectptr.p->accumulatingIndexOp = RNIL;
     apiConnectptr.p->executingIndexOp = RNIL;
@@ -11859,7 +12073,6 @@ void Dbtc::inithost(Signal* signal) 
     hostptr.p->inPackedList = false;
     hostptr.p->lqhTransStatus = LTS_IDLE;
     hostptr.p->noOfWordsTCKEYCONF = 0;
-    hostptr.p->noOfWordsTCINDXCONF = 0;
     hostptr.p->noOfPackedWordsLqh = 0;
     hostptr.p->hostLqhBlockRef = calcLqhBlockRef(hostptr.i);
     hostptr.p->m_nf_bits = 0;
@@ -12124,13 +12337,15 @@ void Dbtc::releaseAbortResources(Signal*
   apiConnectptr.p->abortState = AS_IDLE;
   releaseAllSeizedIndexOperations(apiConnectptr.p);
 
-  if(apiConnectptr.p->m_exec_flag || apiConnectptr.p->apiFailState == ZTRUE){
+  if (tc_testbit(apiConnectptr.p->m_flags, ApiConnectRecord::TF_EXEC_FLAG) ||
+      apiConnectptr.p->apiFailState == ZTRUE)
+  {
     jam();
     bool ok = false;
     Uint32 blockRef = apiConnectptr.p->ndbapiBlockref;
     ReturnSignal ret = apiConnectptr.p->returnsignal;
     apiConnectptr.p->returnsignal = RS_NO_RETURN;
-    apiConnectptr.p->m_exec_flag = 0;
+    tc_clearbit(apiConnectptr.p->m_flags, ApiConnectRecord::TF_EXEC_FLAG);
     switch(ret){
     case RS_TCROLLBACKCONF:
       jam();
@@ -12232,7 +12447,8 @@ void Dbtc::seizeApiConnect(Signal* signa
     apiConnectptr.p->nextApiConnect = RNIL;
     setApiConTimer(apiConnectptr.i, 0, __LINE__);
     apiConnectptr.p->apiConnectstate = CS_CONNECTED; /* STATE OF CONNECTION */
-    apiConnectptr.p->triggerPending = false;
+    tc_clearbit(apiConnectptr.p->m_flags,
+                ApiConnectRecord::TF_TRIGGER_PENDING);
     apiConnectptr.p->m_special_op_flags = 0;
   } else {
     jam();
@@ -13447,11 +13663,12 @@ void Dbtc::execFIRE_TRIG_ORD(Signal* sig
     {
       jam();      
       opPtr.p->noReceivedTriggers++;
-      opPtr.p->triggerExecutionCount++;
+      opPtr.p->triggerExecutionCount++; // Default 1 LQHKEYREQ per trigger
 
       // Insert fired trigger in execution queue
       transPtr.p->theFiredTriggers.add(trigPtr);
-      if (opPtr.p->noReceivedTriggers == opPtr.p->noFiredTriggers) {
+      if (opPtr.p->noReceivedTriggers == opPtr.p->noFiredTriggers ||
+          transPtr.p->isExecutingDeferredTriggers()) {
 	executeTriggers(signal, &transPtr);
       }
       return;
@@ -13650,7 +13867,9 @@ void Dbtc::execTCINDXREQ(Signal* signal)
     jam();
     releaseSections(handle);
     terrorCode = ZCLUSTER_IN_SINGLEUSER_MODE;
-    regApiPtr->m_exec_flag |= TcKeyReq::getExecuteFlag(tcIndxRequestInfo);
+    regApiPtr->m_flags |=
+      TcKeyReq::getExecuteFlag(tcIndxRequestInfo) ?
+      ApiConnectRecord::TF_EXEC_FLAG : 0;
     apiConnectptr = transPtr;
     abortErrorLab(signal);
     return;
@@ -13661,7 +13880,9 @@ void Dbtc::execTCINDXREQ(Signal* signal)
     releaseSections(handle);
     // Failed to allocate index operation
     terrorCode = 288;
-    regApiPtr->m_exec_flag |= TcKeyReq::getExecuteFlag(tcIndxRequestInfo);
+    regApiPtr->m_flags |=
+      TcKeyReq::getExecuteFlag(tcIndxRequestInfo) ?
+      ApiConnectRecord::TF_EXEC_FLAG : 0;
     apiConnectptr = transPtr;
     abortErrorLab(signal);
     return;
@@ -13752,94 +13973,6 @@ void Dbtc::execTCINDXREQ(Signal* signal)
   }
 }
 
-
-void Dbtc::sendTcIndxConf(Signal* signal, UintR TcommitFlag) 
-{
-  HostRecordPtr localHostptr;
-  ApiConnectRecord * const regApiPtr = apiConnectptr.p;
-  const UintR TopWords = (UintR)regApiPtr->tcindxrec;
-  localHostptr.i = refToNode(regApiPtr->ndbapiBlockref);
-  const Uint32 type = getNodeInfo(localHostptr.i).m_type;
-  const bool is_api = (type >= NodeInfo::API && type <= NodeInfo::MGM);
-  const BlockNumber TblockNum = refToBlock(regApiPtr->ndbapiBlockref);
-  const Uint32 Tmarker = (regApiPtr->commitAckMarker == RNIL ? 0 : 1);
-  ptrAss(localHostptr, hostRecord);
-  UintR TcurrLen = localHostptr.p->noOfWordsTCINDXCONF;
-  UintR confInfo = 0;
-  TcIndxConf::setNoOfOperations(confInfo, (TopWords >> 1));
-  TcIndxConf::setCommitFlag(confInfo, TcommitFlag == 1);
-  TcIndxConf::setMarkerFlag(confInfo, Tmarker);
-  const UintR TpacketLen = 6 + TopWords;
-  regApiPtr->tcindxrec = 0;
-
-  if(TcommitFlag || (regApiPtr->lqhkeyreqrec == regApiPtr->lqhkeyconfrec)){
-    jam();
-    regApiPtr->m_exec_flag = 0;
-  }
-
-  if ((TpacketLen + 1 /** gci_lo */ > 25) || !is_api){
-    TcIndxConf * const tcIndxConf = (TcIndxConf *)signal->getDataPtrSend();
-    
-    jam();
-    tcIndxConf->apiConnectPtr = regApiPtr->ndbapiConnect;
-    tcIndxConf->gci_hi = Uint32(regApiPtr->globalcheckpointid >> 32);
-    Uint32 *gci_lo = (Uint32*)&tcIndxConf->operations[TopWords >> 1];
-    * gci_lo = Uint32(regApiPtr->globalcheckpointid);
-    tcIndxConf->confInfo = confInfo;
-    tcIndxConf->transId1 = regApiPtr->transid[0];
-    tcIndxConf->transId2 = regApiPtr->transid[1];
-    copyFromToLen(&regApiPtr->tcIndxSendArray[0],
-                  (UintR*)&tcIndxConf->operations,
-                  (UintR)ZTCOPCONF_SIZE);
-    sendSignal(regApiPtr->ndbapiBlockref,
-               GSN_TCINDXCONF, signal,
-               (TpacketLen - 1) + 1 /** gci_lo */, JBB);
-    return;
-  } else if (((TcurrLen + TpacketLen + 1 /** gci_lo */) > 25) &&
-             (TcurrLen > 0)) {
-    jam();
-    sendPackedTCINDXCONF(signal, localHostptr.p, localHostptr.i);
-    TcurrLen = 0;
-  } else {
-    jam();
-    updatePackedList(signal, localHostptr.p, localHostptr.i);
-  }//if
-// -------------------------------------------------------------------------
-// The header contains the block reference of receiver plus the real signal
-// length - 3, since we have the real signal length plus one additional word
-// for the header we have to do - 4.
-// -------------------------------------------------------------------------
-  UintR Tpack0 = (TblockNum << 16) + (TpacketLen - 4 + 1 /** gci_lo */);
-  UintR Tpack1 = regApiPtr->ndbapiConnect;
-  UintR Tpack2 = Uint32(regApiPtr->globalcheckpointid >> 32);
-  UintR Tpack3 = confInfo;
-  UintR Tpack4 = regApiPtr->transid[0];
-  UintR Tpack5 = regApiPtr->transid[1];
-  UintR Tpack6 = Uint32(regApiPtr->globalcheckpointid);
-
-  localHostptr.p->noOfWordsTCINDXCONF = TcurrLen + TpacketLen + 1 /* gci_lo */;
-
-  localHostptr.p->packedWordsTCINDXCONF[TcurrLen + 0] = Tpack0;
-  localHostptr.p->packedWordsTCINDXCONF[TcurrLen + 1] = Tpack1;
-  localHostptr.p->packedWordsTCINDXCONF[TcurrLen + 2] = Tpack2;
-  localHostptr.p->packedWordsTCINDXCONF[TcurrLen + 3] = Tpack3;
-  localHostptr.p->packedWordsTCINDXCONF[TcurrLen + 4] = Tpack4;
-  localHostptr.p->packedWordsTCINDXCONF[TcurrLen + 5] = Tpack5;
-
-  UintR Ti;
-  for (Ti = 6; Ti < TpacketLen; Ti++) {
-    localHostptr.p->packedWordsTCINDXCONF[TcurrLen + Ti] = 
-          regApiPtr->tcIndxSendArray[Ti - 6];
-  }//for
-  localHostptr.p->packedWordsTCINDXCONF[TcurrLen + TpacketLen] = Tpack6;
-
-  if (unlikely(!ndb_check_micro_gcp(getNodeInfo(localHostptr.i).m_version)))
-  {
-    jam();
-    ndbassert(Tpack6 == 0 || getNodeInfo(localHostptr.i).m_version == 0);
-  }
-}//Dbtc::sendTcIndxConf()
-
 void Dbtc::execINDXKEYINFO(Signal* signal)
 {
   jamEntry();
@@ -13964,7 +14097,7 @@ Dbtc::saveINDXKEYINFO(Signal* signal,
     releaseIndexOperation(apiConnectptr.p, indexOp);
     terrorCode = 289;
     if(TcKeyReq::getExecuteFlag(indexOp->tcIndxReq.requestInfo))
-      apiConnectptr.p->m_exec_flag= 1;
+      apiConnectptr.p->m_flags |= ApiConnectRecord::TF_EXEC_FLAG;
     abortErrorLab(signal);
     return -1;
   }
@@ -14006,7 +14139,7 @@ Dbtc::saveINDXATTRINFO(Signal* signal,
     releaseIndexOperation(apiConnectptr.p, indexOp);
     terrorCode = 289;
     if(TcKeyReq::getExecuteFlag(indexOp->tcIndxReq.requestInfo))
-      apiConnectptr.p->m_exec_flag= 1;
+      apiConnectptr.p->m_flags |= ApiConnectRecord::TF_EXEC_FLAG;
     abortErrorLab(signal);
     return -1;
   }
@@ -14193,7 +14326,7 @@ void Dbtc::execTCKEYCONF(Signal* signal)
   /**
    * Check on TCKEYCONF whether the the transaction was committed
    */
-  Uint32 Tcommit = TcKeyConf::getCommitFlag(confInfo);
+  ndbassert(TcKeyConf::getCommitFlag(confInfo) == false);
 
   indexOpPtr.p = indexOp;
   if (!indexOp) {
@@ -14246,28 +14379,6 @@ void Dbtc::execTCKEYCONF(Signal* signal)
     executeIndexOperation(signal, regApiPtr, indexOp);
     break;
   }
-  case(IOS_INDEX_OPERATION): {
-    // We are done, send TCINDXCONF
-    jam();    
-    Uint32 Ttcindxrec = regApiPtr->tcindxrec;
-    // Copy reply from TcKeyConf
-
-    ndbassert(regApiPtr->noIndexOp);
-    regApiPtr->noIndexOp--; // Decrease count
-    regApiPtr->tcIndxSendArray[Ttcindxrec] = indexOp->tcIndxReq.senderData;
-    regApiPtr->tcIndxSendArray[Ttcindxrec + 1] = 
-      tcKeyConf->operations[0].attrInfoLen;
-    regApiPtr->tcindxrec = Ttcindxrec + 2;
-    if (regApiPtr->noIndexOp == 0) {
-      jam();
-      sendTcIndxConf(signal, Tcommit);
-    } else if (regApiPtr->tcindxrec == ZTCOPCONF_SIZE) {
-      jam();
-      sendTcIndxConf(signal, 0);
-    }
-    releaseIndexOperation(regApiPtr, indexOp);
-    break;
-  }
   }
 }
 
@@ -14298,23 +14409,11 @@ void Dbtc::execTCKEYREF(Signal* signal)
   case(IOS_INDEX_ACCESS_WAIT_FOR_TRANSID_AI):
   case(IOS_INDEX_ACCESS_WAIT_FOR_TCKEYCONF): {
     jam();    
-    /**
-     * Increase count as it will be decreased below...
-     *   (and the code is written to handle failing lookup on "real" table
-     *    not lookup on index table)
-     */
-    regApiPtr->noIndexOp++;
-    // else continue
-  }
-  case(IOS_INDEX_OPERATION): {
     // Send TCINDXREF 
     
-    jam();
     TcKeyReq * const tcIndxReq = &indexOp->tcIndxReq;
     TcKeyRef * const tcIndxRef = (TcKeyRef *)signal->getDataPtrSend();
     
-    ndbassert(regApiPtr->noIndexOp);
-    regApiPtr->noIndexOp--; // Decrease count
     tcIndxRef->connectPtr = tcIndxReq->senderData;
     tcIndxRef->transId[0] = tcKeyRef->transId[0];
     tcIndxRef->transId[1] = tcKeyRef->transId[1];
@@ -14510,20 +14609,6 @@ void Dbtc::execTRANSID_AI(Signal* signal
     // else continue waiting for more TRANSID_AI
     break;
   }
-  case(IOS_INDEX_OPERATION): {
-    // Should never receive TRANSID_AI in this state!!
-    jam();    
-    TcKeyRef * const tcIndxRef = (TcKeyRef *)signal->getDataPtrSend();
-
-    tcIndxRef->connectPtr = indexOp->tcIndxReq.senderData;
-    tcIndxRef->transId[0] = regApiPtr->transid[0];
-    tcIndxRef->transId[1] = regApiPtr->transid[1];
-    tcIndxRef->errorCode = 4349;
-    tcIndxRef->errorData = regApiPtr->errorData;
-    sendSignal(regApiPtr->ndbapiBlockref, GSN_TCINDXREF, signal, 
-	       TcKeyRef::SignalLength, JBB);
-    return;
-  }
   }
 }
 
@@ -14719,10 +14804,8 @@ void Dbtc::executeIndexOperation(Signal*
     tcKeyReq->scanInfo = indexOp->fragmentId; // As read from Index table
     TcKeyReq::setDistributionKeyFlag(tcKeyRequestInfo, 1U);
   }
-  indexOp->indexOpState = IOS_INDEX_OPERATION;
-  regApiPtr->m_special_op_flags = TcConnectRecord::SOF_INDEX_BASE_TABLE_ACCESS;
-  regApiPtr->executingIndexOp = indexOp->indexOpId;;
-  regApiPtr->noIndexOp++; // Increase count
+  regApiPtr->m_special_op_flags = 0;
+  regApiPtr->executingIndexOp = 0;
 
   /* KeyInfo section
    * Get the KeyInfo we received from the index table lookup
@@ -14753,6 +14836,9 @@ void Dbtc::executeIndexOperation(Signal*
     signal->header.m_noOfSections = 2;
     indexOp->attrInfoSectionIVal = RNIL;
   }
+
+  releaseIndexOperation(regApiPtr, indexOp);
+
   TcKeyReq::setKeyLength(tcKeyRequestInfo, keyInfoFromTransIdAI.sz);
   TcKeyReq::setAIInTcKeyReq(tcKeyRequestInfo, 0);
   TcKeyReq::setCommitFlag(tcKeyRequestInfo, 0);
@@ -14780,12 +14866,27 @@ void Dbtc::executeIndexOperation(Signal*
   const Uint32 currSavePointId = regApiPtr->currSavePointId;
   regApiPtr->currSavePointId = tmp.p->savePointId;
 
+#ifdef ERROR_INSERT
+  bool err8072 = ERROR_INSERTED(8072);
+  if (err8072)
+  {
+    CLEAR_ERROR_INSERT_VALUE;
+  }
+#endif
+
   /* Execute TCKEYREQ now - it is now responsible for freeing
    * the KeyInfo and AttrInfo sections 
    */
   EXECUTE_DIRECT(DBTC, GSN_TCKEYREQ, signal, TcKeyReq::StaticLength);
   jamEntry();
-  
+
+#ifdef ERROR_INSERT
+  if (err8072)
+  {
+    SET_ERROR_INSERT_VALUE(8072);
+  }
+#endif
+
   if (unlikely(regApiPtr->apiConnectstate == CS_ABORTING))
   {
     // TODO : Presumably the abort cleans up the operation
@@ -14865,6 +14966,31 @@ void Dbtc::saveTriggeringOpState(Signal*
                 LqhKeyConf::SignalLength);  
 }
 
+void
+Dbtc::trigger_op_finished(Signal* signal, ApiConnectRecordPtr regApiPtr,
+                          TcConnectRecord* triggeringOp)
+{
+  if (!regApiPtr.p->isExecutingDeferredTriggers())
+  {
+    ndbassert(triggeringOp->triggerExecutionCount > 0);
+    triggeringOp->triggerExecutionCount--;
+    if (triggeringOp->triggerExecutionCount == 0)
+    {
+      /**
+       * We have completed current trigger execution
+       * Continue triggering operation
+       */
+      jam();
+      continueTriggeringOp(signal, triggeringOp);
+    }
+  }
+  else
+  {
+    jam();
+    lqhKeyConf_checkTransactionState(signal, regApiPtr);
+  }
+}
+
 void Dbtc::continueTriggeringOp(Signal* signal, TcConnectRecord* trigOp)
 {
   LqhKeyConf * lqhKeyConf = (LqhKeyConf *)signal->getDataPtr();
@@ -14872,6 +14998,9 @@ void Dbtc::continueTriggeringOp(Signal* 
                 (UintR*)lqhKeyConf,
 		LqhKeyConf::SignalLength);
 
+  ndbassert(trigOp->savedState[LqhKeyConf::SignalLength-1] != ~Uint32(0));
+  trigOp->savedState[LqhKeyConf::SignalLength-1] = ~Uint32(0);
+
   lqhKeyConf->noFiredTriggers = 0;
   trigOp->noReceivedTriggers = 0;
 
@@ -14879,18 +15008,6 @@ void Dbtc::continueTriggeringOp(Signal* 
   execLQHKEYCONF(signal);
 }
 
-void Dbtc::scheduleFiredTrigger(ApiConnectRecordPtr* transPtr,
-                                TcConnectRecordPtr* opPtr)
-{
-  // Set initial values for trigger fireing operation
-  opPtr->p->triggerExecutionCount++;
-
-  // Insert fired trigger in execution queue
-  transPtr->p->theFiredTriggers.add(opPtr->p->accumulatingTriggerData);
-  opPtr->p->accumulatingTriggerData.i = RNIL;
-  opPtr->p->accumulatingTriggerData.p = NULL;
-}
-
 void Dbtc::executeTriggers(Signal* signal, ApiConnectRecordPtr* transPtr)
 {
   ApiConnectRecord* regApiPtr = transPtr->p;
@@ -14901,7 +15018,10 @@ void Dbtc::executeTriggers(Signal* signa
   if (!regApiPtr->theFiredTriggers.isEmpty()) {
     jam();
     if ((regApiPtr->apiConnectstate == CS_STARTED) ||
-        (regApiPtr->apiConnectstate == CS_START_COMMITTING)) {
+        (regApiPtr->apiConnectstate == CS_START_COMMITTING) ||
+        (regApiPtr->apiConnectstate == CS_SEND_FIRE_TRIG_REQ) ||
+        (regApiPtr->apiConnectstate == CS_WAIT_FIRE_TRIG_REQ))
+    {
       jam();
       regApiPtr->theFiredTriggers.first(trigPtr);
       while (trigPtr.i != RNIL) {
@@ -14911,7 +15031,8 @@ void Dbtc::executeTriggers(Signal* signa
         ptrCheckGuard(opPtr, ctcConnectFilesize, localTcConnectRecord);
 	FiredTriggerPtr nextTrigPtr = trigPtr;
 	regApiPtr->theFiredTriggers.next(nextTrigPtr);
-        if (opPtr.p->noReceivedTriggers == opPtr.p->noFiredTriggers) {
+        if (opPtr.p->noReceivedTriggers == opPtr.p->noFiredTriggers ||
+            regApiPtr->isExecutingDeferredTriggers()) {
           jam();
           // Fireing operation is ready to have a trigger executing
           executeTrigger(signal, trigPtr.p, transPtr, &opPtr);
@@ -14944,9 +15065,11 @@ void Dbtc::executeTriggers(Signal* signa
       {
         // Wait until transaction is ready to execute a trigger
         jam();
-        if (!regApiPtr->triggerPending) {
+        if (!tc_testbit(regApiPtr->m_flags,
+                        ApiConnectRecord::TF_TRIGGER_PENDING))
+        {
           jam();
-          regApiPtr->triggerPending = true;
+          regApiPtr->m_flags |= ApiConnectRecord::TF_TRIGGER_PENDING;
           signal->theData[0] = TcContinueB::TRIGGER_PENDING;
           signal->theData[1] = transPtr->i;
           signal->theData[2] = regApiPtr->transid[0];
@@ -14978,6 +15101,7 @@ void Dbtc::executeTrigger(Signal* signal
        c_theDefinedTriggers.getPtr(firedTriggerData->triggerId)) 
       != NULL)
   {
+    transPtr->p->pendingTriggers--;
     switch(firedTriggerData->triggerType) {
     case(TriggerType::SECONDARY_INDEX):
       jam();
@@ -15017,8 +15141,8 @@ void Dbtc::executeIndexTrigger(Signal* s
   }
   case(TriggerEvent::TE_UPDATE): {
     jam();
-    deleteFromIndexTable(signal, firedTriggerData, transPtr, opPtr, 
-			 indexData, true); // Hold the triggering operation
+    opPtr->p->triggerExecutionCount++; // One is already added...and this is 2
+    deleteFromIndexTable(signal, firedTriggerData, transPtr, opPtr, indexData);
     insertIntoIndexTable(signal, firedTriggerData, transPtr, opPtr, indexData);
     break;
   }
@@ -15141,8 +15265,7 @@ void Dbtc::insertIntoIndexTable(Signal* 
                                 TcFiredTriggerData* firedTriggerData, 
                                 ApiConnectRecordPtr* transPtr,
                                 TcConnectRecordPtr* opPtr,
-                                TcIndexData* indexData,
-                                bool holdOperation)
+                                TcIndexData* indexData)
 {
   ApiConnectRecord* regApiPtr = transPtr->p;
   TcConnectRecord* opRecord = opPtr->p;
@@ -15156,10 +15279,6 @@ void Dbtc::insertIntoIndexTable(Signal* 
   ptrCheckGuard(indexTabPtr, ctabrecFilesize, tableRecord);
   tcKeyReq->apiConnectPtr = transPtr->i;
   tcKeyReq->senderData = opPtr->i;
-  if (holdOperation) {
-    jam();
-    opRecord->triggerExecutionCount++;
-  }//if
 
   /* Key for insert to unique index table is the afterValues from the
    * base table operation (from update or insert on base).
@@ -15172,6 +15291,15 @@ void Dbtc::insertIntoIndexTable(Signal* 
   LocalDataBuffer<11> afterValues(pool, firedTriggerData->afterValues);
   LocalDataBuffer<11> keyValues(pool, firedTriggerData->keyValues);
 
+  if (afterValues.getSize() == 0)
+  {
+    jam();
+    ndbrequire(tc_testbit(regApiPtr->m_flags,
+                          ApiConnectRecord::TF_DEFERRED_CONSTRAINTS));
+    trigger_op_finished(signal, *transPtr, opRecord);
+    return;
+  }
+
   Uint32 keyIVal= RNIL;
   Uint32 attrIVal= RNIL;
   bool appendOk= false;
@@ -15204,15 +15332,7 @@ void Dbtc::insertIntoIndexTable(Signal* 
     {
       jam();
       releaseSection(keyIVal);
-      opRecord->triggerExecutionCount--;
-      if (opRecord->triggerExecutionCount == 0) {
-        /*
-          We have completed current trigger execution
-          Continue triggering operation
-        */
-        jam();
-        continueTriggeringOp(signal, opRecord);	
-      }//if
+      trigger_op_finished(signal, *transPtr, opRecord);
       return;
     }
     
@@ -15306,8 +15426,7 @@ void Dbtc::deleteFromIndexTable(Signal* 
                                 TcFiredTriggerData* firedTriggerData, 
                                 ApiConnectRecordPtr* transPtr,
                                 TcConnectRecordPtr* opPtr,
-                                TcIndexData* indexData,
-                                bool holdOperation)
+                                TcIndexData* indexData)
 {
   ApiConnectRecord* regApiPtr = transPtr->p;
   TcConnectRecord* opRecord = opPtr->p;
@@ -15319,10 +15438,7 @@ void Dbtc::deleteFromIndexTable(Signal* 
   ptrCheckGuard(indexTabPtr, ctabrecFilesize, tableRecord);
   tcKeyReq->apiConnectPtr = transPtr->i;
   tcKeyReq->senderData = opPtr->i;
-  if (holdOperation) {
-    jam();
-    opRecord->triggerExecutionCount++;
-  }//if
+
   // Calculate key length and renumber attribute id:s
   AttributeBuffer::DataBufferPool & pool = c_theAttributeBufferPool;
   LocalDataBuffer<11> beforeValues(pool, firedTriggerData->beforeValues);
@@ -15330,7 +15446,16 @@ void Dbtc::deleteFromIndexTable(Signal* 
   Uint32 keyIVal= RNIL;
   Uint32 attrId= 0;
   bool hasNull= false;
-  
+
+  if (beforeValues.getSize() == 0)
+  {
+    jam();
+    ndbrequire(tc_testbit(regApiPtr->m_flags,
+                          ApiConnectRecord::TF_DEFERRED_CONSTRAINTS));
+    trigger_op_finished(signal, *transPtr, opRecord);
+    return;
+  }
+
   /* Build Delete KeyInfo section from beforevalues */
   if (unlikely((! appendAttrDataToSection(keyIVal,
                                           beforeValues,
@@ -15352,15 +15477,7 @@ void Dbtc::deleteFromIndexTable(Signal* 
   {
     jam();
     releaseSection(keyIVal);
-    opRecord->triggerExecutionCount--;
-    if (opRecord->triggerExecutionCount == 0) {
-      /*
-        We have completed current trigger execution
-        Continue triggering operation
-      */
-      jam();
-      continueTriggeringOp(signal, opRecord);	
-    }//if
+    trigger_op_finished(signal, *transPtr, opRecord);
     return;
   }
 

=== modified file 'storage/ndb/src/kernel/blocks/dbtup/Dbtup.hpp'
--- a/storage/ndb/src/kernel/blocks/dbtup/Dbtup.hpp	2011-02-10 10:16:09 +0000
+++ b/storage/ndb/src/kernel/blocks/dbtup/Dbtup.hpp	2011-03-23 15:57:37 +0000
@@ -960,7 +960,10 @@ ArrayPool<TupTriggerData> c_triggerPool;
       subscriptionDeleteTriggers(triggerPool),
       subscriptionUpdateTriggers(triggerPool),
       constraintUpdateTriggers(triggerPool),
-      tuxCustomTriggers(triggerPool)
+      tuxCustomTriggers(triggerPool),
+      deferredInsertTriggers(triggerPool),
+      deferredDeleteTriggers(triggerPool),
+      deferredUpdateTriggers(triggerPool)
       {}
     
     Bitmask<MAXNROFATTRIBUTESINWORDS> notNullAttributeMask;
@@ -1090,7 +1093,10 @@ ArrayPool<TupTriggerData> c_triggerPool;
     DLList<TupTriggerData> subscriptionDeleteTriggers;
     DLList<TupTriggerData> subscriptionUpdateTriggers;
     DLList<TupTriggerData> constraintUpdateTriggers;
-    
+    DLList<TupTriggerData> deferredInsertTriggers;
+    DLList<TupTriggerData> deferredUpdateTriggers;
+    DLList<TupTriggerData> deferredDeleteTriggers;
+
     // List of ordered indexes
     DLList<TupTriggerData> tuxCustomTriggers;
     
@@ -1505,19 +1511,31 @@ typedef Ptr<HostBuffer> HostBufferPtr;
     STATIC_CONST( SZ32 = 1 );
   };
 
+  enum When
+  {
+    KRS_PREPARE = 0,
+    KRS_COMMIT = 1,
+    KRS_PRE_COMMIT0 = 2, // There can be multiple pre commit phases...
+    KRS_PRE_COMMIT1 = 3
+  };
+
 struct KeyReqStruct {
 
-  KeyReqStruct(EmulatedJamBuffer * _jamBuffer) {
+  KeyReqStruct(EmulatedJamBuffer * _jamBuffer, When when = KRS_PREPARE) {
 #if defined VM_TRACE || defined ERROR_INSERT
     memset(this, 0xf3, sizeof(* this));
 #endif
     jamBuffer = _jamBuffer;
+    m_when = when;
+    m_deferred_constraints = true;
   }
-  KeyReqStruct(Dbtup* tup) {
+  KeyReqStruct(Dbtup* tup, When when = KRS_PREPARE) {
 #if defined VM_TRACE || defined ERROR_INSERT
     memset(this, 0xf3, sizeof(* this));
 #endif
     jamBuffer = tup->jamBuffer();
+    m_when = when;
+    m_deferred_constraints = true;
   }
   
 /**
@@ -1564,6 +1582,7 @@ struct KeyReqStruct {
   /* Flag: is tuple in expanded or in shrunken/stored format? */
   bool is_expanded;
   bool m_is_lcp;
+  enum When m_when;
 
   struct Var_data {
     /*
@@ -1611,6 +1630,7 @@ struct KeyReqStruct {
   bool            last_row;
   bool            m_use_rowid;
   Uint8           m_reorg;
+  bool            m_deferred_constraints;
 
   Signal*         signal;
   Uint32 no_fired_triggers;
@@ -1982,6 +2002,12 @@ private:
 //------------------------------------------------------------------
   void execDROP_TRIG_IMPL_REQ(Signal* signal);
 
+  /**
+   * Deferred triggers execute when execFIRE_TRIG_REQ
+   *   is called
+   */
+  void execFIRE_TRIG_REQ(Signal* signal);
+
 // *****************************************************************
 // Setting up the environment for reads, inserts, updates and deletes.
 // *****************************************************************
@@ -2567,11 +2593,11 @@ private:
                                     Tablerec* tablePtr,
                                     bool disk);
 
-#if 0
-  void checkDeferredTriggers(Signal* signal, 
+  void checkDeferredTriggers(KeyReqStruct *req_struct,
                              Operationrec* regOperPtr,
-                             Tablerec* regTablePtr);
-#endif
+                             Tablerec* regTablePtr,
+                             bool disk);
+
   void checkDetachedTriggers(KeyReqStruct *req_struct,
                              Operationrec* regOperPtr,
                              Tablerec* regTablePtr,
@@ -2582,9 +2608,19 @@ private:
                              Operationrec* regOperPtr,
                              bool disk);
 
+  void checkDeferredTriggersDuringPrepare(KeyReqStruct *req_struct,
+                                          DLList<TupTriggerData>& triggerList,
+                                          Operationrec* const regOperPtr,
+                                          bool disk);
   void fireDeferredTriggers(KeyReqStruct *req_struct,
                             DLList<TupTriggerData>& triggerList,
-                            Operationrec* regOperPtr);
+                            Operationrec* const regOperPtr,
+                            bool disk);
+
+  void fireDeferredConstraints(KeyReqStruct *req_struct,
+                               DLList<TupTriggerData>& triggerList,
+                               Operationrec* const regOperPtr,
+                               bool disk);
 
   void fireDetachedTriggers(KeyReqStruct *req_struct,
                             DLList<TupTriggerData>& triggerList,

=== modified file 'storage/ndb/src/kernel/blocks/dbtup/DbtupCommit.cpp'
--- a/storage/ndb/src/kernel/blocks/dbtup/DbtupCommit.cpp	2011-02-10 10:16:09 +0000
+++ b/storage/ndb/src/kernel/blocks/dbtup/DbtupCommit.cpp	2011-03-23 15:57:37 +0000
@@ -580,7 +580,7 @@ void Dbtup::execTUP_COMMITREQ(Signal* si
   FragrecordPtr regFragPtr;
   OperationrecPtr regOperPtr;
   TablerecPtr regTabPtr;
-  KeyReqStruct req_struct(this);
+  KeyReqStruct req_struct(this, KRS_COMMIT);
   TransState trans_state;
   Uint32 no_of_fragrec, no_of_tablerec;
 

=== modified file 'storage/ndb/src/kernel/blocks/dbtup/DbtupExecQuery.cpp'
--- a/storage/ndb/src/kernel/blocks/dbtup/DbtupExecQuery.cpp	2011-02-08 08:36:36 +0000
+++ b/storage/ndb/src/kernel/blocks/dbtup/DbtupExecQuery.cpp	2011-03-23 15:57:37 +0000
@@ -597,9 +597,11 @@ void Dbtup::execTUPKEYREQ(Signal* signal
 
    sig1 = tupKeyReq->m_row_id_page_no;
    sig2 = tupKeyReq->m_row_id_page_idx;
+   sig3 = tupKeyReq->deferred_constraints;
 
    req_struct.m_row_id.m_page_no = sig1;
    req_struct.m_row_id.m_page_idx = sig2;
+   req_struct.m_deferred_constraints = sig3;
 
    /* Get AttrInfo section if this is a long TUPKEYREQ */
    Uint32 attrInfoIVal= tupKeyReq->attrInfoIVal;
@@ -1927,6 +1929,7 @@ int Dbtup::handleDeleteReq(Signal* signa
   {
     regOperPtr->tupVersion= req_struct->m_tuple_ptr->get_tuple_version();
   }
+  req_struct->changeMask.set();
 
   if(disk && regOperPtr->m_undo_buffer_space == 0)
   {

=== modified file 'storage/ndb/src/kernel/blocks/dbtup/DbtupGen.cpp'
--- a/storage/ndb/src/kernel/blocks/dbtup/DbtupGen.cpp	2011-02-07 13:21:49 +0000
+++ b/storage/ndb/src/kernel/blocks/dbtup/DbtupGen.cpp	2011-03-23 15:57:37 +0000
@@ -128,6 +128,8 @@ Dbtup::Dbtup(Block_context& ctx, Uint32 
   addRecSignal(GSN_DROP_FRAG_REQ, &Dbtup::execDROP_FRAG_REQ);
   addRecSignal(GSN_SUB_GCP_COMPLETE_REP, &Dbtup::execSUB_GCP_COMPLETE_REP);
 
+  addRecSignal(GSN_FIRE_TRIG_REQ, &Dbtup::execFIRE_TRIG_REQ);
+
   fragoperrec = 0;
   fragrecord = 0;
   alterTabOperRec = 0;

=== modified file 'storage/ndb/src/kernel/blocks/dbtup/DbtupTrigger.cpp'
--- a/storage/ndb/src/kernel/blocks/dbtup/DbtupTrigger.cpp	2011-02-03 14:20:36 +0000
+++ b/storage/ndb/src/kernel/blocks/dbtup/DbtupTrigger.cpp	2011-03-23 15:57:37 +0000
@@ -32,6 +32,7 @@
 #include <signaldata/DropTrigImpl.hpp>
 #include <signaldata/TuxMaint.hpp>
 #include <signaldata/AlterIndxImpl.hpp>
+#include "../dblqh/Dblqh.hpp"
 
 /* **************************************************************** */
 /* ---------------------------------------------------------------- */
@@ -523,6 +524,96 @@ Dbtup::dropTrigger(Tablerec* table, cons
   return 0;
 }//Dbtup::dropTrigger()
 
+void
+Dbtup::execFIRE_TRIG_REQ(Signal* signal)
+{
+  jam();
+  Uint32 opPtrI = signal->theData[0];
+  Uint32 pass = signal->theData[5];
+
+  FragrecordPtr regFragPtr;
+  OperationrecPtr regOperPtr;
+  TablerecPtr regTabPtr;
+  KeyReqStruct req_struct(this, (When)(KRS_PRE_COMMIT0 + pass));
+
+  regOperPtr.i = opPtrI;
+
+  jamEntry();
+
+  c_operation_pool.getPtr(regOperPtr);
+
+  regFragPtr.i = regOperPtr.p->fragmentPtr;
+  Uint32 no_of_fragrec = cnoOfFragrec;
+  ptrCheckGuard(regFragPtr, no_of_fragrec, fragrecord);
+
+  TransState trans_state = get_trans_state(regOperPtr.p);
+  ndbrequire(trans_state == TRANS_STARTED);
+
+  Uint32 no_of_tablerec = cnoOfTablerec;
+  regTabPtr.i = regFragPtr.p->fragTableId;
+  ptrCheckGuard(regTabPtr, no_of_tablerec, tablerec);
+
+  req_struct.signal = signal;
+  req_struct.TC_ref = signal->theData[1];
+  req_struct.TC_index = signal->theData[2];
+  req_struct.trans_id1 = signal->theData[3];
+  req_struct.trans_id2 = signal->theData[4];
+
+  PagePtr page;
+  Tuple_header* tuple_ptr = (Tuple_header*)
+    get_ptr(&page, &regOperPtr.p->m_tuple_location, regTabPtr.p);
+  req_struct.m_tuple_ptr = tuple_ptr;
+
+  OperationrecPtr lastOperPtr;
+  lastOperPtr.i = tuple_ptr->m_operation_ptr_i;
+  c_operation_pool.getPtr(lastOperPtr);
+
+  /**
+   * Deferred triggers should fire only once per primary key
+   *   regardless of no of DML on that primary key
+   *
+   * We keep track of this on *last* operation (which btw, implies that
+   *   a trigger can't update "own" tuple...i.e first op would be better...)
+   *
+   * NOTE: Since we also use passes...we check if pass is the correct one
+   *       using a cas-like call
+   */
+  if (c_lqh->cas_fire_trig_pass(lastOperPtr.p->userpointer,
+                                pass, pass + 1) != pass)
+  {
+    jam();
+    signal->theData[0] = 0;
+    signal->theData[1] = 0;
+    return;
+  }
+
+  /**
+   * This is deferred triggers...
+   *   which is basically the same as detached,
+   *     i.e before value is <before transaction>
+   *     and after values is <after transaction>
+   *   with the difference that they execute (fire) while
+   *   still having a transaction context...
+   *   i.e can abort transactions, modify transaction
+   */
+  req_struct.no_fired_triggers = 0;
+
+  /**
+   * See DbtupCommit re "Setting the op-list has this effect"
+   */
+  Uint32 save[2] = { lastOperPtr.p->nextActiveOp, lastOperPtr.p->prevActiveOp };
+  lastOperPtr.p->nextActiveOp = RNIL;
+  lastOperPtr.p->prevActiveOp = RNIL;
+
+  checkDeferredTriggers(&req_struct, lastOperPtr.p, regTabPtr.p, false);
+
+  lastOperPtr.p->nextActiveOp = save[0];
+  lastOperPtr.p->prevActiveOp = save[1];
+
+  signal->theData[0] = 0;
+  signal->theData[1] = req_struct.no_fired_triggers;
+}
+
 /* ---------------------------------------------------------------- */
 /* -------------- checkImmediateTriggersAfterOp ------------------ */
 /*                                                                  */
@@ -542,13 +633,24 @@ Dbtup::checkImmediateTriggersAfterInsert
     return;
   }
 
-  if ((regOperPtr->op_struct.primary_replica) &&
-      (!(regTablePtr->afterInsertTriggers.isEmpty()))) {
-    jam();
-    fireImmediateTriggers(req_struct,
-                          regTablePtr->afterInsertTriggers,
-                          regOperPtr,
-                          disk);
+  if (regOperPtr->op_struct.primary_replica)
+  {
+    if (! regTablePtr->afterInsertTriggers.isEmpty())
+    {
+      jam();
+      fireImmediateTriggers(req_struct,
+                            regTablePtr->afterInsertTriggers,
+                            regOperPtr,
+                            disk);
+    }
+
+    if (! regTablePtr->deferredInsertTriggers.isEmpty())
+    {
+      checkDeferredTriggersDuringPrepare(req_struct,
+                                         regTablePtr->deferredInsertTriggers,
+                                         regOperPtr,
+                                         disk);
+    }
   }
 }
 
@@ -562,21 +664,34 @@ Dbtup::checkImmediateTriggersAfterUpdate
     return;
   }
 
-  if ((regOperPtr->op_struct.primary_replica) &&
-      (!(regTablePtr->afterUpdateTriggers.isEmpty()))) {
-    jam();
-    fireImmediateTriggers(req_struct,
-                          regTablePtr->afterUpdateTriggers,
-                          regOperPtr,
-                          disk);
-  }
-  if ((regOperPtr->op_struct.primary_replica) &&
-      (!(regTablePtr->constraintUpdateTriggers.isEmpty()))) {
-    jam();
-    fireImmediateTriggers(req_struct,
-                          regTablePtr->constraintUpdateTriggers,
-                          regOperPtr,
-                          disk);
+  if (regOperPtr->op_struct.primary_replica)
+  {
+    if (! regTablePtr->afterUpdateTriggers.isEmpty())
+    {
+      jam();
+      fireImmediateTriggers(req_struct,
+                            regTablePtr->afterUpdateTriggers,
+                            regOperPtr,
+                            disk);
+    }
+
+    if (! regTablePtr->constraintUpdateTriggers.isEmpty())
+    {
+      jam();
+      fireImmediateTriggers(req_struct,
+                            regTablePtr->constraintUpdateTriggers,
+                            regOperPtr,
+                            disk);
+    }
+
+    if (! regTablePtr->deferredUpdateTriggers.isEmpty())
+    {
+      jam();
+      checkDeferredTriggersDuringPrepare(req_struct,
+                                         regTablePtr->deferredUpdateTriggers,
+                                         regOperPtr,
+                                         disk);
+    }
   }
 }
 
@@ -590,17 +705,48 @@ Dbtup::checkImmediateTriggersAfterDelete
     return;
   }
 
-  if ((regOperPtr->op_struct.primary_replica) &&
-      (!(regTablePtr->afterDeleteTriggers.isEmpty()))) {
+  if (regOperPtr->op_struct.primary_replica)
+  {
+    if (! regTablePtr->afterDeleteTriggers.isEmpty())
+    {
+      fireImmediateTriggers(req_struct,
+                            regTablePtr->afterDeleteTriggers,
+                            regOperPtr,
+                            disk);
+    }
+
+    if (! regTablePtr->deferredDeleteTriggers.isEmpty())
+    {
+      checkDeferredTriggersDuringPrepare(req_struct,
+                                         regTablePtr->deferredDeleteTriggers,
+                                         regOperPtr,
+                                         disk);
+    }
+  }
+}
+
+void
+Dbtup::checkDeferredTriggersDuringPrepare(KeyReqStruct *req_struct,
+                                          DLList<TupTriggerData>& triggerList,
+                                          Operationrec* const regOperPtr,
+                                          bool disk)
+{
+  jam();
+  TriggerPtr trigPtr;
+  triggerList.first(trigPtr);
+  while (trigPtr.i != RNIL)
+  {
     jam();
-    executeTriggers(req_struct,
-                    regTablePtr->afterDeleteTriggers,
-                    regOperPtr,
-                    disk);
+    if (trigPtr.p->monitorAllAttributes ||
+        trigPtr.p->attributeMask.overlaps(req_struct->changeMask))
+    {
+      jam();
+      req_struct->no_fired_triggers |= (1 << 31);
+      return;
+    }
   }
 }
 
-#if 0
 /* ---------------------------------------------------------------- */
 /* --------------------- checkDeferredTriggers -------------------- */
 /*                                                                  */
@@ -610,14 +756,95 @@ Dbtup::checkImmediateTriggersAfterDelete
 /* Executes deferred triggers by sending FIRETRIGORD                */
 /*                                                                  */
 /* ---------------------------------------------------------------- */
-void Dbtup::checkDeferredTriggers(Signal* signal, 
-                                  Operationrec* const regOperPtr,
-                                  Tablerec* const regTablePtr)
+void Dbtup::checkDeferredTriggers(KeyReqStruct *req_struct,
+                                  Operationrec* regOperPtr,
+                                  Tablerec* regTablePtr,
+                                  bool disk)
 {
   jam();
-  // NYI
+  Uint32 save_type = regOperPtr->op_struct.op_type;
+  Tuple_header *save_ptr = req_struct->m_tuple_ptr;
+  DLList<TupTriggerData> * deferred_list = 0;
+  DLList<TupTriggerData> * constraint_list = 0;
+
+  switch (save_type) {
+  case ZUPDATE:
+  case ZINSERT:
+    req_struct->m_tuple_ptr =get_copy_tuple(&regOperPtr->m_copy_tuple_location);
+    break;
+  }
+
+  /**
+   * Set correct operation type and fix change mask
+   * Note ALLOC is set in "orig" tuple
+   */
+  if (save_ptr->m_header_bits & Tuple_header::ALLOC) {
+    if (save_type == ZDELETE) {
+      // insert + delete = nothing
+      jam();
+      return;
+      goto end;
+    }
+    regOperPtr->op_struct.op_type = ZINSERT;
+  }
+  else if (save_type == ZINSERT) {
+    /**
+     * Tuple was not created but last op is INSERT.
+     * This is possible only on DELETE + INSERT
+     */
+    regOperPtr->op_struct.op_type = ZUPDATE;
+  }
+
+  switch(regOperPtr->op_struct.op_type) {
+  case(ZINSERT):
+    jam();
+    deferred_list = &regTablePtr->deferredInsertTriggers;
+    constraint_list = &regTablePtr->afterInsertTriggers;
+    break;
+  case(ZDELETE):
+    jam();
+    deferred_list = &regTablePtr->deferredDeleteTriggers;
+    constraint_list = &regTablePtr->afterDeleteTriggers;
+    break;
+  case(ZUPDATE):
+    jam();
+    deferred_list = &regTablePtr->deferredUpdateTriggers;
+    constraint_list = &regTablePtr->afterUpdateTriggers;
+    break;
+  default:
+    ndbrequire(false);
+    break;
+  }
+
+  if (req_struct->m_deferred_constraints == false)
+  {
+    constraint_list = 0;
+  }
+
+  if (deferred_list->isEmpty() &&
+      (constraint_list == 0 || constraint_list->isEmpty()))
+  {
+    goto end;
+  }
+
+  /**
+   * Compute change-mask
+   */
+  set_commit_change_mask_info(regTablePtr, req_struct, regOperPtr);
+  if (!deferred_list->isEmpty())
+  {
+    fireDeferredTriggers(req_struct, * deferred_list, regOperPtr, disk);
+  }
+
+  if (constraint_list && !constraint_list->isEmpty())
+  {
+    fireDeferredConstraints(req_struct, * constraint_list, regOperPtr, disk);
+  }
+
+end:
+  regOperPtr->op_struct.op_type = save_type;
+  req_struct->m_tuple_ptr = save_ptr;
 }//Dbtup::checkDeferredTriggers()
-#endif
 
 /* ---------------------------------------------------------------- */
 /* --------------------- checkDetachedTriggers -------------------- */
@@ -716,6 +943,13 @@ end:
   req_struct->m_tuple_ptr = save_ptr;
 }
 
+static
+bool
+is_constraint(const Dbtup::TupTriggerData * trigPtr)
+{
+  return trigPtr->triggerType == TriggerType::SECONDARY_INDEX;
+}
+
 void 
 Dbtup::fireImmediateTriggers(KeyReqStruct *req_struct,
                              DLList<TupTriggerData>& triggerList, 
@@ -729,6 +963,38 @@ Dbtup::fireImmediateTriggers(KeyReqStruc
     if (trigPtr.p->monitorAllAttributes ||
         trigPtr.p->attributeMask.overlaps(req_struct->changeMask)) {
       jam();
+
+      if (req_struct->m_when == KRS_PREPARE &&
+          req_struct->m_deferred_constraints &&
+          is_constraint(trigPtr.p))
+      {
+        req_struct->no_fired_triggers |= (1 << 31);
+      }
+      else
+      {
+        executeTrigger(req_struct,
+                       trigPtr.p,
+                       regOperPtr,
+                       disk);
+      }
+    }
+    triggerList.next(trigPtr);
+  }//while
+}//Dbtup::fireImmediateTriggers()
+
+void
+Dbtup::fireDeferredConstraints(KeyReqStruct *req_struct,
+                               DLList<TupTriggerData>& triggerList,
+                               Operationrec* const regOperPtr,
+                               bool disk)
+{
+  TriggerPtr trigPtr;
+  triggerList.first(trigPtr);
+  while (trigPtr.i != RNIL) {
+    jam();
+    if (trigPtr.p->monitorAllAttributes ||
+        trigPtr.p->attributeMask.overlaps(req_struct->changeMask)) {
+      jam();
       executeTrigger(req_struct,
                      trigPtr.p,
                      regOperPtr,
@@ -736,14 +1002,13 @@ Dbtup::fireImmediateTriggers(KeyReqStruc
     }//if
     triggerList.next(trigPtr);
   }//while
-}//Dbtup::fireImmediateTriggers()
+}//Dbtup::fireDeferredTriggers()
 
-#if 0
-void 
-Dbtup::fireDeferredTriggers(Signal* signal,
-                            KeyReqStruct *req_struct,
-                            DLList<TupTriggerData>& triggerList, 
-                            Operationrec* const regOperPtr)
+void
+Dbtup::fireDeferredTriggers(KeyReqStruct *req_struct,
+                            DLList<TupTriggerData>& triggerList,
+                            Operationrec* const regOperPtr,
+                            bool disk)
 {
   TriggerPtr trigPtr;
   triggerList.first(trigPtr);
@@ -753,13 +1018,13 @@ Dbtup::fireDeferredTriggers(Signal* sign
         trigPtr.p->attributeMask.overlaps(req_struct->changeMask)) {
       jam();
       executeTrigger(req_struct,
-                     trigPtr,
-                     regOperPtr);
+                     trigPtr.p,
+                     regOperPtr,
+                     disk);
     }//if
     triggerList.next(trigPtr);
   }//while
 }//Dbtup::fireDeferredTriggers()
-#endif
 
 void 
 Dbtup::fireDetachedTriggers(KeyReqStruct *req_struct,
@@ -1064,6 +1329,44 @@ out:
     return;
   }
 
+  if (triggerType == TriggerType::SECONDARY_INDEX &&
+      req_struct->m_when != KRS_PREPARE)
+  {
+    ndbrequire(req_struct->m_deferred_constraints);
+    if (req_struct->m_when == KRS_PRE_COMMIT0)
+    {
+      switch(regOperPtr->op_struct.op_type){
+      case ZINSERT:
+        req_struct->no_fired_triggers |= (1 << 31);
+        return;
+        break;
+      case ZUPDATE:
+        req_struct->no_fired_triggers |= (1 << 31);
+        noAfterWords = 0;
+        break;
+      case ZDELETE:
+        break;
+      default:
+        ndbrequire(false);
+      }
+    }
+    else
+    {
+      ndbrequire(req_struct->m_when == KRS_PRE_COMMIT1);
+      switch(regOperPtr->op_struct.op_type){
+      case ZINSERT:
+        break;
+      case ZUPDATE:
+        noBeforeWords = 0;
+        break;
+      case ZDELETE:
+        return;
+      default:
+        ndbrequire(false);
+      }
+    }
+  }
+
   req_struct->no_fired_triggers++;
 
   if (longsignal == false)

=== modified file 'storage/ndb/src/ndbapi/NdbOperationDefine.cpp'
--- a/storage/ndb/src/ndbapi/NdbOperationDefine.cpp	2011-02-10 07:55:45 +0000
+++ b/storage/ndb/src/ndbapi/NdbOperationDefine.cpp	2011-03-23 15:57:37 +0000
@@ -1404,5 +1404,10 @@ NdbOperation::handleOperationOptions (co
     op->m_flags &= ~Uint8(OF_QUEUEABLE);
   }
 
+  if (opts->optionsPresent & OperationOptions::OO_DEFERRED_CONSTAINTS)
+  {
+    op->m_flags |= OF_DEFERRED_CONSTRAINTS;
+  }
+
   return 0;
 }

=== modified file 'storage/ndb/src/ndbapi/NdbOperationExec.cpp'
--- a/storage/ndb/src/ndbapi/NdbOperationExec.cpp	2011-02-10 08:10:20 +0000
+++ b/storage/ndb/src/ndbapi/NdbOperationExec.cpp	2011-03-23 15:57:37 +0000
@@ -472,6 +472,7 @@ NdbOperation::prepareSend(Uint32 aTC_Con
   Uint8 tInterpretIndicator = theInterpretIndicator;
   Uint8 tNoDisk = (m_flags & OF_NO_DISK) != 0;
   Uint8 tQueable = (m_flags & OF_QUEUEABLE) != 0;
+  Uint8 tDeferred = (m_flags & OF_DEFERRED_CONSTRAINTS) != 0;
 
   /**
    * A dirty read, can not abort the transaction
@@ -490,6 +491,7 @@ NdbOperation::prepareSend(Uint32 aTC_Con
   tcKeyReq->setInterpretedFlag(tReqInfo, tInterpretIndicator);
   tcKeyReq->setNoDiskFlag(tReqInfo, tNoDisk);
   tcKeyReq->setQueueOnRedoProblemFlag(tReqInfo, tQueable);
+  tcKeyReq->setDeferredConstraints(tReqInfo, tDeferred);
 
   OperationType tOperationType = theOperationType;
   Uint8 abortOption = (ao == DefaultAbortOption) ? (Uint8) m_abortOption : (Uint8) ao;
@@ -1417,12 +1419,18 @@ NdbOperation::prepareSendNdbRecord(Abort
   m_abortOption= theSimpleIndicator && theOperationType==ReadRequest ?
     (Uint8) AO_IgnoreError : (Uint8) abortOption;
 
+  Uint8 tQueable = (m_flags & OF_QUEUEABLE) != 0;
+  Uint8 tDeferred = (m_flags & OF_DEFERRED_CONSTRAINTS) != 0;
+
   TcKeyReq::setAbortOption(tcKeyReq->requestInfo, m_abortOption);
   TcKeyReq::setCommitFlag(tcKeyReq->requestInfo, theCommitIndicator);
   TcKeyReq::setStartFlag(tcKeyReq->requestInfo, theStartIndicator);
   TcKeyReq::setSimpleFlag(tcKeyReq->requestInfo, theSimpleIndicator);
   TcKeyReq::setDirtyFlag(tcKeyReq->requestInfo, theDirtyIndicator);
 
+  TcKeyReq::setQueueOnRedoProblemFlag(tcKeyReq->requestInfo, tQueable);
+  TcKeyReq::setDeferredConstraints(tcKeyReq->requestInfo, tDeferred);
+
   theStatus= WaitResponse;
   theReceiver.prepareSend();
 


Attachment: [text/bzr-bundle] bzr/jonas@mysql.com-20110323155737-ysmgr6oyj73evhvp.bundle
Thread
bzr commit into mysql-5.1-telco-7.0 branch (jonas:4252) jonas oreland23 Mar