int ha_partition::handle_ordered_index_scan_key_not_found()
{
  int error;
  uint i, old_elements= m_queue.elements;
  uchar *part_buf= m_ordered_rec_buffer;
  uchar *curr_rec_buf= NULL;
  DBUG_ENTER("ha_partition::handle_ordered_index_scan_key_not_found");
  DBUG_ASSERT(m_key_not_found);
  /*
    Loop over all used partitions to get the correct offset
    into m_ordered_rec_buffer.
  */
  for (i= 0; i < m_tot_parts; i++)
  {
    if (!bitmap_is_set(&m_part_info->used_partitions, i))
      continue;

    if (bitmap_is_set(&m_key_not_found_partitions, i))
    {
      /*
        This partition is used and did return HA_ERR_KEY_NOT_FOUND
        in index_read_map.
      */
      curr_rec_buf= part_buf + PARTITION_BYTES_IN_POS;
      error= m_file[i]->index_next(curr_rec_buf);
      /* HA_ERR_KEY_NOT_FOUND is not allowed from index_next! */
      DBUG_ASSERT(error != HA_ERR_KEY_NOT_FOUND);
      if (!error)
        queue_insert(&m_queue, part_buf);
      else if (error != HA_ERR_END_OF_FILE && error != HA_ERR_KEY_NOT_FOUND)
        DBUG_RETURN(error);
    }
    part_buf+= m_rec_length + PARTITION_BYTES_IN_POS;
  }
  DBUG_ASSERT(curr_rec_buf);
  bitmap_clear_all(&m_key_not_found_partitions);
  m_key_not_found= false;

  if (m_queue.elements > old_elements)
  {
    /* Update m_top_entry, which may have changed. */
    uchar *key_buffer= queue_top(&m_queue);
    m_top_entry= uint2korr(key_buffer);
  }
  DBUG_RETURN(0);
}
int ha_partition::handle_ordered_index_scan_key_not_found()
{
  int error;
  uint i, old_elements= m_queue.elements;
  uchar *part_buf= m_ordered_rec_buffer;
  uchar *curr_rec_buf= NULL;
  DBUG_ENTER("ha_partition::handle_ordered_index_scan_key_not_found");
  DBUG_ASSERT(m_key_not_found);
   
  for (i= 0; i < m_tot_parts; i++)
  {
    if (!bitmap_is_set(&m_part_info->used_partitions, i))
      continue;

    if (bitmap_is_set(&m_key_not_found_partitions, i))
    {
       
      curr_rec_buf= part_buf + PARTITION_BYTES_IN_POS;
      error= m_file[i]->index_next(curr_rec_buf);
       
      DBUG_ASSERT(error != HA_ERR_KEY_NOT_FOUND);
      if (!error)
        queue_insert(&m_queue, part_buf);
      else if (error != HA_ERR_END_OF_FILE && error != HA_ERR_KEY_NOT_FOUND)
        DBUG_RETURN(error);
    }
    part_buf+= m_rec_length + PARTITION_BYTES_IN_POS;
  }
  DBUG_ASSERT(curr_rec_buf);
  bitmap_clear_all(&m_key_not_found_partitions);
  m_key_not_found= false;

  if (m_queue.elements > old_elements)
  {
     
    uchar *key_buffer= queue_top(&m_queue);
    m_top_entry= uint2korr(key_buffer);
  }
  DBUG_RETURN(0);
}