diff options
author | unknown <ram@gw.udmsearch.izhnet.ru> | 2002-05-23 19:26:16 +0500 |
---|---|---|
committer | unknown <ram@gw.udmsearch.izhnet.ru> | 2002-05-23 19:26:16 +0500 |
commit | d011676f442d0833432dd5ee6ff7c9fa890d21d4 (patch) | |
tree | c5a8cbf56ea21127e0ba4d444db78aa46cbe0925 /heap | |
parent | 1130adb4a81e35c3ec1e0c73db2622ef15f69a6e (diff) | |
download | mariadb-git-d011676f442d0833432dd5ee6ff7c9fa890d21d4.tar.gz |
Heap table code cleanup
Diffstat (limited to 'heap')
-rw-r--r-- | heap/heapdef.h | 4 | ||||
-rw-r--r-- | heap/hp_hash.c | 41 | ||||
-rw-r--r-- | heap/hp_open.c | 42 | ||||
-rw-r--r-- | heap/hp_rfirst.c | 3 | ||||
-rw-r--r-- | heap/hp_rkey.c | 48 | ||||
-rw-r--r-- | heap/hp_rlast.c | 3 | ||||
-rw-r--r-- | heap/hp_rnext.c | 3 | ||||
-rw-r--r-- | heap/hp_rprev.c | 3 |
8 files changed, 76 insertions, 71 deletions
diff --git a/heap/heapdef.h b/heap/heapdef.h index 0308f7dd62c..c81624059d5 100644 --- a/heap/heapdef.h +++ b/heap/heapdef.h @@ -82,11 +82,11 @@ extern void hp_make_key(HP_KEYDEF *keydef,byte *key,const byte *rec); 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 uint hp_rb_null_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); -extern uint hp_rb_pack_key(HP_INFO *info, uint inx, uchar *key, - const uchar *old, uint k_length); +extern uint hp_rb_pack_key(HP_KEYDEF *keydef, uchar *key, const uchar *old); #ifdef THREAD extern pthread_mutex_t THR_LOCK_heap; #else diff --git a/heap/hp_hash.c b/heap/hp_hash.c index f170df4fdb8..424322fd5e7 100644 --- a/heap/hp_hash.c +++ b/heap/hp_hash.c @@ -26,16 +26,17 @@ ha_rows hp_rb_records_in_range(HP_INFO *info, int inx, const byte *start_key, enum ha_rkey_function end_search_flag) { ha_rows start_pos, end_pos; - TREE *rb_tree = &info->s->keydef[inx].rb_tree; + HP_KEYDEF *keyinfo= info->s->keydef + inx; + TREE *rb_tree = &keyinfo->rb_tree; heap_rb_param custom_arg; info->lastinx = inx; - custom_arg.keyseg = info->s->keydef[inx].seg; + custom_arg.keyseg = keyinfo->seg; custom_arg.search_flag = SEARCH_FIND | SEARCH_SAME; custom_arg.key_length = start_key_len; if (start_key) { - hp_rb_pack_key(info, inx, info->recbuf, start_key, start_key_len); + hp_rb_pack_key(keyinfo, info->recbuf, start_key); start_pos= tree_record_pos(rb_tree, info->recbuf, start_search_flag, &custom_arg); } @@ -47,7 +48,7 @@ ha_rows hp_rb_records_in_range(HP_INFO *info, int inx, const byte *start_key, custom_arg.key_length = end_key_len; if (end_key) { - hp_rb_pack_key(info, inx, info->recbuf, end_key, end_key_len); + hp_rb_pack_key(keyinfo, info->recbuf, end_key); end_pos= tree_record_pos(rb_tree, info->recbuf, end_search_flag, &custom_arg); } @@ -473,12 +474,10 @@ uint hp_rb_make_key(HP_KEYDEF *keydef, byte *key, return key - start_key; } -uint hp_rb_pack_key(HP_INFO *info, uint inx, uchar *key, const uchar *old, - uint k_length) +uint hp_rb_pack_key(HP_KEYDEF *keydef, uchar *key, const uchar *old) { HA_KEYSEG *seg, *endseg; uchar *start_key= key; - HP_KEYDEF *keydef= info->s->keydef + inx; for (seg= keydef->seg, endseg= seg + keydef->keysegs; seg < endseg; old+= seg->length, seg++) @@ -494,28 +493,24 @@ uint hp_rb_pack_key(HP_INFO *info, uint inx, uchar *key, const uchar *old, return key - start_key; } -uint hp_rb_key_length(HP_KEYDEF *keydef, const byte *key) +uint hp_rb_key_length(HP_KEYDEF *keydef, + const byte *key __attribute__((unused))) +{ + return keydef->length; +} + +uint hp_rb_null_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 + for (seg= keydef->seg, endseg= seg + keydef->keysegs; seg < endseg; seg++) { - return keydef->length; + if (seg->null_bit && !*key++) + continue; + key+= seg->length; } + return key - start_key; } /* diff --git a/heap/hp_open.c b/heap/hp_open.c index 7f189adc497..3aa35e2cf88 100644 --- a/heap/hp_open.c +++ b/heap/hp_open.c @@ -48,30 +48,37 @@ HP_INFO *heap_open(const char *name, int mode, uint keys, HP_KEYDEF *keydef, pthread_mutex_lock(&THR_LOCK_heap); if (!(share = hp_find_named_heap(name))) { + HP_KEYDEF *keyinfo; DBUG_PRINT("info",("Initializing new table")); - for (i=key_segs=max_length=0 ; i < keys ; i++) + for (i=key_segs=max_length=0, keyinfo= keydef; i < keys; i++, keyinfo++) { - 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++) + bzero((char*) &keyinfo->block,sizeof(keyinfo->block)); + bzero((char*) &keyinfo->rb_tree ,sizeof(keyinfo->rb_tree)); + for (j=length=0 ; j < keyinfo->keysegs; j++) { - length+=keydef[i].seg[j].length; - if (keydef[i].seg[j].null_bit) + length+=keyinfo->seg[j].length; + if (keyinfo->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++; + if (!(keyinfo->flag & HA_NULL_ARE_EQUAL)) + keyinfo->flag |= HA_NULL_PART_KEY; + if (keyinfo->algorithm == HA_KEY_ALG_BTREE) + keyinfo->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); + keyinfo->length= length; + length+= keyinfo->rb_tree.size_of_element + + ((keyinfo->algorithm == HA_KEY_ALG_BTREE) ? sizeof(byte*) : 0); if (length > max_length) max_length= length; + key_segs+= keyinfo->keysegs; + if (keyinfo->algorithm == HA_KEY_ALG_BTREE) + { + key_segs++; /* additional HA_KEYTYPE_END segment */ + if (keyinfo->flag & HA_NULL_PART_KEY) + keyinfo->get_key_length = hp_rb_null_key_length; + else + keyinfo->get_key_length = hp_rb_key_length; + } } if (!(share= (HP_SHARE*) my_malloc((uint) sizeof(HP_SHARE)+ keys*sizeof(HP_KEYDEF)+ @@ -86,9 +93,8 @@ HP_INFO *heap_open(const char *name, int mode, uint keys, HP_KEYDEF *keydef, 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++) + for (i= 0, keyinfo= share->keydef; i < keys; i++, keyinfo++) { - HP_KEYDEF *keyinfo= share->keydef + i; uint nsegs= keydef[i].keysegs; if (keydef[i].algorithm == HA_KEY_ALG_BTREE) diff --git a/heap/hp_rfirst.c b/heap/hp_rfirst.c index 654874d5c8d..39b0d4385f2 100644 --- a/heap/hp_rfirst.c +++ b/heap/hp_rfirst.c @@ -31,7 +31,8 @@ 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 + hp_rb_key_length(keyinfo, pos), sizeof(byte*)); + memcpy(&pos, pos + (*keyinfo->get_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 502e97e2f06..4e47fd52e9b 100644 --- a/heap/hp_rkey.c +++ b/heap/hp_rkey.c @@ -20,56 +20,56 @@ int heap_rkey(HP_INFO *info, byte *record, int inx, const byte *key, uint key_len, enum ha_rkey_function find_flag) { byte *pos; - HP_SHARE *share=info->s; - HP_KEYDEF *keyinfo = share->keydef+inx; + HP_SHARE *share= info->s; + HP_KEYDEF *keyinfo= share->keydef + inx; DBUG_ENTER("heap_rkey"); DBUG_PRINT("enter",("base: %lx inx: %d",info,inx)); if ((uint) inx >= share->keys) { - DBUG_RETURN(my_errno=HA_ERR_WRONG_INDEX); + DBUG_RETURN(my_errno= HA_ERR_WRONG_INDEX); } - info->lastinx=inx; - info->current_record = (ulong) ~0L; /* For heap_rrnd() */ + info->lastinx= inx; + info->current_record= (ulong) ~0L; /* For heap_rrnd() */ if (keyinfo->algorithm == HA_KEY_ALG_BTREE) { heap_rb_param custom_arg; - hp_rb_pack_key(info, inx, info->recbuf, key, key_len); + hp_rb_pack_key(keyinfo, info->recbuf, key); - custom_arg.keyseg = info->s->keydef[inx].seg; - custom_arg.key_length = key_len; - custom_arg.search_flag = SEARCH_FIND | SEARCH_SAME; + custom_arg.keyseg= info->s->keydef[inx].seg; + custom_arg.key_length= key_len; + custom_arg.search_flag= SEARCH_FIND | SEARCH_SAME; /* for next rkey() after deletion */ if (find_flag == HA_READ_AFTER_KEY) - info->last_find_flag = HA_READ_KEY_OR_NEXT; + info->last_find_flag= HA_READ_KEY_OR_NEXT; else if (find_flag == HA_READ_BEFORE_KEY) - info->last_find_flag = HA_READ_KEY_OR_PREV; + info->last_find_flag= HA_READ_KEY_OR_PREV; else - info->last_find_flag = find_flag; - info->lastkey_len = key_len; - if (!(pos = tree_search_key(&keyinfo->rb_tree, info->recbuf, info->parents, - &info->last_pos, find_flag, &custom_arg))) + info->last_find_flag= find_flag; + info->lastkey_len= key_len; + if (!(pos= tree_search_key(&keyinfo->rb_tree, info->recbuf, info->parents, + &info->last_pos, find_flag, &custom_arg))) { - info->update = 0; - DBUG_RETURN(my_errno = HA_ERR_KEY_NOT_FOUND); + info->update= 0; + DBUG_RETURN(my_errno= HA_ERR_KEY_NOT_FOUND); } - memcpy(&pos, pos + hp_rb_key_length(keyinfo, pos), sizeof(byte*)); - info->current_ptr = pos; + memcpy(&pos, pos + (*keyinfo->get_key_length)(keyinfo, pos), sizeof(byte*)); + info->current_ptr= pos; } else { - if (!(pos=hp_search(info,share->keydef+inx,key,0))) + if (!(pos= hp_search(info, share->keydef + inx, key, 0))) { - info->update=0; + info->update= 0; DBUG_RETURN(my_errno); } if (!(keyinfo->flag & HA_NOSAME)) - memcpy(info->lastkey,key,(size_t) keyinfo->length); + memcpy(info->lastkey, key, (size_t) keyinfo->length); } - memcpy(record,pos,(size_t) share->reclength); - info->update=HA_STATE_AKTIV; + memcpy(record, pos, (size_t) share->reclength); + info->update= HA_STATE_AKTIV; DBUG_RETURN(0); } diff --git a/heap/hp_rlast.c b/heap/hp_rlast.c index 6832b6e2428..e51a0e8a8f1 100644 --- a/heap/hp_rlast.c +++ b/heap/hp_rlast.c @@ -32,7 +32,8 @@ 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 + hp_rb_key_length(keyinfo, pos), sizeof(byte*)); + memcpy(&pos, pos + (*keyinfo->get_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 c01ca52d5ae..a1bc480333e 100644 --- a/heap/hp_rnext.c +++ b/heap/hp_rnext.c @@ -47,7 +47,8 @@ int heap_rnext(HP_INFO *info, byte *record) } if (pos) { - memcpy(&pos, pos + hp_rb_key_length(keyinfo, pos), sizeof(byte*)); + memcpy(&pos, pos + (*keyinfo->get_key_length)(keyinfo, pos), + sizeof(byte*)); info->current_ptr = pos; } else diff --git a/heap/hp_rprev.c b/heap/hp_rprev.c index 071746fa3de..d8f5c01dcea 100644 --- a/heap/hp_rprev.c +++ b/heap/hp_rprev.c @@ -47,7 +47,8 @@ int heap_rprev(HP_INFO *info, byte *record) } if (pos) { - memcpy(&pos, pos + hp_rb_key_length(keyinfo, pos), sizeof(byte*)); + memcpy(&pos, pos + (*keyinfo->get_key_length)(keyinfo, pos), + sizeof(byte*)); info->current_ptr = pos; } else |