List:Commits« Previous MessageNext Message »
From:Ole John Aske Date:June 20 2011 2:25pm
Subject:bzr commit into mysql-5.1-telco-7.0-spj-scan-vs-scan branch
(ole.john.aske:3510)
View as plain text  
#At file:///net/fimafeng09/export/home/tmp/oleja/mysql/mysql-5.1-telco-7.0-spj-scan-scan/ based on revid:jonas@stripped

 3510 Ole John Aske	2011-06-20 [merge]
      Merge

    added:
      mysql-test/suite/ndb/r/ndb_alter_table_online_multi.result
      mysql-test/suite/ndb/r/ndb_select_count.result
      mysql-test/suite/ndb/t/ndb_alter_table_online_multi.test
      mysql-test/suite/ndb/t/ndb_select_count.test
    modified:
      mysql-test/suite/ndb/r/ndb_alter_table_online.result
      mysql-test/suite/ndb/r/ndb_index_ordered.result
      mysql-test/suite/ndb/r/ndb_multi.result
      mysql-test/suite/ndb/t/ndb_alter_table_online.test
      mysql-test/suite/ndb/t/ndb_index_ordered.test
      mysql-test/suite/ndb/t/ndb_multi.test
      sql/ha_ndbcluster.cc
      storage/ndb/src/ndbapi/NdbQueryBuilder.hpp
      storage/ndb/src/ndbapi/NdbQueryOperation.cpp
      storage/ndb/src/ndbapi/NdbQueryOperation.hpp
      storage/ndb/src/ndbapi/NdbQueryOperationImpl.hpp
=== modified file 'mysql-test/suite/ndb/r/ndb_alter_table_online.result'
--- a/mysql-test/suite/ndb/r/ndb_alter_table_online.result	2011-04-11 13:36:12 +0000
+++ b/mysql-test/suite/ndb/r/ndb_alter_table_online.result	2011-06-17 10:15:34 +0000
@@ -142,67 +142,6 @@ select name from ndb_show_tables_results
 name
 DROP TABLE t1;
 *******************************
-* basic concurent online alter test
-*******************************
-* With Commit
-*******************************
-CREATE TABLE t1 (a INT UNSIGNED KEY, b INT UNSIGNED) ENGINE NDB;
-begin;
-update t1 set b = 0 where a = 1;
-update t1 set b = 1 where a = 2;
-delete from t1      where a = 3;
-insert into t1 values (5,5),(6,6);
-update t1 set b = 0 where a = 6;
-ALTER TABLE t1 ADD c CHAR(19), ADD d VARCHAR(255), ADD e char(255);
-Warnings:
-Warning	1478	Converted FIXED field to DYNAMIC to enable on-line ADD COLUMN
-Warning	1478	Converted FIXED field to DYNAMIC to enable on-line ADD COLUMN
-Warning	1478	Converted FIXED field to DYNAMIC to enable on-line ADD COLUMN
-update t1 set b = 0 where a = 2;
-update t1 set b = 0 where a = 4;
-update t1 set b = 0 where a = 5;
-insert into t1 values (7,0,null,null,null),(8,0,'8','8','8');
-commit;
-SELECT * FROM t1 ORDER BY a;
-a	b	c	d	e
-1	0	NULL	NULL	NULL
-2	0	NULL	NULL	NULL
-4	0	NULL	NULL	NULL
-5	0	NULL	NULL	NULL
-6	0	NULL	NULL	NULL
-7	0	NULL	NULL	NULL
-8	0	8	8	8
-DROP TABLE t1;
-*******************************
-* basic concurent online alter test
-*******************************
-* With Rollback
-*******************************
-CREATE TABLE t1 (a INT UNSIGNED KEY, b INT UNSIGNED) ENGINE NDB;
-begin;
-update t1 set b = 0 where a = 1;
-update t1 set b = 1 where a = 2;
-delete from t1      where a = 3;
-insert into t1 values (5,5),(6,6);
-update t1 set b = 0 where a = 6;
-ALTER TABLE t1 ADD c CHAR(19), ADD d VARCHAR(255), ADD e char(255);
-Warnings:
-Warning	1478	Converted FIXED field to DYNAMIC to enable on-line ADD COLUMN
-Warning	1478	Converted FIXED field to DYNAMIC to enable on-line ADD COLUMN
-Warning	1478	Converted FIXED field to DYNAMIC to enable on-line ADD COLUMN
-update t1 set b = 0 where a = 2;
-update t1 set b = 0 where a = 4;
-update t1 set b = 0 where a = 5;
-insert into t1 values (7,0,null,null,null),(8,0,'8','8','8');
-rollback;
-SELECT * FROM t1 ORDER BY a;
-a	b	c	d	e
-1	1	NULL	NULL	NULL
-2	2	NULL	NULL	NULL
-3	3	NULL	NULL	NULL
-4	4	NULL	NULL	NULL
-DROP TABLE t1;
-*******************************
 * The following ALTER operations are not supported on-line
 *******************************
 * Not supported Test#1

=== added file 'mysql-test/suite/ndb/r/ndb_alter_table_online_multi.result'
--- a/mysql-test/suite/ndb/r/ndb_alter_table_online_multi.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/ndb/r/ndb_alter_table_online_multi.result	2011-06-17 10:15:34 +0000
@@ -0,0 +1,61 @@
+*******************************
+* basic concurent online alter test
+*******************************
+* With Commit
+*******************************
+CREATE TABLE t1 (a INT UNSIGNED KEY, b INT UNSIGNED) ENGINE NDB;
+begin;
+update t1 set b = 0 where a = 1;
+update t1 set b = 1 where a = 2;
+delete from t1      where a = 3;
+insert into t1 values (5,5),(6,6);
+update t1 set b = 0 where a = 6;
+ALTER TABLE t1 ADD c CHAR(19), ADD d VARCHAR(255), ADD e char(255);
+Warnings:
+Warning	1478	Converted FIXED field to DYNAMIC to enable on-line ADD COLUMN
+Warning	1478	Converted FIXED field to DYNAMIC to enable on-line ADD COLUMN
+Warning	1478	Converted FIXED field to DYNAMIC to enable on-line ADD COLUMN
+update t1 set b = 0 where a = 2;
+update t1 set b = 0 where a = 4;
+update t1 set b = 0 where a = 5;
+insert into t1 values (7,0,null,null,null),(8,0,'8','8','8');
+commit;
+SELECT * FROM t1 ORDER BY a;
+a	b	c	d	e
+1	0	NULL	NULL	NULL
+2	0	NULL	NULL	NULL
+4	0	NULL	NULL	NULL
+5	0	NULL	NULL	NULL
+6	0	NULL	NULL	NULL
+7	0	NULL	NULL	NULL
+8	0	8	8	8
+DROP TABLE t1;
+*******************************
+* basic concurent online alter test
+*******************************
+* With Rollback
+*******************************
+CREATE TABLE t1 (a INT UNSIGNED KEY, b INT UNSIGNED) ENGINE NDB;
+begin;
+update t1 set b = 0 where a = 1;
+update t1 set b = 1 where a = 2;
+delete from t1      where a = 3;
+insert into t1 values (5,5),(6,6);
+update t1 set b = 0 where a = 6;
+ALTER TABLE t1 ADD c CHAR(19), ADD d VARCHAR(255), ADD e char(255);
+Warnings:
+Warning	1478	Converted FIXED field to DYNAMIC to enable on-line ADD COLUMN
+Warning	1478	Converted FIXED field to DYNAMIC to enable on-line ADD COLUMN
+Warning	1478	Converted FIXED field to DYNAMIC to enable on-line ADD COLUMN
+update t1 set b = 0 where a = 2;
+update t1 set b = 0 where a = 4;
+update t1 set b = 0 where a = 5;
+insert into t1 values (7,0,null,null,null),(8,0,'8','8','8');
+rollback;
+SELECT * FROM t1 ORDER BY a;
+a	b	c	d	e
+1	1	NULL	NULL	NULL
+2	2	NULL	NULL	NULL
+3	3	NULL	NULL	NULL
+4	4	NULL	NULL	NULL
+DROP TABLE t1;

=== modified file 'mysql-test/suite/ndb/r/ndb_index_ordered.result'
--- a/mysql-test/suite/ndb/r/ndb_index_ordered.result	2011-06-15 10:37:56 +0000
+++ b/mysql-test/suite/ndb/r/ndb_index_ordered.result	2011-06-17 10:15:04 +0000
@@ -637,21 +637,6 @@ select count(*)- 4 from t1 use index (v)
 count(*)- 4
 0
 drop table t1;
-create table t1(a int primary key, b int not null, index(b));
-insert into t1 values (1,1), (2,2);
-set autocommit=0;
-begin;
-select count(*) from t1;
-count(*)
-2
-ALTER TABLE t1 ADD COLUMN c int;
-select a from t1 where b = 2;
-a
-2
-show tables;
-Tables_in_test
-t1
-drop table t1;
 create table t1 (a int, c varchar(10),
 primary key using hash (a), index(c)) engine=ndb;
 insert into t1 (a, c) values (1,'aaa'),(3,'bbb');

=== modified file 'mysql-test/suite/ndb/r/ndb_multi.result'
--- a/mysql-test/suite/ndb/r/ndb_multi.result	2011-03-22 08:32:32 +0000
+++ b/mysql-test/suite/ndb/r/ndb_multi.result	2011-06-17 10:15:04 +0000
@@ -196,3 +196,19 @@ insert into t1 values(37);
 alter table t1 engine ndb;
 truncate t1;
 drop table t1;
+create table t1(a int primary key, b int not null, index(b)) engine = ndb;
+insert into t1 values (1,1), (2,2);
+set autocommit=0;
+begin;
+select count(*) from t1;
+count(*)
+2
+ALTER OFFLINE TABLE t1 ADD COLUMN c int;
+select a from t1 where b = 2;
+a
+2
+commit;
+show tables;
+Tables_in_test
+t1
+drop table t1;

=== added file 'mysql-test/suite/ndb/r/ndb_select_count.result'
--- a/mysql-test/suite/ndb/r/ndb_select_count.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/ndb/r/ndb_select_count.result	2011-06-20 12:34:27 +0000
@@ -0,0 +1,19 @@
+create table t1(
+k int not null auto_increment primary key,
+i int,
+j int
+) engine=ndbcluster;
+insert into t1(i,j) values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7);
+select count(*) from t1;
+count(*)
+7
+begin;
+delete from t1 where k = 10000;
+select count(*) from t1;
+count(*)
+7
+commit;
+select count(*) from t1;
+count(*)
+7
+drop table t1;

=== modified file 'mysql-test/suite/ndb/t/ndb_alter_table_online.test'
--- a/mysql-test/suite/ndb/t/ndb_alter_table_online.test	2011-04-11 13:36:12 +0000
+++ b/mysql-test/suite/ndb/t/ndb_alter_table_online.test	2011-06-17 10:15:34 +0000
@@ -139,91 +139,6 @@ select name from ndb_show_tables_results
 DROP TABLE t1;
 
 --echo *******************************
---echo * basic concurent online alter test
---echo *******************************
---echo * With Commit
---echo *******************************
-
-connection server1;
-
-CREATE TABLE t1 (a INT UNSIGNED KEY, b INT UNSIGNED) ENGINE NDB;
-let $v=4;
-disable_query_log;
-while ($v)
-{
-  --eval INSERT INTO t1 VALUES($v,$v); 
-  dec $v;
-}
-enable_query_log;
-
-
-connection server2;
-begin;
-update t1 set b = 0 where a = 1;
-update t1 set b = 1 where a = 2;
-delete from t1      where a = 3;
-
-insert into t1 values (5,5),(6,6);
-update t1 set b = 0 where a = 6;
-
-connection server1;
-ALTER TABLE t1 ADD c CHAR(19), ADD d VARCHAR(255), ADD e char(255);
-
-connection server2;
-update t1 set b = 0 where a = 2;
-update t1 set b = 0 where a = 4;
-update t1 set b = 0 where a = 5;
-insert into t1 values (7,0,null,null,null),(8,0,'8','8','8');
-commit;
-
-connection server1;
-SELECT * FROM t1 ORDER BY a;
-
-DROP TABLE t1;
-
---echo *******************************
---echo * basic concurent online alter test
---echo *******************************
---echo * With Rollback
---echo *******************************
-
-connection server1;
-
-CREATE TABLE t1 (a INT UNSIGNED KEY, b INT UNSIGNED) ENGINE NDB;
-let $v=4;
-disable_query_log;
-while ($v)
-{
-  --eval INSERT INTO t1 VALUES($v,$v); 
-  dec $v;
-}
-enable_query_log;
-
-connection server2;
-begin;
-update t1 set b = 0 where a = 1;
-update t1 set b = 1 where a = 2;
-delete from t1      where a = 3;
-
-insert into t1 values (5,5),(6,6);
-update t1 set b = 0 where a = 6;
-
-connection server1;
-ALTER TABLE t1 ADD c CHAR(19), ADD d VARCHAR(255), ADD e char(255);
-
-connection server2;
-update t1 set b = 0 where a = 2;
-update t1 set b = 0 where a = 4;
-update t1 set b = 0 where a = 5;
-insert into t1 values (7,0,null,null,null),(8,0,'8','8','8');
-rollback;
-
-connection server1;
-SELECT * FROM t1 ORDER BY a;
-
-DROP TABLE t1;
-
---echo *******************************
 --echo * The following ALTER operations are not supported on-line
 --echo *******************************
 --echo * Not supported Test#1

=== added file 'mysql-test/suite/ndb/t/ndb_alter_table_online_multi.test'
--- a/mysql-test/suite/ndb/t/ndb_alter_table_online_multi.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/ndb/t/ndb_alter_table_online_multi.test	2011-06-17 10:15:34 +0000
@@ -0,0 +1,88 @@
+-- source include/not_embedded.inc
+-- source include/have_multi_ndb.inc
+
+--echo *******************************
+--echo * basic concurent online alter test
+--echo *******************************
+--echo * With Commit
+--echo *******************************
+
+connection server1;
+
+CREATE TABLE t1 (a INT UNSIGNED KEY, b INT UNSIGNED) ENGINE NDB;
+let $v=4;
+disable_query_log;
+while ($v)
+{
+  --eval INSERT INTO t1 VALUES($v,$v); 
+  dec $v;
+}
+enable_query_log;
+
+
+connection server2;
+begin;
+update t1 set b = 0 where a = 1;
+update t1 set b = 1 where a = 2;
+delete from t1      where a = 3;
+
+insert into t1 values (5,5),(6,6);
+update t1 set b = 0 where a = 6;
+
+connection server1;
+ALTER TABLE t1 ADD c CHAR(19), ADD d VARCHAR(255), ADD e char(255);
+
+connection server2;
+update t1 set b = 0 where a = 2;
+update t1 set b = 0 where a = 4;
+update t1 set b = 0 where a = 5;
+insert into t1 values (7,0,null,null,null),(8,0,'8','8','8');
+commit;
+
+connection server1;
+SELECT * FROM t1 ORDER BY a;
+
+DROP TABLE t1;
+
+--echo *******************************
+--echo * basic concurent online alter test
+--echo *******************************
+--echo * With Rollback
+--echo *******************************
+
+connection server1;
+
+CREATE TABLE t1 (a INT UNSIGNED KEY, b INT UNSIGNED) ENGINE NDB;
+let $v=4;
+disable_query_log;
+while ($v)
+{
+  --eval INSERT INTO t1 VALUES($v,$v); 
+  dec $v;
+}
+enable_query_log;
+
+connection server2;
+begin;
+update t1 set b = 0 where a = 1;
+update t1 set b = 1 where a = 2;
+delete from t1      where a = 3;
+
+insert into t1 values (5,5),(6,6);
+update t1 set b = 0 where a = 6;
+
+connection server1;
+ALTER TABLE t1 ADD c CHAR(19), ADD d VARCHAR(255), ADD e char(255);
+
+connection server2;
+update t1 set b = 0 where a = 2;
+update t1 set b = 0 where a = 4;
+update t1 set b = 0 where a = 5;
+insert into t1 values (7,0,null,null,null),(8,0,'8','8','8');
+rollback;
+
+connection server1;
+SELECT * FROM t1 ORDER BY a;
+
+DROP TABLE t1;
+

=== modified file 'mysql-test/suite/ndb/t/ndb_index_ordered.test'
--- a/mysql-test/suite/ndb/t/ndb_index_ordered.test	2011-06-15 10:37:56 +0000
+++ b/mysql-test/suite/ndb/t/ndb_index_ordered.test	2011-06-17 10:15:04 +0000
@@ -332,22 +332,6 @@ select count(*)- 4 from t1 use index (v)
 
 drop table t1;
 
-# bug#7798
-create table t1(a int primary key, b int not null, index(b));
-insert into t1 values (1,1), (2,2);
-connect (con1,localhost,root,,test);
-connect (con2,localhost,root,,test);
-connection con1;
-set autocommit=0;
-begin;
-select count(*) from t1;
-connection con2;
-ALTER TABLE t1 ADD COLUMN c int;
-connection con1;
-select a from t1 where b = 2;
-show tables;
-drop table t1;
-
 # mysqld 5.0.13 crash, no bug#
 create table t1 (a int, c varchar(10),
   primary key using hash (a), index(c)) engine=ndb;

=== modified file 'mysql-test/suite/ndb/t/ndb_multi.test'
--- a/mysql-test/suite/ndb/t/ndb_multi.test	2011-03-22 08:32:32 +0000
+++ b/mysql-test/suite/ndb/t/ndb_multi.test	2011-06-17 10:15:04 +0000
@@ -246,3 +246,18 @@ truncate t1;
 # Cleanup
 drop table t1;
 connection server1;
+
+# bug#7798
+create table t1(a int primary key, b int not null, index(b)) engine = ndb;
+insert into t1 values (1,1), (2,2);
+set autocommit=0;
+begin;
+select count(*) from t1;
+connection server2;
+ALTER OFFLINE TABLE t1 ADD COLUMN c int;
+connection server1;
+select a from t1 where b = 2;
+commit;
+show tables;
+drop table t1;
+

=== added file 'mysql-test/suite/ndb/t/ndb_select_count.test'
--- a/mysql-test/suite/ndb/t/ndb_select_count.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/ndb/t/ndb_select_count.test	2011-06-20 12:34:27 +0000
@@ -0,0 +1,18 @@
+-- source include/have_ndb.inc
+
+create table t1(
+  k int not null auto_increment primary key,
+  i int,
+  j int
+) engine=ndbcluster;
+
+insert into t1(i,j) values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7);
+
+select count(*) from t1;
+begin;
+delete from t1 where k = 10000; # none existant, rbwr
+select count(*) from t1;
+commit;
+select count(*) from t1;
+
+drop table t1;

=== modified file 'sql/ha_ndbcluster.cc'
--- a/sql/ha_ndbcluster.cc	2011-06-17 15:47:25 +0000
+++ b/sql/ha_ndbcluster.cc	2011-06-20 14:24:53 +0000
@@ -634,9 +634,9 @@ SHOW_VAR ndb_status_variables_dynamic[]=
 };
 
 SHOW_VAR ndb_status_conflict_variables[]= {
-  {"fn_max",       (char*) &g_ndb_slave_state.total_violation_count[CFT_NDB_MAX], SHOW_LONG},
-  {"fn_old",       (char*) &g_ndb_slave_state.total_violation_count[CFT_NDB_OLD], SHOW_LONG},
-  {"fn_max_del_win", (char*) &g_ndb_slave_state.total_violation_count[CFT_NDB_MAX_DEL_WIN], SHOW_LONG},
+  {"fn_max",       (char*) &g_ndb_slave_state.total_violation_count[CFT_NDB_MAX], SHOW_LONGLONG},
+  {"fn_old",       (char*) &g_ndb_slave_state.total_violation_count[CFT_NDB_OLD], SHOW_LONGLONG},
+  {"fn_max_del_win", (char*) &g_ndb_slave_state.total_violation_count[CFT_NDB_MAX_DEL_WIN], SHOW_LONGLONG},
   {NullS, NullS, SHOW_LONG}
 };
 
@@ -5504,6 +5504,7 @@ int ha_ndbcluster::end_bulk_delete()
 
   assert(m_rows_deleted >= ignore_count);
   m_rows_deleted-= ignore_count;
+  no_uncommitted_rows_update(ignore_count);
   DBUG_RETURN(0);
 }
 
@@ -5696,6 +5697,7 @@ int ha_ndbcluster::ndb_delete_row(const 
   {
     assert(m_rows_deleted >= ignore_count);
     m_rows_deleted-= ignore_count;
+    no_uncommitted_rows_update(ignore_count);
   }
   DBUG_RETURN(0);
 }

=== modified file 'storage/ndb/src/ndbapi/NdbQueryBuilder.hpp'
--- a/storage/ndb/src/ndbapi/NdbQueryBuilder.hpp	2011-06-16 10:26:41 +0000
+++ b/storage/ndb/src/ndbapi/NdbQueryBuilder.hpp	2011-06-20 14:24:53 +0000
@@ -479,13 +479,8 @@ private:
  * times. It is valid until it is explicitely released().
  *
  * The NdbQueryDef *must* be keept alive until the last thread
- * which executing a query based on this NdbQueryDef has completed execution 
- * *and* result handling. Used from multiple threads this implies either:
- *
- *  - Keep the NdbQueryDef until all threads terminates.
- *  - Implement reference counting on the NdbQueryDef.
- *  - Use the supplied copy constructor to give each thread its own copy
- *    of the NdbQueryDef.
+ * which executing a query based on this NdbQueryDef has called
+ * NdbQuery::close().
  *
  * A NdbQueryDef is scheduled for execution by appending it to an open 
  * transaction - optionally together with a set of parameters specifying 

=== modified file 'storage/ndb/src/ndbapi/NdbQueryOperation.cpp'
--- a/storage/ndb/src/ndbapi/NdbQueryOperation.cpp	2011-06-16 10:26:41 +0000
+++ b/storage/ndb/src/ndbapi/NdbQueryOperation.cpp	2011-06-20 14:24:53 +0000
@@ -1389,7 +1389,7 @@ NdbQueryImpl::NdbQueryImpl(NdbTransactio
   m_state(Initial),
   m_tcState(Inactive),
   m_next(NULL),
-  m_queryDef(queryDef),
+  m_queryDef(&queryDef),
   m_error(),
   m_transaction(trans),
   m_scanTransaction(NULL),
@@ -1452,9 +1452,13 @@ NdbQueryImpl::NdbQueryImpl(NdbTransactio
 
 NdbQueryImpl::~NdbQueryImpl()
 {
- 
-  // Do this to check that m_queryDef still exists.
-  assert(getNoOfOperations() == m_queryDef.getNoOfOperations());
+  /** BEWARE:
+   *  Don't refer NdbQueryDef or NdbQueryOperationDefs after 
+   *  NdbQuery::close() as at this stage the appliaction is 
+   *  allowed to destruct the Def's.
+   */
+  assert(m_state==Closed);
+  assert(m_rootFrags==NULL);
 
   // NOTE: m_operations[] was allocated as a single memory chunk with
   // placement new construction of each operation.
@@ -1465,8 +1469,6 @@ NdbQueryImpl::~NdbQueryImpl()
     }
     m_operations = NULL;
   }
-  delete[] m_rootFrags;
-  m_rootFrags = NULL;
   m_state = Destructed;
 }
 
@@ -1478,6 +1480,9 @@ NdbQueryImpl::postFetchRelease()
     { m_operations[i].postFetchRelease();
     }
   }
+  delete[] m_rootFrags;
+  m_rootFrags = NULL;
+
   m_rowBufferAlloc.reset();
   m_tupleSetAlloc.reset();
   m_resultStreamAlloc.reset();
@@ -1957,7 +1962,7 @@ NdbQueryImpl::awaitMoreResults(bool forc
   assert(m_applFrags.getCurrent() == NULL);
 
   /* Check if there are any more completed fragments available.*/
-  if (m_queryDef.isScanQuery())
+  if (getQueryDef().isScanQuery())
   {
     assert (m_scanTransaction);
     assert (m_state==Executing);
@@ -2052,7 +2057,7 @@ NdbQueryImpl::awaitMoreResults(bool forc
     assert(m_pendingFrags == 0);
     assert(m_finalBatchFrags == getRootFragCount());
     return FetchResult_noMoreData;
-  } // if(m_queryDef.isScanQuery())
+  } // if(getQueryDef().isScanQuery())
 
 } //NdbQueryImpl::awaitMoreResults
 
@@ -2131,32 +2136,41 @@ NdbQueryImpl::close(bool forceSend)
   int res = 0;
 
   assert (m_state >= Initial && m_state < Destructed);
-  Ndb* const ndb = m_transaction.getNdb();
-
-  if (m_tcState != Inactive)
+  if (m_state != Closed)
   {
-    /* We have started a scan, but we have not yet received the last batch
-     * for all root fragments. We must therefore close the scan to release 
-     * the scan context at TC.*/
-    res = closeTcCursor(forceSend);
-  }
+    if (m_tcState != Inactive)
+    {
+      /* We have started a scan, but we have not yet received the last batch
+       * for all root fragments. We must therefore close the scan to release 
+       * the scan context at TC.*/
+      res = closeTcCursor(forceSend);
+    }
 
-  // Throw any pending results
-  m_fullFrags.clear();
-  m_applFrags.clear();
+    // Throw any pending results
+    m_fullFrags.clear();
+    m_applFrags.clear();
 
-  if (m_scanTransaction != NULL)
-  {
-    assert (m_state != Closed);
-    assert (m_scanTransaction->m_scanningQuery == this);
-    m_scanTransaction->m_scanningQuery = NULL;
-    ndb->closeTransaction(m_scanTransaction);
-    ndb->theRemainingStartTransactions--;  // Compensate; m_scanTransaction was not a real Txn
-    m_scanTransaction = NULL;
+    Ndb* const ndb = m_transaction.getNdb();
+    if (m_scanTransaction != NULL)
+    {
+      assert (m_state != Closed);
+      assert (m_scanTransaction->m_scanningQuery == this);
+      m_scanTransaction->m_scanningQuery = NULL;
+      ndb->closeTransaction(m_scanTransaction);
+      ndb->theRemainingStartTransactions--;  // Compensate; m_scanTransaction was not a real Txn
+      m_scanTransaction = NULL;
+    }
+
+    postFetchRelease();
+    m_state = Closed;  // Even if it was previously 'Failed' it is closed now!
   }
 
-  postFetchRelease();
-  m_state = Closed;  // Even if it was previously 'Failed' it is closed now!
+  /** BEWARE:
+   *  Don't refer NdbQueryDef or its NdbQueryOperationDefs after ::close()
+   *  as the application is allowed to destruct the Def's after this point.
+   */
+  m_queryDef= NULL;
+
   return res;
 } //NdbQueryImpl::close
 
@@ -2819,7 +2833,7 @@ NdbQueryImpl::sendFetchMore(NdbRootFragm
 {
   assert(getRoot().m_resultStreams!=NULL);
   assert(!emptyFrag.finalBatchReceived());
-  assert(m_queryDef.isScanQuery());
+  assert(getQueryDef().isScanQuery());
 
   const Uint32 fragNo = emptyFrag.getFragNo();
   emptyFrag.reset();
@@ -2892,7 +2906,7 @@ NdbQueryImpl::sendFetchMore(NdbRootFragm
 int
 NdbQueryImpl::closeTcCursor(bool forceSend)
 {
-  assert (m_queryDef.isScanQuery());
+  assert (getQueryDef().isScanQuery());
 
   NdbImpl* const ndb = m_transaction.getNdb()->theImpl;
   const Uint32 timeout  = ndb->get_waitfor_timeout();

=== modified file 'storage/ndb/src/ndbapi/NdbQueryOperation.hpp'
--- a/storage/ndb/src/ndbapi/NdbQueryOperation.hpp	2011-04-06 14:16:13 +0000
+++ b/storage/ndb/src/ndbapi/NdbQueryOperation.hpp	2011-06-20 13:25:48 +0000
@@ -180,7 +180,15 @@ public:
   NdbTransaction* getNdbTransaction() const;
 
   /**
-   * Close query
+   * Close query.
+   *
+   * Will release most of the internally allocated objects owned 
+   * by this NdbQuery and detach itself from the NdbQueryDef
+   * used to instantiate it.
+   *
+   * The application may destruct the NdbQueryDef after 
+   * ::close() has been called on *all* NdbQuery objects
+   * instantiated from it.
    */
   void close(bool forceSend = false);
 

=== modified file 'storage/ndb/src/ndbapi/NdbQueryOperationImpl.hpp'
--- a/storage/ndb/src/ndbapi/NdbQueryOperationImpl.hpp	2011-04-06 14:16:13 +0000
+++ b/storage/ndb/src/ndbapi/NdbQueryOperationImpl.hpp	2011-06-20 13:25:48 +0000
@@ -142,7 +142,8 @@ public:
   /** Close query: 
    *  - Release datanode resources,
    *  - Discard pending result sets,
-   *  - optionaly dealloc NdbQuery structures
+   *  - Delete internal buffer and structures for receiving results.
+   *  - Disconnect with NdbQueryDef - it might now be destructed .
    */
   int close(bool forceSend);
 
@@ -191,7 +192,10 @@ public:
 
   /** Get the (transaction independent) definition of this query. */
   const NdbQueryDefImpl& getQueryDef() const
-  { return m_queryDef; }
+  {
+    assert(m_queryDef);
+    return *m_queryDef;
+  }
 
   /** Process TCKEYCONF message. Return true if query is complete. */
   bool execTCKEYCONF();
@@ -213,7 +217,7 @@ public:
    */
   void setStartIndicator()
   { 
-    assert(!m_queryDef.isScanQuery());
+    assert(!getQueryDef().isScanQuery());
     m_startIndicator = true; 
   }
 
@@ -224,7 +228,7 @@ public:
    */
   void setCommitIndicator()
   {  
-    assert(!m_queryDef.isScanQuery());
+    assert(!getQueryDef().isScanQuery());
     m_commitIndicator = true; 
   }
 
@@ -415,7 +419,7 @@ private:
   /** Next query in same transaction.*/
   NdbQueryImpl* m_next;
   /** Definition of this query.*/
-  const NdbQueryDefImpl& m_queryDef;
+  const NdbQueryDefImpl* m_queryDef;
 
   /** Possible error status of this query.*/
   NdbError m_error;

No bundle (reason: revision is a merge).
Thread
bzr commit into mysql-5.1-telco-7.0-spj-scan-vs-scan branch(ole.john.aske:3510) Ole John Aske20 Jun