Commit 8d6634c9 authored by unknown's avatar unknown
Browse files

Added more tests for new UPDATE ... ORDER BY ... LIMIT optimization


heap/_check.c:
  Change arguments to ha_key_cmp
heap/hp_create.c:
  Change arguments to ha_key_cmp
include/my_base.h:
  Remove SEARCH_RETURN_B_POS and instead always send an array to ha_key_cmp() as last argument
myisam/mi_check.c:
  Change arguments to ha_key_cmp
myisam/mi_rnext_same.c:
  Change arguments to ha_key_cmp
myisam/mi_search.c:
  Change arguments to ha_key_cmp
myisam/mi_write.c:
  Change arguments to ha_key_cmp
myisammrg/myrg_queue.c:
  Change arguments to ha_key_cmp
mysys/my_handler.c:
  Remove SEARCH_RETURN_B_POS and instead always send an array to ha_key_cmp() as last argument
  (This removes an if in a loop at the expensive of an int on the stack)
sql/records.cc:
  Simplify new rr_index() code
  Create common error handling function for rr_() functions.
  Remove loop from rr_index() as handler::index_next() can never return HA_ERR_RECORD_DELETED
sql/sql_load.cc:
  Simplify
sql/sql_update.cc:
  Simplify code
  Fixed bug when one is updating an index column that could be used with ORDER BY
sql/structs.h:
  Removed not needed structure element
parent 3c02a053
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -167,7 +167,7 @@ static int check_one_rb_key(HP_INFO *info, uint keynr, ulong records,
  ulong found= 0;
  byte *key, *recpos;
  uint key_length;
  uint not_used;
  uint not_used[2];
  
  if ((key= tree_search_edge(&keydef->rb_tree, info->parents,
			     &info->last_pos, offsetof(TREE_ELEMENT, left))))
@@ -177,7 +177,7 @@ static int check_one_rb_key(HP_INFO *info, uint keynr, ulong records,
      memcpy(&recpos, key + (*keydef->get_key_length)(keydef,key), sizeof(byte*));
      key_length= hp_rb_make_key(keydef, info->recbuf, recpos, 0);
      if (ha_key_cmp(keydef->seg, (uchar*) info->recbuf, (uchar*) key,
		     key_length, SEARCH_FIND | SEARCH_SAME, &not_used))
		     key_length, SEARCH_FIND | SEARCH_SAME, not_used))
      {
	error= 1;
	DBUG_PRINT("error",("Record in wrong link:  key: %d  Record: %lx\n", 
+2 −2
Original line number Diff line number Diff line
@@ -170,9 +170,9 @@ int heap_create(const char *name, uint keys, HP_KEYDEF *keydef,

static int keys_compare(heap_rb_param *param, uchar *key1, uchar *key2)
{
  uint not_used;
  uint not_used[2];
  return ha_key_cmp(param->keyseg, key1, key2, param->key_length, 
		    param->search_flag, &not_used);
		    param->search_flag, not_used);
}

static void init_block(HP_BLOCK *block, uint reclength, ulong min_records,
+0 −2
Original line number Diff line number Diff line
@@ -319,8 +319,6 @@ enum ha_base_keytype {
#define SEARCH_NULL_ARE_EQUAL 32768	/* NULL in keys are equal */
#define SEARCH_NULL_ARE_NOT_EQUAL 65536	/* NULL in keys are not equal */

#define SEARCH_RETURN_B_POS (65536*2)   /* see ha_key_cmp for description */

	/* bits in opt_flag */
#define QUICK_USED	1
#define READ_CACHE_USED	2
+18 −18
Original line number Diff line number Diff line
@@ -619,6 +619,7 @@ int mi_collect_stats_nonulls_next(HA_KEYSEG *keyseg, ulonglong *notnull,
{
  uint diffs[2];
  uint first_null_seg, kp;
  HA_KEYSEG *seg;

  /* 
     Find the first keypart where values are different or either of them is
@@ -629,9 +630,8 @@ int mi_collect_stats_nonulls_next(HA_KEYSEG *keyseg, ulonglong *notnull,
                      value in prev_key.
  */
  ha_key_cmp(keyseg, prev_key, last_key, USE_WHOLE_KEY, 
             SEARCH_FIND | SEARCH_NULL_ARE_NOT_EQUAL | SEARCH_RETURN_B_POS,
             diffs);
  HA_KEYSEG *seg= keyseg + diffs[0] - 1;
             SEARCH_FIND | SEARCH_NULL_ARE_NOT_EQUAL, diffs);
  seg= keyseg + diffs[0] - 1;

  /* Find first NULL in last_key */
  first_null_seg= ha_find_null(seg, last_key + diffs[1]) - keyseg;
@@ -658,7 +658,7 @@ static int chk_index(MI_CHECK *param, MI_INFO *info, MI_KEYDEF *keyinfo,
  uchar key[MI_MAX_POSSIBLE_KEY_BUFF],*temp_buff,*keypos,*old_keypos,*endpos;
  my_off_t next_page,record;
  char llbuff[22];
  uint diff_pos;
  uint diff_pos[2];
  DBUG_ENTER("chk_index");
  DBUG_DUMP("buff",(byte*) buff,mi_getint(buff));

@@ -716,7 +716,7 @@ static int chk_index(MI_CHECK *param, MI_INFO *info, MI_KEYDEF *keyinfo,
    }
    if ((*keys)++ &&
	(flag=ha_key_cmp(keyinfo->seg,info->lastkey,key,key_length,
			 comp_flag, &diff_pos)) >=0)
			 comp_flag, diff_pos)) >=0)
    {
      DBUG_DUMP("old",(byte*) info->lastkey, info->lastkey_length);
      DBUG_DUMP("new",(byte*) key, key_length);
@@ -735,14 +735,14 @@ static int chk_index(MI_CHECK *param, MI_INFO *info, MI_KEYDEF *keyinfo,
        if (param->stats_method == MI_STATS_METHOD_NULLS_NOT_EQUAL)
          ha_key_cmp(keyinfo->seg,info->lastkey,key,USE_WHOLE_KEY,
                     SEARCH_FIND | SEARCH_NULL_ARE_NOT_EQUAL,
                     &diff_pos);
                     diff_pos);
        else if (param->stats_method == MI_STATS_METHOD_IGNORE_NULLS)
        {
          diff_pos= mi_collect_stats_nonulls_next(keyinfo->seg, 
          diff_pos[0]= mi_collect_stats_nonulls_next(keyinfo->seg, 
                                                  param->notnull_count,
                                                  info->lastkey, key);
        }
	param->unique_count[diff_pos-1]++;
	param->unique_count[diff_pos[0]-1]++;
      }
      else
      {  
@@ -3340,15 +3340,15 @@ int sort_write_record(MI_SORT_PARAM *sort_param)
static int sort_key_cmp(MI_SORT_PARAM *sort_param, const void *a,
			const void *b)
{
  uint not_used;
  uint not_used[2];
  return (ha_key_cmp(sort_param->seg, *((uchar**) a), *((uchar**) b),
		     USE_WHOLE_KEY, SEARCH_SAME,&not_used));
		     USE_WHOLE_KEY, SEARCH_SAME, not_used));
} /* sort_key_cmp */


static int sort_key_write(MI_SORT_PARAM *sort_param, const void *a)
{
  uint diff_pos;
  uint diff_pos[2];
  char llbuff[22],llbuff2[22];
  SORT_INFO *sort_info=sort_param->sort_info;
  MI_CHECK *param= sort_info->param;
@@ -3358,19 +3358,19 @@ static int sort_key_write(MI_SORT_PARAM *sort_param, const void *a)
  {
    cmp=ha_key_cmp(sort_param->seg,sort_info->key_block->lastkey,
		   (uchar*) a, USE_WHOLE_KEY,SEARCH_FIND | SEARCH_UPDATE,
		   &diff_pos);
		   diff_pos);
    if (param->stats_method == MI_STATS_METHOD_NULLS_NOT_EQUAL)
      ha_key_cmp(sort_param->seg,sort_info->key_block->lastkey,
                 (uchar*) a, USE_WHOLE_KEY, 
                 SEARCH_FIND | SEARCH_NULL_ARE_NOT_EQUAL, &diff_pos);
                 SEARCH_FIND | SEARCH_NULL_ARE_NOT_EQUAL, diff_pos);
    else if (param->stats_method == MI_STATS_METHOD_IGNORE_NULLS)
    {
      diff_pos= mi_collect_stats_nonulls_next(sort_param->seg,
      diff_pos[0]= mi_collect_stats_nonulls_next(sort_param->seg,
                                                 sort_param->notnull,
                                                 sort_info->key_block->lastkey,
                                                 (uchar*)a);
    }
    sort_param->unique[diff_pos-1]++;
    sort_param->unique[diff_pos[0]-1]++;
  }
  else
  {
+2 −2
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@
int mi_rnext_same(MI_INFO *info, byte *buf)
{
  int error;
  uint inx,not_used;
  uint inx,not_used[2];
  MI_KEYDEF *keyinfo;
  DBUG_ENTER("mi_rnext_same");

@@ -69,7 +69,7 @@ int mi_rnext_same(MI_INFO *info, byte *buf)
			       info->s->state.key_root[inx])))
          break;
        if (ha_key_cmp(keyinfo->seg, info->lastkey, info->lastkey2,
                       info->last_rkey_length, SEARCH_FIND, &not_used))
                       info->last_rkey_length, SEARCH_FIND, not_used))
        {
          error=1;
          my_errno=HA_ERR_END_OF_FILE;
Loading