diff --git a/heap/hp_rfirst.c b/heap/hp_rfirst.c
index 39b0d4385f248eb318b60193a309f6b076ee8e12..1668376ed1c2bb2ef48c9961c878a699084a4626 100644
--- a/heap/hp_rfirst.c
+++ b/heap/hp_rfirst.c
@@ -24,6 +24,7 @@ int heap_rfirst(HP_INFO *info, byte *record, int inx)
   HP_KEYDEF *keyinfo = share->keydef + inx;
   
   DBUG_ENTER("heap_rfirst");
+  info->lastinx= inx;
   if (keyinfo->algorithm == HA_KEY_ALG_BTREE)
   {
     byte *pos;
diff --git a/heap/hp_rlast.c b/heap/hp_rlast.c
index e51a0e8a8f1a63571ea99ff16ca25c957ba7ad77..b1a4973910846081239c42be61144e7c7e0db4e2 100644
--- a/heap/hp_rlast.c
+++ b/heap/hp_rlast.c
@@ -25,6 +25,7 @@ int heap_rlast(HP_INFO *info, byte *record, int inx)
   HP_KEYDEF *keyinfo= share->keydef + inx;
 
   DBUG_ENTER("heap_rlast");
+  info->lastinx= inx;
   if (keyinfo->algorithm == HA_KEY_ALG_BTREE)
   {
     byte *pos;