MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:knielsen Date:October 26 2007 11:09am
Subject:bk commit into 5.1 tree (knielsen:1.2676) BUG#31874
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of knielsen. When knielsen does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2007-10-26 13:09:35+02:00, knielsen@ymer.(none) +4 -0
  Bug #31874: Failure for NDB update/delete with combined range and equality constraints
  
  In update/delete with read_multi_range, when mixing pk lookups and range
  scans, sometimes update/delete did not correctly distinguish whether
  the current row was from pk lookup or from scan. This caused query
  failure (or potentially memory corruption and crash).
  
  Fix by setting proper flags in the read_multi_range_next() method.

  mysql-test/suite/ndb/r/ndb_read_multi_range.result@stripped, 2007-10-26 13:09:30+02:00, knielsen@ymer.(none) +15 -0
    Add test case.

  mysql-test/suite/ndb/t/ndb_read_multi_range.test@stripped, 2007-10-26 13:09:30+02:00, knielsen@ymer.(none) +15 -0
    Add test case.

  sql/ha_ndbcluster.cc@stripped, 2007-10-26 13:09:31+02:00, knielsen@ymer.(none) +29 -5
    Fix missing setting of flag to distinguish between pk lookups and range
    scans in read_multi_range.

  sql/ha_ndbcluster.h@stripped, 2007-10-26 13:09:31+02:00, knielsen@ymer.(none) +1 -0
    Fix missing setting of flag to distinguish between pk lookups and range
    scans in read_multi_range.

diff -Nrup a/mysql-test/suite/ndb/r/ndb_read_multi_range.result b/mysql-test/suite/ndb/r/ndb_read_multi_range.result
--- a/mysql-test/suite/ndb/r/ndb_read_multi_range.result	2007-08-21 15:37:49 +02:00
+++ b/mysql-test/suite/ndb/r/ndb_read_multi_range.result	2007-10-26 13:09:30 +02:00
@@ -492,3 +492,18 @@ id
 3
 drop trigger kaboom;
 drop table t1;
+create table t1 (
+a int not null primary key,
+b int
+) engine = ndb;
+insert into t1 values (7,2),(8,3),(10,4);
+update t1 set b = 5 where a in (7,8) or a >= 10;
+select * from t1 order by a;
+a	b
+7	5
+8	5
+10	5
+delete from t1 where a in (7,8) or a >= 10;
+select * from t1 order by a;
+a	b
+drop table t1;
diff -Nrup a/mysql-test/suite/ndb/t/ndb_read_multi_range.test b/mysql-test/suite/ndb/t/ndb_read_multi_range.test
--- a/mysql-test/suite/ndb/t/ndb_read_multi_range.test	2007-08-21 15:37:49 +02:00
+++ b/mysql-test/suite/ndb/t/ndb_read_multi_range.test	2007-10-26 13:09:30 +02:00
@@ -338,3 +338,18 @@ select * from t2 order by id;
 
 drop trigger kaboom;
 drop table t1;
+
+#bug#31874
+
+create table t1 (
+  a int not null primary key,
+  b int
+) engine = ndb;
+insert into t1 values (7,2),(8,3),(10,4);
+
+update t1 set b = 5 where a in (7,8) or a >= 10;
+select * from t1 order by a;
+delete from t1 where a in (7,8) or a >= 10;
+select * from t1 order by a;
+
+drop table t1;
diff -Nrup a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc
--- a/sql/ha_ndbcluster.cc	2007-10-25 11:02:33 +02:00
+++ b/sql/ha_ndbcluster.cc	2007-10-26 13:09:31 +02:00
@@ -4202,7 +4202,11 @@ int ha_ndbcluster::close_scan()
   NdbScanOperation *cursor= m_active_cursor;
   
   if (!cursor)
-    DBUG_RETURN(0);
+  {
+    cursor = m_multi_cursor;
+    if (!cursor)
+      DBUG_RETURN(0);
+  }
 
   if ((error= scan_handle_lock_tuple(cursor, trans)) != 0)
     DBUG_RETURN(error);
@@ -4222,6 +4226,7 @@ int ha_ndbcluster::close_scan()
   
   cursor->close(m_force_send, TRUE);
   m_active_cursor= NULL;
+  m_multi_cursor= NULL;
   DBUG_RETURN(0);
 }
 
@@ -5012,6 +5017,10 @@ int ha_ndbcluster::external_lock(THD *th
       DBUG_PRINT("warning", ("m_active_cursor != NULL"));
     m_active_cursor= NULL;
 
+    if (m_multi_cursor)
+      DBUG_PRINT("warning", ("m_multi_cursor != NULL"));
+    m_multi_cursor= NULL;
+
     if (m_blobs_pending)
       DBUG_PRINT("warning", ("blobs_pending != 0"));
     m_blobs_pending= 0;
@@ -6797,7 +6806,8 @@ ha_ndbcluster::ha_ndbcluster(handlerton 
   m_force_send(TRUE),
   m_autoincrement_prefetch((ha_rows) 32),
   m_transaction_on(TRUE),
-  m_cond(NULL)
+  m_cond(NULL),
+  m_multi_cursor(NULL)
 {
   int i;
  
@@ -9763,7 +9773,7 @@ ha_ndbcluster::read_multi_range_first(KE
        mask, flags, parallelism, 0);
     if (!scanOp)
       ERR_RETURN(m_active_trans->getNdbError());
-    m_active_cursor= scanOp;
+    m_multi_cursor= scanOp;
 
     /*
       We do not get_blob_values() here, as when using blobs we always
@@ -9779,7 +9789,7 @@ ha_ndbcluster::read_multi_range_first(KE
   }
   else
   {
-    m_active_cursor= 0;
+    m_multi_cursor= 0;
   }
 
   buffer->end_of_used_area= row_buf;
@@ -9820,6 +9830,12 @@ ha_ndbcluster::read_multi_range_next(KEY
       */
       KEY_MULTI_RANGE *old_multi_range_curr= multi_range_curr;
       multi_range_curr= old_multi_range_curr + 1;
+      /*
+        Clear m_active_cursor; it is used as a flag in update_row() /
+        delete_row() to know whether the current tuple is from a scan
+        or pk operation.
+      */
+      m_active_cursor= NULL;
       const NdbOperation *op= m_current_multi_operation;
       m_current_multi_operation= m_active_trans->getNextCompletedOperation(op);
       const uchar *src_row= m_multi_range_result_ptr;
@@ -9893,6 +9909,13 @@ ha_ndbcluster::read_multi_range_next(KEY
             one on the next call.
           */
           m_next_row= 0;
+          /*
+            Set m_active_cursor; it is used as a flag in update_row() /
+            delete_row() to know whether the current tuple is from a scan or
+            pk operation.
+          */
+          m_active_cursor= m_multi_cursor;
+
           DBUG_RETURN(0);
         }
         else if (current_range_no > expected_range_no)
@@ -9941,7 +9964,7 @@ ha_ndbcluster::read_multi_range_next(KEY
 int
 ha_ndbcluster::read_multi_range_fetch_next()
 {
-  NdbIndexScanOperation *cursor= (NdbIndexScanOperation *)m_active_cursor;
+  NdbIndexScanOperation *cursor= (NdbIndexScanOperation *)m_multi_cursor;
 
   if (!cursor)
     return 0;                                   // Scan already done.
@@ -9958,6 +9981,7 @@ ha_ndbcluster::read_multi_range_fetch_ne
       /* We have fetched the last row from the scan. */
       cursor->close(FALSE, TRUE);
       m_active_cursor= 0;
+      m_multi_cursor= 0;
       m_next_row= 0;
       return 0;
     }
diff -Nrup a/sql/ha_ndbcluster.h b/sql/ha_ndbcluster.h
--- a/sql/ha_ndbcluster.h	2007-09-27 19:05:53 +02:00
+++ b/sql/ha_ndbcluster.h	2007-10-26 13:09:31 +02:00
@@ -698,6 +698,7 @@ private:
   */
   KEY_MULTI_RANGE *m_multi_range_defined_end;
   const NdbOperation *m_current_multi_operation;
+  NdbIndexScanOperation *m_multi_cursor;
   Ndb *get_ndb();
 };
 
Thread
bk commit into 5.1 tree (knielsen:1.2676) BUG#31874knielsen26 Oct