[Commits] 23756b1925c: Spider Patch Integration

jacob.mathew at mariadb.com jacob.mathew at mariadb.com
Tue Jun 13 21:13:20 EEST 2017


revision-id: 23756b1925cfb31f3086f5a6b4efa84888f83c18 (mariadb-10.2.3-104-g23756b1925c)
parent(s): 8e1b1cd781e034c53527ec3e8bf2c5c64bc1a61b
author: Jacob Mathew
committer: Jacob Mathew
timestamp: 2017-06-13 11:09:29 -0700
message:

Spider Patch Integration

Spiral patch 048.

---
 sql/ha_partition.cc | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 sql/ha_partition.h  |   3 ++
 sql/handler.h       |   2 ++
 3 files changed, 104 insertions(+), 1 deletion(-)

diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc
index b3ca86cbdb1..c3183b86724 100644
--- a/sql/ha_partition.cc
+++ b/sql/ha_partition.cc
@@ -4290,6 +4290,7 @@ int ha_partition::write_row(uchar * buf)
   sql_mode_t saved_sql_mode= thd->variables.sql_mode;
   bool saved_auto_inc_field_not_null= table->auto_increment_field_not_null;
   DBUG_ENTER("ha_partition::write_row");
+  DBUG_PRINT("info", ("partition this=%p", this));
 
   /*
     If we have an auto_increment column and we are writing a changed row
@@ -4363,6 +4364,7 @@ int ha_partition::write_row(uchar * buf)
   }
   m_last_part= part_id;
   DBUG_PRINT("info", ("Insert in partition %d", part_id));
+  DBUG_PRINT("info", ("partition m_last_part=%d", m_last_part));
   start_part_bulk_insert(thd, part_id);
 
   tmp_disable_binlog(thd); /* Do not replicate the low-level changes. */
@@ -4393,6 +4395,7 @@ int ha_partition::pre_write_row(uchar * buf)
   uchar *rec0= m_rec0;
 #endif
   DBUG_ENTER("ha_partition::pre_write_row");
+  DBUG_PRINT("info", ("partition this=%p", this));
   DBUG_ASSERT(buf == m_rec0);
 
   /* If we have a timestamp column, update it to the current time */
@@ -4468,6 +4471,7 @@ int ha_partition::pre_write_row(uchar * buf)
   }
   m_last_part= part_id;
   DBUG_PRINT("info", ("Insert in partition %d", part_id));
+  DBUG_PRINT("info", ("partition m_last_part=%d", m_last_part));
   start_part_bulk_insert(thd, part_id);
 
   tmp_disable_binlog(thd); /* Do not replicate the low-level changes. */
@@ -4516,6 +4520,7 @@ int ha_partition::update_row(const uchar *old_data, uchar *new_data)
   int error= 0;
   longlong func_value;
   DBUG_ENTER("ha_partition::update_row");
+  DBUG_PRINT("info", ("partition this=%p", this));
   m_err_rec= NULL;
 
   // Need to read partition-related columns, to locate the row's partition:
@@ -4554,11 +4559,14 @@ int ha_partition::update_row(const uchar *old_data, uchar *new_data)
   */
   if (old_part_id != m_last_part)
   {
+    DBUG_PRINT("info", ("partition old_part_id=%d", old_part_id));
+    DBUG_PRINT("info", ("partition m_last_part=%d", m_last_part));
     m_err_rec= old_data;
     DBUG_RETURN(HA_ERR_ROW_IN_WRONG_PARTITION);
   }
 
   m_last_part= new_part_id;
+  DBUG_PRINT("info", ("partition m_last_part=%d", m_last_part));
   start_part_bulk_insert(thd, new_part_id);
   if (new_part_id == old_part_id)
   {
@@ -4666,6 +4674,7 @@ int ha_partition::delete_row(const uchar *buf)
   int error;
   THD *thd= ha_thd();
   DBUG_ENTER("ha_partition::delete_row");
+  DBUG_PRINT("info", ("partition this=%p", this));
   m_err_rec= NULL;
 
   DBUG_ASSERT(bitmap_is_subset(&m_part_info->full_part_field_set,
@@ -4707,6 +4716,7 @@ int ha_partition::delete_row(const uchar *buf)
   }
 
   m_last_part= part_id;
+  DBUG_PRINT("info", ("partition m_last_part=%d", m_last_part));
   tmp_disable_binlog(thd);
   error= m_file[part_id]->ha_delete_row(buf);
   reenable_binlog(thd);
@@ -5047,6 +5057,7 @@ int ha_partition::rnd_init(bool scan)
   uint i= 0;
   uint32 part_id;
   DBUG_ENTER("ha_partition::rnd_init");
+  DBUG_PRINT("info", ("partition this=%p", this));
 
   /*
     For operations that may need to change data, we may need to extend
@@ -5062,8 +5073,11 @@ int ha_partition::rnd_init(bool scan)
       requires a complete record.
     */
     if (bitmap_is_overlapping(&m_part_info->full_part_field_set,
-                              table->write_set))
+      table->write_set))
+    {
+      DBUG_PRINT("info", ("partition set full bitmap"));
       bitmap_set_all(table->read_set);
+    }
     else
     {
       /*
@@ -5072,6 +5086,7 @@ int ha_partition::rnd_init(bool scan)
         fields of the partition functions are read such that we can
         calculate the partition id to place updated and deleted records.
       */
+      DBUG_PRINT("info", ("partition set part_field bitmap"));
       bitmap_union(table->read_set, &m_part_info->full_part_field_set);
     }
   }
@@ -5156,6 +5171,7 @@ int ha_partition::pre_rnd_init(bool scan)
   uint i= 0;
   uint32 part_id;
   DBUG_ENTER("ha_partition::pre_rnd_init");
+  DBUG_PRINT("info", ("partition this=%p", this));
 
   /*
     For operations that may need to change data, we may need to extend
@@ -5172,7 +5188,10 @@ int ha_partition::pre_rnd_init(bool scan)
     */
     if (bitmap_is_overlapping(&m_part_info->full_part_field_set,
                               table->write_set))
+    {
+      DBUG_PRINT("info", ("partition set full bitmap"));
       bitmap_set_all(table->read_set);
+    }
     else
     {
       /*
@@ -5181,6 +5200,7 @@ int ha_partition::pre_rnd_init(bool scan)
         fields of the partition functions are read such that we can
         calculate the partition id to place updated and deleted records.
       */
+      DBUG_PRINT("info", ("partition set part_field bitmap"));
       bitmap_union(table->read_set, &m_part_info->full_part_field_set);
     }
   }
@@ -5370,6 +5390,7 @@ int ha_partition::rnd_next(uchar *buf)
   int result= HA_ERR_END_OF_FILE, error;
   uint part_id= m_part_spec.start_part;
   DBUG_ENTER("ha_partition::rnd_next");
+  DBUG_PRINT("info", ("partition this=%p", this));
 
   /* upper level will increment this once again at end of call */
   decrement_statistics(&SSV::ha_read_rnd_next_count);
@@ -5408,6 +5429,7 @@ int ha_partition::rnd_next(uchar *buf)
     if (!result)
     {
       m_last_part= part_id;
+      DBUG_PRINT("info", ("partition m_last_part=%d", m_last_part));
       m_part_spec.start_part= part_id;
       table->status= 0;
       DBUG_RETURN(0);
@@ -5438,6 +5460,7 @@ int ha_partition::rnd_next(uchar *buf)
       break;
     }
     m_last_part= part_id;
+    DBUG_PRINT("info", ("partition m_last_part=%d", m_last_part));
     m_part_spec.start_part= part_id;
     file= m_file[part_id];
     DBUG_PRINT("info", ("rnd_init on partition %d", part_id));
@@ -5524,6 +5547,7 @@ int ha_partition::rnd_pos(uchar * buf, uchar *pos)
   uint part_id;
   handler *file;
   DBUG_ENTER("ha_partition::rnd_pos");
+  DBUG_PRINT("info", ("partition this=%p", this));
   decrement_statistics(&SSV::ha_read_rnd_count);
 
   part_id= uint2korr((const uchar *) pos);
@@ -5531,6 +5555,7 @@ int ha_partition::rnd_pos(uchar * buf, uchar *pos)
   file= m_file[part_id];
   DBUG_ASSERT(bitmap_is_set(&(m_part_info->read_partitions), part_id));
   m_last_part= part_id;
+  DBUG_PRINT("info", ("partition m_last_part=%d", m_last_part));
   DBUG_RETURN(file->ha_rnd_pos(buf, (pos + PARTITION_BYTES_IN_POS)));
 }
 
@@ -5694,6 +5719,7 @@ int ha_partition::index_init(uint inx, bool sorted)
   int error= 0;
   uint i;
   DBUG_ENTER("ha_partition::index_init");
+  DBUG_PRINT("info", ("partition this=%p", this));
 
   DBUG_PRINT("info", ("inx %u sorted %u", inx, sorted));
   active_index= inx;
@@ -5729,8 +5755,24 @@ int ha_partition::index_init(uint inx, bool sorted)
     calculate the partition id to place updated and deleted records.
     But this is required for operations that may need to change data only.
   */
+/*
   if (get_lock_type() == F_WRLCK)
     bitmap_union(table->read_set, &m_part_info->full_part_field_set);
+*/
+  if (get_lock_type() == F_WRLCK)
+  {
+    if (bitmap_is_overlapping(&m_part_info->full_part_field_set,
+                              table->write_set))
+    {
+      DBUG_PRINT("info", ("partition set full bitmap"));
+      bitmap_set_all(table->read_set);
+    }
+    else
+    {
+      DBUG_PRINT("info", ("partition set part_field bitmap"));
+      bitmap_union(table->read_set, &m_part_info->full_part_field_set);
+    }
+  }
   if (sorted)
   {
     /*
@@ -6033,6 +6075,7 @@ int ha_partition::index_read_map(uchar *buf, const uchar *key,
                                  enum ha_rkey_function find_flag)
 {
   DBUG_ENTER("ha_partition::index_read_map");
+  DBUG_PRINT("info", ("partition this=%p", this));
   decrement_statistics(&SSV::ha_read_key_count);
   end_range= 0;
   m_index_scan_type= partition_index_read;
@@ -6304,6 +6347,7 @@ int ha_partition::index_read_idx_map(uchar *buf, uint index,
 {
   int error= HA_ERR_KEY_NOT_FOUND;
   DBUG_ENTER("ha_partition::index_read_idx_map");
+  DBUG_PRINT("info", ("partition this=%p", this));
 
   if (find_flag == HA_READ_KEY_EXACT)
   {
@@ -6338,7 +6382,10 @@ int ha_partition::index_read_idx_map(uchar *buf, uint index,
         break;
     }
     if (part <= m_part_spec.end_part)
+    {
       m_last_part= part;
+      DBUG_PRINT("info", ("partition m_last_part=%d", m_last_part));
+    }
   }
   else
   {
@@ -6622,7 +6669,10 @@ int ha_partition::ft_init()
     */
     if (bitmap_is_overlapping(&m_part_info->full_part_field_set,
                               table->write_set))
+    {
+      DBUG_PRINT("info", ("partition set full bitmap"));
       bitmap_set_all(table->read_set);
+    }
     else
     {
       /*
@@ -6631,6 +6681,7 @@ int ha_partition::ft_init()
         fields of the partition functions are read such that we can
         calculate the partition id to place updated and deleted records.
       */
+      DBUG_PRINT("info", ("partition set part_field bitmap"));
       bitmap_union(table->read_set, &m_part_info->full_part_field_set);
     }
   }
@@ -6707,7 +6758,10 @@ int ha_partition::pre_ft_init()
     */
     if (bitmap_is_overlapping(&m_part_info->full_part_field_set,
                               table->write_set))
+    {
+      DBUG_PRINT("info", ("partition set full bitmap"));
       bitmap_set_all(table->read_set);
+    }
     else
     {
       /*
@@ -6716,6 +6770,7 @@ int ha_partition::pre_ft_init()
         fields of the partition functions are read such that we can
         calculate the partition id to place updated and deleted records.
       */
+      DBUG_PRINT("info", ("partition set part_field bitmap"));
       bitmap_union(table->read_set, &m_part_info->full_part_field_set);
     }
   }
@@ -6958,6 +7013,7 @@ int ha_partition::ft_read(
     if (!result)
     {
       m_last_part= part_id;
+      DBUG_PRINT("info", ("partition m_last_part=%d", m_last_part));
       m_part_spec.start_part= part_id;
       table->status= 0;
       DBUG_RETURN(0);
@@ -6986,6 +7042,7 @@ int ha_partition::ft_read(
       break;
     }
     m_last_part= part_id;
+    DBUG_PRINT("info", ("partition m_last_part=%d", m_last_part));
     m_part_spec.start_part= part_id;
     file= m_file[part_id];
     DBUG_PRINT("info", ("ft_init on partition %d", part_id));
@@ -7828,6 +7885,7 @@ int ha_partition::handle_unordered_next(uchar *buf, bool is_next_same)
   handler *file;
   int error;
   DBUG_ENTER("ha_partition::handle_unordered_next");
+  DBUG_PRINT("info", ("partition this=%p", this));
 
   if (m_part_spec.start_part >= m_tot_parts)
   {
@@ -7848,6 +7906,7 @@ int ha_partition::handle_unordered_next(uchar *buf, bool is_next_same)
       &m_range_info[m_part_spec.start_part])))
     {
       m_last_part= m_part_spec.start_part;
+      DBUG_PRINT("info", ("partition m_last_part=%d", m_last_part));
       DBUG_RETURN(0);
     }
   }
@@ -7856,6 +7915,7 @@ int ha_partition::handle_unordered_next(uchar *buf, bool is_next_same)
     if (!(error= file->read_range_next()))
     {
       m_last_part= m_part_spec.start_part;
+      DBUG_PRINT("info", ("partition m_last_part=%d", m_last_part));
       DBUG_RETURN(0);
     }
   }
@@ -7865,6 +7925,7 @@ int ha_partition::handle_unordered_next(uchar *buf, bool is_next_same)
                                           m_start_key.length)))
     {
       m_last_part= m_part_spec.start_part;
+      DBUG_PRINT("info", ("partition m_last_part=%d", m_last_part));
       DBUG_RETURN(0);
     }
   }
@@ -7873,6 +7934,7 @@ int ha_partition::handle_unordered_next(uchar *buf, bool is_next_same)
     if (!(error= file->ha_index_next(buf)))
     {
       m_last_part= m_part_spec.start_part;
+      DBUG_PRINT("info", ("partition m_last_part=%d", m_last_part));
       DBUG_RETURN(0);                           // Row was in range
     }
   }
@@ -7908,6 +7970,7 @@ int ha_partition::handle_unordered_scan_next_partition(uchar * buf)
   uint i= m_part_spec.start_part;
   int saved_error= HA_ERR_END_OF_FILE;
   DBUG_ENTER("ha_partition::handle_unordered_scan_next_partition");
+  DBUG_PRINT("info", ("partition this=%p", this));
 
   if (i)
     i= bitmap_get_next_set(&m_part_info->read_partitions, i - 1);
@@ -7965,6 +8028,7 @@ int ha_partition::handle_unordered_scan_next_partition(uchar * buf)
     if (!error)
     {
       m_last_part= i;
+      DBUG_PRINT("info", ("partition m_last_part=%d", m_last_part));
       DBUG_RETURN(0);
     }
     if ((error != HA_ERR_END_OF_FILE) && (error != HA_ERR_KEY_NOT_FOUND))
@@ -8021,6 +8085,7 @@ int ha_partition::handle_ordered_index_scan(uchar *buf, bool reverse_order)
   uchar *part_rec_buf_ptr= m_ordered_rec_buffer;
   int saved_error= HA_ERR_END_OF_FILE;
   DBUG_ENTER("ha_partition::handle_ordered_index_scan");
+  DBUG_PRINT("info", ("partition this=%p", this));
 
   if (
     !m_using_extended_keys &&
@@ -8247,12 +8312,16 @@ void ha_partition::return_top_record(uchar *buf)
   uint part_id;
   uchar *key_buffer= queue_top(&m_queue);
   uchar *rec_buffer= key_buffer + PARTITION_BYTES_IN_POS;
+  DBUG_ENTER("ha_partition::return_top_record");
+  DBUG_PRINT("info", ("partition this=%p", this));
 
   part_id= uint2korr(key_buffer);
   memcpy(buf, rec_buffer, m_rec_length);
   m_last_part= part_id;
+  DBUG_PRINT("info", ("partition m_last_part=%d", m_last_part));
   m_top_entry= part_id;
   m_file[part_id]->return_record_by_parent();
+  DBUG_VOID_RETURN;
 }
 
 
@@ -10331,6 +10400,8 @@ void ha_partition::print_error(int error, myf errflag)
     {
       DBUG_ASSERT(0);
       m_last_part= 0;
+      DBUG_PRINT("info", ("partition m_last_part=%d", m_last_part));
+      DBUG_PRINT("info", ("partition m_last_part=%p", &m_last_part));
     }
     m_file[m_last_part]->print_error(error, errflag);
   }
@@ -11427,6 +11498,33 @@ TABLE_LIST *ha_partition::get_next_global_for_child()
 }
 
 
+#ifdef HANDLER_HAS_CHECK_AND_SET_BITMAP_FOR_UPDATE
+void ha_partition::check_and_set_bitmap_for_update(bool rnd)
+{
+  handler **file;
+  DBUG_ENTER("ha_partition::check_and_set_bitmap_for_update");
+  DBUG_PRINT("info", ("partition this=%p", this));
+  for (file= m_file; *file; file++)
+  {
+    (*file)->check_and_set_bitmap_for_update(rnd);
+  }
+
+  if (bitmap_is_overlapping(&m_part_info->full_part_field_set,
+                            table->write_set))
+  {
+    DBUG_PRINT("info", ("partition set full bitmap"));
+    bitmap_set_all(table->read_set);
+  }
+  else
+  {
+    DBUG_PRINT("info", ("partition set part_field bitmap"));
+    bitmap_union(table->read_set, &m_part_info->full_part_field_set);
+  }
+  DBUG_VOID_RETURN;
+}
+#endif
+
+
 const COND *ha_partition::cond_push(const COND *cond)
 {
   handler **file= m_file;
diff --git a/sql/ha_partition.h b/sql/ha_partition.h
index ee4dbf26524..b846f253f86 100644
--- a/sql/ha_partition.h
+++ b/sql/ha_partition.h
@@ -1443,6 +1443,9 @@ class ha_partition :public handler
     virtual int assign_to_keycache(THD* thd, HA_CHECK_OPT *check_opt);
     virtual int preload_keys(THD* thd, HA_CHECK_OPT* check_opt);
     virtual TABLE_LIST *get_next_global_for_child();
+#ifdef HANDLER_HAS_CHECK_AND_SET_BITMAP_FOR_UPDATE
+    virtual void check_and_set_bitmap_for_update(bool rnd);
+#endif
 
   /*
     -------------------------------------------------------------------------
diff --git a/sql/handler.h b/sql/handler.h
index 65f9da64a7b..dc5fd32ab5a 100644
--- a/sql/handler.h
+++ b/sql/handler.h
@@ -47,6 +47,7 @@
 #define HANDLER_HAS_NEED_INFO_FOR_AUTO_INC
 #define HANDLER_HAS_CAN_USE_FOR_AUTO_INC_INIT
 #define HANDLER_HAS_DIRECT_AGGREGATE
+#define HANDLER_HAS_CHECK_AND_SET_BITMAP_FOR_UPDATE
 #define INFO_KIND_UPDATE_FIELDS 101
 #define INFO_KIND_UPDATE_VALUES 102
 #define INFO_KIND_FORCE_LIMIT_BEGIN 103
@@ -3813,6 +3814,7 @@ class handler :public Sql_alloc
 
  /* Needed for partition / spider */
   virtual TABLE_LIST *get_next_global_for_child() { return NULL; }
+  virtual void check_and_set_bitmap_for_update(bool rnd) { return; };
 
  /**
    Part of old, deprecated in-place ALTER API.


More information about the commits mailing list