diff options
Diffstat (limited to 'heap/hp_rlast.c')
-rw-r--r-- | heap/hp_rlast.c | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/heap/hp_rlast.c b/heap/hp_rlast.c index 463b6dc9aac..7f883d3a18b 100644 --- a/heap/hp_rlast.c +++ b/heap/hp_rlast.c @@ -21,9 +21,37 @@ int heap_rlast(HP_INFO *info, byte *record) { + HP_SHARE *share = info->s; + HP_KEYDEF *keyinfo; + 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)); + if (info->lastinx < 0) + DBUG_RETURN(my_errno = HA_ERR_WRONG_INDEX); + keyinfo = share->keydef + info->lastinx; + 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->ref_offs, 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)); + } } |