MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Martin Skold Date:September 1 2009 8:04am
Subject:bzr commit into mysql-5.1-telco-6.2 branch (Martin.Skold:2970) Bug#46712
View as plain text  
#At file:///home/marty/MySQL/mysql-5.1-telco-6.2/

 2970 Martin Skold	2009-09-01
      Bug #46712 Auto_increment work incorrectly when using triggers and NDB Cluster, added same optimization as prior for increasing prefetch for batched inserts
      modified:
        sql/ha_ndbcluster.cc
        sql/ha_ndbcluster.h

=== modified file 'sql/ha_ndbcluster.cc'
--- a/sql/ha_ndbcluster.cc	2009-08-31 14:53:01 +0000
+++ b/sql/ha_ndbcluster.cc	2009-09-01 08:03:59 +0000
@@ -4301,10 +4301,12 @@ void ha_ndbcluster::start_bulk_insert(ha
   if (rows == (ha_rows) 0)
   {
     /* We don't know how many will be inserted, guess */
+    m_estimated_batched_insert= TRUE;
     m_rows_to_insert=
       (m_autoincrement_prefetch > NDB_DEFAULT_AUTO_PREFETCH)
       ? m_autoincrement_prefetch
       : NDB_DEFAULT_AUTO_PREFETCH;
+    m_autoincrement_prefetch= m_rows_to_insert;
   }
   else
   {
@@ -6534,6 +6536,9 @@ void ha_ndbcluster::get_auto_increment(u
                                        ulonglong *first_value,
                                        ulonglong *nb_reserved_values)
 {
+  uint cache_size;
+  uint remaining;
+  uint min_prefetch;
   Uint64 auto_value;
   THD *thd= current_thd;
   DBUG_ENTER("get_auto_increment");
@@ -6541,13 +6546,34 @@ void ha_ndbcluster::get_auto_increment(u
   Ndb *ndb= get_ndb(table->in_use);
   uint retries= NDB_AUTO_INCREMENT_RETRIES;
   int retry_sleep= 30; /* 30 milliseconds, transaction */
-
+  
+  cache_size= m_autoincrement_prefetch;
+  if (m_estimated_batched_insert && m_rows_inserted > m_rows_to_insert)
+  {
+    /*
+      We guessed too low, increase estimate by the 
+     */
+    m_rows_to_insert+= m_autoincrement_prefetch;
+  }
+  /*
+    Set the prefetch to estimated remaining rows, but not lower
+    than user setting
+   */
+  remaining= m_rows_to_insert - m_rows_inserted;
+  min_prefetch= 
+    (remaining < thd->variables.ndb_autoincrement_prefetch_sz) ?
+    thd->variables.ndb_autoincrement_prefetch_sz
+    : remaining;
+  cache_size= ((remaining < m_autoincrement_prefetch) ?
+	       min_prefetch
+	       : remaining);
+  
   for (;;)
   {
     Ndb_tuple_id_range_guard g(m_share);
     if (m_skip_auto_increment &&
         ndb->readAutoIncrementValue(m_table, g.range, auto_value) ||
-        ndb->getAutoIncrementValue(m_table, g.range, auto_value, m_autoincrement_prefetch, increment, offset))
+        ndb->getAutoIncrementValue(m_table, g.range, auto_value, cache_size, increment, offset))
     {
       if (--retries && !thd->killed &&
           ndb->getNdbError().status == NdbError::TemporaryError)

=== modified file 'sql/ha_ndbcluster.h'
--- a/sql/ha_ndbcluster.h	2009-05-26 18:53:34 +0000
+++ b/sql/ha_ndbcluster.h	2009-09-01 08:03:59 +0000
@@ -699,7 +699,10 @@ private:
   ha_rows m_rows_to_insert; // TODO: merge it with handler::estimation_rows_to_insert?
   ha_rows m_rows_inserted;
   ha_rows m_rows_changed;
-  bool m_delete_cannot_batch;
+  union {
+    bool m_delete_cannot_batch;
+    bool m_estimated_batched_insert;
+  };
   bool m_update_cannot_batch;
   uint m_bytes_per_write;
   bool m_skip_auto_increment;

Thread
bzr commit into mysql-5.1-telco-6.2 branch (Martin.Skold:2970) Bug#46712Martin Skold1 Sep