List:Commits« Previous MessageNext Message »
From:Magnus Blåudd Date:October 22 2010 2:13pm
Subject:bzr commit into mysql-5.1-telco-7.0 branch (magnus.blaudd:3896)
View as plain text  
#At file:///home/msvensson/mysql/tmp/lx6uGZPKtZ/7.0/ based on revid:magnus.blaudd@strippedjwhgq1t

 3896 Magnus Blåudd	2010-10-22 [merge]
      Merge 7.0 -> 7.0

    modified:
      include/my_base.h
      sql/ha_ndbcluster.cc
      sql/ha_ndbcluster.h
      sql/handler.h
      sql/mysql_priv.h
      sql/sql_base.cc
      sql/sql_delete.cc
      sql/sql_update.cc
=== modified file 'include/my_base.h'
--- a/include/my_base.h	2009-10-01 05:56:05 +0000
+++ b/include/my_base.h	2010-10-22 14:12:01 +0000
@@ -375,11 +375,6 @@ enum ha_base_keytype {
 */
 #define HA_STATUS_AUTO          64
 /*
-  update the number of rows updated and deleted since last reset call.
-  handler::rows_updated, rows_deleted
-*/
-#define HA_STATUS_WRITTEN_ROWS  128
-/*
   Errorcodes given by handler functions
 
   opt_sum_query() assumes these codes are > 1

=== modified file 'sql/ha_ndbcluster.cc'
--- a/sql/ha_ndbcluster.cc	2010-10-22 12:35:05 +0000
+++ b/sql/ha_ndbcluster.cc	2010-10-22 14:13:23 +0000
@@ -2473,8 +2473,12 @@ void ha_ndbcluster::release_metadata(THD
   DBUG_VOID_RETURN;
 }
 
-int ha_ndbcluster::get_ndb_lock_type(enum thr_lock_type type,
-                                     const MY_BITMAP *column_bitmap)
+
+/*
+  Map from thr_lock_type to NdbOperation::LockMode
+*/
+static inline
+NdbOperation::LockMode get_ndb_lock_mode(enum thr_lock_type type)
 {
   if (type >= TL_WRITE_ALLOW_WRITE)
     return NdbOperation::LM_Exclusive;
@@ -2483,6 +2487,7 @@ int ha_ndbcluster::get_ndb_lock_type(enu
   return NdbOperation::LM_CommittedRead;
 }
 
+
 static const ulong index_type_flags[]=
 {
   /* UNDEFINED_INDEX */
@@ -2588,10 +2593,8 @@ int ha_ndbcluster::pk_read(const uchar *
   DBUG_DUMP("key", key, key_len);
   DBUG_ASSERT(trans);
 
-  NdbOperation::LockMode lm=
-    (NdbOperation::LockMode)get_ndb_lock_type(m_lock.type, table->read_set);
-  
-  if (!(op= pk_unique_index_read_key(table->s->primary_key, key, buf, lm,
+  if (!(op= pk_unique_index_read_key(table->s->primary_key, key, buf,
+                                     get_ndb_lock_mode(m_lock.type),
                                      (m_user_defined_partitioning ?
                                       part_id :
                                       NULL))))
@@ -2654,10 +2657,9 @@ int ha_ndbcluster::ndb_pk_update_row(THD
     bitmap_copy(&m_bitmap, table->read_set);
     bitmap_union(&m_bitmap, table->write_set);
     bitmap_invert(&m_bitmap);
-    NdbOperation::LockMode lm=
-      (NdbOperation::LockMode)get_ndb_lock_type(m_lock.type, &m_bitmap);
     if (!(op= trans->readTuple(key_rec, (const char *)key_row,
-                               m_ndb_record, (char *)new_data, lm,
+                               m_ndb_record, (char *)new_data,
+                               get_ndb_lock_mode(m_lock.type),
                                (const unsigned char *)(m_bitmap.bitmap),
                                poptions,
                                sizeof(NdbOperation::OperationOptions))))
@@ -2855,8 +2857,7 @@ int ha_ndbcluster::peek_indexed_rows(con
   {
     DBUG_RETURN(error);
   }
-  NdbOperation::LockMode lm=
-      (NdbOperation::LockMode)get_ndb_lock_type(m_lock.type, NULL);
+  const NdbOperation::LockMode lm = get_ndb_lock_mode(m_lock.type);
   first= NULL;
   if (write_op != NDB_UPDATE && table->s->primary_key != MAX_KEY)
   {
@@ -2967,9 +2968,9 @@ int ha_ndbcluster::unique_index_read(con
   DBUG_DUMP("key", key, key_len);
   DBUG_ASSERT(trans);
 
-  NdbOperation::LockMode lm=
-    (NdbOperation::LockMode)get_ndb_lock_type(m_lock.type, table->read_set);
-  if (!(op= pk_unique_index_read_key(active_index, key, buf, lm, NULL)))
+  if (!(op= pk_unique_index_read_key(active_index, key, buf,
+                                     get_ndb_lock_mode(m_lock.type),
+                                     NULL)))
     ERR_RETURN(trans->getNdbError());
   
   if (execute_no_commit_ie(m_thd_ndb, trans) != 0 ||
@@ -3285,8 +3286,7 @@ int ha_ndbcluster::ordered_index_scan(co
   if (m_active_cursor && (error= close_scan()))
     DBUG_RETURN(error);
 
-  NdbOperation::LockMode lm=
-    (NdbOperation::LockMode)get_ndb_lock_type(m_lock.type, table->read_set);
+  const NdbOperation::LockMode lm = get_ndb_lock_mode(m_lock.type);
 
   NdbScanOperation::ScanOptions options;
   options.optionsPresent=NdbScanOperation::ScanOptions::SO_SCANFLAGS;
@@ -3363,7 +3363,7 @@ int ha_ndbcluster::ordered_index_scan(co
 
 static
 int
-guess_scan_flags(NdbOperation::LockMode lm, 
+guess_scan_flags(NdbOperation::LockMode lm,
 		 const NDBTAB* tab, const MY_BITMAP* readset)
 {
   int flags= 0;
@@ -3445,8 +3445,7 @@ int ha_ndbcluster::full_table_scan(const
     if (unlikely(!(trans= start_transaction(error))))
       DBUG_RETURN(error);
 
-  NdbOperation::LockMode lm=
-    (NdbOperation::LockMode)get_ndb_lock_type(m_lock.type, table->read_set);
+  const NdbOperation::LockMode lm = get_ndb_lock_mode(m_lock.type);
   NdbScanOperation::ScanOptions options;
   options.optionsPresent = (NdbScanOperation::ScanOptions::SO_SCANFLAGS |
                             NdbScanOperation::ScanOptions::SO_PARALLEL);
@@ -5736,11 +5735,6 @@ int ha_ndbcluster::info(uint flag)
         stats.auto_increment_value= (ulonglong)auto_increment_value64;
     }
   }
-  if (flag & HA_STATUS_WRITTEN_ROWS)
-  {
-    stats.rows_updated= m_rows_updated;
-    stats.rows_deleted= m_rows_deleted;
-  }
 
   if(result == -1)
     result= HA_ERR_NO_CONNECTION;
@@ -5816,8 +5810,7 @@ int ha_ndbcluster::extra(enum ha_extra_f
 }
 
 
-bool ha_ndbcluster::read_before_write_removal_possible(List<Item> *fields,
-                                                       List<Item> *values)
+bool ha_ndbcluster::read_before_write_removal_possible()
 {
   THD *thd= table->in_use;
   DBUG_ENTER("read_before_write_removal_possible");
@@ -5832,7 +5825,6 @@ bool ha_ndbcluster::read_before_write_re
   if (uses_blob_value(table->write_set) ||
       (thd->lex->sql_command == SQLCOM_DELETE &&
        table_share->blob_fields) ||
-      (values && !check_constant_expressions(values)) ||
       (table_share->primary_key != MAX_KEY &&
        bitmap_is_overlapping(table->write_set, m_pk_bitmap_p)))
   {
@@ -5841,13 +5833,12 @@ bool ha_ndbcluster::read_before_write_re
   if (m_has_unique_index)
   {
     KEY *key;
-    uint i;
-    for (i= 0; i < table_share->keys; i++)
+    for (uint i= 0; i < table_share->keys; i++)
     {
       key= table->key_info + i;
       if ((key->flags & HA_NOSAME) &&
           bitmap_is_overlapping(table->write_set,
-                                m_key_fields[key - table->key_info]))
+                                m_key_fields[i]))
       {
         DBUG_RETURN(FALSE);
       }
@@ -5859,6 +5850,15 @@ bool ha_ndbcluster::read_before_write_re
 }
 
 
+ha_rows ha_ndbcluster::read_before_write_removal_rows_written(void) const
+{
+  DBUG_ENTER("read_before_write_removal_rows_written");
+  DBUG_PRINT("info", ("updated: %llu, deleted: %llu",
+                      m_rows_updated, m_rows_deleted));
+  DBUG_RETURN(m_rows_updated + m_rows_deleted);
+}
+
+
 int ha_ndbcluster::reset()
 {
   DBUG_ENTER("ha_ndbcluster::reset");
@@ -11717,8 +11717,7 @@ ha_ndbcluster::read_multi_range_first(KE
 
   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);
+  const NdbOperation::LockMode lm = get_ndb_lock_mode(m_lock.type);
   uchar *row_buf= (uchar *)buffer->buffer;
   const uchar *end_of_buffer= buffer->buffer_end;
   uint num_scan_ranges= 0;

=== modified file 'sql/ha_ndbcluster.h'
--- a/sql/ha_ndbcluster.h	2010-10-22 12:35:05 +0000
+++ b/sql/ha_ndbcluster.h	2010-10-22 14:13:23 +0000
@@ -434,8 +434,8 @@ class ha_ndbcluster: public handler
 #endif
   void get_dynamic_partition_info(PARTITION_STATS *stat_info, uint part_id);
   uint32 calculate_key_hash_value(Field **field_array);
-  bool read_before_write_removal_possible(List<Item> *fields,
-                                          List<Item> *values);
+  bool read_before_write_removal_possible();
+  ha_rows read_before_write_removal_rows_written(void) const;
   int extra(enum ha_extra_function operation);
   int extra_opt(enum ha_extra_function operation, ulong cache_size);
   int reset();
@@ -682,8 +682,6 @@ private:
   int next_result(uchar *buf); 
   int close_scan();
   void unpack_record(uchar *dst_row, const uchar *src_row);
-  int get_ndb_lock_type(enum thr_lock_type type,
-                        const MY_BITMAP *column_bitmap);
 
   void set_dbname(const char *pathname);
   void set_tabname(const char *pathname);

=== modified file 'sql/handler.h'
--- a/sql/handler.h	2010-10-12 14:53:28 +0000
+++ b/sql/handler.h	2010-10-22 14:13:23 +0000
@@ -1119,7 +1119,6 @@ public:
   ulonglong max_index_file_length;
   ulonglong delete_length;		/* Free bytes */
   ulonglong auto_increment_value;
-  ha_rows rows_updated, rows_deleted;
   /*
     The number of records in the table. 
       0    - means the table has exactly 0 rows
@@ -1578,9 +1577,15 @@ public:
     operation from the handler and instead use a generated read to
     optimise simple UPDATE's and DELETE's.
   */
-  virtual bool read_before_write_removal_possible(List<Item> *fields,
-                                                  List<Item> *values)
+  virtual bool read_before_write_removal_possible(void)
   { return FALSE; }
+  /*
+    Return the number of rows the handler has written while using
+    read before write removal
+   */
+  virtual ha_rows read_before_write_removal_rows_written(void) const
+  { DBUG_ASSERT(0); return (ha_rows) 0; }
+
 
   /**
     In an UPDATE or DELETE, if the row under the cursor was locked by another

=== modified file 'sql/mysql_priv.h'
--- a/sql/mysql_priv.h	2010-10-20 14:06:09 +0000
+++ b/sql/mysql_priv.h	2010-10-22 14:13:23 +0000
@@ -1738,7 +1738,6 @@ bool close_cached_connection_tables(THD 
                                     LEX_STRING *connect_string,
                                     bool have_lock = FALSE);
 void copy_field_from_tmp_record(Field *field,int offset);
-bool check_constant_expressions(List<Item> *values);
 bool fill_record(THD *thd, Field **field, List<Item> &values,
                  bool ignore_errors);
 bool fill_record_n_invoke_before_triggers(THD *thd, List<Item> &fields,

=== modified file 'sql/sql_base.cc'
--- a/sql/sql_base.cc	2010-10-12 11:54:35 +0000
+++ b/sql/sql_base.cc	2010-10-22 14:13:23 +0000
@@ -8180,35 +8180,6 @@ err_no_arena:
 ******************************************************************************/
 
 /*
-  Check if all expressions in list are constant expressions
-
-  SYNOPSIS
-    check_constant_expressions()
-    values                       List of expressions
-
-  RETURN
-    TRUE                         Only constant expressions
-    FALSE                        At least one non-constant expression
-*/
-
-bool check_constant_expressions(List<Item> *values)
-{
-  List_iterator_fast<Item> v(*values);
-  Item *value;
-  DBUG_ENTER("check_constant_expressions");
-
-  while ((value= v++))
-  {
-    if (!value->const_item())
-    {
-      DBUG_RETURN(FALSE);
-    }
-  }
-  DBUG_RETURN(TRUE);
-}
-
-
-/*
   Fill fields with given items.
 
   SYNOPSIS

=== modified file 'sql/sql_delete.cc'
--- a/sql/sql_delete.cc	2010-10-18 13:46:27 +0000
+++ b/sql/sql_delete.cc	2010-10-22 14:13:23 +0000
@@ -47,7 +47,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *
   bool          using_limit=limit != HA_POS_ERROR;
   bool		transactional_table, safe_update, const_cond;
   bool          direct_delete_loop;
-  bool          might_use_read_removal= FALSE;
+  bool          using_read_removal= FALSE;
   bool          const_cond_result;
   ha_rows	deleted= 0;
   bool          triggers_applicable;
@@ -289,8 +289,8 @@ bool mysql_delete(THD *thd, TABLE_LIST *
       direct_delete_loop)
   {
     /* See comment in sql_update.cc for similar code */
-    might_use_read_removal= 
-      table->file->read_before_write_removal_possible(NULL, NULL);
+    using_read_removal=
+      table->file->read_before_write_removal_possible();
   }
   init_ftfuncs(thd, select_lex, 1);
   thd_proc_info(thd, "updating");
@@ -462,10 +462,9 @@ cleanup:
   DBUG_ASSERT(transactional_table || !deleted || thd->transaction.stmt.modified_non_trans_table);
   free_underlaid_joins(thd, select_lex);
 
-  if (might_use_read_removal)
+  if (using_read_removal)
   {
-    table->file->info(HA_STATUS_WRITTEN_ROWS);
-    deleted= table->file->stats.rows_deleted;
+    deleted= table->file->read_before_write_removal_rows_written();
   }
 
   if (error < 0 || 

=== modified file 'sql/sql_update.cc'
--- a/sql/sql_update.cc	2010-10-18 11:48:36 +0000
+++ b/sql/sql_update.cc	2010-10-22 14:13:23 +0000
@@ -87,6 +87,35 @@ static bool check_fields(THD *thd, List<
 }
 
 
+/*
+  Check if all expressions in list are constant expressions
+
+  SYNOPSIS
+    check_constant_expressions()
+    values                       List of expressions
+
+  RETURN
+    TRUE                         Only constant expressions
+    FALSE                        At least one non-constant expression
+*/
+
+static bool check_constant_expressions(List<Item> &values)
+{
+  Item *value;
+  List_iterator_fast<Item> v(values);
+  DBUG_ENTER("check_constant_expressions");
+
+  while ((value= v++))
+  {
+    if (!value->const_item())
+    {
+      DBUG_RETURN(FALSE);
+    }
+  }
+  DBUG_RETURN(TRUE);
+}
+
+
 /**
   Re-read record if more columns are needed for error message.
 
@@ -190,7 +219,7 @@ int mysql_update(THD *thd,
   bool		safe_update= test(thd->options & OPTION_SAFE_UPDATES);
   bool		used_key_is_modified, transactional_table, will_batch;
   bool		can_compare_record;
-  bool          might_use_read_removal= FALSE;
+  bool          using_read_removal= FALSE;
   int           res;
   int		error, loc_error;
   uint		used_index= MAX_KEY, dup_key_found;
@@ -551,7 +580,8 @@ int mysql_update(THD *thd,
       select && select->quick &&
       !ignore &&
       !using_limit &&
-      direct_update_loop)
+      direct_update_loop &&
+      check_constant_expressions(values))
   {
     /*
       In certain cases the handler can avoid doing a real read before
@@ -560,8 +590,8 @@ int mysql_update(THD *thd,
       them for real. This extra call tells the handler that this
       is possible for this handler until next reset of handler.
     */
-    might_use_read_removal=
-      table->file->read_before_write_removal_possible(&fields, &values);
+    using_read_removal=
+      table->file->read_before_write_removal_possible();
   }
   updated= found= 0;
   /*
@@ -855,7 +885,7 @@ int mysql_update(THD *thd,
   DBUG_ASSERT(transactional_table || !updated || thd->transaction.stmt.modified_non_trans_table);
   free_underlaid_joins(thd, select_lex);
 
-  if (might_use_read_removal)
+  if (using_read_removal)
   {
     /*
       updated counter is not valid when using read before write removal
@@ -867,8 +897,8 @@ int mysql_update(THD *thd,
       hard checks on UPDATE statement. Still it is used very often with
       all those limitations.
     */
-    table->file->info(HA_STATUS_WRITTEN_ROWS);
-    updated= table->file->stats.rows_updated;
+
+    updated= table->file->read_before_write_removal_rows_written();
     /*
       If we could compare the records then the records were
       either found by reading the table or they were

No bundle (reason: revision is a merge).
Thread
bzr commit into mysql-5.1-telco-7.0 branch (magnus.blaudd:3896) Magnus Blåudd22 Oct