BTREE heap key structure is now the same as MyISAM

_mi_compare_text -> mi_compate_text
Changes according Monty's suggestions
parent ba963bb6
......@@ -79,8 +79,9 @@ extern int hp_rec_key_cmp(HP_KEYDEF *keydef,const byte *rec1,
extern int hp_key_cmp(HP_KEYDEF *keydef,const byte *rec,
const byte *key);
extern void hp_make_key(HP_KEYDEF *keydef,byte *key,const byte *rec);
extern void hp_rb_make_key(HP_KEYDEF *keydef, byte *key,
extern uint hp_rb_make_key(HP_KEYDEF *keydef, byte *key,
const byte *rec, byte *recpos);
extern uint hp_rb_key_length(HP_KEYDEF *keydef, const byte *key);
extern my_bool hp_if_null_in_key(HP_KEYDEF *keyinfo, const byte *record);
extern int hp_close(register HP_INFO *info);
extern void hp_clear(HP_SHARE *info);
......
......@@ -65,12 +65,11 @@ int hp_rb_delete_key(HP_INFO *info, register HP_KEYDEF *keyinfo,
heap_rb_param custom_arg;
if (flag)
info->last_pos = NULL; /* For heap_rnext/heap_rprev */
info->last_pos= NULL; /* For heap_rnext/heap_rprev */
hp_rb_make_key(keyinfo, info->recbuf, record, recpos);
custom_arg.keyseg = keyinfo->seg;
custom_arg.key_length = keyinfo->length;
custom_arg.search_flag = SEARCH_SAME;
custom_arg.keyseg= keyinfo->seg;
custom_arg.key_length= hp_rb_make_key(keyinfo, info->recbuf, record, recpos);
custom_arg.search_flag= SEARCH_SAME;
return tree_delete(&keyinfo->rb_tree, info->recbuf, &custom_arg);
}
......
......@@ -391,14 +391,13 @@ int hp_rec_key_cmp(HP_KEYDEF *keydef, const byte *rec1, const byte *rec2)
if (rec1[seg->null_pos] & seg->null_bit)
continue;
}
switch (seg->type) {
case HA_KEYTYPE_END:
return 0;
case HA_KEYTYPE_TEXT:
if (seg->type == HA_KEYTYPE_TEXT)
{
if (my_sortcmp(seg->charset,rec1+seg->start,rec2+seg->start,seg->length))
return 1;
break;
default:
}
else
{
if (bcmp(rec1+seg->start,rec2+seg->start,seg->length))
return 1;
}
......@@ -454,21 +453,24 @@ void hp_make_key(HP_KEYDEF *keydef, byte *key, const byte *rec)
}
}
void hp_rb_make_key(HP_KEYDEF *keydef, byte *key,
uint hp_rb_make_key(HP_KEYDEF *keydef, byte *key,
const byte *rec, byte *recpos)
{
byte *start_key= key;
HA_KEYSEG *seg, *endseg;
/* -1 means that HA_KEYTYPE_END segment will not copy */
for (seg= keydef->seg, endseg= seg + keydef->keysegs - 1; seg < endseg;
seg++)
for (seg= keydef->seg, endseg= seg + keydef->keysegs; seg < endseg; seg++)
{
if (seg->null_bit)
*key++= 1 - test(rec[seg->null_pos] & seg->null_bit);
{
if (!(*key++= 1 - test(rec[seg->null_pos] & seg->null_bit)))
continue;
}
memcpy(key, rec + seg->start, (size_t) seg->length);
key+= seg->length;
}
memcpy(key, &recpos, sizeof(byte*));
return key - start_key;
}
uint hp_rb_pack_key(HP_INFO *info, uint inx, uchar *key, const uchar *old,
......@@ -482,13 +484,40 @@ uint hp_rb_pack_key(HP_INFO *info, uint inx, uchar *key, const uchar *old,
old+= seg->length, seg++)
{
if (seg->null_bit)
*key++= 1 - *old++;
{
if (!(*key++= (char) 1 - *old++))
continue;
}
memcpy((byte*) key, old, seg->length);
key+= seg->length;
}
return key - start_key;
}
uint hp_rb_key_length(HP_KEYDEF *keydef, const byte *key)
{
const byte *start_key= key;
HA_KEYSEG *seg, *endseg;
if (keydef->flag & HA_NULL_PART_KEY)
{
for (seg= keydef->seg, endseg= seg + keydef->keysegs; seg < endseg; seg++)
{
if (seg->null_bit)
{
if (!*key++)
continue;
}
key += seg->length;
}
return key - start_key;
}
else
{
return keydef->length;
}
}
/*
Test if any of the key parts are NULL.
Return:
......
......@@ -26,7 +26,7 @@
static int keys_compare(heap_rb_param *param, uchar *key1, uchar *key2)
{
uint not_used;
return hp_rb_key_cmp(param->keyseg, key1, key2, param->key_length,
return ha_key_cmp(param->keyseg, key1, key2, param->key_length,
param->search_flag, &not_used);
}
......@@ -52,25 +52,28 @@ HP_INFO *heap_open(const char *name, int mode, uint keys, HP_KEYDEF *keydef,
for (i=key_segs=max_length=0 ; i < keys ; i++)
{
key_segs+= keydef[i].keysegs;
if (keydef[i].algorithm == HA_KEY_ALG_BTREE)
key_segs++;
bzero((char*) &keydef[i].block,sizeof(keydef[i].block));
bzero((char*) &keydef[i].rb_tree ,sizeof(keydef[i].rb_tree));
for (j=length=0 ; j < keydef[i].keysegs; j++)
{
length+=keydef[i].seg[j].length;
if (keydef[i].seg[j].null_bit &&
!(keydef[i].flag & HA_NULL_ARE_EQUAL))
if (keydef[i].seg[j].null_bit)
{
if (!(keydef[i].flag & HA_NULL_ARE_EQUAL))
keydef[i].flag |= HA_NULL_PART_KEY;
if (keydef[i].algorithm == HA_KEY_ALG_BTREE &&
keydef[i].seg[j].null_bit)
if (keydef[i].algorithm == HA_KEY_ALG_BTREE)
keydef[i].rb_tree.size_of_element++;
}
}
keydef[i].length= length;
keydef[i].ref_offs= length + keydef[i].rb_tree.size_of_element -
sizeof(byte*);
if (length + keydef[i].rb_tree.size_of_element > max_length)
max_length= length + keydef[i].rb_tree.size_of_element;
length+= keydef[i].rb_tree.size_of_element +
((keydef[i].algorithm == HA_KEY_ALG_BTREE) ? sizeof(byte*) : 0);
if (length > max_length)
max_length= length;
}
if (!(share = (HP_SHARE*) my_malloc((uint) sizeof(HP_SHARE)+
if (!(share= (HP_SHARE*) my_malloc((uint) sizeof(HP_SHARE)+
keys*sizeof(HP_KEYDEF)+
key_segs*sizeof(HA_KEYSEG),
MYF(MY_ZEROFILL))))
......@@ -78,44 +81,46 @@ HP_INFO *heap_open(const char *name, int mode, uint keys, HP_KEYDEF *keydef,
pthread_mutex_unlock(&THR_LOCK_heap);
DBUG_RETURN(0);
}
share->keydef=(HP_KEYDEF*) (share+1);
keyseg=(HA_KEYSEG*) (share->keydef+keys);
init_block(&share->block,reclength+1,min_records,max_records);
share->keydef= (HP_KEYDEF*) (share + 1);
keyseg= (HA_KEYSEG*) (share->keydef + keys);
init_block(&share->block, reclength + 1, min_records, max_records);
/* Fix keys */
memcpy(share->keydef,keydef,(size_t) (sizeof(keydef[0])*keys));
for (i=0 ; i < keys ; i++)
memcpy(share->keydef, keydef, (size_t) (sizeof(keydef[0]) * keys));
for (i= 0; i < keys; i++)
{
HP_KEYDEF *keyinfo = share->keydef + i;
keyinfo->seg = keyseg;
memcpy(keyseg, keydef[i].seg,
(size_t) (sizeof(keyseg[0]) * keydef[i].keysegs));
keyseg += keydef[i].keysegs;
HP_KEYDEF *keyinfo= share->keydef + i;
uint nsegs= keydef[i].keysegs;
if (keydef[i].algorithm == HA_KEY_ALG_BTREE)
{
init_tree(&keyinfo->rb_tree, 0, 0, keydef[i].length +
keydef[i].rb_tree.size_of_element,
(qsort_cmp2)keys_compare, 1, NULL, NULL);
keyinfo->delete_key = hp_rb_delete_key;
keyinfo->write_key = hp_rb_write_key;
init_tree(&keyinfo->rb_tree, 0, 0, 0, (qsort_cmp2)keys_compare, 1,
NULL, NULL);
keyinfo->delete_key= hp_rb_delete_key;
keyinfo->write_key= hp_rb_write_key;
nsegs++;
}
else
{
init_block(&keyinfo->block, sizeof(HASH_INFO), min_records,
max_records);
keyinfo->delete_key = hp_delete_key;
keyinfo->write_key = hp_write_key;
keyinfo->delete_key= hp_delete_key;
keyinfo->write_key= hp_write_key;
}
keyinfo->seg= keyseg;
memcpy(keyseg, keydef[i].seg,
(size_t) (sizeof(keyseg[0]) * nsegs));
keyseg+= nsegs;
}
share->min_records=min_records;
share->max_records=max_records;
share->data_length=share->index_length=0;
share->reclength=reclength;
share->blength=1;
share->keys=keys;
share->max_key_length=max_length;
share->changed=0;
if (!(share->name=my_strdup(name,MYF(0))))
share->min_records= min_records;
share->max_records= max_records;
share->data_length= share->index_length= 0;
share->reclength= reclength;
share->blength= 1;
share->keys= keys;
share->max_key_length= max_length;
share->changed= 0;
if (!(share->name= my_strdup(name,MYF(0))))
{
my_free((gptr) share,MYF(0));
pthread_mutex_unlock(&THR_LOCK_heap);
......@@ -125,8 +130,8 @@ HP_INFO *heap_open(const char *name, int mode, uint keys, HP_KEYDEF *keydef,
thr_lock_init(&share->lock);
VOID(pthread_mutex_init(&share->intern_lock,MY_MUTEX_INIT_FAST));
#endif
share->open_list.data=(void*) share;
heap_share_list=list_add(heap_share_list,&share->open_list);
share->open_list.data= (void*) share;
heap_share_list= list_add(heap_share_list,&share->open_list);
}
if (!(info= (HP_INFO*) my_malloc((uint) sizeof(HP_INFO)+
2 * share->max_key_length,
......@@ -139,21 +144,21 @@ HP_INFO *heap_open(const char *name, int mode, uint keys, HP_KEYDEF *keydef,
#ifdef THREAD
thr_lock_data_init(&share->lock,&info->lock,NULL);
#endif
info->open_list.data=(void*) info;
heap_open_list=list_add(heap_open_list,&info->open_list);
info->open_list.data= (void*) info;
heap_open_list= list_add(heap_open_list,&info->open_list);
pthread_mutex_unlock(&THR_LOCK_heap);
info->s=share;
info->lastkey=(byte*) (info+1);
info->recbuf = (byte*) (info->lastkey + share->max_key_length);
info->mode=mode;
info->s= share;
info->lastkey= (byte*) (info + 1);
info->recbuf= (byte*) (info->lastkey + share->max_key_length);
info->mode= mode;
info->current_record= (ulong) ~0L; /* No current record */
info->current_ptr=0;
info->current_hash_ptr=0;
info->current_ptr= 0;
info->current_hash_ptr= 0;
info->lastinx= info->errkey= -1;
info->update=0;
info->update= 0;
#ifndef DBUG_OFF
info->opt_flag=READ_CHECK_USED; /* Check when changing */
info->opt_flag= READ_CHECK_USED; /* Check when changing */
#endif
DBUG_PRINT("exit",("heap: %lx reclength: %d records_in_block: %d",
info,share->reclength,share->block.records_in_block));
......
......@@ -31,7 +31,7 @@ int heap_rfirst(HP_INFO *info, byte *record, int inx)
if ((pos = tree_search_edge(&keyinfo->rb_tree, info->parents,
&info->last_pos, offsetof(TREE_ELEMENT, left))))
{
memcpy(&pos, pos + keyinfo->ref_offs, sizeof(byte*));
memcpy(&pos, pos + hp_rb_key_length(keyinfo, pos), sizeof(byte*));
info->current_ptr = pos;
memcpy(record, pos, (size_t)share->reclength);
info->update = HA_STATE_AKTIV;
......
......@@ -55,7 +55,7 @@ int heap_rkey(HP_INFO *info, byte *record, int inx, const byte *key,
info->update = 0;
DBUG_RETURN(my_errno = HA_ERR_KEY_NOT_FOUND);
}
memcpy(&pos, pos + keyinfo->ref_offs, sizeof(byte*));
memcpy(&pos, pos + hp_rb_key_length(keyinfo, pos), sizeof(byte*));
info->current_ptr = pos;
}
else
......
......@@ -32,7 +32,7 @@ int heap_rlast(HP_INFO *info, byte *record, int inx)
if ((pos = tree_search_edge(&keyinfo->rb_tree, info->parents,
&info->last_pos, offsetof(TREE_ELEMENT, right))))
{
memcpy(&pos, pos + keyinfo->ref_offs, sizeof(byte*));
memcpy(&pos, pos + hp_rb_key_length(keyinfo, pos), sizeof(byte*));
info->current_ptr = pos;
memcpy(record, pos, (size_t)share->reclength);
info->update = HA_STATE_AKTIV;
......
......@@ -47,7 +47,7 @@ int heap_rnext(HP_INFO *info, byte *record)
}
if (pos)
{
memcpy(&pos, pos + keyinfo->ref_offs, sizeof(byte*));
memcpy(&pos, pos + hp_rb_key_length(keyinfo, pos), sizeof(byte*));
info->current_ptr = pos;
}
else
......
......@@ -47,7 +47,7 @@ int heap_rprev(HP_INFO *info, byte *record)
}
if (pos)
{
memcpy(&pos, pos + keyinfo->ref_offs, sizeof(byte*));
memcpy(&pos, pos + hp_rb_key_length(keyinfo, pos), sizeof(byte*));
info->current_ptr = pos;
}
else
......
......@@ -93,25 +93,25 @@ int hp_rb_write_key(HP_INFO *info, HP_KEYDEF *keyinfo, const byte *record,
{
heap_rb_param custom_arg;
info->last_pos = NULL; /* For heap_rnext/heap_rprev */
hp_rb_make_key(keyinfo, info->recbuf, record, recpos);
custom_arg.keyseg = keyinfo->seg;
custom_arg.key_length = keyinfo->length;
info->last_pos= NULL; /* For heap_rnext/heap_rprev */
custom_arg.keyseg= keyinfo->seg;
custom_arg.key_length= hp_rb_make_key(keyinfo, info->recbuf, record, recpos);
if ((keyinfo->flag & HA_NOSAME) &&
(!(keyinfo->flag & HA_NULL_PART_KEY) ||
!hp_if_null_in_key(keyinfo, record)))
{
custom_arg.search_flag = SEARCH_FIND | SEARCH_SAME;
custom_arg.search_flag= SEARCH_FIND | SEARCH_SAME;
if (tree_search_key(&keyinfo->rb_tree, info->recbuf, info->parents,
&info->last_pos, 0, &custom_arg))
{
my_errno = HA_ERR_FOUND_DUPP_KEY;
my_errno= HA_ERR_FOUND_DUPP_KEY;
return 1;
}
}
custom_arg.search_flag = SEARCH_SAME;
return tree_insert(&keyinfo->rb_tree, (void*)info->recbuf, keyinfo->length +
sizeof(byte*), &custom_arg) ? 0 : 1;
custom_arg.search_flag= SEARCH_SAME;
return tree_insert(&keyinfo->rb_tree, (void*)info->recbuf,
custom_arg.key_length + sizeof(byte*),
&custom_arg) ? 0 : 1;
}
/* Find where to place new record */
......
......@@ -84,7 +84,6 @@ typedef struct st_hp_keydef /* Key definition with open */
uint keysegs; /* Number of key-segment */
uint length; /* Length of key (automatic) */
uint8 algorithm; /* HASH / BTREE */
uint ref_offs; /* Data reference offset */
HA_KEYSEG *seg;
HP_BLOCK block; /* Where keys are saved */
TREE rb_tree;
......@@ -131,7 +130,7 @@ typedef struct st_heap_info
byte *lastkey; /* Last used key with rkey */
byte *recbuf; /* Record buffer for rb-tree keys */
enum ha_rkey_function last_find_flag;
TREE_ELEMENT *parents[MAX_TREE_HIGHT+1];
TREE_ELEMENT *parents[MAX_TREE_HEIGHT+1];
TREE_ELEMENT **last_pos;
uint lastkey_len;
#ifdef THREAD
......
......@@ -50,14 +50,10 @@ typedef struct st_HA_KEYSEG /* Key-portion */
{ length=mi_uint2korr((key)+1); (key)+=3; length_pack=3; } \
}
extern int _mi_compare_text(CHARSET_INFO *, uchar *, uint, uchar *, uint ,
extern int mi_compare_text(CHARSET_INFO *, uchar *, uint, uchar *, uint ,
my_bool);
extern int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a,
register uchar *b, uint key_length, uint nextflag,
uint *diff_pos);
extern int hp_rb_key_cmp(register HA_KEYSEG *keyseg, register uchar *a,
register uchar *b, uint key_length, uint nextflag,
uint *diff_pos);
#endif /* _my_handler_h */
......@@ -20,7 +20,7 @@
extern "C" {
#endif
#define MAX_TREE_HIGHT 40 /* = max 1048576 leafs in tree */
#define MAX_TREE_HEIGHT 40 /* = max 1048576 leafs in tree */
#define ELEMENT_KEY(tree,element)\
(tree->offset_to_key ? (void*)((byte*) element+tree->offset_to_key) :\
*((void**) (element+1)))
......@@ -52,7 +52,7 @@ typedef struct st_tree_element {
typedef struct st_tree {
TREE_ELEMENT *root,null_element;
TREE_ELEMENT **parents[MAX_TREE_HIGHT];
TREE_ELEMENT **parents[MAX_TREE_HEIGHT];
uint offset_to_key,elements_in_tree,size_of_element,memory_limit,allocated;
qsort_cmp2 compare;
void* custom_arg;
......
......@@ -104,7 +104,7 @@ int FTB_WORD_cmp(void *v __attribute__((unused)), FTB_WORD *a, FTB_WORD *b)
int FTB_WORD_cmp_list(void *v __attribute__((unused)), FTB_WORD **a, FTB_WORD **b)
{
/* ORDER BY word DESC, ndepth DESC */
int i=_mi_compare_text(default_charset_info, (*b)->word+1,(*b)->len-1,
int i= mi_compare_text(default_charset_info, (*b)->word+1,(*b)->len-1,
(*a)->word+1,(*a)->len-1,0);
if (!i)
i=CMP_NUM((*b)->ndepth,(*a)->ndepth);
......@@ -203,7 +203,7 @@ void _ftb_init_index_search(FT_INFO *ftb)
SEARCH_FIND | SEARCH_BIGGER, keyroot);
if (!r)
{
r=_mi_compare_text(default_charset_info,
r= mi_compare_text(default_charset_info,
info->lastkey + (ftbw->flags&FTB_FLAG_TRUNC),
ftbw->len - (ftbw->flags&FTB_FLAG_TRUNC),
ftbw->word + (ftbw->flags&FTB_FLAG_TRUNC),
......@@ -359,7 +359,7 @@ int ft_boolean_read_next(FT_INFO *ftb, char *record)
SEARCH_BIGGER , keyroot);
if (!r)
{
r=_mi_compare_text(default_charset_info,
r= mi_compare_text(default_charset_info,
info->lastkey + (ftbw->flags&FTB_FLAG_TRUNC),
ftbw->len - (ftbw->flags&FTB_FLAG_TRUNC),
ftbw->word + (ftbw->flags&FTB_FLAG_TRUNC),
......@@ -443,7 +443,7 @@ float ft_boolean_find_relevance(FT_INFO *ftb, byte *record, uint length)
for (a=0, b=ftb->queue.elements, c=(a+b)/2; b-a>1; c=(a+b)/2)
{
ftbw=(FTB_WORD *)(ftb->list[c]);
if (_mi_compare_text(default_charset_info, word.pos,word.len,
if (mi_compare_text(default_charset_info, word.pos,word.len,
(uchar*) ftbw->word+1,ftbw->len-1,
(ftbw->flags&FTB_FLAG_TRUNC) ) >0)
b=c;
......@@ -453,7 +453,7 @@ float ft_boolean_find_relevance(FT_INFO *ftb, byte *record, uint length)
for (; c>=0; c--)
{
ftbw=(FTB_WORD *)(ftb->list[c]);
if (_mi_compare_text(default_charset_info, word.pos,word.len,
if (mi_compare_text(default_charset_info, word.pos,word.len,
(uchar*) ftbw->word+1,ftbw->len-1,
(ftbw->flags&FTB_FLAG_TRUNC) ))
break;
......
......@@ -93,7 +93,7 @@ static int walk_and_match(FT_WORD *word, uint32 count, ALL_IN_ONE *aio)
while(!r)
{
if (_mi_compare_text(default_charset_info,
if (mi_compare_text(default_charset_info,
aio->info->lastkey,keylen,
aio->keybuff,keylen,0)) break;
......
......@@ -37,7 +37,7 @@ typedef struct st_ft_docstat {
static int FT_WORD_cmp(void* cmp_arg, FT_WORD *w1, FT_WORD *w2)
{
return _mi_compare_text(default_charset_info,
return mi_compare_text(default_charset_info,
(uchar*) w1->pos, w1->len,
(uchar*) w2->pos, w2->len,
(my_bool) (cmp_arg != 0));
......
......@@ -28,7 +28,7 @@ static TREE *stopwords3=NULL;
static int FT_STOPWORD_cmp(void* cmp_arg __attribute__((unused)),
FT_STOPWORD *w1, FT_STOPWORD *w2)
{
return _mi_compare_text(default_charset_info,
return mi_compare_text(default_charset_info,
(uchar *)w1->pos,w1->len,
(uchar *)w2->pos,w2->len,0);
}
......
......@@ -160,7 +160,7 @@ int _mi_ft_cmp(MI_INFO *info, uint keynr, const byte *rec1, const byte *rec2)
{
if ((ftsi1.pos != ftsi2.pos) &&
(!ftsi1.pos || !ftsi2.pos ||
_mi_compare_text(default_charset_info,
mi_compare_text(default_charset_info,
(uchar*) ftsi1.pos,ftsi1.len,
(uchar*) ftsi2.pos,ftsi2.len,0)))
return THOSE_TWO_DAMN_KEYS_ARE_REALLY_DIFFERENT;
......@@ -185,7 +185,7 @@ int _mi_ft_update(MI_INFO *info, uint keynr, byte *keybuf,
error=0;
while(old_word->pos && new_word->pos)
{
cmp=_mi_compare_text(default_charset_info,
cmp= mi_compare_text(default_charset_info,
(uchar*) old_word->pos,old_word->len,
(uchar*) new_word->pos,new_word->len,0);
cmp2= cmp ? 0 : (fabs(old_word->weight - new_word->weight) > 1.e-5);
......
This diff is collapsed.
......@@ -382,15 +382,15 @@ void *tree_search_key(TREE *tree, const void *key,
void *tree_search_edge(TREE *tree, TREE_ELEMENT **parents,
TREE_ELEMENT ***last_pos, int child_offs)
{
TREE_ELEMENT *element = tree->root;
TREE_ELEMENT *element= tree->root;
*parents = &tree->null_element;
*parents= &tree->null_element;
while (element != &tree->null_element)
{
*++parents = element;
element = ELEMENT_CHILD(element, child_offs);
*++parents= element;
element= ELEMENT_CHILD(element, child_offs);
}
*last_pos = parents;
*last_pos= parents;
return **last_pos != &tree->null_element ?
ELEMENT_KEY(tree, **last_pos) : NULL;
}
......@@ -398,26 +398,26 @@ void *tree_search_edge(TREE *tree, TREE_ELEMENT **parents,
void *tree_search_next(TREE *tree, TREE_ELEMENT ***last_pos, int l_offs,
int r_offs)
{
TREE_ELEMENT *x = **last_pos;
TREE_ELEMENT *x= **last_pos;
if (ELEMENT_CHILD(x, r_offs) != &tree->null_element)
{
x = ELEMENT_CHILD(x, r_offs);
*++*last_pos = x;
x= ELEMENT_CHILD(x, r_offs);
*++*last_pos= x;
while (ELEMENT_CHILD(x, l_offs) != &tree->null_element)
{
x = ELEMENT_CHILD(x, l_offs);
*++*last_pos = x;
x= ELEMENT_CHILD(x, l_offs);
*++*last_pos= x;
}
return ELEMENT_KEY(tree, x);
}
else
{
TREE_ELEMENT *y = *--*last_pos;
TREE_ELEMENT *y= *--*last_pos;
while (y != &tree->null_element && x == ELEMENT_CHILD(y, r_offs))
{
x = y;
y = *--*last_pos;
x= y;
y= *--*last_pos;
}
return y == &tree->null_element ? NULL : ELEMENT_KEY(tree, y);
}
......@@ -431,28 +431,26 @@ uint tree_record_pos(TREE *tree, const void *key,
enum ha_rkey_function flag, void *custom_arg)
{
int cmp;
TREE_ELEMENT *element = tree->root;
uint left = 1;
uint right = tree->elements_in_tree;
uint last_left_step_pos = tree->elements_in_tree;
uint last_right_step_pos = 1;
uint last_equal_pos = HA_POS_ERROR;
TREE_ELEMENT *element= tree->root;
double left= 1;
double right= tree->elements_in_tree;
uint last_equal_pos= HA_POS_ERROR;
while (element != &tree->null_element)
{
if ((cmp = (*tree->compare)(custom_arg, ELEMENT_KEY(tree, element),
if ((cmp= (*tree->compare)(custom_arg, ELEMENT_KEY(tree, element),
key)) == 0)
{
switch (flag) {
case HA_READ_KEY_EXACT:
last_equal_pos = (left + right) >> 1;
cmp = 1;
last_equal_pos= (left + right) / 2;
cmp= 1;
break;
case HA_READ_BEFORE_KEY:
cmp = 1;
cmp= 1;
break;
case HA_READ_AFTER_KEY:
cmp = -1;
cmp= -1;
break;
default:
return HA_POS_ERROR;
......@@ -460,24 +458,22 @@ uint tree_record_pos(TREE *tree, const void *key,
}
if (cmp < 0) /* element < key */
{
last_right_step_pos = (left + right) >> 1;
element = element->right;
left = last_right_step_pos;
element= element->right;
left= (left + right) / 2;
}
else
{
last_left_step_pos = (left + right) >> 1;
element = element->left;
right = last_left_step_pos;
element= element->left;
right= (left + right) / 2;
}
}
switch (flag) {
case HA_READ_KEY_EXACT:
return last_equal_pos;
case HA_READ_BEFORE_KEY:
return last_right_step_pos;
return (uint) right;
case HA_READ_AFTER_KEY:
return last_left_step_pos;
return (uint) left;
default:
return HA_POS_ERROR;
}
......
......@@ -42,10 +42,8 @@ int ha_heap::open(const char *name, int mode, uint test_if_locked)
{
parts+=table->key_info[key].key_parts;
if (table->key_info[key].algorithm == HA_KEY_ALG_BTREE)
{
parts++; /* additional HA_KEYTYPE_END keyseg */
}
}
if (!(keydef=(HP_KEYDEF*) my_malloc(table->keys*sizeof(HP_KEYDEF)+
parts*sizeof(HA_KEYSEG),MYF(MY_WME))))
......@@ -55,7 +53,7 @@ int ha_heap::open(const char *name, int mode, uint test_if_locked)
{
KEY *pos=table->key_info+key;
KEY_PART_INFO *key_part= pos->key_part;
KEY_PART_INFO *key_part_end= key_part+pos->key_parts;
KEY_PART_INFO *key_part_end= key_part + pos->key_parts;
mem_per_row+= (pos->key_length + (sizeof(char*) * 2));
......@@ -94,14 +92,13 @@ int ha_heap::open(const char *name, int mode, uint test_if_locked)
}
else
{
seg->null_bit=0;
seg->null_pos=0;
seg->null_bit= 0;
seg->null_pos= 0;
}
}
if (pos->algorithm == HA_KEY_ALG_BTREE)
{
/* additional HA_KEYTYPE_END keyseg */
keydef[key].keysegs++;
seg->type= HA_KEYTYPE_END;
seg->length= sizeof(byte*);
seg->flag= 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment