summaryrefslogtreecommitdiff
path: root/heap
diff options
context:
space:
mode:
authorunknown <ram@gw.udmsearch.izhnet.ru>2002-05-21 21:54:08 +0500
committerunknown <ram@gw.udmsearch.izhnet.ru>2002-05-21 21:54:08 +0500
commitc811538f89925b7111e4ee0e3b940726f32a64d9 (patch)
tree33c8cdcfd2d233bc3b663c05fd4bd9ca99b2bb5e /heap
parent1b49cd8ca1391d5141750fae62fa0c9c13da6e86 (diff)
downloadmariadb-git-c811538f89925b7111e4ee0e3b940726f32a64d9.tar.gz
BTREE heap key structure is now the same as MyISAM
_mi_compare_text -> mi_compate_text Changes according Monty's suggestions heap/heapdef.h: BTREE heap key structure is now the same as MyISAM heap/hp_delete.c: BTREE heap key structure is now the same as MyISAM heap/hp_hash.c: BTREE heap key structure is now the same as MyISAM heap/hp_open.c: BTREE heap key structure is now the same as MyISAM heap/hp_rfirst.c: BTREE heap key structure is now the same as MyISAM heap/hp_rkey.c: BTREE heap key structure is now the same as MyISAM heap/hp_rlast.c: BTREE heap key structure is now the same as MyISAM heap/hp_rnext.c: BTREE heap key structure is now the same as MyISAM heap/hp_rprev.c: BTREE heap key structure is now the same as MyISAM heap/hp_write.c: BTREE heap key structure is now the same as MyISAM include/heap.h: BTREE heap key structure is now the same as MyISAM include/my_handler.h: Removed hp_rb_key_cmp() _mi_compare_text -> mi_compate_text include/my_tree.h: Fixed typo myisam/ft_boolean_search.c: _mi_compare_text -> mi_compate_text myisam/ft_nlq_search.c: _mi_compare_text -> mi_compate_text myisam/ft_parser.c: _mi_compare_text -> mi_compate_text myisam/ft_stopwords.c: _mi_compare_text -> mi_compate_text myisam/ft_update.c: _mi_compare_text -> mi_compate_text mysys/my_handler.c: Removed hp_rb_key_cmp() _mi_compare_text -> mi_compate_text mysys/tree.c: BTREE heap key structure is now the same as MyISAM sql/ha_heap.cc: BTREE heap key structure is now the same as MyISAM
Diffstat (limited to 'heap')
-rw-r--r--heap/heapdef.h3
-rw-r--r--heap/hp_delete.c9
-rw-r--r--heap/hp_hash.c53
-rw-r--r--heap/hp_open.c111
-rw-r--r--heap/hp_rfirst.c2
-rw-r--r--heap/hp_rkey.c2
-rw-r--r--heap/hp_rlast.c2
-rw-r--r--heap/hp_rnext.c2
-rw-r--r--heap/hp_rprev.c2
-rw-r--r--heap/hp_write.c18
10 files changed, 119 insertions, 85 deletions
diff --git a/heap/heapdef.h b/heap/heapdef.h
index aeb345522f5..0308f7dd62c 100644
--- a/heap/heapdef.h
+++ b/heap/heapdef.h
@@ -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);
diff --git a/heap/hp_delete.c b/heap/hp_delete.c
index 82513044058..4ba2f2c5310 100644
--- a/heap/hp_delete.c
+++ b/heap/hp_delete.c
@@ -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);
}
diff --git a/heap/hp_hash.c b/heap/hp_hash.c
index dbd330ea4f4..f170df4fdb8 100644
--- a/heap/hp_hash.c
+++ b/heap/hp_hash.c
@@ -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,12 +484,39 @@ 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.
diff --git a/heap/hp_open.c b/heap/hp_open.c
index 49f9a2cfc33..7f189adc497 100644
--- a/heap/hp_open.c
+++ b/heap/hp_open.c
@@ -26,8 +26,8 @@
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,
- param->search_flag, &not_used);
+ return ha_key_cmp(param->keyseg, key1, key2, param->key_length,
+ param->search_flag, &not_used);
}
static void init_block(HP_BLOCK *block,uint reclength,ulong min_records,
@@ -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))
- keydef[i].flag |= HA_NULL_PART_KEY;
- if (keydef[i].algorithm == HA_KEY_ALG_BTREE &&
- keydef[i].seg[j].null_bit)
- keydef[i].rb_tree.size_of_element++;
+ 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].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;
+ keydef[i].length= length;
+ 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->lastinx= info->errkey= -1;
- info->update=0;
+ info->current_ptr= 0;
+ info->current_hash_ptr= 0;
+ info->lastinx= info->errkey= -1;
+ 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));
diff --git a/heap/hp_rfirst.c b/heap/hp_rfirst.c
index 390d18fc58f..654874d5c8d 100644
--- a/heap/hp_rfirst.c
+++ b/heap/hp_rfirst.c
@@ -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;
diff --git a/heap/hp_rkey.c b/heap/hp_rkey.c
index 649370cf0b0..502e97e2f06 100644
--- a/heap/hp_rkey.c
+++ b/heap/hp_rkey.c
@@ -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
diff --git a/heap/hp_rlast.c b/heap/hp_rlast.c
index 4c2379427b0..6832b6e2428 100644
--- a/heap/hp_rlast.c
+++ b/heap/hp_rlast.c
@@ -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;
diff --git a/heap/hp_rnext.c b/heap/hp_rnext.c
index 12ce354335d..c01ca52d5ae 100644
--- a/heap/hp_rnext.c
+++ b/heap/hp_rnext.c
@@ -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
diff --git a/heap/hp_rprev.c b/heap/hp_rprev.c
index 98f7a02d55b..071746fa3de 100644
--- a/heap/hp_rprev.c
+++ b/heap/hp_rprev.c
@@ -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
diff --git a/heap/hp_write.c b/heap/hp_write.c
index 801505216bd..fcfe922d9c0 100644
--- a/heap/hp_write.c
+++ b/heap/hp_write.c
@@ -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 */