List:Commits« Previous MessageNext Message »
From:Jonas Oreland Date:November 24 2010 1:16pm
Subject:bzr commit into mysql-5.1-telco-6.3 branch (jonas:3346) Bug#57481
View as plain text  
#At file:///home/jonas/src/telco-6.3/ based on revid:jonas@stripped

 3346 Jonas Oreland	2010-11-24
      ndb - bug#57481 - make sure to close previous mrr scans, before starting new

    modified:
      mysql-test/suite/ndb/r/ndb_read_multi_range.result
      mysql-test/suite/ndb/t/ndb_read_multi_range.test
      sql/ha_ndbcluster.cc
=== modified file 'mysql-test/suite/ndb/r/ndb_read_multi_range.result'
--- a/mysql-test/suite/ndb/r/ndb_read_multi_range.result	2009-02-03 13:35:56 +0000
+++ b/mysql-test/suite/ndb/r/ndb_read_multi_range.result	2010-11-24 13:16:09 +0000
@@ -588,3 +588,24 @@ i	i	9
 m	m	13
 v	v	22
 drop table t1, t2;
+create table t1 (pk int primary key, a int) engine=ndb;
+create table t2 (pk int primary key, a int) engine=ndb;
+insert into t2 values
+(0,0), (1,1), (2,2), (3,3), (4,4),
+(5,5), (6,6), (7,7), (8,8), (9,9);
+insert into t1
+select
+t1.a + t2.a*10 + t3.a*100 + t4.a*1000, 
+(t1.a + t2.a*10 + t3.a*100 + t4.a*1000) / 1000
+from
+t2 as t1, t2 as t2, t2 as t3, t2 as t4
+where (t1.a + t2.a*10 + t3.a*100 + t4.a*1000) < 3000;
+explain
+SELECT DISTINCT STRAIGHT_JOIN t1.pk FROM 
+t1 LEFT JOIN t2 ON t2.a = t1.a AND t2.pk != 6;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3000	Using temporary
+1	SIMPLE	t2	range	PRIMARY	PRIMARY	4	NULL	2	Using where; Distinct
+SELECT DISTINCT STRAIGHT_JOIN t1.pk FROM 
+t1 LEFT JOIN t2 ON t2.a = t1.a AND t2.pk != 6;
+drop table t1, t2;

=== modified file 'mysql-test/suite/ndb/t/ndb_read_multi_range.test'
--- a/mysql-test/suite/ndb/t/ndb_read_multi_range.test	2009-02-03 13:35:56 +0000
+++ b/mysql-test/suite/ndb/t/ndb_read_multi_range.test	2010-11-24 13:16:09 +0000
@@ -428,3 +428,53 @@ select * from t1
     or (a = 'v')
     order by a asc, b asc;
 drop table t1, t2;
+
+########################
+# Check propper reinit of a mrr executed multiple time as part of a join.
+# The mrr access is driven by a scan and executed as for every tuple 
+# in the scaned table.
+#
+# In certain queries the optimizer don't read the entire mrr result set
+# before it fetch the next tuple from the scanned table. 
+# The next mrr operation would then still have an open scan which wasn't
+# cleaned up as expected. This may cause all available NdbOperation,
+# NdbTransaction or lock objects to be consumed before the operation 
+# could finish.
+#####################
+
+create table t1 (pk int primary key, a int) engine=ndb;
+create table t2 (pk int primary key, a int) engine=ndb;
+
+insert into t2 values
+   (0,0), (1,1), (2,2), (3,3), (4,4),
+   (5,5), (6,6), (7,7), (8,8), (9,9);
+
+##
+# 10^4 cross product on t2 creates 10.000 rows:
+# Insert volume has been tunes to insert only 3.000
+# of these as this is sufficient to produce an 'out of connection objects'
+##
+insert into t1
+ select
+   t1.a + t2.a*10 + t3.a*100 + t4.a*1000, 
+   (t1.a + t2.a*10 + t3.a*100 + t4.a*1000) / 1000
+from
+  t2 as t1, t2 as t2, t2 as t3, t2 as t4
+where (t1.a + t2.a*10 + t3.a*100 + t4.a*1000) < 3000;
+
+
+# Execute a 'scan(t1) join mrr(t2)'
+#  - 'DISTINCT t1.pk' will cause optimizer to stop fetching mrr(t2) 
+#     when the first matching 't2.a = t1.a' is found.
+#  - 'LEFT JOIN' is to ensure that 'Using join buffer' is *not* used
+#
+explain
+SELECT DISTINCT STRAIGHT_JOIN t1.pk FROM 
+   t1 LEFT JOIN t2 ON t2.a = t1.a AND t2.pk != 6;
+
+--disable_result_log
+SELECT DISTINCT STRAIGHT_JOIN t1.pk FROM 
+   t1 LEFT JOIN t2 ON t2.a = t1.a AND t2.pk != 6;
+--enable_result_log
+
+drop table t1, t2;

=== modified file 'sql/ha_ndbcluster.cc'
--- a/sql/ha_ndbcluster.cc	2010-11-24 13:05:04 +0000
+++ b/sql/ha_ndbcluster.cc	2010-11-24 13:16:09 +0000
@@ -10945,6 +10945,7 @@ ha_ndbcluster::read_multi_range_first(KE
   const NdbOperation* op;
   Thd_ndb *thd_ndb= m_thd_ndb;
   NdbTransaction *trans= m_thd_ndb->trans;
+  int error;
 
   DBUG_ENTER("ha_ndbcluster::read_multi_range_first");
   DBUG_PRINT("info", ("blob fields=%d read_set=0x%x", table_share->blob_fields, table->read_set->bitmap[0]));
@@ -10966,6 +10967,14 @@ ha_ndbcluster::read_multi_range_first(KE
                                                 sorted, 
                                                 buffer));
   }
+
+  /**
+   * There may still be an open m_multi_cursor from the previous mrr access on this handler.
+   * Close it now to free up resources for this NdbScanOperation.
+   */ 
+  if (unlikely(error= close_scan()))
+    DBUG_RETURN(error);
+
   thd_ndb->query_state|= NDB_QUERY_MULTI_READ_RANGE;
   m_disable_multi_read= FALSE;
 
@@ -11001,8 +11010,8 @@ ha_ndbcluster::read_multi_range_first(KE
   */
 
   DBUG_ASSERT(cur_index_type != UNDEFINED_INDEX);
+  DBUG_ASSERT(m_multi_cursor==NULL);
 
-  m_multi_cursor= 0;
   const NdbOperation* lastOp= trans ? trans->getLastDefinedOperation() : 0;
   NdbOperation::LockMode lm= 
     (NdbOperation::LockMode)get_ndb_lock_type(m_lock.type, table->read_set);
@@ -11010,7 +11019,6 @@ ha_ndbcluster::read_multi_range_first(KE
   const uchar *end_of_buffer= buffer->buffer_end;
   uint num_scan_ranges= 0;
   uint i;
-  int error;
   bool any_real_read= FALSE;
 
   if (m_read_before_write_removal_possible)


Attachment: [text/bzr-bundle] bzr/jonas@mysql.com-20101124131609-7eegarkflxjvcxmq.bundle
Thread
bzr commit into mysql-5.1-telco-6.3 branch (jonas:3346) Bug#57481Jonas Oreland24 Nov