diff options
Diffstat (limited to 'heap/hp_rlast.c')
-rw-r--r-- | heap/hp_rlast.c | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/heap/hp_rlast.c b/heap/hp_rlast.c index 463b6dc9aac..b1a49739108 100644 --- a/heap/hp_rlast.c +++ b/heap/hp_rlast.c @@ -19,11 +19,38 @@ /* Read first record with the current key */ -int heap_rlast(HP_INFO *info, byte *record) +int heap_rlast(HP_INFO *info, byte *record, int inx) { + HP_SHARE *share= info->s; + HP_KEYDEF *keyinfo= share->keydef + inx; + DBUG_ENTER("heap_rlast"); - info->current_ptr=0; - info->current_hash_ptr=0; - info->update=HA_STATE_NEXT_FOUND; - DBUG_RETURN(heap_rprev(info,record)); + info->lastinx= inx; + if (keyinfo->algorithm == HA_KEY_ALG_BTREE) + { + byte *pos; + + if ((pos = tree_search_edge(&keyinfo->rb_tree, info->parents, + &info->last_pos, offsetof(TREE_ELEMENT, right)))) + { + 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; + } + else + { + my_errno = HA_ERR_END_OF_FILE; + DBUG_RETURN(my_errno); + } + DBUG_RETURN(0); + } + else + { + info->current_ptr=0; + info->current_hash_ptr=0; + info->update=HA_STATE_NEXT_FOUND; + DBUG_RETURN(heap_rprev(info,record)); + } } |