[Commits] 0bbaadc: [Code cleanup] Refactor duplicate code within myisam and maria sort.cc

Vicentiu Ciorbaru vicentiu at mariadb.org
Mon Dec 21 13:45:14 EET 2015


revision-id: 0bbaadc1866384dacfd9ebb7b33865007a6e587d (mariadb-10.1.9-13-g0bbaadc)
parent(s): 44b107da90a106c128dca278d04c68d804e51497
author: Vicențiu Ciorbaru
committer: Vicențiu Ciorbaru
timestamp: 2015-12-21 13:43:38 +0200
message:

[Code cleanup] Refactor duplicate code within myisam and maria sort.cc

Setting read and write methods for the SORT_PARAM struct based on
variable length key is done within a single function.

---
 storage/maria/ma_sort.c | 62 ++++++++++++++++++++---------------------------
 storage/myisam/sort.c   | 64 +++++++++++++++++++++----------------------------
 2 files changed, 53 insertions(+), 73 deletions(-)

diff --git a/storage/maria/ma_sort.c b/storage/maria/ma_sort.c
index 967d4a1..a4ce4f8 100644
--- a/storage/maria/ma_sort.c
+++ b/storage/maria/ma_sort.c
@@ -90,6 +90,27 @@ static inline int
 my_var_write(MARIA_SORT_PARAM *info, IO_CACHE *to_file, uchar *bufs);
 
 /*
+  Sets the appropriate read and write methods for the MI_SORT_PARAM
+  based on the variable length key flag.
+*/
+static void set_sort_param_read_write(MARIA_SORT_PARAM *sort_param)
+{
+  if (sort_param->keyinfo->flag & HA_VAR_LENGTH_KEY)
+  {
+    sort_param->write_keys=     write_keys_varlen;
+    sort_param->read_to_buffer= read_to_buffer_varlen;
+    sort_param->write_key=      write_merge_key_varlen;
+  }
+  else
+  {
+    sort_param->write_keys=     write_keys;
+    sort_param->read_to_buffer= read_to_buffer;
+    sort_param->write_key=      write_merge_key;
+  }
+}
+
+
+/*
   Creates a index of sorted keys
 
   SYNOPSIS
@@ -118,18 +139,7 @@ int _ma_create_index_by_sort(MARIA_SORT_PARAM *info, my_bool no_messages,
                       (ulong) sortbuff_size, info->key_length,
                       (ulong) info->sort_info->max_records));
 
-  if (info->keyinfo->flag & HA_VAR_LENGTH_KEY)
-  {
-    info->write_keys= write_keys_varlen;
-    info->read_to_buffer= read_to_buffer_varlen;
-    info->write_key=write_merge_key_varlen;
-  }
-  else
-  {
-    info->write_keys= write_keys;
-    info->read_to_buffer=read_to_buffer;
-    info->write_key=write_merge_key;
-  }
+  set_sort_param_read_write(info);
 
   my_b_clear(&tempfile);
   my_b_clear(&tempfile_for_exceptions);
@@ -378,18 +388,7 @@ pthread_handler_t _ma_thr_find_all_keys(void *arg)
     if (sort_param->sort_info->got_error)
       goto err;
 
-    if (sort_param->keyinfo->flag & HA_VAR_LENGTH_KEY)
-    {
-      sort_param->write_keys=     write_keys_varlen;
-      sort_param->read_to_buffer= read_to_buffer_varlen;
-      sort_param->write_key=      write_merge_key_varlen;
-    }
-    else
-    {
-      sort_param->write_keys=     write_keys;
-      sort_param->read_to_buffer= read_to_buffer;
-      sort_param->write_key=      write_merge_key;
-    }
+    set_sort_param_read_write(sort_param);
 
     my_b_clear(&sort_param->tempfile);
     my_b_clear(&sort_param->tempfile_for_exceptions);
@@ -614,18 +613,9 @@ int _ma_thr_write_keys(MARIA_SORT_PARAM *sort_param)
   {
     if (got_error)
       continue;
-    if (sinfo->keyinfo->flag & HA_VAR_LENGTH_KEY)
-    {
-      sinfo->write_keys=write_keys_varlen;
-      sinfo->read_to_buffer=read_to_buffer_varlen;
-      sinfo->write_key=write_merge_key_varlen;
-    }
-    else
-    {
-      sinfo->write_keys=write_keys;
-      sinfo->read_to_buffer=read_to_buffer;
-      sinfo->write_key=write_merge_key;
-    }
+
+    set_sort_param_read_write(sinfo);
+
     if (sinfo->buffpek.elements)
     {
       uint maxbuffer=sinfo->buffpek.elements-1;
diff --git a/storage/myisam/sort.c b/storage/myisam/sort.c
index 604910e..f490e5f 100644
--- a/storage/myisam/sort.c
+++ b/storage/myisam/sort.c
@@ -86,6 +86,28 @@ static int write_merge_key_varlen(MI_SORT_PARAM *info,
 static inline int
 my_var_write(MI_SORT_PARAM *info, IO_CACHE *to_file, uchar *bufs);
 
+
+/*
+  Sets the appropriate read and write methods for the MI_SORT_PARAM
+  based on the variable length key flag.
+*/
+static void set_sort_param_read_write(MI_SORT_PARAM *sort_param)
+{
+  if (sort_param->keyinfo->flag & HA_VAR_LENGTH_KEY)
+  {
+    sort_param->write_keys=     write_keys_varlen;
+    sort_param->read_to_buffer= read_to_buffer_varlen;
+    sort_param->write_key=      write_merge_key_varlen;
+  }
+  else
+  {
+    sort_param->write_keys=     write_keys;
+    sort_param->read_to_buffer= read_to_buffer;
+    sort_param->write_key=      write_merge_key;
+  }
+}
+
+
 /*
   Creates a index of sorted keys
 
@@ -113,18 +135,7 @@ int _create_index_by_sort(MI_SORT_PARAM *info,my_bool no_messages,
   DBUG_ENTER("_create_index_by_sort");
   DBUG_PRINT("enter",("sort_length: %u", info->key_length));
 
-  if (info->keyinfo->flag & HA_VAR_LENGTH_KEY)
-  {
-    info->write_keys=write_keys_varlen;
-    info->read_to_buffer=read_to_buffer_varlen;
-    info->write_key= write_merge_key_varlen;
-  }
-  else
-  {
-    info->write_keys=write_keys;
-    info->read_to_buffer=read_to_buffer;
-    info->write_key=write_merge_key;
-  }
+  set_sort_param_read_write(info);
 
   my_b_clear(&tempfile);
   my_b_clear(&tempfile_for_exceptions);
@@ -333,7 +344,6 @@ static ha_rows find_all_keys(MI_SORT_PARAM *info, ha_rows keys,
   DBUG_RETURN((*maxbuffer)*(keys-1)+idx);
 } /* find_all_keys */
 
-
 /* Search after all keys and place them in a temp. file */
 
 pthread_handler_t thr_find_all_keys(void *arg)
@@ -357,18 +367,7 @@ pthread_handler_t thr_find_all_keys(void *arg)
     if (sort_param->sort_info->got_error)
       goto err;
 
-    if (sort_param->keyinfo->flag & HA_VAR_LENGTH_KEY)
-    {
-      sort_param->write_keys=     write_keys_varlen;
-      sort_param->read_to_buffer= read_to_buffer_varlen;
-      sort_param->write_key=      write_merge_key_varlen;
-    }
-    else
-    {
-      sort_param->write_keys=     write_keys;
-      sort_param->read_to_buffer= read_to_buffer;
-      sort_param->write_key=      write_merge_key;
-    }
+    set_sort_param_read_write(sort_param);
 
     my_b_clear(&sort_param->tempfile);
     my_b_clear(&sort_param->tempfile_for_exceptions);
@@ -593,18 +592,9 @@ int thr_write_keys(MI_SORT_PARAM *sort_param)
   {
     if (got_error)
       continue;
-    if (sinfo->keyinfo->flag & HA_VAR_LENGTH_KEY)
-    {
-      sinfo->write_keys=write_keys_varlen;
-      sinfo->read_to_buffer=read_to_buffer_varlen;
-      sinfo->write_key=write_merge_key_varlen;
-    }
-    else
-    {
-      sinfo->write_keys=write_keys;
-      sinfo->read_to_buffer=read_to_buffer;
-      sinfo->write_key=write_merge_key;
-    }
+
+    set_sort_param_read_write(sinfo);
+
     if (sinfo->buffpek.elements)
     {
       uint maxbuffer=sinfo->buffpek.elements-1;


More information about the commits mailing list